コード例 #1
0
 void destroy_ConnectionPool(void) {
     // pop until queue is empty
     photodb_client client;
     while (!client_queue.size() != 0) {
         client_queue.pop(client, 1, 0);
     }
     cout << "release OK" << endl;
 }
コード例 #2
0
    void init_thrift_connection_pool(unsigned int max_client, char* meta_server_address, int meta_server_port, char* content_server_address, int content_server_port) {
        if (client_queue.size() > 0) return;
        for (unsigned int i = 0; i < max_client; i++) {
            // init a client
            photodb_client *client = new photodb_client;

            boost::shared_ptr<TTransport> content_socket(new TSocket(content_server_address, content_server_port));
            boost::shared_ptr<TTransport> content_transport(new TFramedTransport(content_socket));
            boost::shared_ptr<TProtocol> content_protocol(new TBinaryProtocol(content_transport));
            try {
                content_transport->open();
                PhotoDBClient *client_content = new PhotoDBClient(content_protocol);
                boost::shared_ptr<TTransport> metadata_socket(new TSocket(meta_server_address, meta_server_port));
                boost::shared_ptr<TTransport> metadata_transport(new TFramedTransport(metadata_socket));
                boost::shared_ptr<TProtocol> metadata_protocol(new TBinaryProtocol(metadata_transport));
                try {
                    //cout << i << endl;
                    metadata_transport->open();
                    PhotoDBClient *client_metadata = new PhotoDBClient(metadata_protocol);

                    client->content = client_content;
                    client->metadata = client_metadata;

                    // Put to queue
                    client_queue.put(*client, 1, 0);

                } catch (TException& tx) {
                    cout << "Can not Open meta PORT number: " << meta_server_port << endl;
                    cout << "Can not Open meta host : " << meta_server_address << endl;
                    cout << "ERROR OPEN: " << tx.what() << endl;
                }
            } catch (TException& tx) {
                cout << "Can not Open content PORT number: " << content_server_port << endl;
                cout << "Can not Open meta host : " << content_server_address << endl;
                cout << "ERROR OPEN: " << tx.what() << endl;
            }
        }
    }