only: binaryProtocolLogger change, isClose change
This commit is contained in:
parent
94181dd2f3
commit
c3635f7c8d
|
@ -112,6 +112,7 @@ public class BinaryProtocol {
|
|||
communicationLoggingListener = linkManager.messageListener::postMessage;
|
||||
|
||||
binaryProtocolLogger = new BinaryProtocolLogger(linkManager);
|
||||
stream.addCloseListener(binaryProtocolLogger::close);
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
|
@ -503,9 +504,6 @@ public class BinaryProtocol {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
if (stream.isClosed())
|
||||
return;
|
||||
binaryProtocolLogger.close();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ public interface IoStream extends WriteStream, Closeable, StreamStatistics {
|
|||
|
||||
long latestActivityTime();
|
||||
|
||||
void addCloseListener(Runnable listener);
|
||||
|
||||
Object getIoLock();
|
||||
|
||||
void onActivity();
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
|||
import com.rusefi.io.IoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class AbstractIoStream implements IoStream {
|
||||
|
@ -15,6 +16,7 @@ public abstract class AbstractIoStream implements IoStream {
|
|||
protected final StreamStats streamStats = new StreamStats();
|
||||
private final AtomicInteger bytesOut = new AtomicInteger();
|
||||
private long latestActivity;
|
||||
private final CopyOnWriteArrayList<Runnable> closeListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public IncomingDataBuffer createDataBuffer() {
|
||||
IncomingDataBuffer incomingData = new IncomingDataBuffer(getClass().getSimpleName(), getStreamStats());
|
||||
|
@ -29,7 +31,16 @@ public abstract class AbstractIoStream implements IoStream {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
if (isClosed)
|
||||
return;
|
||||
isClosed = true;
|
||||
for (Runnable listener : closeListeners)
|
||||
listener.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCloseListener(Runnable listener) {
|
||||
closeListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.devexperts.logging.Logging;
|
|||
import com.fazecast.jSerialComm.SerialPort;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.io.IoStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
@ -21,7 +22,7 @@ public class BufferedSerialIoStream extends SerialIoStream {
|
|||
/**
|
||||
* @see #openPort(String)
|
||||
*/
|
||||
private BufferedSerialIoStream(SerialPort sp, String port) {
|
||||
private BufferedSerialIoStream(@NotNull SerialPort sp, String port) {
|
||||
super(sp, port);
|
||||
dataBuffer = createDataBuffer();
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ import com.rusefi.NamedThreadFactory;
|
|||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.binaryprotocol.test.Bug3923;
|
||||
import com.rusefi.io.IoStream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
|
@ -30,7 +32,7 @@ public abstract class SerialIoStream extends AbstractIoStream {
|
|||
SerialPortThreadFactory.set(new NamedThreadFactory("ECU SerialIoStream jSerialComm"));
|
||||
}
|
||||
|
||||
public SerialIoStream(@Nullable SerialPort sp, String port) {
|
||||
public SerialIoStream(@NotNull SerialPort sp, String port) {
|
||||
this.sp = sp;
|
||||
this.port = port;
|
||||
}
|
||||
|
@ -50,10 +52,11 @@ public abstract class SerialIoStream extends AbstractIoStream {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
if (isClosed())
|
||||
return;
|
||||
log.info(port + ": Closing port...");
|
||||
super.close();
|
||||
if (sp != null)
|
||||
sp.closePort();
|
||||
sp.closePort();
|
||||
log.info(port + ": Closed port.");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue