return;
}
log.debug("starting service " + serviceName);
ServiceContext ctx = createServiceContext(serviceName);
if (!installedServices.contains(ctx))
installedServices.add(ctx);
// If we are already started (can happen in dependencies) just return
if (ctx.state == ServiceContext.RUNNING || ctx.state == ServiceContext.FAILED)
{
log.debug("Ignoring start request for service: " + ctx.objectName);
return;
}
// Start() is called before create(), so call create() to compensate
if (ctx.state != ServiceContext.CREATED && ctx.state != ServiceContext.STOPPED)
{
log.debug("Start requested before create, calling create now for service: " + serviceName);
create(serviceName);
}
// Get the fancy service proxy (for the lifecycle API)
if (ctx.proxy == null)
ctx.proxy = getServiceProxy(ctx.objectName, null);
// JSR 77, and to avoid circular dependencies
int oldState = ctx.state;
ctx.state = ServiceContext.RUNNING;
// Are all the mbeans I depend on started? if not just return
for (Iterator iterator = ctx.iDependOn.iterator(); iterator.hasNext();)
{
ServiceContext sctx = (ServiceContext) iterator.next();
int state = sctx.state;
// A dependent is not running
if (!(state == ServiceContext.RUNNING))
{
log.debug("waiting in start " + serviceName + " on " + sctx.objectName);
ctx.state = oldState;
return;
}
}
// Call start on the service Proxy
try
{
ctx.proxy.start();
sendControllerNotification(ServiceMBean.START_EVENT, serviceName);
}
catch (Throwable e)
{
ctx.state = ServiceContext.FAILED;
ctx.problem = e;
log.warn("Problem starting service " + serviceName, e);
return;
}
// Those that depend on me are waiting for my start, recursively start them
log.debug("Starting dependent components for: " + serviceName
+ " dependent components: " + 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);
start(ctx2.objectName);
}
tmp.clear();
}