Пример #1
0
    TGridClientPtr start(const GridClientConfiguration& cfg) {
        boost::shared_ptr<GridClientConnectionPool> connPool(new GridClientConnectionPool(cfg));

        std::shared_ptr<GridClientCommandExecutorPrivate> exec;

        switch (cfg.protocolConfiguration().protocol()) {
            case TCP:
                exec.reset(new GridClientTcpCommandExecutor(connPool));

                break;

            case HTTP:
                exec.reset(new GridClientHttpCommandExecutor(connPool));

                break;

            default: {
                assert(false);

                exec.reset(new GridClientTcpCommandExecutor(connPool));
            }
            break;
        }

        std::shared_ptr<GridClientImpl> client(new GridClientImpl(cfg, exec));

        boost::lock_guard<boost::mutex> lock(mux);

        clients[client->id()] = client;

        GG_LOG_INFO("Client started [id=%s, protocol=%s]",
            client->id().uuid().c_str(), cfg.protocolConfiguration().protocol() == TCP ? "TCP" : "HTTP");

        return client;
    }
Пример #2
0
/**
 * Public constructor.
 */
GridClientImpl::GridClientImpl(const GridClientConfiguration& cfg,
        std::shared_ptr<GridClientCommandExecutorPrivate>& exec)
        : sharedData(new GridClientSharedData(cfg.protocolConfiguration().uuid(), cfg, exec))
           ,topRefresher(new GridClientTopologyRefresher(cfg.topologyRefreshFrequency(), *this))
           ,threadPool(new GridThreadPool(cfg.threadPoolSize())) {
    // Check configuration sanity
    if (!cfg.servers().empty() && !cfg.routers().empty())
        throw GridClientException("Both servers and routers are specified in configuration, which is not allowed.");

    TGridClientTopologyListenerList topLsnrs = cfg.topologyListeners();

    for (auto i = topLsnrs.begin(); i != topLsnrs.end(); i++)
        addTopologyListener(*i);

    // Refresh the topology based on new data.
    refreshTopology();
}
Пример #3
0
GridClientConnectionPool::GridClientConnectionPool(const GridClientConfiguration& config)
    : config(config), protoCfg(config.protocolConfiguration()), connectionTracker(TRACKER_INTERVAL_MS, *this) {
    closed = false;
}