Esempio n. 1
0
  /**
   * @param serviceID
   * @return
   */
  static RemoteServiceRegistration getServiceRegistration(final String serviceID) {

    final String filter =
        "".equals(serviceID)
            ? null
            : '(' //$NON-NLS-1$
                + Constants.SERVICE_ID
                + "="
                + serviceID
                + ")"; //$NON-NLS-1$ //$NON-NLS-2$

    try {
      final ServiceReference[] refs =
          RemoteOSGiActivator.getActivator().getContext().getServiceReferences(null, filter);
      if (refs == null) {
        if (log != null) {
          log.log(LogService.LOG_WARNING, "COULD NOT FIND " + filter); // $NON-NLS-1$
        }
        return null;
      }
      return (RemoteServiceRegistration) serviceRegistrations.get(refs[0]);
    } catch (final InvalidSyntaxException e) {
      e.printStackTrace();
      return null;
    }
  }
Esempio n. 2
0
  private NetworkChannelFactory getNetworkChannelFactory(final String protocol)
      throws RemoteOSGiException {
    try {
      final Filter filter =
          RemoteOSGiActivator.getActivator()
              .getContext()
              .createFilter(
                  "(" //$NON-NLS-1$
                      + NetworkChannelFactory.PROTOCOL_PROPERTY
                      + "="
                      + protocol //$NON-NLS-1$
                      + ")"); //$NON-NLS-1$
      final ServiceReference[] refs = networkChannelFactoryTracker.getServiceReferences();

      if (refs != null) {
        for (int i = 0; i < refs.length; i++) {
          if (filter.match(refs[i])) {
            return (NetworkChannelFactory) networkChannelFactoryTracker.getService(refs[i]);
          }
        }
      }
      throw new RemoteOSGiException(
          "No NetworkChannelFactory for " //$NON-NLS-1$
              + protocol
              + " found."); //$NON-NLS-1$

    } catch (final InvalidSyntaxException e) {
      // does not happen
      e.printStackTrace();
      return null;
    }
  }
Esempio n. 3
0
  static {
    final String verString = System.getProperty("java.class.version"); // $NON-NLS-1$
    if (verString != null && Float.parseFloat(verString) >= 49) {
      IS_JAVA5 = true;
    }
    final String osgiVerString = System.getProperty(Constants.FRAMEWORK_VERSION);
    if (osgiVerString != null && (!osgiVerString.trim().startsWith("1.3"))) { // $NON-NLS-1$
      IS_R4 = true;
    }
    Method m = null;
    Method n = null;
    try {
      m = Bundle.class.getMethod("getEntry", new Class[] {String.class});
      n = Bundle.class.getMethod("getEntryPaths", new Class[] {String.class});
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
    }
    getEntry = m;
    getEntryPaths = n;

    File b = null;
    try {
      b =
          getEntry == null
              ? RemoteOSGiActivator.getActivator()
                  .getContext()
                  .getDataFile("../..")
                  .getCanonicalFile()
              : null;
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
    base = b;
  }
Esempio n. 4
0
  /**
   * creates a new RemoteOSGiServiceImpl instance.
   *
   * @throws IOException in case of IO problems.
   */
  RemoteOSGiServiceImpl() throws IOException {
    // find out own IP address
    try {
      MY_ADDRESS =
          InetAddress.getAllByName(InetAddress.getLocalHost().getHostName())[0].getHostAddress();
    } catch (final Throwable t) {
      MY_ADDRESS =
          System.getProperty(
              "ch.ethz.iks.r_osgi.ip", //$NON-NLS-1$
              "127.0.0.1"); //$NON-NLS-1$
    }

    // set the debug switches
    final BundleContext context = RemoteOSGiActivator.getActivator().getContext();
    String prop = context.getProperty(PROXY_DEBUG_PROPERTY);
    PROXY_DEBUG = prop != null ? Boolean.valueOf(prop).booleanValue() : false;
    prop = context.getProperty(MSG_DEBUG_PROPERTY);
    MSG_DEBUG = prop != null ? Boolean.valueOf(prop).booleanValue() : false;
    prop = context.getProperty(DEBUG_PROPERTY);
    DEBUG = prop != null ? Boolean.valueOf(prop).booleanValue() : false;

    if (log != null) {
      if (PROXY_DEBUG) {
        log.log(LogService.LOG_INFO, "PROXY DEBUG OUTPUTS ENABLED"); // $NON-NLS-1$
      }
      if (MSG_DEBUG) {
        log.log(LogService.LOG_INFO, "MESSAGE DEBUG OUTPUTS ENABLED"); // $NON-NLS-1$
      }
      if (DEBUG) {
        log.log(LogService.LOG_INFO, "INTERNAL DEBUG OUTPUTS ENABLED"); // $NON-NLS-1$
      }
    } else {
      if (PROXY_DEBUG || MSG_DEBUG || DEBUG) {
        System.err.println(
            "WARNING: NO LOG SERVICE PRESENT, DEBUG PROPERTIES HAVE NO EFFECT ..."); //$NON-NLS-1$
        PROXY_DEBUG = false;
        MSG_DEBUG = false;
        DEBUG = false;
      }
    }

    // set port
    prop = context.getProperty(R_OSGi_PORT_PROPERTY);
    R_OSGI_PORT = prop != null ? Integer.parseInt(prop) : 9278;

    // initialize the transactionID with a random value
    nextXid = (short) Math.round(Math.random() * Short.MAX_VALUE);

    // get the package admin
    final ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
    if (ref == null) {
      // TODO: handle this more gracefully
      throw new RuntimeException(
          "No package admin service available, R-OSGi terminates."); //$NON-NLS-1$
    }
    pkgAdmin = (PackageAdmin) context.getService(ref);

    setupTrackers(context);
  }
Esempio n. 5
0
 /**
  * @param ref the <code>RemoteServiceReference</code>.
  * @return the service object or <code>null</code> if the service is not (yet) present.
  * @see
  *     ch.ethz.iks.r_osgi.RemoteOSGiService#getFetchedService(ch.ethz.iks.r_osgi.RemoteServiceReference)
  * @category RemoteOSGiService
  * @since 0.6
  */
 public Object getRemoteService(final RemoteServiceReference ref) {
   if (ref == null) {
     throw new IllegalArgumentException("Remote Reference is null."); // $NON-NLS-1$
   }
   ServiceReference sref = getFetchedServiceReference(ref);
   if (sref == null) {
     fetchService(ref);
     sref = getFetchedServiceReference(ref);
   }
   return sref == null ? null : RemoteOSGiActivator.getActivator().getContext().getService(sref);
 }
Esempio n. 6
0
 /**
  * @param ref the <code>RemoteServiceReference</code> to the service.
  * @return the service reference of the service (or service proxy) or <code>null</code> if the
  *     service is not (yet) present.
  * @see
  *     ch.ethz.iks.r_osgi.RemoteOSGiService#getFetchedServiceReference(ch.ethz.iks.r_osgi.RemoteServiceReference)
  * @category RemoteOSGiService
  * @since 0.6
  */
 private ServiceReference getFetchedServiceReference(final RemoteServiceReference ref) {
   try {
     final ServiceReference[] refs =
         RemoteOSGiActivator.getActivator()
             .getContext()
             .getServiceReferences(
                 ref.getServiceInterfaces()[0],
                 "(" //$NON-NLS-1$
                     + SERVICE_URI
                     + "="
                     + ref.getURI()
                     + ")"); //$NON-NLS-1$ //$NON-NLS-2$
     if (refs != null) {
       return refs[0];
     }
   } catch (final InvalidSyntaxException doesNotHappen) {
     doesNotHappen.printStackTrace();
   }
   return null;
 }
Esempio n. 7
0
 /**
  * @throws InterruptedException
  * @see
  *     ch.ethz.iks.r_osgi.RemoteOSGiService#getRemoteServiceBundle(ch.ethz.iks.r_osgi.RemoteServiceReference)
  * @since 1.0.0.RC4
  */
 public Object getRemoteServiceBundle(final RemoteServiceReference ref, final int timeout)
     throws InterruptedException {
   if (ref == null) {
     throw new IllegalArgumentException("Remote Reference is null."); // $NON-NLS-1$
   }
   getChannel(ref.getURI()).getCloneBundle(ref);
   if (timeout < 0) {
     return null;
   }
   // TODO: FIXME use at least all service interfaces
   final ServiceTracker tracker =
       new ServiceTracker(
           RemoteOSGiActivator.getActivator().getContext(), ref.getServiceInterfaces()[0], null);
   tracker.open();
   tracker.waitForService(0);
   // TODO: FIXME compare that the service is actually the one from the
   // fetched
   // bundle!
   return tracker.getService();
 }
Esempio n. 8
0
 /**
  * @see ch.ethz.iks.r_osgi.RemoteOSGiService#getRemoteServiceReferences(ch.ethz.iks.r_osgi.URI,
  *     java.lang.String, org.osgi.framework.Filter)
  */
 public RemoteServiceReference[] getRemoteServiceReferences(
     final URI service, final String clazz, final Filter filter) {
   final String uri = getChannelURI(service);
   ChannelEndpointImpl channel = (ChannelEndpointImpl) channels.get(uri);
   if (channel == null) {
     try {
       connect(service);
       channel = (ChannelEndpointImpl) channels.get(uri);
     } catch (final IOException ioe) {
       throw new RemoteOSGiException("Cannot connect to " + uri); // $NON-NLS-1$
     }
   }
   if (clazz == null) {
     return channel.getAllRemoteReferences(null);
   }
   try {
     return channel.getAllRemoteReferences(
         RemoteOSGiActivator.getActivator()
             .getContext()
             .createFilter(
                 filter != null
                     ? "(&"
                         + filter
                         + "(" //$NON-NLS-1$ //$NON-NLS-2$
                         + Constants.OBJECTCLASS
                         + "="
                         + clazz
                         + "))"
                     : "(" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                         + Constants.OBJECTCLASS
                         + "="
                         + clazz
                         + ")")); //$NON-NLS-1$ //$NON-NLS-2$
   } catch (final InvalidSyntaxException ise) {
     ise.printStackTrace();
     return null;
   }
 }