Package org.gridgain.internal.mcp.utils
Class ConnectionUtils
java.lang.Object
org.gridgain.internal.mcp.utils.ConnectionUtils
Utility class for managing a shared IgniteClient instance across the MCP server lifecycle.
This class implements a singleton pattern for IgniteClient.
Ensures efficient resource utilization and connection pooling.
The shared client is initialized once during server startup and reused across all tool invocations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns the current user ID from the IgniteClient configuration.static org.apache.ignite.client.IgniteClientRetrieves the shared IgniteClient instance for database operations.static voidinitialize(ConnectionConfig config) Initializes the shared IgniteClient with the provided configuration.static voidshutdown()Closes the shared IgniteClient and releases all associated resources.
-
Constructor Details
-
ConnectionUtils
public ConnectionUtils()
-
-
Method Details
-
initialize
Initializes the shared IgniteClient with the provided configuration.This method should be called exactly once during server startup, before any tools attempt to access the client. The client is configured with:
- Server addresses (host:port)
- Connection timeout
- Basic authentication (if credentials provided)
- SSL/TLS encryption (if enabled)
Subsequent calls to this method will be ignored with a warning logged.
- Parameters:
config- connection configuration containing host, port, credentials, and SSL settings- Throws:
IllegalArgumentException- if SSL is enabled but trust store path is not configuredIllegalStateException- if client initialization fails due to invalid configuration or network issues
-
shutdown
public static void shutdown()Closes the shared IgniteClient and releases all associated resources.This method should be called during server shutdown (typically in a shutdown hook) to ensure graceful cleanup of database connections and prevent resource leaks.
After calling this method, the client instance is set to null, and any subsequent calls to
getSharedClient()will throwIllegalStateExceptionuntilinitialize(ConnectionConfig)is called again.If the client is not initialized (null), this method has no effect.
This method is idempotent and safe to call multiple times.
-
getCurrentUserId
Returns the current user ID from the IgniteClient configuration.- Returns:
- user ID from client authenticator, or "anonymous" if not authenticated
-