use of org.apache.aries.blueprint.utils.ServiceListener in project aries by apache.
the class ServiceRecipe method unregister.
public void unregister() {
ServiceRegistration reg = registration.get();
if (reg != null) {
LOGGER.debug("Unregistering service {}", name);
// set to null before actually unregistering the service
if (listeners != null) {
LOGGER.debug("Calling listeners for service unregistration");
for (ServiceListener listener : listeners) {
listener.unregister(service, registrationProperties);
}
}
ServiceUtil.safeUnregisterService(reg);
registration.compareAndSet(reg, null);
}
}
use of org.apache.aries.blueprint.utils.ServiceListener in project aries by apache.
the class CmManagedServiceFactory method preUnregister.
protected void preUnregister(Object service, Dictionary properties, ServiceRegistration registration) {
if (listeners != null && !listeners.isEmpty()) {
Hashtable props = new Hashtable();
JavaUtils.copy(properties, props);
for (ServiceListener listener : listeners) {
listener.unregister(service, props);
}
}
}
use of org.apache.aries.blueprint.utils.ServiceListener in project aries by apache.
the class CmManagedServiceFactory method postRegister.
protected void postRegister(Object service, Dictionary properties, ServiceRegistration registration) {
if (listeners != null && !listeners.isEmpty()) {
Hashtable props = new Hashtable();
JavaUtils.copy(properties, props);
for (ServiceListener listener : listeners) {
listener.register(service, props);
}
}
}
use of org.apache.aries.blueprint.utils.ServiceListener in project aries by apache.
the class ServiceRecipe method createService.
private void createService() {
try {
if (service == null) {
LOGGER.debug("Creating service instance");
//We can't use the BlueprintRepository because we don't know what interfaces
//to use yet! We have to be a bit smarter.
ExecutionContext old = ExecutionContext.Holder.setContext(blueprintContainer.getRepository());
try {
Object o = serviceRecipe.create();
if (o instanceof Convertible) {
o = blueprintContainer.getRepository().convert(o, new ReifiedType(Object.class));
validateClasses(o);
} else if (o instanceof UnwrapperedBeanHolder) {
UnwrapperedBeanHolder holder = (UnwrapperedBeanHolder) o;
if (holder.unwrapperedBean instanceof ServiceFactory) {
//If a service factory is used, make sure the proxy classes implement this
//interface so that later on, internalGetService will create the real
//service from it.
LOGGER.debug("{} implements ServiceFactory, creating proxy that also implements this", holder.unwrapperedBean);
Collection<Class<?>> cls = getClassesForProxying(holder.unwrapperedBean);
cls.add(blueprintContainer.loadClass("org.osgi.framework.ServiceFactory"));
o = BeanRecipe.wrap(holder, cls);
} else {
validateClasses(holder.unwrapperedBean);
o = BeanRecipe.wrap(holder, getClassesForProxying(holder.unwrapperedBean));
}
} else if (!(o instanceof ServiceFactory)) {
validateClasses(o);
}
service = o;
} catch (Exception e) {
LOGGER.error("Error retrieving service from " + this, e);
throw new ComponentDefinitionException(e);
} finally {
ExecutionContext.Holder.setContext(old);
}
LOGGER.debug("Service created: {}", service);
}
// When the service is first requested, we need to create listeners and call them
if (!initialServiceRegistration && listeners == null) {
LOGGER.debug("Creating listeners");
if (listenersRecipe != null) {
listeners = (List) createRecipe(listenersRecipe);
} else {
listeners = Collections.emptyList();
}
LOGGER.debug("Listeners created: {}", listeners);
if (registration.get() != null) {
LOGGER.debug("Calling listeners for initial service registration");
for (ServiceListener listener : listeners) {
listener.register(service, registrationProperties);
}
} else {
LOGGER.debug("Calling listeners for initial service unregistration");
for (ServiceListener listener : listeners) {
listener.unregister(service, registrationProperties);
}
}
}
} catch (RuntimeException e) {
LOGGER.error("Error retrieving service from " + this, e);
throw e;
}
}
Aggregations