Skip to content

Commit 31d8994

Browse files
committed
first running test for android usage.
1 parent 354c84c commit 31d8994

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

src/net/sharksystem/asp3/ASP3ChunkSerialization.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
7575
ASP3Storage storage, DataInputStream dis,
7676
ASP3ReceivedChunkListener listener) throws IOException {
7777

78+
StringBuilder b = new StringBuilder();
79+
b.append("ASPChunkSerialization.readChunks (sender: ");
80+
b.append(sender);
81+
b.append(") ");
82+
83+
String logStart = b.toString();
84+
7885
try {
7986
while(true) { // until IOException informs end of communication
8087
// read URI
@@ -84,8 +91,8 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
8491
int number = dis.readInt();
8592

8693
//<<<<<<<<<<<<<<<<<<debug
87-
StringBuilder b = new StringBuilder();
88-
b.append("ASPChunkDeserialization: ");
94+
b = new StringBuilder();
95+
b.append(logStart);
8996
b.append("read chunkURI / #messages / sender");
9097
b.append(uri);
9198
b.append(" / ");
@@ -100,15 +107,15 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
100107
if(chunk != null) {
101108
//<<<<<<<<<<<<<<<<<<debug
102109
b = new StringBuilder();
103-
b.append("ASPChunkDeserialization: ");
110+
b.append(logStart);
104111
b.append("got chunk: ");
105112
b.append(uri);
106113
System.out.println(b.toString());
107114
//>>>>>>>>>>>>>>>>>>>debug
108115
} else {
109116
//<<<<<<<<<<<<<<<<<<debug
110117
b = new StringBuilder();
111-
b.append("ASPChunkDeserialization: ");
118+
b.append(logStart);
112119
b.append("ERROR: no chunk found for sender/uri: ");
113120
b.append(" / ");
114121
b.append(uri);
@@ -122,7 +129,7 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
122129
String message = dis.readUTF();
123130
//<<<<<<<<<<<<<<<<<<debug
124131
b = new StringBuilder();
125-
b.append("ASPChunkDeserialization: ");
132+
b.append(logStart);
126133
b.append("read message: ");
127134
b.append(message);
128135
System.out.println(b.toString());
@@ -139,8 +146,8 @@ static void readChunks(String sender, ASP3ChunkStorage chunkStorage,
139146
// done - connection closed
140147

141148
//<<<<<<<<<<<<<<<<<<debug
142-
StringBuilder b = new StringBuilder();
143-
b.append("ASPChunkDeserialization: ");
149+
b = new StringBuilder();
150+
b.append(logStart);
144151
b.append("connection close - done");
145152
System.out.println(b.toString());
146153
//>>>>>>>>>>>>>>>>>>>debug

src/net/sharksystem/asp3/ASP3Engine.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.io.OutputStream;
88
import java.util.ArrayList;
99
import java.util.HashMap;
10-
import java.util.Iterator;
1110
import java.util.List;
1211

1312
/**
@@ -23,6 +22,13 @@ public abstract class ASP3Engine implements ASP3ChunkStorage, ASP3ProtocolEngine
2322
static String DEFAULT_OWNER = ANONYMOUS_OWNER;
2423
static int DEFAULT_INIT_ERA = 0;
2524

25+
/**
26+
* that engine transmitts serialized chunks to another peer.
27+
* After transmission that channel is closed. In immediate closure would
28+
* result in an IOException on the other side
29+
*/
30+
private int sleepBeforeConnectionClosed = 5000;
31+
2632
protected String owner = ANONYMOUS_OWNER;
2733

2834
protected int era = 0;
@@ -251,20 +257,33 @@ public void handleConnection(InputStream is, OutputStream os,
251257
b.append("ended iterating chunks");
252258
System.out.println(b.toString());
253259
//>>>>>>>>>>>>>>>>>>>debug
254-
255-
// TODO IMPORTANT!!!
256-
// sync incomming messagea as long as connected
257260
}
258261
catch(IOException ioe) {
259-
// TODO
260-
System.err.println("ioe: " + ioe.getLocalizedMessage());
262+
//<<<<<<<<<<<<<<<<<<debug
263+
StringBuilder b = new StringBuilder();
264+
b.append(this.getLogStart());
265+
b.append("IOEXception: ");
266+
b.append(ioe.getLocalizedMessage());
267+
System.out.println(b.toString());
268+
//>>>>>>>>>>>>>>>>>>>debug
261269
}
262270
finally {
263271
try {
264272
// remember that we drop conversation with that peer
265273
this.activePeers.remove(peer);
266274

267-
dis.close();
275+
//<<<<<<<<<<<<<<<<<<debug
276+
StringBuilder b = new StringBuilder();
277+
b.append(this.getLogStart());
278+
b.append("about closing output stream");
279+
System.out.println(b.toString());
280+
//>>>>>>>>>>>>>>>>>>>debug
281+
try {
282+
Thread.sleep(sleepBeforeConnectionClosed);
283+
} catch (InterruptedException ex) {
284+
// ignore
285+
}
286+
//dis.close();
268287
dos.close();
269288
} catch (IOException ex) {
270289
// ignore

test/ASP3ChunkReceiverTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ASP3ChunkReceiverTester implements ASP3ReceivedChunkListener {
1212

1313
@Override
1414
public void chunkReceived(String sender, String uri, int era) {
15-
System.out.println("ChunkReceiverTester.chunkReceived called" +
15+
System.out.println("ChunkReceiverTester.chunkReceived called: (sender/uri/era) " +
1616
sender +
1717
" / " +
1818
uri +
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)