Skip to content

Commit

Permalink
Lazy creation of monitor connection
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
klausdorer committed Jun 20, 2020
1 parent 668fd24 commit e7ccd2a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions srcAgent/magma/fatproxy/impl/SimsparkAgentFatProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ public class SimsparkAgentFatProxyServer extends SimsparkAgentProxyServer implem
public SimsparkAgentFatProxyServer(SimsparkAgentProxyServerParameter parameterObject)
{
super(parameterObject);

try {
new MonitorThread().start();
Thread.sleep(1000);
if (monitor == null || !monitor.isConnected()) {
System.err.println("could not connect monitor port.");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}

/**
Expand All @@ -59,13 +49,29 @@ public SimsparkAgentFatProxyServer(SimsparkAgentProxyServerParameter parameterOb
* @return a new instance of agent proxy
*/
@Override
protected AgentProxy createAgentProxy(Socket clientSocket)
protected synchronized AgentProxy createAgentProxy(Socket clientSocket)
{
if (monitor == null || !monitor.isConnected()) {
startMonitor();
}
AgentProxy agentProxy = new AgentFatProxy(clientSocket, ssHost, ssPort, showMessages, monitor);
agentProxy.start(clientSocket, ssHost, ssPort, showMessages);
return agentProxy;
}

private void startMonitor()
{
try {
new MonitorThread().start();
Thread.sleep(1000);
if (monitor == null || !monitor.isConnected()) {
System.err.println("could not connect monitor port.");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}

private class MonitorThread extends Thread
{
@Override
Expand All @@ -77,6 +83,7 @@ public void run()
monitor.addRuntimeListener(SimsparkAgentFatProxyServer.this);
monitor.startMonitor();
} catch (ConnectionException e) {
e.printStackTrace();
}
}
}
Expand Down

0 comments on commit e7ccd2a

Please sign in to comment.