Package biopb.tensor
Class TensorConnectionPool
java.lang.Object
biopb.tensor.TensorConnectionPool
Thread-local connection pool for TensorFlightClient connections.
This pool is used by SerializableTensorImg to reconstruct connections
after deserialization. Each thread maintains its own FlightClient for
lock-free read access, with automatic cleanup on thread death or JVM shutdown.
Design mirrors Python's thread-local connection pool with:
- Per-thread FlightClient storage (lock-free reads)
- Connection registry for cleanup
- Thread death eviction
- Shutdown hook for resource cleanup
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA pooled connection containing FlightClient and authentication option.static final classShared cache for cross-thread cache hits. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clear all pooled connections (for testing).static voidcloseConnection(org.apache.arrow.flight.Location location, String token) Close a specific connection for the given location and token.getConnection(org.apache.arrow.flight.Location location, String token, org.apache.arrow.memory.BufferAllocator allocator) Get or create a pooled connection for the given location and token.static intGet the total connection count across all threads (for testing/monitoring).getSharedCache(biopb.tensor.TensorConnectionPool.ConnectionKey key, long maxBytes) Get or create a shared cache for the given connection key.static intGet the thread count with active connections (for testing/monitoring).
-
Method Details
-
getConnection
public static TensorConnectionPool.PooledConnection getConnection(org.apache.arrow.flight.Location location, String token, org.apache.arrow.memory.BufferAllocator allocator) Get or create a pooled connection for the given location and token. Uses thread-local storage for lock-free reads. New connections are registered for cleanup when the thread dies or JVM shuts down.- Parameters:
location- Flight server locationtoken- Bearer token for authentication (null disables auth)allocator- Buffer allocator for the connection- Returns:
- PooledConnection containing FlightClient and auth option
-
closeConnection
Close a specific connection for the given location and token. Removes the connection from the current thread's pool and the registry.- Parameters:
location- Flight server locationtoken- Bearer token for authentication
-
getConnectionCount
public static int getConnectionCount()Get the total connection count across all threads (for testing/monitoring). -
getThreadCount
public static int getThreadCount()Get the thread count with active connections (for testing/monitoring). -
clear
public static void clear()Clear all pooled connections (for testing).
-