/** * Revoke the service registration and dispose the service * <p> * Does nothing if there is no current registration */ protected void disposeConnection () { if ( this.serviceReg != null ) { final AbstractConnectionService connection = this.connection; connection.disconnect (); this.connection = null; this.serviceReg.unregister (); this.serviceReg = null; // now dispose the connection connection.dispose (); } } }
@Override public synchronized void connect () { this.connectionRequested = true; checkConnect (); }
protected synchronized void checkConnect () { if ( this.connectionRequested && ( !this.lazyActivation || shouldConnect () ) ) { performConnect (); } else { performDisconnect (); } }
/** * Create a new connection and register it with OSGi */ protected void createConnection () { this.connection = createConnectionService ( this.factory, this.connectionInformation ); if ( this.connection != null ) { this.connection.connect (); final Hashtable<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_PID, this.connectionId ); properties.put ( DriverFactory.INTERFACE_NAME, this.connectionInformation.getInterface () ); properties.put ( DriverFactory.DRIVER_NAME, this.connectionInformation.getDriver () ); logger.info ( "Registered new connection service: {}", properties ); this.serviceReg = this.context.registerService ( new String[] { this.clazz.getName (), org.eclipse.scada.core.connection.provider.ConnectionService.class.getName () }, this.connection, properties ); } }
/** * Revoke the service registration and dispose the service * <p> * Does nothing if there is no current registration */ protected void disposeConnection () { if ( this.serviceReg != null ) { logger.info ( "We got an old service ... dispose" ); final AbstractConnectionService connection = this.connection; this.connection = null; this.serviceReg.unregister (); this.serviceReg = null; // now dispose the connection connection.dispose (); } }
@Override public void dispose () { logger.info ( "Disposing: {}", this.connection ); disconnect (); if ( this.controller != null ) { this.controller.dispose (); } if ( this.connection != null ) { this.connection.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 ); } }
@Override public synchronized void disconnect () { this.connectionRequested = false; checkConnect (); }