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();
}
}
Aggregations