Skip to content

Commit 8a895c8

Browse files
committed
first closed channel test runs.
1 parent 2aae589 commit 8a895c8

17 files changed

+122
-63
lines changed

src/net/sharksystem/asap/ASAPChannel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public interface ASAPChannel {
99
CharSequence getUri() throws IOException;
1010
Set<CharSequence> getRecipients() throws IOException;
1111
HashMap<String, String> getExtraData() throws IOException;
12+
ASAPChannelMessages getMessages() throws IOException;
1213
}

src/net/sharksystem/asap/ASAPChannelImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public HashMap<String, String> getExtraData() throws IOException {
3434
return this.asapEngine.getStorage().getChunk(uri, this.asapEngine.getEra()).getExtraData();
3535
}
3636

37+
@Override
38+
public ASAPChannelMessages getMessages() throws IOException {
39+
return this.asapEngine.getChunkStorage().getASAPChunkCache(this.getUri(), this.asapEngine.getEra());
40+
}
41+
3742
public void setOwner(CharSequence owner) throws IOException {
3843
this.asapEngine.putExtra(this.getUri(), CHANNEL_OWNER, owner.toString());
3944
}

src/net/sharksystem/asap/ASAPChunkChain.java renamed to src/net/sharksystem/asap/ASAPChannelMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
* @author thsc
2121
*/
22-
public interface ASAPChunkChain {
22+
public interface ASAPChannelMessages {
2323
/**
2424
*
2525
* @return number of messages fitting to that uri regardless of era

src/net/sharksystem/asap/ASAPChunk.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public interface ASAPChunk {
7878
/**
7979
* set a list of recipients. Former recipients are dikscarded
8080
* @param recipients
81-
* @throws IOException
81+
* @throws IOException
8282
*/
83-
void setRecipients(List<CharSequence> recipients) throws IOException;
83+
void setRecipients(Set<CharSequence> recipients) throws IOException;
8484

8585
/**
8686
* recipient is removed

src/net/sharksystem/asap/ASAPChunkFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void addRecipient(CharSequence recipient) throws IOException {
123123
}
124124

125125
@Override
126-
public void setRecipients(List<CharSequence> newRecipients) throws IOException {
126+
public void setRecipients(Set<CharSequence> newRecipients) throws IOException {
127127
this.recipients = new HashSet<>();
128128
for(CharSequence recipient : newRecipients) {
129129
this.recipients.add(recipient);

src/net/sharksystem/asap/ASAPChunkStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public interface ASAPChunkStorage {
3030
* @return a chunk cache which hides details of era
3131
* @throws IOException
3232
*/
33-
public ASAPChunkChain getASAPChunkCache(CharSequence uri, int toEra) throws IOException;
33+
public ASAPChannelMessages getASAPChunkCache(CharSequence uri, int toEra) throws IOException;
3434
}

src/net/sharksystem/asap/ASAPChunkStorageFS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.io.IOException;
88
import java.util.ArrayList;
99
import java.util.List;
10-
import static net.sharksystem.asap.ASAPChunkFS.DATA_EXTENSION;
10+
1111
import static net.sharksystem.asap.ASAPChunkFS.META_DATA_EXTENSION;
1212

1313
/**
@@ -114,14 +114,14 @@ public void dropChunks(int era) throws IOException {
114114
}
115115

116116
@Override
117-
public ASAPChunkChain getASAPChunkCache(CharSequence uri, int toEra) throws IOException {
117+
public ASAPChannelMessages getASAPChunkCache(CharSequence uri, int toEra) throws IOException {
118118
// go back 1000 eras
119119
int fromEra = toEra;
120120
for(int i = 0; i < 1000; i++) {
121121
fromEra = ASAPEngine.previousEra(fromEra);
122122
}
123123

124-
return new ASAPInMemoChunkChain(this,
124+
return new ASAPInMemoChannelMessages(this,
125125
uri,
126126
fromEra, // set starting era
127127
toEra // anything before

src/net/sharksystem/asap/ASAPEngine.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package net.sharksystem.asap;
22

3-
import net.sharksystem.asap.management.ASAPManagementMessage;
43
import net.sharksystem.asap.management.ASAPManagementStorage;
4+
import net.sharksystem.asap.management.ASAPManagementStorageImpl;
55
import net.sharksystem.asap.protocol.*;
66
import net.sharksystem.asap.util.Log;
77

88
import java.io.IOException;
99
import java.io.InputStream;
1010
import java.io.OutputStream;
11-
import java.util.ArrayList;
12-
import java.util.HashMap;
13-
import java.util.List;
14-
import java.util.Set;
11+
import java.util.*;
1512

1613
/**
1714
* That ASAPEngine manages exchange of stored messages with peers.
@@ -94,12 +91,12 @@ public CharSequence getExtra(CharSequence uri, String key) throws IOException {
9491
}
9592

9693
@Override
97-
public void createChannel(CharSequence uri, List<CharSequence> recipients) throws IOException, ASAPException {
94+
public void createChannel(CharSequence uri, Set<CharSequence> recipients) throws IOException, ASAPException {
9895
this.createChannel(this.getOwner(), uri, recipients);
9996
}
10097

10198
@Override
102-
public void createChannel(CharSequence owner, CharSequence uri, List<CharSequence> recipients)
99+
public void createChannel(CharSequence owner, CharSequence uri, Set<CharSequence> recipients)
103100
throws IOException, ASAPException {
104101

105102
this.setRecipients(uri, recipients);
@@ -116,7 +113,7 @@ public void createChannel(CharSequence owner, CharSequence uri, List<CharSequenc
116113

117114
@Override
118115
public void createChannel(CharSequence urlTarget, CharSequence recipient) throws IOException, ASAPException {
119-
ArrayList<CharSequence> recipients = new ArrayList<>();
116+
Set<CharSequence> recipients = new HashSet<>();
120117
recipients.add(recipient);
121118
this.createChannel(urlTarget, recipients);
122119
}
@@ -139,23 +136,17 @@ public boolean isASAPManagementStorageSet() {
139136
}
140137

141138
public void notifyChannelCreated(CharSequence appName, CharSequence owner,
142-
CharSequence uri, List<CharSequence> recipients)
139+
CharSequence uri, Set<CharSequence> recipients)
143140
throws ASAPException, IOException {
144141

145-
byte[] createClosedASAPChannelMessage =
146-
ASAPManagementMessage.getCreateClosedASAPChannelMessage(
147-
owner, appName, uri, recipients);
148-
149-
// put into create channel
150-
this.add(ASAPManagementStorage.ASAP_CREATE_CHANNEL, createClosedASAPChannelMessage);
151-
142+
new ASAPManagementStorageImpl(this).notifyChannelCreated(appName, owner, uri, recipients);
152143
}
153144

154145
public void addRecipient(CharSequence urlTarget, CharSequence recipient) throws IOException {
155146
this.chunkStorage.getChunk(urlTarget, this.era).addRecipient(recipient);
156147
}
157148

158-
public void setRecipients(CharSequence urlTarget, List<CharSequence> recipients) throws IOException {
149+
public void setRecipients(CharSequence urlTarget, Set<CharSequence> recipients) throws IOException {
159150
this.chunkStorage.getChunk(urlTarget, this.era).setRecipients(recipients);
160151
}
161152

@@ -234,19 +225,19 @@ public void removeChannel(CharSequence uri) throws IOException {
234225
chunk.drop();
235226
}
236227

237-
public ASAPChunkChain getChunkChain(int position) throws IOException, ASAPException {
228+
public ASAPChannelMessages getChunkChain(int position) throws IOException, ASAPException {
238229
return this.getChunkChain(position, this.era);
239230
}
240231

241-
public ASAPChunkChain getChunkChain(CharSequence uri, int toEra) throws IOException {
232+
public ASAPChannelMessages getChunkChain(CharSequence uri, int toEra) throws IOException {
242233
return this.chunkStorage.getASAPChunkCache(uri, toEra);
243234
}
244235

245-
public ASAPChunkChain getChunkChain(CharSequence uri) throws IOException {
236+
public ASAPChannelMessages getChunkChain(CharSequence uri) throws IOException {
246237
return this.getChunkChain(uri, this.getEra());
247238
}
248239

249-
public ASAPChunkChain getChunkChain(int position, int toEra)
240+
public ASAPChannelMessages getChunkChain(int position, int toEra)
250241
throws IOException, ASAPException {
251242

252243
List<CharSequence> channelURIs = this.getChannelURIs();

src/net/sharksystem/asap/ASAPInMemoChunkChain.java renamed to src/net/sharksystem/asap/ASAPInMemoChannelMessages.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @author thsc
1212
*/
13-
class ASAPInMemoChunkChain implements ASAPChunkChain {
13+
class ASAPInMemoChannelMessages implements ASAPChannelMessages {
1414
public static final int DEFAULT_MAX_CACHE_SIZE = 1000;
1515
private final CharSequence uri;
1616
private final ASAPChunkStorageFS chunkStorage;
@@ -27,8 +27,8 @@ class ASAPInMemoChunkChain implements ASAPChunkChain {
2727

2828
private int numberOfMessages = 0;
2929

30-
public ASAPInMemoChunkChain(ASAPChunkStorageFS chunkStorage,
31-
CharSequence uri, int fromEra, int toEra, int maxCacheLen) {
30+
public ASAPInMemoChannelMessages(ASAPChunkStorageFS chunkStorage,
31+
CharSequence uri, int fromEra, int toEra, int maxCacheLen) {
3232

3333
this.uri = uri;
3434
this.chunkStorage = chunkStorage;
@@ -37,8 +37,8 @@ public ASAPInMemoChunkChain(ASAPChunkStorageFS chunkStorage,
3737
this.maxCacheLen = maxCacheLen;
3838
}
3939

40-
public ASAPInMemoChunkChain(ASAPChunkStorageFS chunkStorage,
41-
CharSequence uri, int fromEra, int toEra) {
40+
public ASAPInMemoChannelMessages(ASAPChunkStorageFS chunkStorage,
41+
CharSequence uri, int fromEra, int toEra) {
4242

4343
this(chunkStorage, uri, fromEra, toEra, DEFAULT_MAX_CACHE_SIZE);
4444
}

src/net/sharksystem/asap/ASAPStorage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface ASAPStorage {
6565
* @param recipients
6666
* @throws IOException
6767
*/
68-
void createChannel(CharSequence urlTarget, List<CharSequence> recipients) throws IOException, ASAPException;
68+
void createChannel(CharSequence urlTarget, Set<CharSequence> recipients) throws IOException, ASAPException;
6969

7070
/**
7171
* Create channel with a maybe different and than local peer - take care!
@@ -75,7 +75,7 @@ public interface ASAPStorage {
7575
* @throws IOException
7676
* @throws ASAPException
7777
*/
78-
void createChannel(CharSequence owner, CharSequence urlTarget, List<CharSequence> recipients) throws IOException, ASAPException;
78+
void createChannel(CharSequence owner, CharSequence urlTarget, Set<CharSequence> recipients) throws IOException, ASAPException;
7979

8080
/**
8181
*
@@ -244,13 +244,13 @@ public interface ASAPStorage {
244244

245245
void removeChannel(CharSequence uri) throws IOException;
246246

247-
ASAPChunkChain getChunkChain(int position) throws IOException, ASAPException;
247+
ASAPChannelMessages getChunkChain(int position) throws IOException, ASAPException;
248248

249-
ASAPChunkChain getChunkChain(int position, int toEra) throws IOException, ASAPException;
249+
ASAPChannelMessages getChunkChain(int position, int toEra) throws IOException, ASAPException;
250250

251-
ASAPChunkChain getChunkChain(CharSequence uri, int toEra) throws IOException;
251+
ASAPChannelMessages getChunkChain(CharSequence uri, int toEra) throws IOException;
252252

253-
ASAPChunkChain getChunkChain(CharSequence uri) throws IOException;
253+
ASAPChannelMessages getChunkChain(CharSequence uri) throws IOException;
254254

255255
/**
256256
* Refresh with external system - re-read files, or whatever.

0 commit comments

Comments
 (0)