parent
4ddf532166
commit
640aace20d
|
@ -10,10 +10,11 @@
|
|||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="jcip-annotations" level="project" />
|
||||
<orderEntry type="library" name="jSerialComm" level="project" />
|
||||
<orderEntry type="library" exported="" name="jSerialComm" level="project" />
|
||||
<orderEntry type="module" module-name="logging-api" exported="" />
|
||||
<orderEntry type="module" module-name="models" />
|
||||
<orderEntry type="module" module-name="models" exported="" />
|
||||
<orderEntry type="library" exported="" name="annotations" level="project" />
|
||||
<orderEntry type="module" module-name="inifile" />
|
||||
<orderEntry type="module" module-name="inifile" exported="" />
|
||||
<orderEntry type="library" exported="" name="javax.json" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -13,6 +13,5 @@
|
|||
<orderEntry type="library" exported="" name="httpclient" level="project" />
|
||||
<orderEntry type="library" exported="" name="annotations" level="project" />
|
||||
<orderEntry type="library" exported="" scope="TEST" name="junit" level="project" />
|
||||
<orderEntry type="library" name="javax.json" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -60,7 +60,7 @@ public class ServerTest {
|
|||
}
|
||||
};
|
||||
|
||||
backend.runControllerConnector(serverPort, serverCreated);
|
||||
backend.runControllerConnector(serverPort, parameter -> serverCreated.countDown());
|
||||
assertTrue(serverCreated.await(30, TimeUnit.SECONDS));
|
||||
assertEquals(0, backend.getCount());
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class ServerTest {
|
|||
};
|
||||
|
||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, applicationServerCreated);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
// start authenticator
|
||||
|
@ -123,7 +123,7 @@ public class ServerTest {
|
|||
};
|
||||
|
||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, applicationServerCreated);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
||||
|
@ -161,11 +161,13 @@ public class ServerTest {
|
|||
|
||||
// first start backend server
|
||||
CountDownLatch controllerServerCreated = new CountDownLatch(1);
|
||||
backend.runControllerConnector(serverPortForControllers, controllerServerCreated);
|
||||
assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, applicationServerCreated);
|
||||
|
||||
backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown());
|
||||
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||
|
||||
assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.Listener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||
|
@ -20,7 +21,6 @@ import javax.json.JsonObject;
|
|||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Backend {
|
||||
|
@ -71,7 +71,7 @@ public class Backend {
|
|||
}
|
||||
|
||||
|
||||
public void runApplicationConnector(int serverPortForApplications, CountDownLatch serverCreated) {
|
||||
public void runApplicationConnector(int serverPortForApplications, Listener serverSocketCreationCallback) {
|
||||
BinaryProtocolServer.tcpServerSocket(serverPortForApplications, "ApplicationServer", new Function<Socket, Runnable>() {
|
||||
@Override
|
||||
public Runnable apply(Socket applicationSocket) {
|
||||
|
@ -114,14 +114,14 @@ public class Backend {
|
|||
}
|
||||
};
|
||||
}
|
||||
}, logger, parameter -> serverCreated.countDown());
|
||||
}, logger, serverSocketCreationCallback);
|
||||
}
|
||||
|
||||
protected void onDisconnectApplication() {
|
||||
logger.info("Disconnecting application");
|
||||
}
|
||||
|
||||
public void runControllerConnector(int serverPortForControllers, CountDownLatch serverCreated) {
|
||||
public void runControllerConnector(int serverPortForControllers, Listener serverSocketCreationCallback) {
|
||||
BinaryProtocolServer.tcpServerSocket(serverPortForControllers, "ControllerServer", new Function<Socket, Runnable>() {
|
||||
@Override
|
||||
public Runnable apply(Socket controllerSocket) {
|
||||
|
@ -133,14 +133,15 @@ public class Backend {
|
|||
controllerConnectionState.requestControllerInfo();
|
||||
|
||||
register(controllerConnectionState);
|
||||
// controllerConnectionState.runEndlessLoop();
|
||||
|
||||
controllerConnectionState.getOutputs();
|
||||
} catch (IOException e) {
|
||||
close(controllerConnectionState);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}, logger, parameter -> serverCreated.countDown());
|
||||
}, logger, serverSocketCreationCallback);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -96,14 +96,18 @@ public class ControllerConnectionState {
|
|||
public void runEndlessLoop() throws IOException {
|
||||
|
||||
while (true) {
|
||||
byte[] commandPacket = GetOutputsCommand.createRequest();
|
||||
|
||||
stream.sendPacket(commandPacket, logger);
|
||||
|
||||
byte[] packet = incomingData.getPacket(logger, "msg", true);
|
||||
if (packet == null)
|
||||
throw new IOException("No response");
|
||||
getOutputs();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void getOutputs() throws IOException {
|
||||
byte[] commandPacket = GetOutputsCommand.createRequest();
|
||||
|
||||
stream.sendPacket(commandPacket, logger);
|
||||
|
||||
byte[] packet = incomingData.getPacket(logger, "msg", true);
|
||||
if (packet == null)
|
||||
throw new IOException("No response");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue