Skip to content

Commit

Permalink
made some refacturing and resume work on the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
thsc42 committed Feb 21, 2023
1 parent 94f7de9 commit 1987adc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/sharksystem/asap/ASAPPeerFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void chunkAssimilated(ASAPMessages receivedMessages, CharSequence format
}

sb = new StringBuilder();
sb.append("\n+++++++++++++++++++++++++++++++++++++++ chunkAssimilated +++++++++++++++++++++++++++++++++++++++++\n");
sb.append("\n+++++++++++++++++++++++++++++++++++++++ chunkReceived +++++++++++++++++++++++++++++++++++++++++\n");
sb.append("E2E|P2P: " + senderE2E + " | " + asapHopList.get(asapHopList.size()-1).sender() + " | uri: " + uri);
sb.append(" | era: ");
if(era == ASAP.TRANSIENT_ERA) sb.append("transient");
Expand Down
52 changes: 50 additions & 2 deletions src/main/java/net/sharksystem/asap/engine/ASAPEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,23 +470,71 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
//>>>>>>>>>>>>>>>>>>>debug

if(listener != null) {
/////// notify listeners - if any
/////// notify listeners - if any and do it in a separate thread
// no extra thread required - it is handled by ASAPPeer Wrapper
// NotifyListenerThread notifyListenerThread = new NotifyListenerThread(listener);
if(eraSender != ASAP.TRANSIENT_ERA) {
listener.chunkStored(this.format,
// notifyListenerThread.chunkStored(this.format,
listener.chunkStored(this.format,
senderE2E,
uri,
eraSender,
asapHopList
);
} else {
// notifyListenerThread.transientMessagesReceived(transientMessages, lastHop);
listener.transientMessagesReceived(transientMessages, lastHop);
}

} else {
Log.writeLog(this, this.toString(), "no chunk assimilated listener found");
}
}
/*
private class NotifyListenerThread extends Thread {
private final ASAPChunkAssimilatedListener listener;
private String format;
private String senderE2E;
private int eraSender;
private List<ASAPHop> asapHopList;
private ASAPInMemoTransientMessages transientMessages;
private ASAPHop lastHop;
private String uri;
private NotifyListenerThread(ASAPChunkAssimilatedListener listener) {
this.listener = listener;
}
public void chunkStored(String format, String senderE2E, String uri, int eraSender, List<ASAPHop> asapHopList) {
this.format = format;
this.senderE2E = senderE2E;
this.uri = uri;
this.eraSender = eraSender;
this.asapHopList = asapHopList;
this.start();
}
public void transientMessagesReceived(ASAPInMemoTransientMessages transientMessages, ASAPHop lastHop) {
this.transientMessages = transientMessages;
this.lastHop = lastHop;
this.start();
}
public void run() {
Log.writeLog(this, "thread notifies listener about received messages");
try {
if(this.transientMessages != null) {
this.listener.transientMessagesReceived(this.transientMessages, this.lastHop);
} else {
this.listener.chunkStored(this.format, this.senderE2E, this.uri, this.eraSender, this.asapHopList);
}
} catch (IOException e) {
Log.writeLogErr(this, "problems notifying listener about received messages: "
+ e.getLocalizedMessage());
}
}
}
*/
private ASAPInternalChunk getIncomingChunk(String encounteredPeer, ASAP_AssimilationPDU_1_0 asapAssimilationPDU)
throws IOException, ASAPException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ public ASAPInMemoTransientMessages(CharSequence format, CharSequence uri, CharSe
this.asapHop = asapHop;
}

private void checkStatus() throws IOException {
if(this.size < 0) throw new IOException("transient message container not yet filled");
}

@Override
public int size() throws IOException {
this.checkStatus();
return this.size;
return this.messageList.size();
}

@Override
Expand Down

0 comments on commit 1987adc

Please sign in to comment.