Skip to content

Commit 223adea

Browse files
committed
about implementing closed channels and introducing concept of asap management storage
1 parent f4302f3 commit 223adea

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void setupFolderMap() throws IOException, ASAPException {
5959
this.folderMap = new HashMap<>();
6060
File rootFolder = new File(rootFolderName.toString());
6161

62-
System.out.println(this.getLogStart() + "iterate subfolder in " + this.rootFolderName);
62+
System.out.println(this.getLogStart() + "setting up ASAPEngine based on subfolders in " + this.rootFolderName);
6363
File[] files = rootFolder.listFiles();
6464
for (File file : files) {
6565
if (file.isDirectory()) {
@@ -342,29 +342,33 @@ public ASAPConnection getASAPConnection(CharSequence recipient) {
342342
public void pushInterests(OutputStream os) throws IOException, ASAPException {
343343
ASAP_1_0 protocol = new ASAP_Modem_Impl();
344344

345+
System.out.println(this.getLogStart() + "start sending interest for each engine");
345346
// issue an interest for each owner / format combination
346347
for(CharSequence format : this.folderMap.keySet()) {
348+
System.out.println(this.getLogStart() + "send interest for app/format: " + format);
347349
protocol.interest(this.owner, null, format,null, -1, -1, os, false);
348350
}
349351
}
350352

351-
public void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
352-
InputStream is) throws ASAPException, IOException {
353+
public boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
354+
InputStream is) throws ASAPException, IOException {
353355

354356
StringBuilder b = new StringBuilder();
355357
b.append(this.getLogStart());
356358
b.append("start processing asap management pdu");
357359
System.out.println(b.toString());
358360

361+
System.out.println(this.getLogStart() + asapPDU);
362+
359363
ASAP_AssimilationPDU_1_0 asap_assimilationPDU_1_0 = null;
360364
if(asapPDU instanceof ASAP_AssimilationPDU_1_0) {
361365
asap_assimilationPDU_1_0 = (ASAP_AssimilationPDU_1_0) asapPDU;
362366
} else {
363367
b = new StringBuilder();
364368
b.append(this.getLogStart());
365-
b.append("asap management pdu must be within an assimilate message - got another one / nothing todo");
369+
b.append("asap management pdu not an assimilate message - let ordinary engine to the job");
366370
System.out.println(b.toString());
367-
return;
371+
return false;
368372
}
369373

370374
CharSequence owner = asapPDU.getPeer();
@@ -412,17 +416,18 @@ public void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
412416
}
413417
}
414418
// ok it the same
415-
return;
419+
return false;
416420
} else {
417421
throw new ASAPException("channel already exists but with different settings");
418422
}
419423
}
420424

421425
// else - channel does not exist - create by setting recipients
422426
asapStorage.createChannel(channelUri, recipients);
427+
return false;
423428
}
424429

425430
private String getLogStart() {
426-
return this.getClass().getSimpleName() + ": ";
431+
return this.getClass().getSimpleName() + "(" + this.getOwner() + "): ";
427432
}
428433
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public interface ASAPManagementProtocolEngine {
1313
* @param is inputstream
1414
* @throws ASAPException
1515
* @throws IOException
16+
* @return true if that pdu was fully executed and no further processing is required
1617
*/
17-
void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
18-
InputStream is) throws ASAPException, IOException;
18+
boolean handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
19+
InputStream is) throws ASAPException, IOException;
1920
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,27 @@ public void run() {
225225
if(asappdu != null) {
226226
System.out.println(this.getLogStart() + "read valid pdu");
227227
this.setRemotePeer(asappdu.getPeer());
228-
// process received pdu
229228

229+
// process received pdu
230+
boolean pduExecuted = false;
230231
if(asappdu.getFormat().equalsIgnoreCase(ASAP_1_0.ASAP_MANAGEMENT_FORMAT)) {
231232
System.out.println(this.getLogStart()
232-
+ "got asap management message - let multiengine handle this one");
233+
+ "got asap management message - let multi-engine handle this one");
233234

234235
try {
235-
this.multiASAPEngineFS.handleASAPManagementPDU(asappdu, protocol, is);
236+
// if return true - message was handled. No further actions required
237+
pduExecuted = this.multiASAPEngineFS.handleASAPManagementPDU(asappdu, protocol, is);
236238
} catch (ASAPException e) {
237239
System.err.println("asap management pdu processing failed - go ahead in read/process loop"
238240
+ e.getLocalizedMessage());
241+
pduExecuted = false; // failed to execute - forget and go ahead
239242
} catch (IOException e) {
240243
this.terminate("asap management pdu processing failed", e);
241244
break;
242245
}
243-
} else {
246+
}
247+
248+
if(!pduExecuted) { // not (completely executed by multi engine
244249
try {
245250
this.executor = new ASAPPDUExecutor(asappdu,
246251
this.is, this.os,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ abstract class PDU_Impl implements ASAP_PDU_1_0{
3838
this.cmd = cmd;
3939
}
4040

41+
public String toString() {
42+
StringBuilder sb = new StringBuilder();
43+
44+
sb.append("cmd: ");
45+
switch(cmd) {
46+
case ASAP_1_0.INTEREST_CMD: sb.append("I"); break;
47+
case ASAP_1_0.OFFER_CMD: sb.append("O"); break;
48+
case ASAP_1_0.ASSIMILATE_CMD: sb.append("A"); break;
49+
}
50+
sb.append(" | sender: "); if(peerSet) sb.append(this.peer); else sb.append("X");
51+
sb.append(" | format: "); sb.append(format);
52+
sb.append(" | channel: "); if(channelSet) sb.append(this.channel); else sb.append("X");
53+
sb.append(" | era: "); if(eraSet) sb.append(era); else sb.append("X");
54+
55+
return sb.toString();
56+
}
57+
4158
protected static void sendHeader(byte cmd, int flags, OutputStream os) throws IOException {
4259
PDU_Impl.sendByteParameter(cmd, os); // mand
4360
PDU_Impl.sendByteParameter((byte)flags, os); // mand

0 commit comments

Comments
 (0)