Object[] services;
synchronized (this) {
services = m_services.toArray();
}
for (int i = 0; i < services.length; i++) {
DependencyService ds = (DependencyService) services[i];
if (makeAvailable) {
if (ds.isInstantiated() && isInstanceBound() && isRequired()) {
if (m_debug) {
m_logger.log(Logger.LOG_DEBUG, "[" + m_debugKey + "] invoke added: " + ref);
}
invokeAdded(ds, ref, service);
}
// The dependency callback will be deferred until all required dependency are available.
if (m_debug) {
m_logger.log(Logger.LOG_DEBUG, "[" + m_debugKey + "] dependency available: " + ref);
}
ds.dependencyAvailable(this); //**
if (!isRequired()) {
// For optional dependency, we always invoke callback, because at this point, we know
// that the service has been started, and the service start method has been called.
// (See the ServiceImpl.bindService method, which will activate optional dependencies using
// startTrackingOptional() method).
if (m_debug) {
m_logger.log(Logger.LOG_DEBUG, "[" + m_debugKey + "] invoke added: " + ref);
}
invokeAdded(ds, ref, service);
}
} else {
if (m_debug) {
m_logger.log(Logger.LOG_DEBUG, "[" + m_debugKey + "] dependency added (was available): " + ref);
}
// First, inject the added service in autoconfig field, if any.
ds.autoConfig(this);
// At this point, either the dependency is optional (meaning that the service has been started,
// because if not, then our dependency would not be active); or the dependency is required,
// meaning that either the service is not yet started, or already started.
// In all cases, we have to inject the required dependency.
// we only try to invoke the method here if we are really already instantiated
if (ds.isInstantiated() && ds.getCompositionInstances().length > 0) {
if (m_debug) {
m_logger.log(Logger.LOG_DEBUG, "[" + m_debugKey + "] invoke added: " + ref);
}
if (invokeAdded(ds, ref, service)) {
// Propagate (if needed) all "setPropagate" dependencies to the dependency service.
ds.propagate(this);
}
}
}
}
}