Skip to content
Snippets Groups Projects
Commit 2f31fa20 authored by BIGARET Sebastien's avatar BIGARET Sebastien
Browse files

Removed inner class, everything is handled by the main class.

parent 88884200
No related branches found
No related tags found
No related merge requests found
......@@ -24,38 +24,41 @@ import eu.telecom_bretagne.praxis.core.execution.Result;
import eu.telecom_bretagne.praxis.core.workflow.WorkflowID;
import eu.telecom_bretagne.praxis.server.execution.platform.WorkflowExecutionEngine;
/**
* @author Sébastien Bigaret
*
*/
public class PlatformToClientBridge
{
/**
* This platform forwards the request of its "downstream" server {@code Sd} to a client connected to another,
* "upstream", server {@code Su}. It collaborates with a {@link WorkflowExecutionEngine} to execute workflows
* directly. It also registers itself as a listener of messages sent by the server {@code Su} and takes care of
* forwarding the execution results to its server {@code Sd}.
* @author Sébastien Bigaret
*
*/
public static class Platform extends AbstractPlatform implements ServerToClientEventListener
public class PlatformToClientBridge extends AbstractPlatform implements ServerToClientEventListener
{
protected Client client;
protected HashMap<WorkflowID, WorkflowID> originalWorkflowIDs = new HashMap<WorkflowID, WorkflowID>();
public static Platform launchPlatform(Client client, Document configuration, String[] connection) throws IOException
public PlatformToClientBridge(CommunicationFacade cnx, Document configuration, String[] client_connection)
throws IOException
{
CommunicationFacade cnx = CommunicationFacade.buildConnection("Platform", connection);
cnx.start();
Platform p = new Platform(client, cnx, configuration);
return p;
super(cnx, configuration);
this.client = new Client();
launchClient(client_connection);
}
public Platform(Client client, CommunicationFacade cnx, Document configuration)
protected void launchClient(String[] connection) throws IOException
{
super(cnx, configuration);
this.client = client;
if ( ! Environment.useLooseCredentials() )
{
Log.log.warning("CSLC unset, cannot start client in bridge");
throw new IOException("Cannot start the client in the bridge");
}
String login = PraxisPreferences.get("client", Environment.getLooseCredentialsConfigurationName());
client.initConnection(connection);
client.getConnection().addListener(this);
client.connectAndWaitAnswer(login, login, false);
}
@Override
public void receivedAuthentificationStatus(ServerToClientEvent event)
{
......@@ -127,64 +130,31 @@ public class PlatformToClientBridge
originalWorkflowIDs.put(executionEngine.getResult().workflowID(), executionEngine.getOriginalWorkflowID());
client.requestExecution(executionEngine.getResult());
}
}
private Platform platform;
private RemoteComponents remoteComponents;
/**
*
* @param downStream
* @param upStream
*/
public PlatformToClientBridge(String id, String[] downStream, String[] upStream) throws IOException
{
Client client = new Client();
launchPlatform(client, id, upStream);
launchClient(client, downStream);
}
protected void launchPlatform(Client client, String id, String[] upStream) throws IOException
{
Document conf;
conf = AbstractPlatform.initConfiguration(Configuration.get("platform."+id));
/* Retrieve the resources declared on the upStream server, and declare them as our resources */
remoteComponents = new RemoteComponents(upStream[0], upStream[1], Integer.parseInt(upStream[2])); // TODO NumberFormatException
remoteComponents.init();
Element programs = conf.getRootElement().getChild("programs");
for (String resource: remoteComponents.getResourceRepository().getResources())
programs.addContent(new Element("program").setAttribute("id", resource));
platform = Platform.launchPlatform(client, conf, upStream);
}
protected void launchClient(Client client, String[] connection) throws IOException
{
if ( ! Environment.useLooseCredentials() )
{
Log.log.warning("CSLC unset, cannot start client in bridge");
throw new IOException("Cannot start the client in the bridge");
}
String login = PraxisPreferences.get("client", Environment.getLooseCredentialsConfigurationName());
client.initConnection(connection);
client.getConnection().addListener(platform);
client.connectAndWaitAnswer(login, login, false);
}
public static void launch() throws IOException
{
// Get the bridge to launch...
String bridge_id = Configuration.get("bridge");
// ...and the appropriate connection
// ...and the appropriate connections
String[] platform_conn = Utile.serverForString(Configuration.get("bridge.platform.connection"));
String[] client_conn = Utile.serverForString(Configuration.get("bridge.client.connection"));
if ("".equals(bridge_id))
return;
new PlatformToClientBridge(bridge_id, client_conn, platform_conn);
Document conf;
conf = AbstractPlatform.initConfiguration(Configuration.get("platform."+bridge_id));
/* Retrieve the resources declared on the upStream server, and declare them as our resources */
RemoteComponents remoteComponents = new RemoteComponents(platform_conn[0], platform_conn[1], Integer.parseInt(platform_conn[2])); // TODO NumberFormatException
remoteComponents.init();
Element programs = conf.getRootElement().getChild("programs");
for (String resource: remoteComponents.getResourceRepository().getResources())
programs.addContent(new Element("program").setAttribute("id", resource));
CommunicationFacade cnx = CommunicationFacade.buildConnection("Platform", platform_conn);
cnx.start();
new PlatformToClientBridge(cnx, conf, client_conn);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment