use of ch.ethz.iks.r_osgi.channels.ChannelEndpoint in project ecf by eclipse.
the class ChannelEndpointMultiplexer method addRedundantEndpoint.
/**
* @see ch.ethz.iks.r_osgi.channels.ChannelEndpointManager#addRedundantEndpoint(ch.ethz.iks.r_osgi.URI,
* ch.ethz.iks.r_osgi.URI)
*/
public void addRedundantEndpoint(final URI service, final URI redundantService) {
final ChannelEndpoint redundantEndpoint = RemoteOSGiServiceImpl.getChannel(redundantService);
primary.hasRedundantLinks = true;
Mapping mapping = (Mapping) mappings.get(service);
if (mapping == null) {
mapping = new Mapping(service.toString());
mappings.put(service.toString(), mapping);
}
mapping.addRedundant(redundantService.toString(), redundantEndpoint);
}
use of ch.ethz.iks.r_osgi.channels.ChannelEndpoint in project ecf by eclipse.
the class RemoteOSGiServiceImpl method cleanup.
/**
* the method is called when the R-OSGi bundle is about to be stopped.
* removes all registered proxy bundles.
*/
void cleanup() {
final ChannelEndpoint[] c = (ChannelEndpoint[]) channels.values().toArray(new ChannelEndpoint[channels.size()]);
channels.clear();
for (int i = 0; i < c.length; i++) {
c[i].dispose();
}
final Object[] factories = networkChannelFactoryTracker.getServices();
if (factories != null) {
for (int i = 0; i < factories.length; i++) {
try {
((NetworkChannelFactory) factories[i]).deactivate(this);
} catch (final IOException ioe) {
if (log != null) {
log.log(LogService.LOG_ERROR, ioe.getMessage(), ioe);
}
}
}
}
eventAdminTracker.close();
remoteServiceTracker.close();
serviceDiscoveryHandlerTracker.close();
remoteServiceListenerTracker.close();
networkChannelFactoryTracker.close();
}
use of ch.ethz.iks.r_osgi.channels.ChannelEndpoint 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();
}
}
use of ch.ethz.iks.r_osgi.channels.ChannelEndpoint in project ecf by eclipse.
the class ChannelEndpointImpl method invokeMethod.
/**
* invoke a method on the remote host. This function is used by all proxy
* bundles.
*
* @param service
* the service uri.
* @param methodSignature
* the method signature.
* @param args
* the method parameter.
* @throws Throwable
* can throw any exception that the original method can throw,
* plus RemoteOSGiException.
* @return the result of the remote method invocation.
* @see ch.ethz.iks.r_osgi.channels.ChannelEndpoint#invokeMethod(java.lang.String,
* java.lang.String, java.lang.Object[])
* @category ChannelEndpoint
*/
public Object invokeMethod(final String service, final String methodSignature, final Object[] args) throws Throwable {
if (networkChannel == null) {
// $NON-NLS-1$
throw new RemoteOSGiException("Channel is closed");
}
// check arguments for streams and replace with placeholder
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof InputStream) {
args[i] = getInputStreamPlaceholder((InputStream) args[i]);
} else if (args[i] instanceof OutputStream) {
args[i] = getOutputStreamPlaceholder((OutputStream) args[i]);
}
}
final RemoteCallMessage invokeMsg = new RemoteCallMessage();
invokeMsg.setServiceID(URI.create(service).getFragment());
invokeMsg.setMethodSignature(methodSignature);
invokeMsg.setArgs(args);
try {
// send the message and get a MethodResultMessage in return
final RemoteCallResultMessage resultMsg = (RemoteCallResultMessage) sendAndWait(invokeMsg);
if (resultMsg.causedException()) {
throw resultMsg.getException();
}
final Object result = resultMsg.getResult();
if (result instanceof InputStreamHandle) {
return getInputStreamProxy((InputStreamHandle) result);
} else if (result instanceof OutputStreamHandle) {
return getOutputStreamProxy((OutputStreamHandle) result);
} else {
if (result != null) {
String returnType = Type.getReturnType(methodSignature).getClassName();
RemoteServiceReferenceImpl refImpl = getRemoteReference(URI.create(service).toString());
if (refImpl != null && refImpl.isOSGiAsync() && AsyncReturnUtil.isAsyncType(returnType))
return AsyncReturnUtil.convertReturnToAsync(result, returnType);
}
return result;
}
} catch (final RemoteOSGiException e) {
throw new RemoteOSGiException(// $NON-NLS-1$
"Method invocation of " + service + " " + methodSignature + " failed.", // $NON-NLS-1$ //$NON-NLS-2$
e);
}
}
use of ch.ethz.iks.r_osgi.channels.ChannelEndpoint in project ecf by eclipse.
the class ChannelEndpointMultiplexer method removeRedundantEndpoint.
/**
* @see ch.ethz.iks.r_osgi.channels.ChannelEndpointManager#removeRedundantEndpoint(ch.ethz.iks.r_osgi.URI,
* ch.ethz.iks.r_osgi.URI)
*/
public void removeRedundantEndpoint(final URI service, final URI redundantService) {
final ChannelEndpoint redundantEndpoint = RemoteOSGiServiceImpl.getChannel(redundantService);
final Mapping mapping = (Mapping) mappings.get(service.toString());
mapping.removeRedundant(redundantEndpoint);
if (mapping.isEmpty()) {
mappings.remove(service);
primary.hasRedundantLinks = false;
}
}
Aggregations