if (myContainer == null || !myContainer.isJoined()) {
initProfile();
myContainer = Runtime.instance().createAgentContainer(profile);
if (myContainer == null) {
throw new ControllerException("JADE startup failed.");
}
}
if (myAgent == null) {
try {
Agent a = (Agent) Class.forName(agentType).newInstance();
if (a instanceof GatewayAgent) {
//#DOTNET_EXCLUDE_BEGIN
((GatewayAgent) a).setListener(new GatewayListenerImpl());
//#DOTNET_EXCLUDE_END
// We are able to detect the GatewayAgent state only if the internal agent is a GatewayAgent instance
gatewayAgentState = NOT_ACTIVE;
}
a.setArguments(agentArguments);
myAgent = myContainer.acceptNewAgent("Control"+myContainer.getContainerName(), a);
if (gatewayAgentState == NOT_ACTIVE) {
// Set the ACTIVE state synchronously so that when checkJADE() completes isGatewayActive() certainly returns true
gatewayAgentState = ACTIVE;
}
myAgent.start();
}
catch (StaleProxyException spe) {
// Just let it through
throw spe;
}
catch (Exception e) {
throw new ControllerException("Error creating GatewayAgent [" + e + "]");
}
}
}