Search in sources :

Example 1 with NetworkChannel

use of ch.ethz.iks.r_osgi.channels.NetworkChannel in project ecf by eclipse.

the class ChannelEndpointImpl method dispose.

/**
 * dispose the channel.
 *
 * @category ChannelEndpoint
 */
public void dispose() {
    if (networkChannel == null) {
        return;
    }
    if (RemoteOSGiServiceImpl.DEBUG) {
        RemoteOSGiServiceImpl.log.log(LogService.LOG_DEBUG, // $NON-NLS-1$
        "DISPOSING ENDPOINT " + getRemoteAddress());
    }
    RemoteOSGiServiceImpl.unregisterChannelEndpoint(getRemoteAddress().toString());
    if (handlerReg != null) {
        handlerReg.unregister();
    }
    final NetworkChannel oldchannel = networkChannel;
    networkChannel = null;
    try {
        oldchannel.close();
    } catch (final IOException ioe) {
        ioe.printStackTrace();
    }
    if (!hasRedundantLinks) {
        // inform all listeners about all services
        final RemoteServiceReference[] refs = (RemoteServiceReference[]) remoteServices.values().toArray(new RemoteServiceReference[remoteServices.size()]);
        for (int i = 0; i < refs.length; i++) {
            RemoteOSGiServiceImpl.notifyRemoteServiceListeners(new RemoteServiceEvent(RemoteServiceEvent.UNREGISTERING, refs[i]));
        }
        // uninstall the proxy bundle
        final Bundle[] proxies = (Bundle[]) proxyBundles.values().toArray(new Bundle[proxyBundles.size()]);
        for (int i = 0; i < proxies.length; i++) {
            try {
                if (proxies[i].getState() != Bundle.UNINSTALLED) {
                    proxies[i].uninstall();
                }
            } catch (final Throwable t) {
            }
        }
    }
    remoteServices = null;
    remoteTopics = null;
    timeOffset = null;
    callbacks.clear();
    localServices.clear();
    proxiedServices.clear();
    closeStreams();
    streams.clear();
    handlerReg = null;
    synchronized (callbacks) {
        callbacks.notifyAll();
    }
}
Also used : NetworkChannel(ch.ethz.iks.r_osgi.channels.NetworkChannel) RemoteServiceReference(ch.ethz.iks.r_osgi.RemoteServiceReference) Bundle(org.osgi.framework.Bundle) RemoteServiceEvent(ch.ethz.iks.r_osgi.RemoteServiceEvent) IOException(java.io.IOException) ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint)

Aggregations

RemoteServiceEvent (ch.ethz.iks.r_osgi.RemoteServiceEvent)1 RemoteServiceReference (ch.ethz.iks.r_osgi.RemoteServiceReference)1 ChannelEndpoint (ch.ethz.iks.r_osgi.channels.ChannelEndpoint)1 NetworkChannel (ch.ethz.iks.r_osgi.channels.NetworkChannel)1 IOException (java.io.IOException)1 Bundle (org.osgi.framework.Bundle)1