/** * Constructor. Only used for tests. */ public ComponentImpl() { this(null, null, new Logger(null)); }
private void logConfigurationException(Throwable err) { m_logger.log(Logger.LOG_ERROR, "Got exception while handling configuration update for pid " + m_pid, err); } }
public final void log(ServiceReference sr, int level, String msg, Throwable throwable) { _log(sr, level, msg, throwable); }
@Override public ComponentImpl setDebug(String debugKey) { // Force debug level in our logger m_logger.setEnabledLevel(LogService.LOG_DEBUG); m_logger.setDebugKey(debugKey); return this; }
private void error(Supplier<String> msg, Exception err) { if (m_logger != null) { m_logger.err("%s", err, msg.get()); } }
private void _log(ServiceReference sr, int level, String msg, Throwable throwable) { if (level <= m_enabledLevel) { StringBuilder sb = new StringBuilder("["); if (m_debugKey != null) { sb.append(m_debugKey).append(" - "); } sb.append(Thread.currentThread().getName()); sb.append("] "); sb.append(msg); // Save our own copy just in case it changes. We could try to do // more conservative locking here, but let's be optimistic. Object[] logger = m_logger; // Use the log service if available. if (logger != null) { _logReflectively(logger, sr, level, sb.toString(), throwable); } // Otherwise, default logging action. else { doLog(sr, level, sb.toString(), throwable); } } }
for (int i = 0 ; i < configTypes.length; i ++) { configurables[i] = settings != null ? Configurable.create(configTypes[i], settings, declaredServiceProperties) : null; logger.debug("Using configuration-type injecting using %s as possible configType.", configTypes[i].getSimpleName()); logger.warn("Failed to create configurable for configuration type %s!", e, configTypes != null ? Arrays.toString(configTypes) : null);
private void debug(Supplier<String> msg) { if (m_logger != null) { m_logger.debug("%s", msg.get()); } } }
@Override public String toString() { if (m_logger.getDebugKey() != null) { return m_logger.getDebugKey(); } return getClassName(); }
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; }
/** * Runs the state machine, to see if a change event has to trigger some component state transition. */ private void handleChange() { if (isHandlingChange()) { return; } m_logger.debug("handleChanged"); handlingChange(true); try { ComponentState oldState; ComponentState newState; do { oldState = m_state; newState = calculateNewState(oldState); m_logger.debug("%s -> %s", oldState, newState); m_state = newState; } while (performTransition(oldState, newState)); } finally { handlingChange(false); clearInvokeCallbackCache(); m_logger.debug("end handling change."); } }
/** * Runs a given task * @param task the task to execute */ private void runTask(Runnable task) { try { task.run(); } catch (Throwable t) { m_logger.log(LogService.LOG_ERROR, "Error processing tasks", t); } } }
m_logger.debug("instantiating component."); int ctorArgsUsed = -1; ctorArgsUsed = ci.m_ctorIndex; } catch (Exception e) { m_logger.log(Logger.LOG_ERROR, "Could not instantiate class " + m_componentDefinition, e); factory = ci.m_instance; } catch (Exception e) { m_logger.log(Logger.LOG_ERROR, "Could not create factory instance of class " + m_instanceFactory + ".", e); m_logger.log(Logger.LOG_ERROR, "Factory cannot be null."); } else { try { m_instanceFactoryCreateMethod, factoryArgs.m_sigs, factoryArgs.m_args, false); } catch (Exception e) { m_logger.log(Logger.LOG_ERROR, "Could not create service instance using factory " + factory + " method " + m_instanceFactoryCreateMethod + ".", e);
/** * Creates a new dependency manager. You need to supply the * <code>BundleContext</code> to be used by the dependency * manager to register services and communicate with the * framework. * * @param context the bundle context */ public DependencyManager(BundleContext context) { this(context, new Logger(context)); }
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 void startDependencies(List<DependencyContext> dependencies) { // Start first optional dependencies first. m_logger.debug("startDependencies."); List<DependencyContext> requiredDeps = new ArrayList<>(); for (DependencyContext d : dependencies) { if (d.isRequired()) { requiredDeps.add(d); continue; } if (d.needsInstance()) { instantiateComponent(); } d.start(); } // now, start required dependencies. for (DependencyContext d : requiredDeps) { if (d.needsInstance()) { instantiateComponent(); } d.start(); } }