reducing complexity
This commit is contained in:
parent
267ab69ff8
commit
a2d8296382
|
@ -43,8 +43,6 @@ public class IoUtil {
|
||||||
static void sendCommand(String command, int retryTimeoutMs, int totalTimeoutSeconds) {
|
static void sendCommand(String command, int retryTimeoutMs, int totalTimeoutSeconds) {
|
||||||
final CountDownLatch responseLatch = new CountDownLatch(1);
|
final CountDownLatch responseLatch = new CountDownLatch(1);
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (LinkManager.hasError())
|
|
||||||
throw new IllegalStateException("IO error");
|
|
||||||
FileLog.MAIN.logLine("Sending command [" + command + "]");
|
FileLog.MAIN.logLine("Sending command [" + command + "]");
|
||||||
final long begin = System.currentTimeMillis();
|
final long begin = System.currentTimeMillis();
|
||||||
CommandQueue.getInstance().write(command, retryTimeoutMs, new InvocationConfirmationListener() {
|
CommandQueue.getInstance().write(command, retryTimeoutMs, new InvocationConfirmationListener() {
|
||||||
|
@ -57,8 +55,6 @@ public class IoUtil {
|
||||||
wait(responseLatch, totalTimeoutSeconds);
|
wait(responseLatch, totalTimeoutSeconds);
|
||||||
if (responseLatch.getCount() > 0)
|
if (responseLatch.getCount() > 0)
|
||||||
FileLog.MAIN.logLine("No confirmation in " + retryTimeoutMs);
|
FileLog.MAIN.logLine("No confirmation in " + retryTimeoutMs);
|
||||||
if (LinkManager.hasError())
|
|
||||||
throw new IllegalStateException("IO error");
|
|
||||||
FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time));
|
FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,13 @@ public interface LinkConnector extends LinkDecoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(String command, boolean fireEvent) throws InterruptedException {
|
public void send(String command, boolean fireEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restart() {
|
public void restart() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasError() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String unpack(String packet) {
|
public String unpack(String packet) {
|
||||||
return LinkDecoder.TEXT_PROTOCOL_DECODER.unpack(packet);
|
return LinkDecoder.TEXT_PROTOCOL_DECODER.unpack(packet);
|
||||||
|
@ -35,5 +30,4 @@ public interface LinkConnector extends LinkDecoder {
|
||||||
|
|
||||||
void restart();
|
void restart();
|
||||||
|
|
||||||
boolean hasError();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,10 +162,6 @@ public class LinkManager {
|
||||||
return connector.unpack(packet);
|
return connector.unpack(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasError() {
|
|
||||||
return connector.hasError();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String unpackConfirmation(String message) {
|
public static String unpackConfirmation(String message) {
|
||||||
if (message.startsWith(CommandQueue.CONFIRMATION_PREFIX))
|
if (message.startsWith(CommandQueue.CONFIRMATION_PREFIX))
|
||||||
return message.substring(CommandQueue.CONFIRMATION_PREFIX.length());
|
return message.substring(CommandQueue.CONFIRMATION_PREFIX.length());
|
||||||
|
|
|
@ -23,12 +23,11 @@ public class PortHolder {
|
||||||
private static final DataListener dataListener = freshData -> LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
private static final DataListener dataListener = freshData -> LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||||
|
|
||||||
public ConnectionStateListener listener;
|
public ConnectionStateListener listener;
|
||||||
private static PortHolder instance = new PortHolder();
|
|
||||||
private final Object portLock = new Object();
|
private final Object portLock = new Object();
|
||||||
|
|
||||||
private BinaryProtocol bp;
|
private BinaryProtocol bp;
|
||||||
|
|
||||||
private PortHolder() {
|
protected PortHolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -88,8 +87,4 @@ public class PortHolder {
|
||||||
|
|
||||||
bp.doSend(command, fireEvent);
|
bp.doSend(command, fireEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PortHolder getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,29 @@ import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.LinkConnector;
|
import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.sun.corba.se.spi.activation.ServerHolder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrey Belomutskiy
|
* @author Andrey Belomutskiy
|
||||||
* 3/3/14
|
* 3/3/14
|
||||||
*/
|
*/
|
||||||
public class SerialConnector implements LinkConnector {
|
public class SerialConnector implements LinkConnector {
|
||||||
|
|
||||||
|
private final PortHolder portHolder = new PortHolder();
|
||||||
|
|
||||||
public SerialConnector(String serialPort) {
|
public SerialConnector(String serialPort) {
|
||||||
PortHolder.getInstance().port = serialPort;
|
portHolder.port = serialPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(ConnectionStateListener listener) {
|
public void connect(ConnectionStateListener listener) {
|
||||||
FileLog.MAIN.logLine("SerialConnector: connecting");
|
FileLog.MAIN.logLine("SerialConnector: connecting");
|
||||||
PortHolder.getInstance().listener = listener;
|
portHolder.listener = listener;
|
||||||
FileLog.MAIN.logLine("scheduleOpening");
|
FileLog.MAIN.logLine("scheduleOpening");
|
||||||
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
|
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FileLog.MAIN.logLine("scheduleOpening>openPort");
|
FileLog.MAIN.logLine("scheduleOpening>openPort");
|
||||||
PortHolder.getInstance().connectAndReadConfiguration();
|
portHolder.connectAndReadConfiguration();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -36,19 +38,12 @@ public class SerialConnector implements LinkConnector {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MessagesCentral.getInstance().postMessage(getClass(), "Restarting serial IO");
|
MessagesCentral.getInstance().postMessage(getClass(), "Restarting serial IO");
|
||||||
// if (closed)
|
portHolder.close();
|
||||||
// return;
|
portHolder.connectAndReadConfiguration();
|
||||||
PortHolder.getInstance().close();
|
|
||||||
PortHolder.getInstance().connectAndReadConfiguration();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasError() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String unpack(String packet) {
|
public String unpack(String packet) {
|
||||||
return packet;
|
return packet;
|
||||||
|
@ -56,6 +51,6 @@ public class SerialConnector implements LinkConnector {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(String text, boolean fireEvent) throws InterruptedException {
|
public void send(String text, boolean fireEvent) throws InterruptedException {
|
||||||
PortHolder.getInstance().packAndSend(text, fireEvent);
|
portHolder.packAndSend(text, fireEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,11 +132,6 @@ public class TcpConnector implements LinkConnector {
|
||||||
public void restart() {
|
public void restart() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasError() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String unpack(String packet) {
|
public String unpack(String packet) {
|
||||||
return packet;
|
return packet;
|
||||||
|
|
Loading…
Reference in New Issue