@Override public void serviceChange ( final ServiceReference<DriverFactory> reference, final DriverFactory factory ) { logger.info ( "Service changed: {} / {} ({}:{})", new Object[] { reference, factory, this.connectionInformation.getInterface (), this.connectionInformation.getDriver () } ); disposeConnection (); this.factory = factory; if ( this.factory != null ) { createAndRegisterConnection (); } }
manager.removeRequest ( request ); if ( manager.isIdle () ) manager.dispose (); return; manager.removeRequest ( request ); if ( manager.isIdle () ) manager.dispose ();
/** * Create a new connection and register it with OSGi */ private void createAndRegisterConnection () { logger.debug ( "Creating new connection" ); this.connection = createConnection (); if ( this.connection != null ) { if ( this.initialOpen ) { logger.debug ( "Initially open" ); this.connection.connect (); } final Hashtable<String, String> properties = new Hashtable<String, String> (); if ( this.connectionId != null ) { properties.put ( Constants.SERVICE_PID, this.connectionId ); } properties.put ( DriverFactory.INTERFACE_NAME, this.connectionInformation.getInterface () ); properties.put ( DriverFactory.DRIVER_NAME, this.connectionInformation.getDriver () ); properties.put ( ConnectionService.CONNECTION_URI, this.connectionInformation.toString () ); logger.info ( "Registered new connection service: {}", properties ); final Set<String> interfaces = new HashSet<String> ( getInterfaces () ); interfaces.add ( ConnectionService.class.getName () ); this.serviceReg = this.context.registerService ( interfaces.toArray ( new String[interfaces.size()] ), this.connection, properties ); } }
/** * Dispose the tracker and the connection */ public void dispose () { if ( this.tracker != null ) { this.tracker.close (); this.tracker = null; } disposeConnection (); }
private synchronized void addRequest ( final ConnectionRequest request ) { logger.info ( "Found new request: {}", request ); final String requestId = request.getRequestId (); if ( requestId == null ) { // public request AbstractConnectionManager manager = this.connections.get ( request.getConnectionInformation () ); if ( manager == null ) { logger.info ( "Create new connection: {}", request ); manager = createConnectionManager ( request ); this.connections.put ( request.getConnectionInformation (), manager ); } manager.addRequest ( request ); } else { // we have a private request AbstractConnectionManager manager = this.privateConnections.get ( requestId ); if ( manager == null ) { logger.info ( "Create new private connection: {} -> {}", new Object[] { request, requestId } ); manager = createConnectionManager ( request ); this.privateConnections.put ( requestId, manager ); } manager.addRequest ( request ); } }