Search in sources :

Example 1 with ChannelEndpoint

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);
}
Also used : ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint)

Example 2 with ChannelEndpoint

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();
}
Also used : NetworkChannelFactory(ch.ethz.iks.r_osgi.channels.NetworkChannelFactory) ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint) IOException(java.io.IOException) ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint)

Example 3 with ChannelEndpoint

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

Example 4 with ChannelEndpoint

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);
    }
}
Also used : RemoteCallResultMessage(ch.ethz.iks.r_osgi.messages.RemoteCallResultMessage) OutputStreamHandle(ch.ethz.iks.r_osgi.streams.OutputStreamHandle) RemoteCallMessage(ch.ethz.iks.r_osgi.messages.RemoteCallMessage) RemoteOSGiException(ch.ethz.iks.r_osgi.RemoteOSGiException) InputStreamHandle(ch.ethz.iks.r_osgi.streams.InputStreamHandle) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint)

Example 5 with ChannelEndpoint

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;
    }
}
Also used : ChannelEndpoint(ch.ethz.iks.r_osgi.channels.ChannelEndpoint)

Aggregations

ChannelEndpoint (ch.ethz.iks.r_osgi.channels.ChannelEndpoint)5 IOException (java.io.IOException)2 RemoteOSGiException (ch.ethz.iks.r_osgi.RemoteOSGiException)1 RemoteServiceEvent (ch.ethz.iks.r_osgi.RemoteServiceEvent)1 RemoteServiceReference (ch.ethz.iks.r_osgi.RemoteServiceReference)1 NetworkChannel (ch.ethz.iks.r_osgi.channels.NetworkChannel)1 NetworkChannelFactory (ch.ethz.iks.r_osgi.channels.NetworkChannelFactory)1 RemoteCallMessage (ch.ethz.iks.r_osgi.messages.RemoteCallMessage)1 RemoteCallResultMessage (ch.ethz.iks.r_osgi.messages.RemoteCallResultMessage)1 InputStreamHandle (ch.ethz.iks.r_osgi.streams.InputStreamHandle)1 OutputStreamHandle (ch.ethz.iks.r_osgi.streams.OutputStreamHandle)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Bundle (org.osgi.framework.Bundle)1