Java Code Examples for org.osgi.framework.ServiceEvent#getType()

The following examples show how to use org.osgi.framework.ServiceEvent#getType() . 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: ServiceListenerTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
boolean checkEvents(int[] eventTypes)
{
  if (events.size() != eventTypes.length) {
    dumpEvents(eventTypes);
    return false;
  }

  for (int i=0; i<eventTypes.length; i++) {
    ServiceEvent evt = (ServiceEvent) events.get(i);
    if (eventTypes[i] != evt.getType() ) {
      dumpEvents(eventTypes);
      return false;
    }
  }
  return true;
}
 
Example 2
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 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: 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 5
Source File: ConfigurationAdminFactory.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void serviceChanged(ServiceEvent event)
{
  final ServiceReference<?> sr = event.getServiceReference();
  final int eventType = event.getType();
  final String[] objectClasses = (String[]) sr.getProperty("objectClass");
  for (final String objectClasse : objectClasses) {
    serviceChanged(sr, eventType, objectClasse);
  }
}
 
Example 6
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 7
Source File: ServletContextListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceChanged(ServiceEvent event) {
    if (event.getType() == ServiceEvent.REGISTERED) {
        try {
            ServletContextListener.registerServlets(bundleContext);
        } catch (Exception e) {
            log.error("Failed to initialize the OpenID UI component", e);
        }
    }
}
 
Example 8
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 9
Source File: LogRef.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Service listener entry point. Releases the log service object if one has
 * been fetched.
 * 
 * @param evt
 *          Service event
 */
public void serviceChanged(ServiceEvent evt)
{
  if (evt.getServiceReference() == logSR
      && evt.getType() == ServiceEvent.UNREGISTERING) {
    ungetLogService();
  }
}
 
Example 10
Source File: UserAdminImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void serviceChanged(ServiceEvent event) {
    ServiceReference sr = event.getServiceReference();
    switch (event.getType()) {
    case ServiceEvent.REGISTERED:
        listeners.addElement(sr);
        if (Activator.log.doDebug())
            Activator.log.debug("UserAdminListener found: " + sr);
        break;
    case ServiceEvent.UNREGISTERING:
        if (listeners.removeElement(sr) && Activator.log.doDebug())
            Activator.log.debug("UserAdminListener gone: " + sr);
        break;
    }
}
 
Example 11
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 12
Source File: ServiceRestartCountCalculator.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
private void logUnknownService(ServiceEvent event) {
    if ( event.getType() == ServiceEvent.UNREGISTERING ) {
        Map<String, Object> props = new HashMap<>();
        for ( String propertyName : event.getServiceReference().getPropertyKeys() ) {
            Object propVal = event.getServiceReference().getProperty(propertyName);
            if ( propVal.getClass() == String[].class )
                propVal = Arrays.toString((String[]) propVal);
            props.put(propertyName, propVal);
        }

        Log.debug(getClass(), "Ignoring unregistration of service with props {}, as it has none of identifier properties {}", props, Arrays.toString(GENERAL_IDENTIFIER_PROPERTIES));
    }
}
 
Example 13
Source File: ControllerTracker.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void serviceChanged ( final ServiceEvent event )
{
    switch ( event.getType () )
    {
        case ServiceEvent.REGISTERED:
            handleAddingService ( event.getServiceReference () );
            break;
        case ServiceEvent.UNREGISTERING:
            handleRemovedService ( event.getServiceReference () );
            break;
    }
}
 
Example 14
Source File: ServiceImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized void serviceChanged ( final ServiceEvent event )
{
    logger.debug ( "Service changed: {}", event );
    final ServiceReference<?> ref = event.getServiceReference ();

    try
    {
        switch ( event.getType () )
        {
            case ServiceEvent.REGISTERED:
                checkAddConditionQuery ( ref );
                checkAddEventQuery ( ref );
                break;
            case ServiceEvent.UNREGISTERING:
                final String id = getQueryId ( ref );
                final MonitorQuery query = this.conditionQueryRefs.remove ( id );
                if ( query != null )
                {
                    removeMonitorQuery ( id, query );
                    this.context.ungetService ( ref );
                }
                final EventQuery eventQuery = this.eventQueryRefs.remove ( id );
                if ( eventQuery != null )
                {
                    removeEventQuery ( id, eventQuery );
                    this.context.ungetService ( ref );
                }
                break;
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to handle service change", e );
    }
}
 
Example 15
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void serviceChanged ( final ServiceEvent event )
{
    switch ( event.getType () )
    {
    case ServiceEvent.REGISTERED:
        addService ( event.getServiceReference () );
        break;
    case ServiceEvent.UNREGISTERING:
        removeService ( event.getServiceReference () );
        break;
    }
}
 
Example 16
Source File: ConnectionInformationList.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected synchronized void handleServiceChanged ( final ServiceEvent event )
{
    switch ( event.getType () )
    {
        case ServiceEvent.UNREGISTERING:
        case ServiceEvent.MODIFIED_ENDMATCH:
            removeService ( event.getServiceReference () );
            break;
        case ServiceEvent.REGISTERED:
            addService ( event.getServiceReference () );
            break;
    }
}
 
Example 17
Source File: RDF2GoActivator.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Listen to changes in the ModelFactories.
 * 
 * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent)
 */
@Override
public void serviceChanged(ServiceEvent event) {
	switch(event.getType()) {
	case ServiceEvent.REGISTERED:
		handleRegisteredEvent(event);
		break;
	case ServiceEvent.UNREGISTERING:
		handleUnregisteredEvent(event);
		break;
	}
	// We do not care for modified
	// case ServiceEvent.MODIFIED:
}
 
Example 18
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 19
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 20
Source File: ServiceRestartCountCalculator.java    From sling-whiteboard with Apache License 2.0 2 votes vote down vote up
private boolean shouldIgnore(ServiceEvent event) {
    
    return event.getType() != ServiceEvent.REGISTERED && event.getType() != ServiceEvent.UNREGISTERING;
}