コード例 #1
0
GridClientConfiguration affinityClientConfiguration() {
    GridClientConfiguration cfg;
    vector<GridClientDataConfiguration> dataCfgVec;

    {
        GridClientDataConfiguration dataCfg;
        GridClientPartitionAffinity* aff = new GridClientPartitionAffinity();

        aff->setDefaultReplicas(512);
        aff->setHashIdResolver(hashIdResolver);

        dataCfg.name("cacheOne");
        dataCfg.affinity(shared_ptr<GridClientDataAffinity>(aff));

        dataCfgVec.push_back(dataCfg);
    }

    {
        GridClientDataConfiguration dataCfg;
        GridClientPartitionAffinity* aff = new GridClientPartitionAffinity();

        aff->setDefaultReplicas(512);
        aff->setHashIdResolver(hashIdResolver);

        dataCfg.name("cacheTwo");
        dataCfg.affinity(shared_ptr<GridClientDataAffinity>(aff));

        dataCfgVec.push_back(dataCfg);
    }

    cfg.dataConfiguration(dataCfgVec);

    return cfg;
}
コード例 #2
0
ファイル: gridclientfactory.cpp プロジェクト: 10fish/gridgain
    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;
    }
コード例 #3
0
/**
 * Main method.
 *
 * @return Result code.
 */
int main () {
    try {
        GridClientConfiguration cfg = clientConfiguration();

        cout << "The client will try to connect to the following addresses:" << endl;

        vector<GridSocketAddress> srvrs = cfg.servers();

        for (vector<GridSocketAddress>::iterator i = srvrs.begin(); i < srvrs.end(); i++)
            cout << i->host() << ":" << i->port() << endl;

        TGridClientPtr client = GridClientFactory::start(cfg);

        clientDataExample(client);
    }
    catch(exception& e) {
        cerr << "Caught unhandled exception: " << e.what() << endl;
    }

    GridClientFactory::stopAll();
}
コード例 #4
0
GridClientConfiguration clientConfiguration() {
    GridClientConfiguration clientConfig;

    vector<GridSocketAddress> servers;

//    To enable communication with GridGain instance by HTTP, not by TCP, uncomment the following lines
//    and comment push_back with TCP.
//    ================================
//    GridClientProtocolConfiguration protoCfg;
//
//    protoCfg.protocol(HTTP);
//
//    clientConfig.setProtocolConfiguration(protoCfg);
//
//    servers.push_back(GridSocketAddress(SERVER_ADDRESS, GridClientProtocolConfiguration::DFLT_HTTP_PORT));

//    To enable communication over SSL uncomment the following lines.
//    ================================
//    GridGain node should be started with config examples/config/spring-cache-ssl.xml .
//
//    GridClientProtocolConfiguration protoCfg;
//
//    protoCfg.sslEnabled(true);
//
//    protoCfg.certificateFilePath("examples/keystore/client.pem");
//
//    protoCfg.certificateFilePassword("123456");
//
//    clientConfig.setProtocolConfiguration(protoCfg);

    cout << "connecting to " << SERVER_ADDRESS << ", port " << TCP_PORT << endl;

    servers.push_back(GridSocketAddress(SERVER_ADDRESS, TCP_PORT));

    clientConfig.servers(servers);

    return clientConfig;
}
コード例 #5
0
ファイル: gridclientimpl.cpp プロジェクト: 10fish/gridgain
/**
 * 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();
}
コード例 #6
0
GridClientConnectionPool::GridClientConnectionPool(const GridClientConfiguration& config)
    : config(config), protoCfg(config.protocolConfiguration()), connectionTracker(TRACKER_INTERVAL_MS, *this) {
    closed = false;
}