1 package eu.javaexperience.electronic.uartbus.rpc.client;
3 import java.io.Closeable;
4 import java.io.IOException;
20 protected static final Logger LOG = JavaExperienceLoggingFacility.getLogger(
new Loggable(
"UartbusStreamerEndpoint"));
22 protected SimpleGet<UartbusConnection> getConnection;
27 this.getConnection = getConnection;
32 if(null == workingConnection)
34 workingConnection = getConnection.get();
37 return workingConnection;
40 public void sendPacket(byte[] data)
44 getApi().sendPacket(data);
48 Mirror.propagateAnyway(e);
52 public void cleanupConncection()
54 workingConnection = null;
57 protected EventMediator<byte[]> packetStream =
new EventMediator<>();
59 public EventMediator<byte[]> getPacketStreamer()
64 protected Thread streamer;
65 protected volatile boolean runStreamer;
67 public synchronized void startStreaming()
71 WaitForEvents w =
new WaitForEvents(1);
72 WaitForEvents[] ws =
new WaitForEvents[] {w};
75 streamer =
new Thread()
92 LoggingTools.tryLogFormatException(LOG, LogLevel.FATAL, e,
"Exception occurred while getting connection for packet streaming (stopping): ");
109 data = conn.getNextPacket();
113 LoggingTools.tryLogFormatException(LOG, LogLevel.ERROR, e,
"Exception while receiving packet (continue): ");
114 cleanupConncection();
119 packetStream.dispatchEvent(data);
125 LoggingTools.tryLogFormatException(LOG, LogLevel.FATAL, e,
"Fatal exception occurred while packet streaming(stopping): ");
139 throw new RuntimeException(
"Packet streaming already running");
150 streamer.interrupt();
synchronized void close()