Java Code Examples for org.osgi.framework.ServiceEvent#MODIFIED

The following examples show how to use org.osgi.framework.ServiceEvent#MODIFIED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceDiscoverer.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public synchronized void serviceChanged ( final ServiceEvent event )
{
    switch ( event.getType () )
    {
        case ServiceEvent.REGISTERED:
            addReference ( event.getServiceReference () );
            break;
        case ServiceEvent.MODIFIED:
            update ();
            break;
        case ServiceEvent.UNREGISTERING:
            removeReference ( event.getServiceReference () );
            break;
    }
}
 
Example 2
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void serviceChanged(ServiceEvent event) { 
  switch (event.getType()) { 
  case ServiceEvent.REGISTERED: 
    log("ServiceEvent.REGISTERED"); 
    dateService = (DateService) Activator.bc.getService(event 
                                                         .getServiceReference()); 
    startUsingService(); 
    break; 
  case ServiceEvent.MODIFIED: 
    log("ServiceEvent.MODIFIED received"); 
    stopUsingService(); 
    dateService = (DateService) Activator.bc.getService(event 
                                                    .getServiceReference()); 
    startUsingService(); 
    break; 
  case ServiceEvent.UNREGISTERING: 
    log("ServiceEvent.UNREGISTERING"); 
    stopUsingService(); 
    break; 
  } 
}
 
Example 3
Source File: LogFrameworkListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The service event callback method inserts all service events into the
 * log.
 * 
 * Event of types REGISTERED, UNREGISTERED are assigned the log
 * level info.
 * 
 * Events of type MODIFIED are assigned the log level DEBUG.
 * 
 * @param se
 *            the service event that has occurred.
 */
public void serviceChanged(ServiceEvent se) {
    ServiceReference<?> sr = se.getServiceReference();
    Bundle bundle = sr.getBundle();
    String msg = null;
    int level = LogService.LOG_INFO;
    switch (se.getType()) {
    case ServiceEvent.REGISTERED:
        msg = "ServiceEvent REGISTERED";
        break;
    case ServiceEvent.UNREGISTERING:
        msg = "ServiceEvent UNREGISTERING";
        break;
    case ServiceEvent.MODIFIED:
        msg = "ServiceEvent MODIFIED";
        level = LogService.LOG_DEBUG;
        break;
    }
    lrsf.log(new LogEntryImpl(bundle, sr, level, msg));
}
 
Example 4
Source File: CMCommands.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void serviceChanged(ServiceEvent event)
{
  switch (event.getType()) {
  case ServiceEvent.REGISTERED:
    @SuppressWarnings("unchecked")
    final ServiceReference<ConfigurationAdmin> sr =
      (ServiceReference<ConfigurationAdmin>) event.getServiceReference();
    if (refCA != sr) {
      refCA = sr;
    }
    break;
  case ServiceEvent.MODIFIED:
    break;
  case ServiceEvent.UNREGISTERING:
    if (refCA != null) {
      refCA = null;
    }
    break;
  default:
    break;
  }
}
 
Example 5
Source File: ServiceTracker.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@code ServiceListener} method for the {@code ServiceTracker} class.
 * This method must NOT be synchronized to avoid deadlock potential.
 * 
 * @param event {@code ServiceEvent} object from the framework.
 */
final public void serviceChanged(final ServiceEvent event) {
	/*
	 * Check if we had a delayed call (which could happen when we
	 * close).
	 */
	if (closed) {
		return;
	}
	@SuppressWarnings("unchecked")
	final ServiceReference<S> reference = (ServiceReference<S>) event.getServiceReference();
	if (DEBUG) {
		System.out.println("ServiceTracker.Tracked.serviceChanged[" + event.getType() + "]: " + reference);
	}

	switch (event.getType()) {
		case ServiceEvent.REGISTERED :
		case ServiceEvent.MODIFIED :
			track(reference, event);
			/*
			 * If the customizer throws an unchecked exception, it is
			 * safe to let it propagate
			 */
			break;
		case ServiceEvent.MODIFIED_ENDMATCH :
		case ServiceEvent.UNREGISTERING :
			untrack(reference, event);
			/*
			 * If the customizer throws an unchecked exception, it is
			 * safe to let it propagate
			 */
			break;
	}
}
 
Example 6
Source File: LogReaderDispatcher.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void serviceChanged(ServiceEvent ev)
{
  @SuppressWarnings("unchecked")
  final
  ServiceReference<LogReaderService> sr =
    (ServiceReference<LogReaderService>) ev.getServiceReference();

  final LogReaderService lr =
    logReaders.containsKey(sr) ? logReaders.get(sr) : (LogReaderService) bc
        .getService(sr);

  if (null != lr) {
    switch (ev.getType()) {
    case ServiceEvent.REGISTERED:
      lr.addLogListener(this);
      logReaders.put(sr, lr);
      break;
    case ServiceEvent.MODIFIED:
      break;
    case ServiceEvent.UNREGISTERING:
      lr.removeLogListener(this);
      logReaders.remove(sr);
      bc.ungetService(sr);
      break;
    }
  }
}
 
Example 7
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String serviceEventName(int type)
{
  switch (type) {
  case ServiceEvent.REGISTERED:
    return "registered";
  case ServiceEvent.UNREGISTERING:
    return "unregistering";
  case ServiceEvent.MODIFIED:
    return "modified";
  default:
    return "<" + type + ">";
  }
}
 
Example 8
Source File: ServiceListenerTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
String toStringEventType(int eventType)
{
  String res = String.valueOf(eventType);

  switch (eventType) {
  case ServiceEvent.REGISTERED:    res +=" (REGISTERED)    "; break;
  case ServiceEvent.MODIFIED:      res +=" (MODIFIED)      "; break;
  case ServiceEvent.UNREGISTERING: res +=" (UNREGISTERING) "; break;
  default:                         res +=" (?)             ";
  }
  return res;
}
 
Example 9
Source File: ServiceTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@code ServiceListener} method for the {@code ServiceTracker} class.
 * This method must NOT be synchronized to avoid deadlock potential.
 * 
 * @param event {@code ServiceEvent} object from the framework.
 */
final public void serviceChanged(final ServiceEvent event) {
	/*
	 * Check if we had a delayed call (which could happen when we
	 * close).
	 */
	if (closed) {
		return;
	}
	@SuppressWarnings("unchecked")
	final ServiceReference<S> reference = (ServiceReference<S>) event.getServiceReference();
	if (DEBUG) {
		System.out.println("ServiceTracker.Tracked.serviceChanged[" + event.getType() + "]: " + reference);
	}

	switch (event.getType()) {
		case ServiceEvent.REGISTERED :
		case ServiceEvent.MODIFIED :
			track(reference, event);
			/*
			 * If the customizer throws an unchecked exception, it is
			 * safe to let it propagate
			 */
			break;
		case ServiceEvent.MODIFIED_ENDMATCH :
		case ServiceEvent.UNREGISTERING :
			untrack(reference, event);
			/*
			 * If the customizer throws an unchecked exception, it is
			 * safe to let it propagate
			 */
			break;
	}
}
 
Example 10
Source File: Repositories.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void serviceChanged(ServiceEvent event) {
  @SuppressWarnings("unchecked")
  RepositoryInfo ri = new RepositoryInfo((ServiceReference<Repository>) event.getServiceReference());
  synchronized (this) {
    switch (event.getType()) {
    case ServiceEvent.REGISTERED:
      repos.put(ri, ri);
      break;
    case ServiceEvent.MODIFIED:
      for (Iterator<RepositoryInfo> i = repos.keySet().iterator(); i.hasNext();) {
        RepositoryInfo old = i.next();
        if (old.getId() == ri.getId()) {
          i.remove();
          repos.put(ri, ri);
        }
      }
      break;
    case ServiceEvent.MODIFIED_ENDMATCH:
    case ServiceEvent.UNREGISTERING:
      repos.remove(ri);
      break;      
    }
    changeCount++;
  }
  for (RepositoryListener rl : listeners) {
    switch (event.getType()) {
    case ServiceEvent.REGISTERED:
      rl.addedRepo(ri);
      repos.put(ri, ri);
      break;
    case ServiceEvent.MODIFIED:
      rl.modifiedRepo(ri);
      break;
    case ServiceEvent.MODIFIED_ENDMATCH:
    case ServiceEvent.UNREGISTERING:
      rl.removedRepo(ri);
      break;      
    }
  }
}
 
Example 11
Source File: MultiListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * A listener for service events
 * @param serviceEvent the event sent by the service
 * @author Johnny Baveras
 */
public void serviceChanged(ServiceEvent serviceEvent) {
  String topic = null;
  boolean knownMessageType = true;

  switch (serviceEvent.getType()) {
  case ServiceEvent.REGISTERED:
    topic = SERVICE_EVENT_REGISTERED_TOPIC;

    
    String[] objectClass = (String[]) serviceEvent.getServiceReference().getProperty(Constants.OBJECTCLASS);
    boolean isLogReaderService = false;
    if (objectClass != null) {
      for (int i=0; i<objectClass.length; i++) {
        if (LogReaderService.class.getName().equals(objectClass[i])) {
          isLogReaderService = true;
        }
      }
    }

    if (isLogReaderService) {
      LogReaderService logReader = (LogReaderService)
        Activator.bc.getService(serviceEvent.getServiceReference());
      if (logReader != null) {
        logReader.addLogListener(this);
      }
    }
    break;
  case ServiceEvent.MODIFIED:
    topic = SERVICE_EVENT_MODIFIED_TOPIC;
    break;
  case ServiceEvent.UNREGISTERING:
    topic = SERVICE_EVENT_UNREGISTERING_TOPIC;
    break;
  default:
    /* Setting the boolean to false if an unknown event arrives */
    knownMessageType = false;
    break;
  }



  /* Stores the properties of the event in the dictionary, if the event is known */
  if (knownMessageType) {
    if(!Activator.handlerTracker.anyHandlersMatching(topic)) {
      return;
    }
    Map<String,Object> props = new HashMap<String,Object>();
    putProp(props, EventConstants.EVENT, serviceEvent);
    putProp(props, EventConstants.SERVICE, serviceEvent.getServiceReference());
    putProp(props, EventConstants.SERVICE_PID, serviceEvent.getServiceReference().getProperty(Constants.SERVICE_PID));
    putProp(props, EventConstants.SERVICE_ID, serviceEvent.getServiceReference().getProperty(Constants.SERVICE_ID));
    putProp(props, EventConstants.SERVICE_OBJECTCLASS, serviceEvent.getServiceReference().getProperty(Constants.OBJECTCLASS));

    /* Tries posting the event once the properties are set */
    try {
      Activator.eventAdmin.postEvent(new Event(topic, props));
    } catch (Exception e) {
      Activator.log.error("EXCEPTION in serviceChanged() :", e);
    }
  } else {
    /* Logs an error if the event, which arrived, were of an unknown type */
    Activator.log.error("Recieved unknown service event message (type="
              +serviceEvent.getType() +"), discarding");
  }
}
 
Example 12
Source File: ReferenceListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void serviceChanged(RefServiceEvent se) {
  ref.comp.scr.postponeCheckin();
  try {
    do {
      boolean wasSelected = false;
      int op;
      synchronized (serviceRefs) {
        if (sEventQueue.isEmpty()) {
          if (se == null) {
            return;
          }
        } else {
          if (se != null) {
            sEventQueue.addLast(se);
          }
          se = sEventQueue.removeFirst();
        }
        switch (se.type) {
        case ServiceEvent.MODIFIED:
        case ServiceEvent.REGISTERED:
          op = serviceRefs.add(se.sr) ? ADD_OP : UPDATE_OP;
          break;
        case ServiceEvent.MODIFIED_ENDMATCH:
        case ServiceEvent.UNREGISTERING:
          serviceRefs.remove(se.sr);
          if  (selectedServiceRef == se.sr) {
            wasSelected = true;
          }
          unbinding.add(se.sr);
          op = DELETE_OP;
          break;
        default:
          // To keep compiler happy
          throw new RuntimeException("Internal error");
        }
      }
      switch (op) {
      case ADD_OP:
        if (!ref.refAvailable()) {
          refAdded(se);
        }
        break;
      case DELETE_OP:
        boolean deleted = false;
        if (!ref.refUnavailable()) {
          if (ref.isMultiple() || wasSelected) {
            refDeleted(se);
            deleted = true;
          }
        }
        synchronized (serviceRefs) {
          unbinding.remove(se.sr);
          if (deleted) {
            setSelected(null);
          }
        }
        break;
      case UPDATE_OP:
        refUpdated(se);
        break;
      }
      se = null;
    } while (!sEventQueue.isEmpty());
  } finally {
    ref.comp.scr.postponeCheckout();
  }
}
 
Example 13
Source File: PluginManager.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Handle ConfigurationPlugin ServiceEvents.
 *
 * @param serviceReference
 *          ServiceReference of the plugin the event concerns
 * @param eventType
 *          Type of the event that caused the change
 */

public synchronized void configurationPluginChanged(ServiceReference<ConfigurationPlugin> serviceReference,
                                                    int eventType)
{
  Object rankingProperty = serviceReference.getProperty(CM_RANKING);
  if (rankingProperty == null) {
    rankingProperty = new Integer(0);
  } else if (rankingProperty.getClass() != Integer.class) {
    rankingProperty = new Integer(0);
  }

  Long serviceId = (Long) serviceReference.getProperty(SERVICE_ID);
  if (serviceId == null) {
    Activator.log.error("Missing service id for a ConfigurationPlugin");
    return;
  }

  int ranking = ((Integer) rankingProperty).intValue();

  switch (eventType) {
  case ServiceEvent.REGISTERED:
    rankings.put(serviceId, rankingProperty);
    insertPluginReference(serviceReference, ranking);
    break;
  case ServiceEvent.MODIFIED:
    int oldRanking = ((Integer) rankings.get(serviceId)).intValue();
    if (ranking == oldRanking) {
      return;
    }
    removePluginReference(serviceId, oldRanking);
    rankings.put(serviceId, rankingProperty);
    insertPluginReference(serviceReference, ranking);
    break;
  case ServiceEvent.UNREGISTERING:
    rankings.remove(serviceId);
    removePluginReference(serviceId, ranking);
    break;
  default:
    break;
  }
}
 
Example 14
Source File: ContentHandlerWrapper.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
ContentHandlerWrapper(FrameworkContext       framework,
	String                 mimetype) {

  this.framework = framework;
  this.mimetype  = mimetype;

  filter =
    "(&" +
    "(" + Constants.OBJECTCLASS + "=" +
    ContentHandler.class.getName() + ")" +
    "(" + URLConstants.URL_CONTENT_MIMETYPE + "=" + mimetype +
    ")" +
    ")";

  final ServiceListener serviceListener =
    new ServiceListener() {
      public void serviceChanged(ServiceEvent evt) {
        @SuppressWarnings("unchecked")
        final
        ServiceReference<ContentHandler> ref =
            (ServiceReference<ContentHandler>) evt.getServiceReference();

        switch (evt.getType()) {
        case ServiceEvent.MODIFIED:
          // fall through
        case ServiceEvent.REGISTERED:
          if (best == null) {
            updateBest();
            return ;
          }

          if (compare(best, ref) > 0) {
            best = ref;
          }
          break;
        case ServiceEvent.MODIFIED_ENDMATCH:
          // fall through
        case ServiceEvent.UNREGISTERING:
          if (best.equals(ref)) {
            best = null;
          }
        }
      }
    };

  try {
    framework.systemBundle.bundleContext.addServiceListener(serviceListener, filter);

  } catch (final Exception e) {
    throw new IllegalArgumentException("Could not register service listener for content handler: " + e);
  }

  if (framework.debug.url) {
    framework.debug.println("created wrapper for " + mimetype + ", filter=" + filter);
  }
}