Subversion Repositories SmartDukaan

Rev

Rev 301 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
301 ashish 1
//  Copyright (c) 2007-2009 Facebook
2
//
3
//  Licensed under the Apache License, Version 2.0 (the "License");
4
//  you may not use this file except in compliance with the License.
5
//  You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//  Unless required by applicable law or agreed to in writing, software
10
//  distributed under the License is distributed on an "AS IS" BASIS,
11
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//  See the License for the specific language governing permissions and
13
//  limitations under the License.
14
//
15
// See accompanying file LICENSE or visit the Scribe site at:
16
// http://developers.facebook.com/scribe/
17
//
18
// @author Bobby Johnson
19
// @author James Wang
20
// @author Jason Sobel
21
// @author Avinash Lakshman
22
// @author Anthony Giardullo
23
 
24
#ifndef SCRIBE_SERVER_H
25
#define SCRIBE_SERVER_H
26
 
27
#include "store.h"
28
#include "store_queue.h"
29
 
30
typedef std::vector<boost::shared_ptr<StoreQueue> > store_list_t;
31
typedef std::map<std::string, boost::shared_ptr<store_list_t> > category_map_t;
32
typedef std::map<std::string, boost::shared_ptr<StoreQueue> > category_prefix_map_t;
33
 
34
class scribeHandler : virtual public scribe::thrift::scribeIf,
35
                              public facebook::fb303::FacebookBase {
36
 
37
 public:
38
  scribeHandler(unsigned long int port, const std::string& conf_file);
39
  ~scribeHandler();
40
 
41
  void shutdown();
42
  void initialize();
43
  void reinitialize();
44
 
45
  scribe::thrift::ResultCode Log(const std::vector<scribe::thrift::LogEntry>& messages);
46
 
47
  void getVersion(std::string& _return) {_return = "2.2";}
48
  facebook::fb303::fb_status getStatus();
49
  void getStatusDetails(std::string& _return);
50
  void setStatus(facebook::fb303::fb_status new_status);
51
  void setStatusDetails(const std::string& new_status_details);
52
 
53
  unsigned long int port; // it's long because that's all I implemented in the conf class
54
 
55
  // number of threads processing new Thrift connections
56
  size_t numThriftServerThreads;
57
 
58
 private:
59
  unsigned long checkPeriod; // periodic check interval for all contained stores
60
 
61
  // This map has an entry for each configured category.
62
  // Each of these entries is a map of type->StoreQueue.
63
  // The StoreQueue contains a store, which could contain additional stores.
64
  category_map_t* pcategories;
65
  category_prefix_map_t* pcategory_prefixes;
66
 
67
  // the default store
68
  boost::shared_ptr<StoreQueue> defaultStore;
69
 
70
  // temp versions of the above 3 pointers to use during initialization
71
  category_map_t* pnew_categories;
72
  category_prefix_map_t* pnew_category_prefixes;
73
  boost::shared_ptr<StoreQueue> tmpDefault;
74
 
75
  std::string configFilename;
76
  facebook::fb303::fb_status status;
77
  std::string statusDetails;
78
  apache::thrift::concurrency::Mutex statusLock;
79
  time_t lastMsgTime;
80
  unsigned long numMsgLastSecond;
81
  unsigned long maxMsgPerSecond;
82
  unsigned long maxQueueSize;
83
  bool newThreadPerCategory;
84
 
85
  /* mutex to syncronize access to scribeHandler.
86
   * A single mutex is fine since it only needs to be locked in write mode
87
   * during start/stop/reinitialize or when we need to create a new category.
88
   */
89
  apache::thrift::concurrency::ReadWriteMutex scribeHandlerLock;
90
 
91
  // disallow empty construction, copy, and assignment
92
  scribeHandler();
93
  scribeHandler(const scribeHandler& rhs);
94
  const scribeHandler& operator=(const scribeHandler& rhs);
95
 
96
 protected:
97
  bool throttleDeny(int num_messages); // returns true if overloaded
98
  void deleteCategoryMap(category_map_t *pcats);
99
  const char* statusAsString(facebook::fb303::fb_status new_status);
100
  bool createCategoryFromModel(const std::string &category,
101
                               const boost::shared_ptr<StoreQueue> &model);
102
  boost::shared_ptr<StoreQueue>
103
    configureStoreCategory(pStoreConf store_conf,
104
                           const std::string &category,
105
                           const boost::shared_ptr<StoreQueue> &model,
106
                           bool category_list=false);
107
  bool configureStore(pStoreConf store_conf, int* num_stores);
108
  void stopStores();
109
  bool throttleRequest(const std::vector<scribe::thrift::LogEntry>&  messages);
110
  boost::shared_ptr<store_list_t>
111
    createNewCategory(const std::string& category);
112
  void addMessage(const scribe::thrift::LogEntry& entry,
113
                  const boost::shared_ptr<store_list_t>& store_list);
114
};
115
 
116
extern boost::shared_ptr<scribeHandler> g_Handler;
117
 
118
#endif // SCRIBE_SERVER_H