Example #1
0
 /**
  * @param serviceURI
  * @return
  */
 private static String getChannelURI(final URI serviceURI) {
   return URI.create(
           serviceURI.getScheme()
               + "://"
               + serviceURI.getHost()
               + ":" //$NON-NLS-1$ //$NON-NLS-2$
               + serviceURI.getPort())
       .toString();
 }
Example #2
0
  /**
   * connect to a remote OSGi host.
   *
   * @param host the address of the remote OSGi peer.
   * @param port the port of the remote OSGi peer.
   * @param protocol the protocol to be used or <code>null</code> for default.
   * @return the array of service urls of services offered by the remote peer.
   * @throws RemoteOSGiException in case of errors.
   * @since 0.6
   */
  public RemoteServiceReference[] connect(final URI uri) throws RemoteOSGiException, IOException {

    final URI endpoint = URI.create(getChannelURI(uri));
    final ChannelEndpointImpl test = (ChannelEndpointImpl) channels.get(endpoint.toString());
    if (test != null) {
      test.usageCounter++;
      return test.getAllRemoteReferences(null);
    }

    final ChannelEndpointImpl channel;
    final String protocol = endpoint.getScheme();

    final NetworkChannelFactory factory = getNetworkChannelFactory(protocol);
    channel = new ChannelEndpointImpl(factory, endpoint);

    return channel.sendLease(getServices(), getTopics());
  }
Example #3
0
 /**
  * @param uri
  * @return
  */
 private ChannelEndpointMultiplexer getMultiplexer(final String uri) {
   final String channel = getChannelURI(URI.create(uri));
   ChannelEndpointMultiplexer multiplexer = (ChannelEndpointMultiplexer) multiplexers.get(channel);
   if (multiplexer == null) {
     multiplexer = new ChannelEndpointMultiplexer((ChannelEndpointImpl) channels.get(channel));
     multiplexers.put(channel, multiplexer);
   }
   return multiplexer;
 }
Example #4
0
 /** @see ch.ethz.iks.r_osgi.RemoteOSGiService#getRemoteServiceReference(ch.ethz.iks.r_osgi.URI) */
 public RemoteServiceReference getRemoteServiceReference(final URI serviceURI) {
   final String uri = getChannelURI(serviceURI);
   ChannelEndpointImpl channel = (ChannelEndpointImpl) channels.get(getChannelURI(serviceURI));
   if (channel == null) {
     try {
       connect(serviceURI);
       channel = (ChannelEndpointImpl) channels.get(uri);
     } catch (final IOException ioe) {
       throw new RemoteOSGiException("Cannot connect to " + uri); // $NON-NLS-1$
     }
   }
   return channel.getRemoteReference(serviceURI.toString());
 }
Example #5
0
  /** register a service with the remote service discovery layer. */
  void registerWithServiceDiscovery(final RemoteServiceRegistration reg) {
    // register the service with all service
    // discovery
    // handler
    final Dictionary props = reg.getProperties();
    final Object[] handler = serviceDiscoveryHandlerTracker.getServices();

    if (handler != null) {
      for (int i = 0; i < handler.length; i++) {
        ((ServiceDiscoveryHandler) handler[i])
            .registerService(
                reg.getReference(),
                props,
                URI.create(
                    "r-osgi://" //$NON-NLS-1$
                        + RemoteOSGiServiceImpl.MY_ADDRESS
                        + ":" //$NON-NLS-1$
                        + RemoteOSGiServiceImpl.R_OSGI_PORT
                        + "#" //$NON-NLS-1$
                        + reg.getServiceID()));
      }
    }
  }
Example #6
0
 /**
  * @see ch.ethz.iks.r_osgi.RemoteOSGiService#getEndpointManager(ch.ethz.iks.r_osgi.URI)
  * @category Remoting
  */
 public ChannelEndpointManager getEndpointManager(final URI remoteEndpointAddress) {
   return getMultiplexer(remoteEndpointAddress.toString());
 }
Example #7
0
 public void asyncRemoteCall(
     URI service, String methodSignature, Object[] args, AsyncRemoteCallCallback callback) {
   final ChannelEndpointImpl endpoint = getChannel(service);
   endpoint.asyncRemoteCall(service.getFragment(), methodSignature, args, callback);
 }