log.warn("Ignoring request to create null service: ", new Exception("STACKTRACE"));
return;
}
log.debug("Creating service " + serviceName);
ServiceContext ctx = createServiceContext(serviceName);
// Register the context and its dependencies if necessary
register(ctx, depends);
// If we are already created (can happen in dependencies) or failed just return
if (ctx.state == ServiceContext.CREATED
|| ctx.state == ServiceContext.RUNNING
|| ctx.state == ServiceContext.FAILED)
{
log.debug("Ignoring create request for service: " + ctx.objectName);
return;
}
// JSR 77, and to avoid circular dependencies
int oldState = ctx.state;
ctx.state = ServiceContext.CREATED;
// Are all the mbeans I depend on created? if not just return
for (Iterator iterator = ctx.iDependOn.iterator(); iterator.hasNext();)
{
ServiceContext sc = (ServiceContext) iterator.next();
int state = sc.state;
// A dependent is not created or running
if (!(state == ServiceContext.CREATED || state == ServiceContext.RUNNING))
{
log.debug("waiting in create of " + serviceName +
" waiting on " + sc.objectName);
ctx.state = oldState;
return;
}
}
// Call create on the service Proxy
try
{
ctx.proxy.create();
sendControllerNotification(ServiceMBean.CREATE_EVENT, serviceName);
}
catch (Throwable e)
{
ctx.state = ServiceContext.FAILED;
ctx.problem = e;
log.warn("Problem creating service " + serviceName, e);
return;
}
// Those that depend on me are waiting for my creation, recursively create them
log.debug("Creating dependent components for: " + serviceName
+ " dependents are: " + ctx.dependsOnMe);
ArrayList<ServiceContext> tmp = new ArrayList<ServiceContext>(ctx.dependsOnMe);
for (int n = 0; n < tmp.size(); n++)
{
// marcf fixme circular dependencies?
ServiceContext ctx2 = tmp.get(n);
create(ctx2.objectName);
}
tmp.clear();
}