RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/logger/remote_output.h
00001 /* remote_output.h                                                 -*- C++ -*-
00002    Jeremy Barnes, 23 May 2011
00003    Copyright (c) 2011 Datacratic.  All rights reserved.
00004 
00005    Output source that goes to a remote sink.  TCP/IP.
00006 
00007    
00008 */
00009 
00010 #pragma once
00011 
00012 #include "logger.h"
00013 #include "soa/service/active_endpoint.h"
00014 
00015 
00016 namespace Datacratic {
00017 
00018 
00019 struct RemoteOutputConnection;
00020 
00021 
00022 /*****************************************************************************/
00023 /* REMOTE OUTPUT                                                             */
00024 /*****************************************************************************/
00025 
00030 struct RemoteOutput
00031     : public LogOutput,
00032       protected ActiveEndpointT<SocketTransport> {
00033 
00034     RemoteOutput();
00035 
00036     virtual ~RemoteOutput();
00037 
00039     void connect(int port, const std::string & hostname, double timeout = 10.0);
00040     
00042     void shutdown();
00043 
00046     void barrier();
00047 
00050     void flush();
00051 
00053     void sync();
00054 
00056     void close();
00057 
00058     virtual void logMessage(const std::string & channel,
00059                             const std::string & message);
00060 
00064     virtual void
00065     notifyCloseTransport(const std::shared_ptr<TransportBase> & transport);
00066 
00070     boost::function<void (const std::string)> onConnectionError;
00071 
00072 private:
00074     void reconnect(boost::function<void ()> onFinished,
00075                    boost::function<void (const std::string &)> onError,
00076                    double timeout);
00077 
00082     void setupConnection(std::shared_ptr<TransportBase> transport,
00083                          boost::function<void ()> onFinished,
00084                          boost::function<void (const std::string &)> onError);
00085 
00086     int port;
00087     std::string hostname;
00088     double timeout;
00089     std::shared_ptr<RemoteOutputConnection> connection;
00090     bool shuttingDown;
00091 
00093     std::vector<std::pair<std::string, std::string> > backlog;
00094 };
00095 
00096 } // namespace Datacratic
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator