Java Code Examples for org.osgi.framework.ServiceEvent#UNREGISTERING
The following examples show how to use
org.osgi.framework.ServiceEvent#UNREGISTERING .
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: ReferenceListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * */ void serviceEvent(ServiceReference<?> s, ServiceEvent se) { Filter f = getTargetFilter(); boolean match = f == null || f.match(s); if (match && ReferenceDescription.SCOPE_PROTOTYPE_REQUIRED.equals(ref.getScope())) { match = Constants.SCOPE_PROTOTYPE.equals(s.getProperty(Constants.SERVICE_SCOPE)); } int type = se.getType(); if (!match) { if (type != ServiceEvent.UNREGISTERING && serviceRefs.contains(s)) { type = ServiceEvent.MODIFIED_ENDMATCH; } else { return; } } serviceChanged(new RefServiceEvent(type, s, se)); }
Example 2
Source File: ServiceDiscoverer.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@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: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 4
Source File: LogFrameworkListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 5
Source File: AbstractExporter.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override public synchronized void serviceChanged ( final ServiceEvent event ) { switch ( event.getType () ) { case ServiceEvent.REGISTERED: addService ( event.getServiceReference () ); break; case ServiceEvent.UNREGISTERING: removeService ( event.getServiceReference () ); break; } }
Example 6
Source File: RDF2GoActivator.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 7
Source File: ServiceListenerTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 8
Source File: UpgradeTaskProvider.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
protected void handleServiceChange ( final ServiceEvent event ) { logger.debug ( "service change - {} - {}", event.getType (), event.getServiceReference () ); switch ( event.getType () ) { case ServiceEvent.UNREGISTERING: case ServiceEvent.REGISTERED: refresh (); break; } }
Example 9
Source File: ControllerTracker.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
@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 10
Source File: ServiceTracker.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * {@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 11
Source File: ServiceRestartCountCalculator.java From sling-whiteboard with Apache License 2.0 | 5 votes |
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 12
Source File: ServiceRestartCountCalculator.java From sling-whiteboard with Apache License 2.0 | 5 votes |
@Override public void serviceChanged(ServiceEvent event) { if ( shouldIgnore(event) ) return; ServiceIdentifier id = tryFindIdFromGeneralProperties(event); if ( id == null ) id = tryFindIdFromSpecificProperties(event); if ( id == null ) { logUnknownService(event); if ( event.getType() == ServiceEvent.UNREGISTERING ) recordUnknownServiceUnregistration(event); return; } ServiceRegistrationsTracker tracker; synchronized (registrations) { if ( event.getType() == ServiceEvent.REGISTERED ) { tracker = registrations.computeIfAbsent(id, ServiceRegistrationsTracker::new); tracker.registered(); } else if ( event.getType() == ServiceEvent.UNREGISTERING ) { tracker = registrations.get(id); if (tracker == null) { Log.debug(getClass(), "Service with identifier {} was unregistered, but no previous registration data was found", id); return; } tracker.unregistered(); } } }
Example 13
Source File: ConnectionInformationList.java From neoscada with Eclipse Public License 1.0 | 5 votes |
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 14
Source File: NetigsoServices.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void serviceChanged(ServiceEvent ev) { final ServiceReference ref = ev.getServiceReference(); if (ev.getType() == ServiceEvent.REGISTERED) { MainLookup.register(ref, this); } if (ev.getType() == ServiceEvent.UNREGISTERING) { MainLookup.unregister(ref, this); } }
Example 15
Source File: ContentHandlerWrapper.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
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); } }
Example 16
Source File: PluginManager.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 17
Source File: MultiListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 18
Source File: ServiceListenerTestSuite.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void serviceChanged(ServiceEvent evt) { events.add(evt); out.println("ServiceEvent: " +toString(evt) ); if (ServiceEvent.UNREGISTERING==evt.getType()) { ServiceReference sr = evt.getServiceReference(); // Validate that no bundle is marked as using the service Bundle[] usingBundles = sr.getUsingBundles(); if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg) should be null " +"but is: "); } // Check if the service can be fetched Object service = bc.getService(sr); usingBundles = sr.getUsingBundles(); if (UNREGISTERSERVICE_VALID_DURING_UNREGISTERING) { // In this mode the service shall be obtainable during // unregistration. if (null==service) { teststatus = false; out.print("*** Service should be available to ServiceListener " +"while handling unregistering event."); } out.println("Service (unreg): " +service); if (checkUsingBundles && usingBundles.length!=1) { teststatus = false; printUsingBundles(sr, "*** One using bundle expected " +"(unreg, after getService), found: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): "); } } else { // In this mode the service shall NOT be obtainable during // unregistration. if (null!=service) { teststatus = false; out.print("*** Service should not be available to ServiceListener " +"while handling unregistering event."); } if (checkUsingBundles && null!=usingBundles) { teststatus = false; printUsingBundles(sr, "*** Using bundles (unreg, after getService), " +"should be null but is: "); } else { printUsingBundles(sr, "Using bundles (unreg, after getService): null"); } } bc.ungetService(sr); // Check that the UNREGISTERING service can not be looked up // using the service registry. try { Long sid = (Long)sr.getProperty(Constants.SERVICE_ID); String sidFilter = "(" +Constants.SERVICE_ID +"=" +sid +")"; ServiceReference[] srs = bc.getServiceReferences((String)null, sidFilter); if (null==srs || 0==srs.length) { out.println("ServiceReference for UNREGISTERING service is not" +" found in the service registry; ok."); } else { teststatus = false; out.println("*** ServiceReference for UNREGISTERING" +" service, " + sr +", not found in the service registry; fail."); out.print("Found the following Service references: "); for (int i=0; null!=srs && i<srs.length; i++) { if (i>0) out.print(", "); out.print(srs[i]); } out.println(); } } catch (Throwable t) { teststatus = false; out.println("*** Unexpected excpetion when trying to lookup a" +" service while it is in state UNREGISTERING; " +t); t.printStackTrace(out); } } }
Example 19
Source File: ReferenceListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 20
Source File: ServiceRestartCountCalculator.java From sling-whiteboard with Apache License 2.0 | 2 votes |
private boolean shouldIgnore(ServiceEvent event) { return event.getType() != ServiceEvent.REGISTERED && event.getType() != ServiceEvent.UNREGISTERING; }