Java Code Examples for org.osgi.framework.ServiceEvent#REGISTERED
The following examples show how to use
org.osgi.framework.ServiceEvent#REGISTERED .
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: 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 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: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 4
Source File: UserAdminImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 5
Source File: ServiceTracker.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 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 6
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 7
Source File: LogReaderDispatcher.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 8
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 9
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 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 |
@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 12
Source File: ServiceImpl.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@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 13
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 14
Source File: BrowserWatchController.java From wisdom with Apache License 2.0 | 5 votes |
public void serviceChanged(ServiceEvent event) { Bundle bundle = event.getServiceReference().getBundle(); switch(event.getType()) { case ServiceEvent.REGISTERED: Object service = context.getService(event.getServiceReference()); if(service instanceof org.wisdom.api.Controller) { String serviceClassName = service.getClass().getName(); triggerReloadFor(serviceClassName); lazyGetInfos(bundle).addController(serviceClassName); log.log(LogService.LOG_INFO, String.format("Controller %s is registered !", serviceClassName)); } } }
Example 15
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 16
Source File: Repositories.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 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: ReferenceListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Start listening for this reference. It is a bit tricky to * get initial state synchronized with the listener. * */ void setTarget(String ccid, Map<String, Object> dict) { if (ccid != null) { cmTarget = ref.getTarget(dict, "CC id = " + ccid); } else { cmTarget = null; } final String filter = getFilter(); Activator.logDebug("Start listening, ref=" + getName() + " with filter=" + filter); ref.comp.listener.removeServiceListener(this); synchronized (serviceRefs) { final HashSet<ServiceReference<?>> oldServiceRefs = new HashSet<ServiceReference<?>>(serviceRefs); serviceRefs.clear(); ServiceReference<?> [] srs; try { ref.comp.listener.addServiceListener(this); srs = ref.comp.bc.getServiceReferences((String)null, filter); } catch (final InvalidSyntaxException ise) { throw new RuntimeException("Should not occur, Filter already checked"); } if (srs != null) { ServiceReference<?> best = null; for (final ServiceReference<?> sr : srs) { if (oldServiceRefs.remove(sr)) { serviceRefs.add(sr); } else { final RefServiceEvent e = new RefServiceEvent(ServiceEvent.REGISTERED, sr); if (best == null || best.compareTo(sr) < 0) { best = sr; sEventQueue.addFirst(e); } else { sEventQueue.addLast(e); } } } } addId(ccid != null ? ccid : Component.NO_CCID, true); for (final ServiceReference<?> oldSR : oldServiceRefs) { sEventQueue.addLast(new RefServiceEvent(ServiceEvent.MODIFIED_ENDMATCH, oldSR)); } } serviceChanged(null); }
Example 19
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 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; }