Пример #1
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();
}
Пример #2
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();
}
Пример #3
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;
}