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