David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame] | 1 | #include "zmq.hpp" |
| 2 | #include "TZmqServer.h" |
| 3 | #include "Storage.h" |
| 4 | |
| 5 | using boost::shared_ptr; |
| 6 | using apache::thrift::TProcessor; |
| 7 | using apache::thrift::server::TZmqServer; |
| 8 | using apache::thrift::server::TZmqMultiServer; |
| 9 | |
| 10 | class StorageHandler : virtual public StorageIf { |
| 11 | public: |
| 12 | StorageHandler() |
| 13 | : value_(0) |
| 14 | {} |
| 15 | |
| 16 | void incr(const int32_t amount) { |
| 17 | value_ += amount; |
| 18 | } |
| 19 | |
| 20 | int32_t get() { |
| 21 | return value_; |
| 22 | } |
| 23 | |
| 24 | private: |
| 25 | int32_t value_; |
| 26 | |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | int main(int argc, char *argv[]) { |
| 31 | shared_ptr<StorageHandler> handler(new StorageHandler()); |
| 32 | shared_ptr<TProcessor> processor(new StorageProcessor(handler)); |
| 33 | |
| 34 | zmq::context_t ctx(1); |
| 35 | TZmqServer reqrep_server(processor, ctx, "tcp://0.0.0.0:9090", ZMQ_REP); |
| 36 | TZmqServer oneway_server(processor, ctx, "tcp://0.0.0.0:9091", ZMQ_UPSTREAM); |
| 37 | TZmqMultiServer multiserver; |
| 38 | multiserver.servers().push_back(&reqrep_server); |
| 39 | multiserver.servers().push_back(&oneway_server); |
| 40 | multiserver.serveForever(); |
| 41 | |
| 42 | return 0; |
| 43 | } |