I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 13fd613b authored by zzz's avatar zzz
Browse files

more client test enhancements

parent 6b67a70b
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ public class SAMReader { ...@@ -20,6 +20,7 @@ public class SAMReader {
private final InputStream _inRaw; private final InputStream _inRaw;
private final SAMClientEventListener _listener; private final SAMClientEventListener _listener;
private volatile boolean _live; private volatile boolean _live;
private Thread _thread;
public SAMReader(I2PAppContext context, InputStream samIn, SAMClientEventListener listener) { public SAMReader(I2PAppContext context, InputStream samIn, SAMClientEventListener listener) {
_log = context.logManager().getLog(SAMReader.class); _log = context.logManager().getLog(SAMReader.class);
...@@ -27,13 +28,22 @@ public class SAMReader { ...@@ -27,13 +28,22 @@ public class SAMReader {
_listener = listener; _listener = listener;
} }
public void startReading() { public synchronized void startReading() {
if (_live)
throw new IllegalStateException();
_live = true; _live = true;
I2PAppThread t = new I2PAppThread(new Runner(), "SAM reader"); I2PAppThread t = new I2PAppThread(new Runner(), "SAM reader");
t.start(); t.start();
_thread = t;
} }
public void stopReading() { _live = false; } public synchronized void stopReading() {
_live = false;
if (_thread != null) {
_thread.interrupt();
_thread = null;
}
}
/** /**
* Async event notification interface for SAM clients * Async event notification interface for SAM clients
...@@ -89,10 +99,11 @@ public class SAMReader { ...@@ -89,10 +99,11 @@ public class SAMReader {
} }
if (c == -1) { if (c == -1) {
_log.error("Error reading from the SAM bridge"); _log.error("Error reading from the SAM bridge");
return; break;
} }
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Error reading from SAM", ioe); _log.error("Error reading from SAM", ioe);
break;
} }
String line = new String(baos.toByteArray()); String line = new String(baos.toByteArray());
...@@ -103,14 +114,15 @@ public class SAMReader { ...@@ -103,14 +114,15 @@ public class SAMReader {
break; break;
} }
_log.debug("Line read from the bridge: " + line); if (_log.shouldDebug())
_log.debug("Line read from the bridge: " + line);
StringTokenizer tok = new StringTokenizer(line); StringTokenizer tok = new StringTokenizer(line);
if (tok.countTokens() < 2) { if (tok.countTokens() < 2) {
_log.error("Invalid SAM line: [" + line + "]"); _log.error("Invalid SAM line: [" + line + "]");
_live = false; _live = false;
return; break;
} }
String major = tok.nextToken(); String major = tok.nextToken();
...@@ -133,6 +145,8 @@ public class SAMReader { ...@@ -133,6 +145,8 @@ public class SAMReader {
processEvent(major, minor, params); processEvent(major, minor, params);
} }
if (_log.shouldWarn())
_log.warn("SAMReader exiting");
} }
} }
......
...@@ -263,6 +263,11 @@ public class SAMStreamSend { ...@@ -263,6 +263,11 @@ public class SAMStreamSend {
} }
closed(); closed();
if (_log.shouldLog(Log.DEBUG))
_log.debug("Runner exiting");
// stop the reader, since we're only doing this once for testing
// you wouldn't do this in a real application
_reader.stopReading();
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment