Skip to content

Commit 9c7bac0

Browse files
committed
after removing chunkReceived and chunkSend interfaces.
1 parent 83f7e55 commit 9c7bac0

File tree

12 files changed

+115
-155
lines changed

12 files changed

+115
-155
lines changed

src/net/sharksystem/asp3/ASP3Chunk.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.IOException;
99
import java.util.Iterator;
10+
import java.util.List;
1011

1112
/**
1213
*
@@ -41,4 +42,38 @@ public interface ASP3Chunk {
4142
public void drop();
4243

4344
public int getEra() throws IOException;
45+
46+
/**
47+
*
48+
* @return recipients of that chunk
49+
*/
50+
List<CharSequence> getRecipients();
51+
52+
/**
53+
* add recipients
54+
* @param recipient
55+
* @throws IOException
56+
*/
57+
void addRecipient(CharSequence recipient) throws IOException;
58+
59+
/**
60+
* set a list of recipients. Former recipients are dikscarded
61+
* @param recipients
62+
* @throws IOException
63+
*/
64+
void setRecipients(List<CharSequence> recipients) throws IOException;
65+
66+
/**
67+
* recipient is removed
68+
* @param recipients
69+
* @throws IOException
70+
*/
71+
void removeRecipient(CharSequence recipients) throws IOException;
72+
73+
/**
74+
* adds a message
75+
* @param message
76+
* @throws IOException
77+
*/
78+
void add(CharSequence message) throws IOException;
4479
}

src/net/sharksystem/asp3/ASP3Chunk2Send.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/net/sharksystem/asp3/ASP3ChunkFS.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author thsc
2020
*/
21-
class ASP3ChunkFS implements ASP3Chunk2Send, ASP3ChunkReceived {
21+
class ASP3ChunkFS implements ASP3Chunk {
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";
@@ -207,16 +207,6 @@ public int getEra() throws IOException {
207207
return this.era;
208208
}
209209

210-
@Override
211-
public CharSequence getSender() throws IOException {
212-
return this.sender;
213-
}
214-
215-
@Override
216-
public void addReceivedMessage(CharSequence message) throws IOException {
217-
this.add(message);
218-
}
219-
220210
private class MessageIter implements Iterator {
221211

222212
private final DataInputStream dis;

src/net/sharksystem/asp3/ASP3ChunkReader.java

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.DataInputStream;
44
import java.io.IOException;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
57

68
class ASP3ChunkReader implements Runnable {
79
private final DataInputStream dis;
@@ -47,66 +49,16 @@ public void run() {
4749
b.append("got received chunk storage ");
4850
System.out.println(b.toString());
4951
//>>>>>>>>>>>>>>>>>>>debug
50-
52+
5153
try {
52-
String uri = dis.readUTF();
53-
//<<<<<<<<<<<<<<<<<<debug
54-
b = new StringBuilder();
55-
b.append(this.getLogStart());
56-
b.append("read chunkURI: ");
57-
b.append(uri);
58-
System.out.println(b.toString());
59-
//>>>>>>>>>>>>>>>>>>>debug
60-
ASP3Chunk2Send chunk =
61-
peerStorage.getChunk(uri, storage.getEra());
62-
63-
if(chunk != null) {
64-
//<<<<<<<<<<<<<<<<<<debug
65-
b = new StringBuilder();
66-
b.append(this.getLogStart());
67-
b.append("got chunk: ");
68-
b.append(uri);
69-
System.out.println(b.toString());
70-
//>>>>>>>>>>>>>>>>>>>debug
71-
} else {
72-
//<<<<<<<<<<<<<<<<<<debug
73-
b = new StringBuilder();
74-
b.append(this.getLogStart());
75-
b.append("ERROR: no chunk found for sender/uri: ");
76-
b.append(peer);
77-
b.append(" / ");
78-
b.append(uri);
79-
System.err.println(b.toString());
80-
//>>>>>>>>>>>>>>>>>>>debug
81-
}
82-
83-
ASP3ChunkSerialization.readChunk(chunk, dis);
84-
85-
for(;;) {
86-
// escapes with IOException
87-
String message = dis.readUTF();
88-
//<<<<<<<<<<<<<<<<<<debug
89-
b = new StringBuilder();
90-
b.append(this.getLogStart());
91-
b.append("read message: ");
92-
b.append(message);
93-
System.out.println(b.toString());
94-
//>>>>>>>>>>>>>>>>>>>debug
95-
96-
//<<<<<<<<<<<<<<<<<<debug
97-
b = new StringBuilder();
98-
b.append(this.getLogStart());
99-
b.append("going to write to received chunk: ");
100-
b.append(uri);
101-
b.append(" / era: ");
102-
b.append(storage.getEra());
103-
System.out.println(b.toString());
104-
//>>>>>>>>>>>>>>>>>>>debug
105-
106-
chunk.add(message);
107-
}
54+
ASP3ChunkSerialization.readChunk(this.storage, peerStorage, dis);
10855
} catch (IOException ex) {
109-
// done
56+
try {
57+
// give up
58+
dis.close();
59+
} catch (IOException ex1) {
60+
// ignore
61+
}
11062
}
11163
}
11264
}

src/net/sharksystem/asp3/ASP3ChunkReceived.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/net/sharksystem/asp3/ASP3ChunkSerialization.java

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
* @author thsc
1111
*/
1212
abstract class ASP3ChunkSerialization {
13-
static void sendChunk(ASP3Chunk2Send chunk, DataOutputStream dos)
13+
static void sendChunk(ASP3Chunk chunk, DataOutputStream dos)
1414
throws IOException {
1515

1616
//<<<<<<<<<<<<<<<<<<debug
1717
StringBuilder b = new StringBuilder();
18-
b.append("send chunk url: ");
18+
b.append("send chunk url / #messages: ");
1919
b.append(chunk.getUri());
20+
b.append(" / ");
21+
b.append(chunk.getNumberMessage());
2022
System.out.println(b.toString());
2123
//>>>>>>>>>>>>>>>>>>>debug
2224

2325
// send url
2426
dos.writeUTF(chunk.getUri());
27+
28+
// send #messages
29+
dos.writeInt(chunk.getNumberMessage());
2530

2631
Iterator<CharSequence> messages = chunk.getMessages();
2732
//<<<<<<<<<<<<<<<<<<debug
@@ -38,6 +43,7 @@ static void sendChunk(ASP3Chunk2Send chunk, DataOutputStream dos)
3843
System.out.println(b.toString());
3944
//>>>>>>>>>>>>>>>>>>>debug
4045

46+
// send message
4147
dos.writeUTF((String) message);
4248

4349
//<<<<<<<<<<<<<<<<<<debug
@@ -54,20 +60,60 @@ static void sendChunk(ASP3Chunk2Send chunk, DataOutputStream dos)
5460
System.out.println(b.toString());
5561
}
5662

57-
static void readChunk(ASP3ChunkReceived chunk, DataInputStream dis)
58-
throws IOException {
63+
static void readChunk(ASP3ChunkStorage chunkStorage, ASP3Storage storage,
64+
DataInputStream dis) throws IOException {
5965

60-
for(;;) {
61-
// escapes with IOException
62-
String message = dis.readUTF();
66+
try {
67+
// read URI
68+
String uri = dis.readUTF();
69+
70+
// read number of messages
71+
int number = dis.readInt();
72+
6373
//<<<<<<<<<<<<<<<<<<debug
6474
StringBuilder b = new StringBuilder();
65-
b.append("chunk deserialisation read message: ");
66-
b.append(message);
75+
b.append("read chunkURI / #messages ");
76+
b.append(uri);
77+
b.append(" / ");
78+
b.append(number);
6779
System.out.println(b.toString());
6880
//>>>>>>>>>>>>>>>>>>>debug
81+
ASP3Chunk chunk =
82+
storage.getChunk(uri, chunkStorage.getEra());
83+
84+
if(chunk != null) {
85+
//<<<<<<<<<<<<<<<<<<debug
86+
b = new StringBuilder();
87+
b.append("got chunk: ");
88+
b.append(uri);
89+
System.out.println(b.toString());
90+
//>>>>>>>>>>>>>>>>>>>debug
91+
} else {
92+
//<<<<<<<<<<<<<<<<<<debug
93+
b = new StringBuilder();
94+
b.append("ERROR: no chunk found for sender/uri: ");
95+
b.append(" / ");
96+
b.append(uri);
97+
System.err.println(b.toString());
98+
//>>>>>>>>>>>>>>>>>>>debug
99+
throw new IOException("couldn't create local chunk storage - give up");
100+
}
69101

70-
chunk.addReceivedMessage(message);
102+
for(;number > 0; number--) {
103+
// escapes with IOException
104+
String message = dis.readUTF();
105+
//<<<<<<<<<<<<<<<<<<debug
106+
b = new StringBuilder();
107+
b.append("chunk deserialisation read message: ");
108+
b.append(message);
109+
System.out.println(b.toString());
110+
//>>>>>>>>>>>>>>>>>>>debug
111+
112+
chunk.add(message);
113+
}
114+
115+
} catch (IOException ex) {
116+
// done
71117
}
72118
}
73119
}

src/net/sharksystem/asp3/ASP3Engine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void removeRecipient(CharSequence urlTarget, CharSequence recipients) thr
6363

6464
@Override
6565
public void add(CharSequence urlTarget, CharSequence message) throws IOException {
66-
ASP3Chunk2Send chunk = this.chunkStorage.getChunk(urlTarget, this.era);
66+
ASP3Chunk chunk = this.chunkStorage.getChunk(urlTarget, this.era);
6767

6868
chunk.add(message);
6969
}
@@ -176,7 +176,7 @@ public void handleConnection(InputStream is, OutputStream os,
176176
do {
177177
lastRound = workingEra == currentEra;
178178

179-
List<ASP3Chunk2Send> chunks = this.chunkStorage.getChunks(workingEra);
179+
List<ASP3Chunk> chunks = this.chunkStorage.getChunks(workingEra);
180180
//<<<<<<<<<<<<<<<<<<debug
181181
b = new StringBuilder();
182182
b.append(this.getLogStart());
@@ -185,7 +185,7 @@ public void handleConnection(InputStream is, OutputStream os,
185185
System.out.println(b.toString());
186186
//>>>>>>>>>>>>>>>>>>>debug
187187

188-
for(ASP3Chunk2Send chunk : chunks) {
188+
for(ASP3Chunk chunk : chunks) {
189189
//<<<<<<<<<<<<<<<<<<debug
190190
b = new StringBuilder();
191191
b.append(this.getLogStart());
@@ -353,7 +353,7 @@ private synchronized void incrementEra() throws IOException {
353353
* @param chunk
354354
* @return
355355
*/
356-
private boolean isPublic(ASP3Chunk2Send chunk) {
356+
private boolean isPublic(ASP3Chunk chunk) {
357357
return chunk.getRecipients().isEmpty();
358358
}
359359

src/net/sharksystem/asp3/ASP3Storage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
*/
1010
public interface ASP3Storage {
1111

12-
public ASP3Chunk2Send getChunk(CharSequence urlTarget, int era) throws IOException;
12+
public ASP3Chunk getChunk(CharSequence urlTarget, int era) throws IOException;
1313

14-
public List<ASP3Chunk2Send> getChunks(int era) throws IOException;
14+
public List<ASP3Chunk> getChunks(int era) throws IOException;
1515

1616
public void dropChunks(int era) throws IOException;
1717
}

src/net/sharksystem/asp3/ASP3StorageFS.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ASP3StorageFS implements ASP3Storage {
2424
}
2525

2626
@Override
27-
public ASP3Chunk2Send getChunk(CharSequence uriTarget, int era) throws IOException {
27+
public ASP3Chunk getChunk(CharSequence uriTarget, int era) throws IOException {
2828
return new ASP3ChunkFS(this, (String) uriTarget, era);
2929
}
3030

@@ -81,8 +81,8 @@ private String getPath(int era) {
8181
}
8282

8383
@Override
84-
public List<ASP3Chunk2Send> getChunks(int era) throws IOException {
85-
List<ASP3Chunk2Send> chunkList = new ArrayList<>();
84+
public List<ASP3Chunk> getChunks(int era) throws IOException {
85+
List<ASP3Chunk> chunkList = new ArrayList<>();
8686

8787
File dir = new File(this.getPath(era));
8888

0 commit comments

Comments
 (0)