Skip to content

Commit e6b3218

Browse files
committed
refactored asp3 to aasp
1 parent a2c73af commit e6b3218

23 files changed

+290
-290
lines changed
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package net.sharksystem.aasp;
72

83
import java.io.IOException;
94
import java.util.Iterator;
105
import java.util.List;
116

127
/**
13-
*
8+
* An AASP chunk contains messages regarding a topic described by an
9+
* uri. Messages are completly opaque to AASP, they are the payload
10+
* of that protocol. Of course, that protocol was created with ASIP in mind.
11+
*
12+
* Most developers will not work directly with that interface. If so: Take care!
13+
*
14+
* Each chunk has an era. The era number space is a circle with
15+
* a definition of proceeding and suceeding era, @see AASPEngine for details.
16+
*
17+
* Each chunk can have a number of recipients. Note: That list can be
18+
* changed by an application as long as that chunk is filled. The AASPEngine
19+
* changes that list when meeting other peers. Actually, it removes any peer
20+
* with whom it got synchronized.
21+
*
22+
*
1423
* @author thsc
1524
*/
16-
public interface ASP3Chunk {
25+
public interface AASPChunk {
1726
/**
1827
*
1928
* @return number of message in that chunk
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
*
1919
* @author thsc
2020
*/
21-
class ASP3ChunkFS implements ASP3Chunk {
21+
class AASPChunkFS implements AASPChunk {
2222
public static final String META_DATA_EXTENSION = "meta";
2323
public static final String DATA_EXTENSION = "content";
2424
public static final String DEFAULT_URL = "content://sharksystem.net/noContext";
25-
private final ASP3StorageFS storage;
25+
private final AASPChunkStorageFS storage;
2626
private String uri = DEFAULT_URL;
2727
private ArrayList<CharSequence> recipients;
2828
private File metaFile;
@@ -33,11 +33,11 @@ class ASP3ChunkFS implements ASP3Chunk {
3333
private String sender;
3434

3535

36-
ASP3ChunkFS(ASP3StorageFS storage, String targetUri, int era) throws IOException {
36+
AASPChunkFS(AASPChunkStorageFS storage, String targetUri, int era) throws IOException {
3737
this(storage, targetUri, era, null);
3838
}
3939

40-
ASP3ChunkFS(ASP3StorageFS storage, String targetUri, int era, String sender) throws IOException {
40+
AASPChunkFS(AASPChunkStorageFS storage, String targetUri, int era, String sender) throws IOException {
4141
this.storage = storage;
4242
this.uri = targetUri;
4343
this.era = era;
@@ -49,9 +49,9 @@ class ASP3ChunkFS implements ASP3Chunk {
4949
this.initFiles(trunkName);
5050
}
5151

52-
ASP3ChunkFS(ASP3StorageFS storage, String trunkName) throws IOException {
52+
AASPChunkFS(AASPChunkStorageFS storage, String trunkName) throws IOException {
5353
this.storage = storage;
54-
this.uri = ASP3ChunkFS.DEFAULT_URL;
54+
this.uri = AASPChunkFS.DEFAULT_URL;
5555

5656
this.initFiles(trunkName);
5757
}

src/net/sharksystem/aasp/ASP3ChunkReader.java renamed to src/net/sharksystem/aasp/AASPChunkReader.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
import java.io.DataInputStream;
44
import java.io.IOException;
55

6-
class ASP3ChunkReader implements Runnable {
6+
/**
7+
* Implements the chunk exchange step in the AAS protocol.
8+
* @author local
9+
*/
10+
11+
class AASPChunkReader implements Runnable {
712
private final DataInputStream dis;
813
private final String peer;
914
private final String owner;
10-
private final ASP3ChunkStorage storage;
11-
private final ASP3ReceivedChunkListener listener;
15+
private final AASPStorage storage;
16+
private final AASPReceivedChunkListener listener;
1217

13-
ASP3ChunkReader(DataInputStream dis, String owner,
14-
String peer, ASP3ChunkStorage storage,
15-
ASP3ReceivedChunkListener listener) {
18+
AASPChunkReader(DataInputStream dis, String owner,
19+
String peer, AASPStorage storage,
20+
AASPReceivedChunkListener listener) {
1621
this.dis = dis;
1722
this.peer = peer;
1823
this.owner = owner;
@@ -40,7 +45,7 @@ public void run() {
4045
System.out.println(b.toString());
4146
//>>>>>>>>>>>>>>>>>>>debug
4247

43-
ASP3Storage peerStorage = null;
48+
AASPChunkStorage peerStorage = null;
4449

4550
// get received storage
4651
peerStorage = this.storage.getReceivedChunkStorage(peer);
@@ -52,7 +57,7 @@ public void run() {
5257
//>>>>>>>>>>>>>>>>>>>debug
5358

5459
try {
55-
ASP3ChunkSerialization.readChunks(peer, this.storage,
60+
AASPChunkSerialization.readChunks(peer, this.storage,
5661
peerStorage, dis, listener);
5762
} catch (IOException ex) {
5863
try {

src/net/sharksystem/aasp/ASP3ChunkSerialization.java renamed to src/net/sharksystem/aasp/AASPChunkSerialization.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import java.util.Iterator;
77

88
/**
9-
*
9+
* Implements parts of the AAS protocol.
1010
* @author thsc
1111
*/
12-
abstract class ASP3ChunkSerialization {
13-
static void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
12+
abstract class AASPChunkSerialization {
13+
static void sendChunk(AASPChunk chunk, DataOutputStream dos)
1414
throws IOException {
1515

1616
//<<<<<<<<<<<<<<<<<<debug
@@ -71,9 +71,9 @@ static void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
7171
* @param listener to be notified about a successfully deserialized chunk
7272
* @throws IOException
7373
*/
74-
static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
75-
ASP3Storage storage, DataInputStream dis,
76-
ASP3ReceivedChunkListener listener) throws IOException {
74+
static void readChunks(String sender, AASPStorage chunkStorage,
75+
AASPChunkStorage storage, DataInputStream dis,
76+
AASPReceivedChunkListener listener) throws IOException {
7777

7878
StringBuilder b = new StringBuilder();
7979
b.append("ASPChunkSerialization.readChunks (sender: ");
@@ -101,7 +101,7 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
101101
b.append(sender);
102102
System.out.println(b.toString());
103103
//>>>>>>>>>>>>>>>>>>>debug
104-
ASP3Chunk chunk =
104+
AASPChunk chunk =
105105
storage.getChunk(uri, chunkStorage.getEra());
106106

107107
if(chunk != null) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.sharksystem.aasp;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
/**
7+
* A storage is a logical unit containing chunks. It offers methods
8+
* to get (and create) and remove (drop) chunks. There is at least
9+
* one storage containing message produced by a local app.
10+
*
11+
* There can be other storages containg messages which arrived from a
12+
* peer during sychronization.
13+
*
14+
* @author thsc
15+
*/
16+
public interface AASPChunkStorage {
17+
18+
public AASPChunk getChunk(CharSequence urlTarget, int era) throws IOException;
19+
20+
public List<AASPChunk> getChunks(int era) throws IOException;
21+
22+
public void dropChunks(int era) throws IOException;
23+
}

src/net/sharksystem/aasp/ASP3StorageFS.java renamed to src/net/sharksystem/aasp/AASPChunkStorageFS.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33
import java.io.File;
44
import java.io.FilenameFilter;
55
import java.io.IOException;
6-
import java.nio.file.DirectoryStream;
7-
import java.nio.file.Files;
8-
import java.nio.file.Path;
9-
import java.nio.file.Paths;
106
import java.util.ArrayList;
117
import java.util.List;
12-
import static net.sharksystem.aasp.ASP3ChunkFS.DATA_EXTENSION;
8+
import static net.sharksystem.aasp.AASPChunkFS.DATA_EXTENSION;
139

1410
/**
1511
*
1612
* @author thsc
1713
*/
18-
class ASP3StorageFS implements ASP3Storage {
14+
class AASPChunkStorageFS implements AASPChunkStorage {
1915

2016
private final String rootDirectory;
2117

22-
ASP3StorageFS(String rootDirectory) {
18+
AASPChunkStorageFS(String rootDirectory) {
2319
this.rootDirectory = rootDirectory;
2420
}
2521

2622
@Override
27-
public ASP3Chunk getChunk(CharSequence uriTarget, int era) throws IOException {
28-
return new ASP3ChunkFS(this, (String) uriTarget, era);
23+
public AASPChunk getChunk(CharSequence uriTarget, int era) throws IOException {
24+
return new AASPChunkFS(this, (String) uriTarget, era);
2925
}
3026

3127
String url2FileName(String url) {
@@ -81,8 +77,8 @@ private String getPath(int era) {
8177
}
8278

8379
@Override
84-
public List<ASP3Chunk> getChunks(int era) throws IOException {
85-
List<ASP3Chunk> chunkList = new ArrayList<>();
80+
public List<AASPChunk> getChunks(int era) throws IOException {
81+
List<AASPChunk> chunkList = new ArrayList<>();
8682

8783
File dir = new File(this.getPath(era));
8884

@@ -103,7 +99,7 @@ public boolean accept(File dir, String fileName) {
10399
if(index != -1) {
104100
String chunkName = name.substring(0, index);
105101
String fName = this.getFullFileNameByChunkName(era, chunkName);
106-
chunkList.add(new ASP3ChunkFS(this, fName));
102+
chunkList.add(new AASPChunkFS(this, fName));
107103
}
108104
}
109105
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* That ASP3Engine manages exchange of stored messages with peers.
1414
* See ASPChunkStorage for details.
1515
*
16-
* @see ASP3ChunkStorage
16+
* @see AASPStorage
1717
* @see ASP3Reader
1818
* @author thsc
1919
*/
20-
public abstract class ASP3Engine implements ASP3ChunkStorage, ASP3ProtocolEngine {
20+
public abstract class AASPEngine implements AASPStorage, AASPProtocolEngine {
2121
public static final String ANONYMOUS_OWNER = "anon";
2222
static String DEFAULT_OWNER = ANONYMOUS_OWNER;
2323
static int DEFAULT_INIT_ERA = 0;
@@ -34,17 +34,17 @@ public abstract class ASP3Engine implements ASP3ChunkStorage, ASP3ProtocolEngine
3434
protected int era = 0;
3535
protected int oldestEra = 0;
3636
protected HashMap<String, Integer> lastSeen = new HashMap<>();
37-
protected ASP3Memento memento = null;
37+
protected AASPMemento memento = null;
3838

39-
/* private */ final private ASP3Storage chunkStorage;
39+
/* private */ final private AASPChunkStorage chunkStorage;
4040

41-
protected ASP3Engine(ASP3Storage chunkStorage)
42-
throws ASP3Exception, IOException {
41+
protected AASPEngine(AASPChunkStorage chunkStorage)
42+
throws AASPException, IOException {
4343

4444
this.chunkStorage = chunkStorage;
4545
}
4646

47-
ASP3Storage getStorage() {
47+
AASPChunkStorage getStorage() {
4848
return this.chunkStorage;
4949
}
5050

@@ -69,7 +69,7 @@ public void removeRecipient(CharSequence urlTarget, CharSequence recipients) thr
6969

7070
@Override
7171
public void add(CharSequence urlTarget, CharSequence message) throws IOException {
72-
ASP3Chunk chunk = this.chunkStorage.getChunk(urlTarget, this.era);
72+
AASPChunk chunk = this.chunkStorage.getChunk(urlTarget, this.era);
7373

7474
chunk.add(message);
7575
}
@@ -91,7 +91,7 @@ private String getLogStart() {
9191

9292
@Override
9393
public void handleConnection(InputStream is, OutputStream os,
94-
ASP3ReceivedChunkListener listener) {
94+
AASPReceivedChunkListener listener) {
9595

9696
DataInputStream dis = new DataInputStream(is);
9797
DataOutputStream dos = new DataOutputStream(os);
@@ -127,7 +127,7 @@ public void handleConnection(InputStream is, OutputStream os,
127127

128128
// start reading from remote peer
129129
Thread readerThread = new Thread(
130-
new ASP3ChunkReader(dis, this.owner, peer, this, listener));
130+
new AASPChunkReader(dis, this.owner, peer, this, listener));
131131

132132
readerThread.start();
133133
//<<<<<<<<<<<<<<<<<<debug
@@ -182,7 +182,7 @@ public void handleConnection(InputStream is, OutputStream os,
182182
do {
183183
lastRound = workingEra == currentEra;
184184

185-
List<ASP3Chunk> chunks = this.chunkStorage.getChunks(workingEra);
185+
List<AASPChunk> chunks = this.chunkStorage.getChunks(workingEra);
186186
//<<<<<<<<<<<<<<<<<<debug
187187
b = new StringBuilder();
188188
b.append(this.getLogStart());
@@ -191,7 +191,7 @@ public void handleConnection(InputStream is, OutputStream os,
191191
System.out.println(b.toString());
192192
//>>>>>>>>>>>>>>>>>>>debug
193193

194-
for(ASP3Chunk chunk : chunks) {
194+
for(AASPChunk chunk : chunks) {
195195
//<<<<<<<<<<<<<<<<<<debug
196196
b = new StringBuilder();
197197
b.append(this.getLogStart());
@@ -217,7 +217,7 @@ public void handleConnection(InputStream is, OutputStream os,
217217
b.append("send chunk");
218218
System.out.println(b.toString());
219219
//>>>>>>>>>>>>>>>>>>>debug
220-
ASP3ChunkSerialization.sendChunk(chunk, dos);
220+
AASPChunkSerialization.sendChunk(chunk, dos);
221221

222222
// remember sent
223223
chunk.removeRecipient(peer);
@@ -373,7 +373,7 @@ private synchronized void incrementEra() throws IOException {
373373
* @param chunk
374374
* @return
375375
*/
376-
private boolean isPublic(ASP3Chunk chunk) {
376+
private boolean isPublic(AASPChunk chunk) {
377377
return chunk.getRecipients().isEmpty();
378378
}
379379

0 commit comments

Comments
 (0)