Package org.osgi.util.tracker

Examples of org.osgi.util.tracker.ServiceTrackerCustomizer


      throws InvalidSyntaxException {
    ServiceTracker st = new ServiceTracker(getContext(), getContext()
        .createFilter(
            "(&(" + org.osgi.framework.Constants.OBJECTCLASS + "="
                + clazz + ")(" + org.osgi.service.remoteserviceadmin.RemoteConstants.SERVICE_IMPORTED + "=*))"),
        new ServiceTrackerCustomizer() {

          public Object addingService(ServiceReference reference) {
            Trace.trace(Activator.PLUGIN_ID, "addingService="
                + reference);
            return getContext().getService(reference);
View Full Code Here


      log(new Status(IStatus.ERROR, getDefault().getBundle().getSymbolicName(), "Unexpected Error in ECFPlugin.start", t)); //$NON-NLS-1$
    }

    // initialize from ContainerTypeDescription services
    if (containerTypeDescriptionTracker == null) {
      containerTypeDescriptionTracker = new ServiceTracker(this.context, ContainerTypeDescription.class.getName(), new ServiceTrackerCustomizer() {
        public Object addingService(ServiceReference reference) {
          ContainerTypeDescription ctd = (ContainerTypeDescription) context.getService(reference);
          if (ctd != null && ctd.getName() != null)
            ContainerFactory.getDefault().addDescription(ctd);
          return ctd;
View Full Code Here

  }

  private void startRegTracker() {
    try {
      final String filter = "(" + org.eclipse.ecf.remoteservice.Constants.SERVICE_CONTAINER_ID + "=" + containerID + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      remoteServicesTracker = new ServiceTracker(context, context.createFilter(filter), new ServiceTrackerCustomizer() {

        public Object addingService(ServiceReference reference) {
          return reference;
        }
View Full Code Here

              // [TCK][r-OSGi] NonSerializableException when running remoteserviceadmin ct
              // https://bugs.eclipse.org/418740
              + "(!(" //$NON-NLS-1$
              + EventConstants.EVENT_TOPIC
              + "=org/osgi/service/remoteserviceadmin/*))))"), //$NON-NLS-1$
          new ServiceTrackerCustomizer() {

            public Object addingService(
                final ServiceReference reference) {

              // https://bugs.eclipse.org/bugs/show_bug.cgi?id=326033
              Collection theTopics;
              Object topic = reference
                  .getProperty(EventConstants.EVENT_TOPIC);
              if (topic instanceof String)
                theTopics = Arrays
                    .asList(new String[] { (String) topic });
              else
                theTopics = Arrays.asList((String[]) topic);

              // Remove filtered topics
              theTopics = StringUtils.rightDifference(
                  topicFilters, theTopics);

             
              final LeaseUpdateMessage lu = new LeaseUpdateMessage();
              lu.setType(LeaseUpdateMessage.TOPIC_UPDATE);
              lu.setServiceID(""); //$NON-NLS-1$
              lu.setPayload(new Object[] {
                  theTopics.toArray(new String[theTopics
                      .size()]), null });
              updateLeases(lu);

              return theTopics;
            }

            public void modifiedService(
                final ServiceReference reference,
                final Object oldTopics) {

              final List oldTopicList = (List) oldTopics;

              // https://bugs.eclipse.org/bugs/show_bug.cgi?id=326033
              Collection newTopicList;
              Object topic = reference
                  .getProperty(EventConstants.EVENT_TOPIC);
              if (topic instanceof String)
                newTopicList = Arrays
                    .asList(new String[] { (String) topic });
              else
                newTopicList = Arrays.asList((String[]) topic);
             
              // Remove filtered topics
              newTopicList = StringUtils.rightDifference(
                  topicFilters, newTopicList);

              final Collection removed = CollectionUtils
                  .rightDifference(newTopicList, oldTopicList);
              final Collection added = CollectionUtils
                  .leftDifference(newTopicList, oldTopicList);
              final String[] addedTopics = (String[]) added
                  .toArray(new String[removed.size()]);
              final String[] removedTopics = (String[]) removed
                  .toArray(addedTopics);
              oldTopicList.removeAll(removed);
              oldTopicList.addAll(added);
              final LeaseUpdateMessage lu = new LeaseUpdateMessage();
              lu.setType(LeaseUpdateMessage.TOPIC_UPDATE);
              lu.setServiceID(""); //$NON-NLS-1$
              lu.setPayload(new Object[] { addedTopics,
                  removedTopics });
              updateLeases(lu);
            }

            public void removedService(
                final ServiceReference reference,
                final Object oldTopics) {
              final List oldTopicsList = (List) oldTopics;
              final String[] removedTopics = (String[]) oldTopicsList
                  .toArray(new String[oldTopicsList.size()]);
              final LeaseUpdateMessage lu = new LeaseUpdateMessage();
              lu.setType(LeaseUpdateMessage.TOPIC_UPDATE);
              lu.setServiceID(""); //$NON-NLS-1$
              lu.setPayload(new Object[] { null, removedTopics });
              updateLeases(lu);
            }
          });
      eventHandlerTracker.open();

      if (DEBUG) {
        log.log(LogService.LOG_DEBUG, "Local topic space " //$NON-NLS-1$
            + Arrays.asList(getTopics()));
      }

      remoteServiceListenerTracker = new ServiceTracker(context,
          RemoteServiceListener.class.getName(), null);
      remoteServiceListenerTracker.open();

      serviceDiscoveryHandlerTracker = new ServiceTracker(context,
          ServiceDiscoveryHandler.class.getName(),
          new ServiceTrackerCustomizer() {

            public Object addingService(
                final ServiceReference reference) {
              // register all known services for discovery
              final ServiceDiscoveryHandler handler = (ServiceDiscoveryHandler) context
                  .getService(reference);

              final RemoteServiceRegistration[] regs = (RemoteServiceRegistration[]) serviceRegistrations
                  .values()
                  .toArray(
                      new RemoteServiceRegistration[serviceRegistrations
                          .size()]);

              for (int i = 0; i < regs.length; i++) {
                handler
                    .registerService(
                        regs[i].getReference(),
                        regs[i].getProperties(),
                        URI
                            .create("r-osgi://" //$NON-NLS-1$
                                + RemoteOSGiServiceImpl.MY_ADDRESS
                                + ":" //$NON-NLS-1$
                                + RemoteOSGiServiceImpl.R_OSGI_PORT
                                + "#" //$NON-NLS-1$
                                + regs[i]
                                    .getServiceID()));
              }
              return handler;
            }

            public void modifiedService(
                final ServiceReference reference,
                final Object service) {

            }

            public void removedService(
                final ServiceReference reference,
                final Object service) {

            }

          });
      serviceDiscoveryHandlerTracker.open();

      remoteServiceTracker = new ServiceTracker(
          context,
          context.createFilter("(" //$NON-NLS-1$
              + RemoteOSGiService.R_OSGi_REGISTRATION + "=*)"), new ServiceTrackerCustomizer() { //$NON-NLS-1$

            public Object addingService(
                final ServiceReference reference) {

              // FIXME: Surrogates have to be monitored
              // separately!!!
              final ServiceReference service = Arrays
                  .asList(
                      (String[]) reference
                          .getProperty(Constants.OBJECTCLASS))
                  .contains(
                      SurrogateRegistration.class
                          .getName()) ? (ServiceReference) reference
                  .getProperty(SurrogateRegistration.SERVICE_REFERENCE)
                  : reference;

              try {
                final RemoteServiceRegistration reg = new RemoteServiceRegistration(
                    reference, service);

                if (log != null) {
                  log.log(LogService.LOG_INFO, "REGISTERING " //$NON-NLS-1$
                      + reference
                      + " AS PROXIED SERVICES"); //$NON-NLS-1$
                }

                serviceRegistrations.put(service, reg);

                registerWithServiceDiscovery(reg);

                final LeaseUpdateMessage lu = new LeaseUpdateMessage();
                lu.setType(LeaseUpdateMessage.SERVICE_ADDED);
                lu.setServiceID(String.valueOf(reg
                    .getServiceID()));
                lu.setPayload(new Object[] {
                    reg.getInterfaceNames(),
                    reg.getProperties() });
                updateLeases(lu);
                return service;
              } catch (final ClassNotFoundException e) {
                e.printStackTrace();
                throw new RemoteOSGiException(
                    "Cannot find class " + service, e); //$NON-NLS-1$
              }
            }

            public void modifiedService(
                final ServiceReference reference,
                final Object service) {
              if (reference.getProperty(R_OSGi_REGISTRATION) == null) {
                removedService(reference, service);
                return;
              }
              final RemoteServiceRegistration reg = (RemoteServiceRegistration) serviceRegistrations
                  .get(reference);

              registerWithServiceDiscovery(reg);

              final LeaseUpdateMessage lu = new LeaseUpdateMessage();
              lu.setType(LeaseUpdateMessage.SERVICE_MODIFIED);
              lu.setServiceID(String.valueOf(reg.getServiceID()));
              lu.setPayload(new Object[] { null,
                  reg.getProperties() });
              updateLeases(lu);
            }

            public void removedService(
                final ServiceReference reference,
                final Object service) {

              final ServiceReference sref = Arrays
                  .asList(
                      (String[]) reference
                          .getProperty(Constants.OBJECTCLASS))
                  .contains(
                      SurrogateRegistration.class
                          .getName()) ? (ServiceReference) reference
                  .getProperty(SurrogateRegistration.SERVICE_REFERENCE)
                  : reference;

              final RemoteServiceRegistration reg = (RemoteServiceRegistration) serviceRegistrations
                  .remove(sref);

              unregisterFromServiceDiscovery(reg);

              final LeaseUpdateMessage lu = new LeaseUpdateMessage();
              lu.setType(LeaseUpdateMessage.SERVICE_REMOVED);
              lu.setServiceID(String.valueOf(reg.getServiceID()));
              lu.setPayload(new Object[] { null, null });
              updateLeases(lu);
            }

          });
      remoteServiceTracker.open();

      networkChannelFactoryTracker = new ServiceTracker(
          context,
          context.createFilter("(" + Constants.OBJECTCLASS + "=" //$NON-NLS-1$ //$NON-NLS-2$
              + NetworkChannelFactory.class.getName() + ")"), new ServiceTrackerCustomizer() { //$NON-NLS-1$

            public Object addingService(
                final ServiceReference reference) {
              final NetworkChannelFactory factory = (NetworkChannelFactory) context
                  .getService(reference);
View Full Code Here

      throws InvalidSyntaxException {
    ServiceTracker st = new ServiceTracker(getContext(), getContext()
        .createFilter(
            "(&(" + org.osgi.framework.Constants.OBJECTCLASS + "="
                + clazz + ")(" + SERVICE_IMPORTED + "=*))"),
        new ServiceTrackerCustomizer() {

          public Object addingService(ServiceReference reference) {
            Trace.trace(Activator.PLUGIN_ID, "addingService="
                + reference);
            return getContext().getService(reference);
View Full Code Here

TOP

Related Classes of org.osgi.util.tracker.ServiceTrackerCustomizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.