Skip to content

Commit 52aff93

Browse files
committed
working on an asap management protocol
1 parent 2959660 commit 52aff93

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

src/net/sharksystem/asap/ASAPEngine.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ public List<CharSequence> getChannelURIs() throws IOException {
154154
return uriList;
155155
}
156156

157+
@Override
158+
public boolean channelExists(CharSequence uri) throws IOException {
159+
return this.chunkStorage.existsChunk(uri, this.getEra());
160+
}
161+
157162
public void removeChannel(CharSequence uri) throws IOException {
158163
ASAPChunk chunk = this.chunkStorage.getChunk(uri, this.getEra());
159164
chunk.drop();

src/net/sharksystem/asap/ASAPEngineFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public String getRootFolder() {
3535
public String getOwner() {
3636
return this.owner;
3737
}
38-
38+
3939
public static ASAPEngine getASAPStorage(String owner, String rootDirectory, CharSequence format)
4040
throws IOException, ASAPException {
4141

src/net/sharksystem/asap/ASAPMementoFS.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ public void restore(ASAPEngine engine) throws IOException {
7474
DataInputStream dis = new DataInputStream(
7575
new FileInputStream(file));
7676

77-
engine.owner = dis.readUTF();
78-
engine.format = dis.readUTF();
79-
engine.era = dis.readInt();
80-
81-
// from hereon optional values - could work with defaults
8277
try {
78+
engine.owner = dis.readUTF();
79+
engine.format = dis.readUTF();
80+
engine.era = dis.readInt();
8381
engine.oldestEra = dis.readInt();
8482
engine.contentChanged = dis.readBoolean();
8583
engine.dropDeliveredChunks = dis.readBoolean();

src/net/sharksystem/asap/ASAPStorage.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* That chunk storage is meant to keep messages which are produced by an
1010
* app for later transmission.
1111
*
12-
* Messages which cannot be sent to their recipients can be stored in AASP chunks.
12+
* Messages which cannot be sent to their recipients can be stored in ASAP chunks.
1313
* Each chunk is addressed with an URI (comparable to URIs e.g. in Android
1414
* Content Provider)
1515
*
@@ -37,8 +37,8 @@
3737
* changed by the ASAPEngine whenever a peer (re-) connects. In that case, the
3838
* current era is declared to be finished and an new era is opened.
3939
* Any new message is now tagged as message from that new era. The ASAPEngine
40-
* transmitts all message to the peer which are stored after the final
41-
* encounter. If no encounter ever happend - all avaiable messages are
40+
* transmits all message to the peer which are stored after the final
41+
* encounter. If no encounter ever happened - allavailablee messages are
4242
* transmitted.
4343
*
4444
* @see ASAPEngine
@@ -130,6 +130,13 @@ public interface ASAPStorage {
130130
* @throws IOException
131131
*/
132132
public void removeRecipient(CharSequence urlTarget, CharSequence recipients) throws IOException;
133+
134+
/**
135+
*
136+
* @param uri channel uri
137+
* @return if channel exists - in other words: at least one message was added with this channel uri
138+
*/
139+
boolean channelExists(CharSequence uri) throws IOException;
133140

134141
/**
135142
* Add a message to that chunk.

src/net/sharksystem/asap/MultiASAPEngineFS_Impl.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,34 @@ public void handleASAPManagementPDU(ASAP_PDU_1_0 asapPDU, ASAP_1_0 protocol,
390390
// find storage
391391
ASAPStorage asapStorage = this.getEngineByFormat(format);
392392

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());
393+
if(asapStorage.channelExists(channelUri)) {
394+
List<CharSequence> existingChannelRecipientsList = asapStorage.getRecipients(channelUri);
395+
if(existingChannelRecipientsList.size() == recipients.size()) {
396+
// could be the same - same recipients?
397+
398+
// iterate all recipient and check whether they are also in local recipient list
399+
for(CharSequence recipient : recipients) {
400+
boolean found = false;
401+
for(CharSequence existingRecipient : existingChannelRecipientsList) {
402+
if(existingRecipient.toString().equalsIgnoreCase(recipient.toString())) {
403+
// got it
404+
found = true;
405+
break; // leave loop and test next
406+
}
407+
}
408+
if(!found) {
409+
throw new ASAPException("channel already exists but with different recipients");
410+
}
411+
}
412+
// ok it the same
413+
return;
414+
} else {
415+
throw new ASAPException("channel already exists but with different settings");
416+
}
417+
}
418+
419+
// else - channel does not exist - create by setting recipients
420+
asapStorage.setRecipients(channelUri, recipients);
398421
}
399422

400423
private String getLogStart() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ public void run() {
233233

234234
try {
235235
this.multiASAPEngineFS.handleASAPManagementPDU(asappdu, protocol, is);
236-
} catch (ASAPException | IOException e) {
236+
} catch (ASAPException e) {
237+
System.err.println("asap management pdu processing failed - go ahead in read/process loop"
238+
+ e.getLocalizedMessage());
239+
} catch (IOException e) {
237240
this.terminate("asap management pdu processing failed", e);
238241
break;
239242
}

0 commit comments

Comments
 (0)