private Bundle getNullObject() { if (m_nullObject == null) { try { m_nullObject = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Bundle.class }, new DefaultNullObject()); } catch (Throwable e) { m_component.getLogger().err("Could not create null object for Bundle.", e); } } return (Bundle) m_nullObject; }
private Object getDefaultImplementation() { if (m_defaultImplementation != null) { if (m_defaultImplementation instanceof Class) { try { m_defaultImplementationInstance = ((Class<?>) m_defaultImplementation).newInstance(); } catch (Throwable e) { m_component.getLogger().err("Could not create default implementation instance of class %s.", e, m_defaultImplementation); } } else { m_defaultImplementationInstance = m_defaultImplementation; } } return m_defaultImplementationInstance; }
private Object getNullObject() { if (m_nullObject == null) { Class<?> trackedServiceName; trackedServiceName = m_trackedServiceName; try { m_nullObject = Proxy.newProxyInstance(trackedServiceName.getClassLoader(), new Class[] { trackedServiceName }, new DefaultNullObject()); } catch (Throwable err) { m_component.getLogger().err("Could not create null object for %s.", err, trackedServiceName); } } return m_nullObject; }
public ServiceEventImpl(ComponentContext ctx, ServiceReference<?> reference, Object service) { super(service); m_service = service; m_bundle = ctx.getBundle(); m_bundleContext = ctx.getBundleContext(); m_serviceObjects = (m_bundleContext != null) ? m_bundleContext.getServiceObjects(reference) : null; m_reference = reference; m_logger = ctx.getLogger(); }
m_component.getLogger().warn("Exception while invoking callback method", e.getCause()); m_component.getLogger().warn("Exception while trying to invoke callback method", e); props.put(key, resourceProperties.get(key).toString()); } else { m_component.getLogger().warn( "Custom resource property is overlapping with the default resource property for key: %s", key);
@SuppressWarnings("unchecked") @Override public Dictionary<String, Object> getProperties() { Event event = getService(); if (event != null) { Bundle bundle = (Bundle) event.getEvent(); if (m_propagateCallbackInstance != null && m_propagateCallbackMethod != null) { try { CallbackTypeDef callbackInfo = new CallbackTypeDef(Bundle.class, bundle); return (Dictionary<String, Object>) InvocationUtil.invokeCallbackMethod(m_propagateCallbackInstance, m_propagateCallbackMethod, callbackInfo.m_sigs, callbackInfo.m_args); } catch (InvocationTargetException e) { m_component.getLogger().warn("Exception while invoking callback method", e.getCause()); } catch (Throwable e) { m_component.getLogger().warn("Exception while trying to invoke callback method", e); } throw new IllegalStateException("Could not invoke callback"); } else { return ServiceUtil.toR6Dictionary(bundle.getHeaders()); } } else { throw new IllegalStateException("cannot find bundle"); } }
return (Dictionary<String, Object>) InvocationUtil.invokeCallbackMethod(m_propagateCallbackInstance, m_propagateCallbackMethod, callbackInfo.m_sigs, callbackInfo.m_args); } catch (InvocationTargetException e) { m_component.getLogger().warn("Exception while invoking callback method", e.getCause()); } catch (Throwable e) { m_component.getLogger().warn("Exception while trying to invoke callback method", e);
/** * Triggers component activation when the future has completed. * @param result * @param error */ private void completed(F result, Throwable error) { if (error != null) { super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", error); } else { // Will trigger component activation (if other dependencies are satisfied), and our invokeCallback method will then be called. m_component.handleEvent(this, EventType.ADDED, new Event(result)); } }
private ConfigurationDependencyImpl createConfigurationDependency(Object service) { BundleContext bc = mock(BundleContext.class); Logger mockLogger = mock(Logger.class); ComponentContext component = mock(ComponentContext.class); when(component.getExecutor()).thenReturn(Executors.newSingleThreadExecutor()); when(component.getLogger()).thenReturn(mockLogger); ConfigurationDependencyImpl result = new ConfigurationDependencyImpl(bc, mockLogger); result.setCallback(service, "updated").setPid("does.not.matter"); result.setComponentContext(component); result.start(); return result; }
@Override public void start() { try { if (m_async) { if (m_exec != null) { m_future.whenCompleteAsync((result, error) -> completed(result, error), m_exec); } else { m_future.whenCompleteAsync((result, error) -> completed(result, error)); } } else { m_future.whenComplete((result, error) -> completed(result, error)); } } catch (Throwable error) { super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", error); } super.start(); }
super.getComponentContext().getLogger().log(LogService.LOG_ERROR, "completable future failed", exc);
@Override public Object addingService(@SuppressWarnings("rawtypes") ServiceReference reference) { try { ServiceEventImpl event = new ServiceEventImpl(m_component, reference, null); if (obtainServiceBeforeInjecting()) { Object service = event.getEvent(); // will dereference the service object. if (service == null) { // service concurrently removed, ignore return null; } } return event; } catch (IllegalStateException e) { // most likely our bundle is being stopped. Only log an exception if our component is enabled. if (m_component.isActive()) { m_component.getLogger().warn("could not handle service dependency for component %s", e, m_component.getComponentDeclaration().getClassName()); } return null; } }
m_component.getLogger().warn("could not handle service dependency for component %s", e, m_component.getComponentDeclaration().getClassName());
m_component.getLogger().err("Could not invoke swap callback", e);