Skip to content

Commit 32676fb

Browse files
committed
about fixing online message exchange but - snapshot - still works
1 parent b02c863 commit 32676fb

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/main/java/net/sharksystem/asap/engine/ASAPChunkStorageFS.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ String getChunkFileTrunkname(int era, String uri) {
7474
String setupChunkFolder(int era, String targetUrl) {
7575
String eraFolderString = this.getPath(era);
7676
File eraFolder = new File(eraFolderString);
77-
Log.writeLog(this, "setup chunk / era folder: " + eraFolderString);
77+
Log.writeLog(this, "setup chunk folder: " + eraFolderString);
78+
Log.writeLog(this, "setup chunk folder-file: " + eraFolder);
7879
if(!eraFolder.exists()) {
7980
Log.writeLog(this, "folder does not exist - create: " + eraFolderString);
8081
eraFolder.mkdirs();

src/main/java/net/sharksystem/asap/engine/ASAPEngine.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
436436

437437
// iterate messages and stream into chunk
438438
InputStream protocolInputStream = asapAssimilationPDU.getInputStream();
439+
Log.writeLog(this, this.toString(), "take data to local chunk or transient message: " + messagesContainer);
439440
this.streamReceivedMessages2Container(messagesContainer, protocolInputStream,
440441
messageOffsets, asapAssimilationPDU.getLength());
441442

@@ -489,6 +490,7 @@ public void handleASAPAssimilate(ASAP_AssimilationPDU_1_0 asapAssimilationPDU, A
489490
private ASAPInternalChunk getIncomingChunk(String encounteredPeer, ASAP_AssimilationPDU_1_0 asapAssimilationPDU)
490491
throws IOException, ASAPException {
491492

493+
Log.writeLog(this, this.toString(), "called: get incoming chunk");
492494
String uri = asapAssimilationPDU.getChannelUri();
493495
int eraSender = asapAssimilationPDU.getEra();
494496
String senderE2E = asapAssimilationPDU.getSender();
@@ -502,9 +504,9 @@ private ASAPInternalChunk getIncomingChunk(String encounteredPeer, ASAP_Assimila
502504
ASAPInternalChunk localChunk = null;
503505
// is there a local chunk - to clone recipients from?
504506
if (this.channelExists(uri)) {
505-
// localChunk = incomingChunkStorage.getChunk(uri, this.getEra());
506-
localChunk = incomingChunkStorage.getChunk(uri, eraSender);
507-
} else {
507+
Log.writeLog(this, this.toString(), "get local chunk to copy channel data");
508+
localChunk = incomingChunkStorage.getChunk(uri, this.getEra()); // get channel information
509+
} else { // no information that can be copied
508510
Log.writeLog(this, this.toString(), "asked to set up new channel: (uri/senderE2E): "
509511
+ uri + " | " + senderE2E);
510512
// this channel is new to local peer - am I allowed to create it?
@@ -518,12 +520,14 @@ private ASAPInternalChunk getIncomingChunk(String encounteredPeer, ASAP_Assimila
518520
this.createChannel(uri);
519521
}
520522
}
523+
Log.writeLog(this, this.toString(), "create new chunk to assimilate received data");
521524
ASAPInternalChunk incomingChunk = incomingStorage.createNewChunk(uri, eraSender);
522525

523526
if (localChunk != null) {
524527
Log.writeLog(this, this.toString(), "copy local meta data into newly created incoming chunk");
525528
incomingChunk.copyMetaData(this.getChannel(uri));
526529
}
530+
Log.writeLog(this, this.toString(), "new incoming chunk created: " + incomingChunk);
527531
return incomingChunk;
528532
} else {
529533
// already exists. Add message if sender == originator and era last era of this channel

src/main/java/net/sharksystem/asap/engine/ASAPInternalChunkFS.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,16 @@ public List<CharSequence> getDeliveredTo() {
8181
this(storage, uri, era, null);
8282
}
8383

84-
ASAPInternalChunkFS(ASAPChunkStorageFS storage, String targetUri, int era, String sender) throws IOException {
84+
ASAPInternalChunkFS(ASAPChunkStorageFS storage, String uri, int era, String sender) throws IOException {
8585
this.storage = storage;
86-
if(targetUri != null) {
87-
this.uri = targetUri;
86+
if(uri != null) {
87+
this.uri = uri;
8888
}
8989
this.era = era;
9090
this.sender = sender;
91-
92-
String trunkName = this.storage.setupChunkFolder(era, targetUri);
91+
92+
//Log.writeLog(this, this.toString(), "construct chunkFS");
93+
String trunkName = this.storage.setupChunkFolder(era, uri);
9394

9495
// init
9596
this.initFiles(trunkName);
@@ -105,12 +106,16 @@ public ASAPInternalChunkFS(ASAPChunkStorageFS storage, String trunkName) throws
105106
private void initFiles(String trunkName) throws IOException {
106107
String messageFileName = trunkName + "." + DATA_EXTENSION;
107108
String metaFileName = trunkName + "." + META_DATA_EXTENSION;
108-
109+
109110
this.messageFile = new File(messageFileName);
110111
this.metaFile = new File(metaFileName);
111112

112113
// init meta file - message file keeps untouched (good idea?)
113114
if(!this.metaFile.exists()) {
115+
if(!this.metaFile.getParentFile().exists()) {
116+
this.metaFile.getParentFile().mkdirs();
117+
Log.writeLog(this, "parent folder created: " + this.messageFile.getParentFile().exists());
118+
}
114119
this.metaFile.createNewFile();
115120
}
116121

@@ -181,32 +186,32 @@ public void addMessage(byte[] messageAsBytes) throws IOException {
181186
}
182187

183188
public void addMessage(InputStream messageByteIS, long length) throws IOException {
184-
Log.writeLog(this, "going to add message to chunkFS" );
189+
//Log.writeLog(this, "going to add message to chunkFS" );
185190
if(length > Integer.MAX_VALUE) {
186191
throw new IOException("message must not be longer than Integer.MAXVALUE");
187192
}
188193

189194
long offset = 0;
190195
if(!this.messageFile.exists()) {
191-
Log.writeLog(this, "content file does not exist yet - create: " + this.messageFile.getName());
192-
Log.writeLog(this, "apath " + this.messageFile.getAbsolutePath());
193-
Log.writeLog(this, "cpath " + this.messageFile.getCanonicalPath());
194-
Log.writeLog(this, "path " + this.messageFile.getPath());
196+
if(!this.messageFile.getParentFile().exists()) {
197+
this.messageFile.getParentFile().mkdirs();
198+
Log.writeLog(this, "parent folder created: " + this.messageFile.getParentFile().exists());
199+
}
195200
this.messageFile.createNewFile();
196201
} else {
197202
offset = this.messageFile.length();
198203
}
199-
Log.writeLog(this, "got chunk content file length: " + offset);
204+
//Log.writeLog(this, "got chunk content file length: " + offset);
200205

201206
OutputStream os = new FileOutputStream(this.messageFile, true);
202-
Log.writeLog(this, "opened chunk content file to append data");
207+
//Log.writeLog(this, "opened chunk content file to append data");
203208

204-
Log.writeLog(this, "write message to the end of chunk file");
209+
//Log.writeLog(this, "write message to the end of chunk file");
205210
while(length-- > 0) {
206211
os.write(messageByteIS.read());
207212
}
208213

209-
Log.writeLog(this, "closing");
214+
//Log.writeLog(this, "closing");
210215
os.close();
211216

212217
// remember offset if not 0
@@ -454,4 +459,7 @@ public int getEra() throws IOException {
454459
return this.era;
455460
}
456461

462+
public String toString() {
463+
return "sender: " + this.sender + " | era: " + era + " | metafile: " + this.metaFile;
464+
}
457465
}

0 commit comments

Comments
 (0)