#include <gridclientconnectionpool.hpp>
Public Member Functions | |
| GridClientConnectionPool (const GridClientConfiguration &config) | |
| virtual | ~GridClientConnectionPool () |
| std::shared_ptr < GridClientTcpConnection > | rentTcpConnection (const std::string &host, int port) |
| std::shared_ptr < GridClientHttpConnection > | rentHttpConnection (const std::string &host, int port) |
| void | turnBack (const TConnectionPtr &conn) |
| void | steal (const TConnectionPtr &conn) |
| void | close () |
| size_t | getAvailableConnectionsCount () const |
| size_t | getAllConnectionsCount () const |
| template<class T > | |
| std::shared_ptr< T > | availableConnection (const string &host, int port) |
Protected Member Functions | |
| template<class T > | |
| std::shared_ptr< T > | availableConnection (const std::string &host, int port) |
| void | authenticateHttpConnection (const std::string &host, int port, std::shared_ptr< GridClientHttpConnection > conn) |
| void | trackConnection (const TConnectionPtr &connection) |
| void | onTimerEvent () |
| void | removeConnection (const TConnectionPtr &connection) |
Connection pool that implements rent/turn-back logic.
When a thread needs a connection, it takes it for rent from this pool. If no such connection is available, it is created and returned.
If connection is available, it is returned to the thread and is no more available to other thread. The thread must then turn back this connection, so that other threads can use it.
Thus, several connections to the same endpoint may be created by this pool, if several threads need to communicate with this endpoint simultaneously.
| GridClientConnectionPool::GridClientConnectionPool | ( | const GridClientConfiguration & | config | ) |
Constructor.
| GridClientConnectionPool::~GridClientConnectionPool | ( | ) | [virtual] |
Destructor.
| void GridClientConnectionPool::authenticateHttpConnection | ( | const std::string & | host, | |
| int | port, | |||
| std::shared_ptr< GridClientHttpConnection > | conn | |||
| ) | [protected] |
Assigns an existing session token to HTTP connection or authenticates connection if there's no session token yet.
| host | Host for this connection. port Port for this connection. | |
| conn | Shared pointer to HTTP connection. |
| std::shared_ptr<T> GridClientConnectionPool::availableConnection | ( | const std::string & | host, | |
| int | port | |||
| ) | [protected] |
Finds an connection, available for rent.
| host | A host for the connection. | |
| port | A port for the connection. |
| std::shared_ptr<T> GridClientConnectionPool::availableConnection | ( | const string & | host, | |
| int | port | |||
| ) |
Find an existing TCP or HTTP connection to a host.
| void GridClientConnectionPool::close | ( | ) |
Closes all connections in this pool and marks this pool as closed.
| size_t GridClientConnectionPool::getAllConnectionsCount | ( | ) | const |
Returns the total number of connections, currently managed by this pool.
| size_t GridClientConnectionPool::getAvailableConnectionsCount | ( | ) | const |
Returns the number of connections available for rent.
| void GridClientConnectionPool::onTimerEvent | ( | ) | [protected, virtual] |
Callback function for connection tracker thread.
Implements GridClientRecurringEventThread::EventListener.
| void GridClientConnectionPool::removeConnection | ( | const TConnectionPtr & | connection | ) | [protected] |
Utility method, that removes a connection from this pool.
This method is NOT thread-safe.
| connection | A connection to remove. |
| std::shared_ptr<GridClientHttpConnection> GridClientConnectionPool::rentHttpConnection | ( | const std::string & | host, | |
| int | port | |||
| ) |
Gives an HTTP connection for rent.
If no connection to the given host-port is currently available, a new one is returned.
After no longer needed, the connection should be turned back using turnBack() method.
| host | A host to connect to. | |
| port | A port to connect to. |
| std::shared_ptr< GridClientTcpConnection > GridClientConnectionPool::rentTcpConnection | ( | const std::string & | host, | |
| int | port | |||
| ) |
Gives a TCP connection for rent.
If no connection to the given host-port is currently available, a new one is returned.
After no longer needed, the connection should be turned back using turnBack() method.
| host | A host to connect to. | |
| port | A port to connect to. |
| GridClientClosedException | if this pool is closed; GridServerUnreachableException if the specified endpoint (host-port) is not reachable; GridClientConnectionResetException if the connection cannot be authenticated. |
| void GridClientConnectionPool::steal | ( | const TConnectionPtr & | conn | ) |
Removes this connecton from the list of registered connections.
The pool won't be able to access the connection or give it for rent after this method has run.
| conn | A connection to steal. It should be taken for rent, otherwise the assertion will fail. |
| void GridClientConnectionPool::trackConnection | ( | const TConnectionPtr & | connection | ) | [protected] |
Action, performed by connection tracker for each connection.
| connection | A connection to process. |
| void GridClientConnectionPool::turnBack | ( | const TConnectionPtr & | conn | ) |
Turns a connection back.
After turned back, this connection is available to other threads, until one of the threads takes it for rent.
| conn | A connection to turn back. |
1.7.1