Skip to content

Commit 2959660

Browse files
committed
start working on an asap management protocol
1 parent 6d916c3 commit 2959660

File tree

5 files changed

+64
-23
lines changed

5 files changed

+64
-23
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package net.sharksystem.asap;
22

3-
import net.sharksystem.asap.protocol.ASAPConnection;
4-
import net.sharksystem.asap.protocol.ASAPConnectionListener;
5-
import net.sharksystem.asap.protocol.ASAP_PDU_1_0;
6-
import net.sharksystem.asap.protocol.ThreadFinishedListener;
3+
import net.sharksystem.asap.protocol.*;
74

85
import java.io.IOException;
96
import java.io.InputStream;
@@ -22,7 +19,7 @@
2219
*
2320
* That interface hides those different engines.
2421
*/
25-
public interface MultiASAPEngineFS {
22+
public interface MultiASAPEngineFS extends ASAPManagementProtocolEngine {
2623
public static final long DEFAULT_MAX_PROCESSING_TIME = Long.MAX_VALUE;
2724

2825
public ASAPEngine getEngineByFormat(CharSequence format) throws ASAPException, IOException;

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,53 @@ public void pushInterests(OutputStream os) throws IOException, ASAPException {
348348
}
349349
}
350350

351-
public void handleASAPManagementPDU(ASAP_AssimilationPDU_1_0 asapPDU, ASAP_1_0 protocol,
352-
InputStream is, OutputStream os) throws ASAPException, IOException {
351+
public void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
352+
InputStream is) throws ASAPException, IOException {
353353

354354
StringBuilder b = new StringBuilder();
355355
b.append(this.getLogStart());
356356
b.append("start processing asap management pdu");
357357
System.out.println(b.toString());
358-
//>>>>>>>>>>>>>>>>>>>debug
358+
359+
ASAP_AssimilationPDU_1_0 asap_assimilationPDU_1_0 = null;
360+
if(asapPDU instanceof ASAP_AssimilationPDU_1_0) {
361+
asap_assimilationPDU_1_0 = (ASAP_AssimilationPDU_1_0) asapPDU;
362+
} else {
363+
b = new StringBuilder();
364+
b.append(this.getLogStart());
365+
b.append("asap management pdu must be within an assimilate message - got another one / nothing todo");
366+
System.out.println(b.toString());
367+
return;
368+
}
359369

360370
ASAPManagementCreateASAPStoragePDU asapManagementPDU =
361-
ASAPManagementProtocolPDU_Impl.parseASAPPDU(asapPDU);
371+
ASAPManagementProtocolPDU_Impl.parseASAPPDU(asap_assimilationPDU_1_0);
372+
373+
CharSequence channelUri = asapManagementPDU.getChannelUri();
374+
CharSequence format = asapManagementPDU.getFormat();
375+
CharSequence owner = asapManagementPDU.getOwner();
376+
List<CharSequence> recipients = asapManagementPDU.getRecipients();
362377

378+
b = new StringBuilder();
379+
b.append(this.getLogStart());
380+
b.append("owner: ");
381+
b.append(owner);
382+
b.append(" | format: ");
383+
b.append(format);
384+
b.append(" | channelUri: ");
385+
b.append(channelUri);
386+
b.append(" | #recipients: ");
387+
b.append(recipients.size());
388+
System.out.println(b.toString());
389+
390+
// find storage
391+
ASAPStorage asapStorage = this.getEngineByFormat(format);
363392

393+
b = new StringBuilder();
394+
b.append(this.getLogStart());
395+
b.append("Implementation not yet finished - TODO");
396+
b.append(recipients.size());
397+
System.out.println(b.toString());
364398
}
365399

366400
private String getLogStart() {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package net.sharksystem.asap.protocol;
22

3-
import net.sharksystem.asap.ASAPChunkReceivedListener;
43
import net.sharksystem.asap.ASAPException;
54

65
import java.io.IOException;
76
import java.io.InputStream;
8-
import java.io.OutputStream;
97

108
public interface ASAPManagementProtocolEngine {
119
/**
1210
* handle asap management pdu
1311
* @param asapPDU received pdu
1412
* @param protocol protocol engine
1513
* @param is inputstream
16-
* @param os outputstream - to send data back
1714
* @throws ASAPException
1815
* @throws IOException
1916
*/
20-
void handleASAPManagementPDU(ASAP_AssimilationPDU_1_0 asapPDU, ASAP_1_0 protocol,
21-
InputStream is, OutputStream os) throws ASAPException, IOException;
17+
void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
18+
InputStream is) throws ASAPException, IOException;
2219
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,16 @@ public void run() {
227227
this.setRemotePeer(asappdu.getPeer());
228228
// process received pdu
229229

230-
if(asappdu.getFormat().equalsIgnoreCase(ASAP_1_0.ASAP_MANAGEMENT_FORMAT.toString())) {
230+
if(asappdu.getFormat().equalsIgnoreCase(ASAP_1_0.ASAP_MANAGEMENT_FORMAT)) {
231231
System.out.println(this.getLogStart()
232-
+ "got asap management message - not processed, took remote peer name only");
232+
+ "got asap management message - let multiengine handle this one");
233+
234+
try {
235+
this.multiASAPEngineFS.handleASAPManagementPDU(asappdu, protocol, is);
236+
} catch (ASAPException | IOException e) {
237+
this.terminate("asap management pdu processing failed", e);
238+
break;
239+
}
233240
} else {
234241
try {
235242
this.executor = new ASAPPDUExecutor(asappdu,

test/net/sharksystem/asap/Point2PointTests.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
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";
23-
public static final String ALICE_ROOT_FOLDER = "tests/alice";
23+
public static final String ALICE_ROOT_FOLDER = "tests/Alice";
2424
public static final String ALICE_APP_FOLDER = ALICE_ROOT_FOLDER + "/appFolder";
25-
public static final String BOB_ROOT_FOLDER = "tests/bob";
25+
public static final String BOB_ROOT_FOLDER = "tests/Bob";
2626
public static final String BOB_APP_FOLDER = BOB_ROOT_FOLDER + "/appFolder";
27-
public static final String ALICE = "alice";
28-
public static final String BOB = "bob";
27+
public static final String ALICE = "Alice";
28+
public static final String BOB = "Bob";
2929
public static final String ALICE2BOB_MESSAGE = "Hi Bob";
3030
public static final String ALICE2BOB_MESSAGE2 = "Hi Bob again";
3131
public static final String BOB2ALICE_MESSAGE = "Hi Alice";
@@ -105,7 +105,7 @@ public void openMessageExchange() throws IOException, ASAPException, Interrupted
105105
// wait until communication probably ends
106106
System.out.flush();
107107
System.err.flush();
108-
Thread.sleep(5000);
108+
Thread.sleep(2000);
109109
System.out.flush();
110110
System.err.flush();
111111

@@ -169,6 +169,8 @@ public void openMessageExchange() throws IOException, ASAPException, Interrupted
169169
// simulate a sync
170170
bobStorage = ASAPEngineFS.getASAPStorage(BOB, BOB_APP_FOLDER, CHAT_FORMAT);
171171
Assert.assertEquals(2, bobStorage.getEra());
172+
173+
Thread.sleep(1000);
172174
}
173175

174176
@Test
@@ -240,7 +242,7 @@ public void notOpenMessageChunkExchange() throws IOException, ASAPException, Int
240242
// wait until communication probably ends
241243
System.out.flush();
242244
System.err.flush();
243-
Thread.sleep(5000);
245+
Thread.sleep(2000);
244246
System.out.flush();
245247
System.err.flush();
246248

@@ -304,6 +306,8 @@ public void notOpenMessageChunkExchange() throws IOException, ASAPException, Int
304306
// simulate a sync
305307
bobStorage = ASAPEngineFS.getASAPStorage(BOB, BOB_APP_FOLDER, CHAT_FORMAT);
306308
Assert.assertEquals(2, bobStorage.getEra());
309+
310+
Thread.sleep(1000);
307311
}
308312

309313
@Test
@@ -392,7 +396,7 @@ public void usageWithImmediateSync() throws IOException, ASAPException, Interrup
392396
// wait until communication probably ends
393397
System.out.flush();
394398
System.err.flush();
395-
Thread.sleep(5000);
399+
Thread.sleep(2000);
396400
System.out.flush();
397401
System.err.flush();
398402

@@ -445,6 +449,8 @@ public void usageWithImmediateSync() throws IOException, ASAPException, Interrup
445449
bobReceivedMessages = bobReceivedChunk.getMessages();
446450
bobReceivedMessage = bobReceivedMessages.next();
447451
Assert.assertEquals(ALICE2BOB_MESSAGE2, bobReceivedMessage);
452+
453+
Thread.sleep(1000);
448454
}
449455

450456
@Test

0 commit comments

Comments
 (0)