Skip to content

Commit 3d5eaf8

Browse files
committed
refactured pdu reader - made it inner class of persistent connection
1 parent a57963c commit 3d5eaf8

File tree

5 files changed

+52
-64
lines changed

5 files changed

+52
-64
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public interface MultiASAPEngineFS {
4747

4848
public void pushInterests(OutputStream os) throws IOException, ASAPException;
4949

50-
Thread getExecutorThread(ASAP_PDU_1_0 asappdu, InputStream is, OutputStream os,
51-
ThreadFinishedListener threadFinishedListener) throws ASAPException;
52-
5350
Set<CharSequence> getOnlinePeers();
5451

5552
boolean existASAPConnection(CharSequence recipient);

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ public void pushInterests(OutputStream os) throws IOException, ASAPException {
346346
protocol.interest(this.owner, null, format,null, -1, -1, os, false);
347347
}
348348
}
349-
350-
@Override
349+
/*
351350
public Thread getExecutorThread(ASAP_PDU_1_0 asappdu, InputStream is, OutputStream os,
352351
ThreadFinishedListener threadFinishedListener) throws ASAPException {
353352
// process pdu
354353
return new ASAPPersistentConnection.ASAPPDUExecutor(asappdu, is, os,
355354
this.getEngineSettings(asappdu.getFormat()),
356355
new ASAP_Modem_Impl(), threadFinishedListener);
357356
}
357+
*/
358358

359359
private String getLogStart() {
360360
return this.getClass().getSimpleName() + ": ";

src/net/sharksystem/asap/protocol/ASAPPDUReader.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/net/sharksystem/asap/protocol/ASAPPersistentConnection.java

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ private synchronized void checkRunningOnlineMessageSender() {
170170
}
171171
}
172172

173-
174173
public void run() {
175174
ASAP_1_0 protocol = new ASAP_Modem_Impl();
176175

@@ -231,13 +230,11 @@ public void run() {
231230
+ "got asap management message - not processed, took remote peer name only");
232231
} else {
233232
try {
234-
this.executor =
235-
new ASAPPDUExecutor(asappdu,
236-
this.is, this.os,
237-
this.multiASAPEngineFS.getEngineSettings(asappdu.getFormat()),
238-
new ASAP_Modem_Impl(),
239-
this);
240-
// this.multiASAPEngineFS.getExecutorThread(asappdu, this.is, this.os, this);
233+
this.executor = new ASAPPDUExecutor(asappdu,
234+
this.is, this.os,
235+
this.multiASAPEngineFS.getEngineSettings(asappdu.getFormat()),
236+
protocol,this);
237+
241238
// get exclusive access to streams
242239
System.out.println(this.startLog() + "asap pdu executor going to wait for stream access");
243240
this.wait4ExclusiveStreamsAccess();
@@ -339,7 +336,7 @@ private StringBuilder startLog() {
339336
return sb;
340337
}
341338

342-
public static class ASAPPDUExecutor extends Thread {
339+
private class ASAPPDUExecutor extends Thread {
343340
private final ASAP_PDU_1_0 asapPDU;
344341
private final InputStream is;
345342
private final OutputStream os;
@@ -418,4 +415,47 @@ public void run() {
418415
}
419416
}
420417
}
418+
419+
private class ASAPPDUReader extends Thread {
420+
private final ASAP_1_0 protocol;
421+
private final InputStream is;
422+
private final ThreadFinishedListener pduReaderListener;
423+
private ASAP_PDU_1_0 asapPDU = null;
424+
private IOException ioException = null;
425+
private ASAPException asapException = null;
426+
427+
ASAPPDUReader(ASAP_1_0 protocol, InputStream is, ThreadFinishedListener listener) {
428+
this.protocol = protocol;
429+
this.is = is;
430+
this.pduReaderListener = listener;
431+
}
432+
433+
IOException getIoException() {
434+
return this.ioException;
435+
}
436+
437+
ASAPException getAsapException() {
438+
return this.asapException;
439+
}
440+
441+
ASAP_PDU_1_0 getASAPPDU() {
442+
return this.asapPDU;
443+
}
444+
445+
public void run() {
446+
try {
447+
this.asapPDU = protocol.readPDU(is);
448+
// this.pduReaderListener.finished(this);
449+
} catch (IOException e) {
450+
this.ioException = e;
451+
} catch (ASAPException e) {
452+
this.asapException = e;
453+
}
454+
finally {
455+
if(this.pduReaderListener != null) {
456+
this.pduReaderListener.finished(this);
457+
}
458+
}
459+
}
460+
}
421461
}

test/net/sharksystem/asap/CommunicationTests.java renamed to test/net/sharksystem/asap/Point2PointTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Here are some basic tests and usage examples.
1818
* @author thsc
1919
*/
20-
public class CommunicationTests {
20+
public class Point2PointTests {
2121
public static final String ALICE_BOB_CHAT_URL = "content://aliceAndBob.talk";
2222
public static final String CHAT_FORMAT = "application/x-sn2-makan";
2323
public static final String ALICE_ROOT_FOLDER = "tests/alice";

0 commit comments

Comments
 (0)