Skip to content

Commit b251b7c

Browse files
committed
about making inter era message exchange default for javaApp interface
1 parent 37c2b80 commit b251b7c

2 files changed

Lines changed: 75 additions & 19 deletions

File tree

src/net/sharksystem/asap/apps/ASAPJavaApplicationFS.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private ASAPJavaApplicationFS(CharSequence owner, CharSequence rootFolder, Colle
3030
// ensure that supported format engine are up and running
3131
for(CharSequence format : supportedFormats) {
3232
this.multiEngine.createEngineByFormat(format);
33+
34+
// setup inter era message delivery
35+
System.out.println(this.getLogStart() + "setup inter era message exchange for " + format);
36+
ASAPEngine engine = multiEngine.getEngineByFormat(format);
37+
new ASAPSingleProcessOnlineMessageSender(this.multiEngine, engine);
3338
}
3439
}
3540
}

test/net/sharksystem/asap/ASAPJavaApplicationTests.java

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,85 @@ public void usageTest() throws IOException, ASAPException, InterruptedException
3535
asapJavaApplicationAlice.sendASAPMessage(APP_FORMAT, "yourSchema://yourURI", recipients, TESTMESSAGE);
3636
asapJavaApplicationAlice.setASAPMessageReceivedListener(APP_FORMAT, new ListenerExample());
3737

38+
// create bob engine
39+
ASAPJavaApplication asapJavaApplicationBob =
40+
ASAPJavaApplicationFS.createASAPJavaApplication(BOB, BOB_ROOT_FOLDER, formats);
41+
42+
ListenerExample listenerBob = new ListenerExample();
43+
asapJavaApplicationBob.setASAPMessageReceivedListener(APP_FORMAT, listenerBob);
44+
3845
///////////////////////////////////////////////////////////////////////////////////////////////////
3946
// create a tcp connection //
4047
///////////////////////////////////////////////////////////////////////////////////////////////////
4148

49+
// create connections for both sides
50+
TCPChannel aliceChannel = new TCPChannel(PORT, true, "a2b");
51+
TCPChannel bobChannel = new TCPChannel(PORT, false, "b2a");
52+
53+
aliceChannel.start(); bobChannel.start();
54+
// wait to connect
55+
aliceChannel.waitForConnection(); bobChannel.waitForConnection();
56+
57+
///////////////////////////////////////////////////////////////////////////////////////////////////
58+
// run asap session //
59+
///////////////////////////////////////////////////////////////////////////////////////////////////
60+
61+
// run engine as thread
62+
ASAPHandleConnectionThread aliceEngineThread = new ASAPHandleConnectionThread(asapJavaApplicationAlice,
63+
aliceChannel.getInputStream(), aliceChannel.getOutputStream());
64+
65+
aliceEngineThread.start();
66+
67+
// let's start communication
68+
asapJavaApplicationBob.handleConnection(bobChannel.getInputStream(), bobChannel.getOutputStream());
69+
70+
// wait until communication probably ends
71+
Thread.sleep(2000); System.out.flush(); System.err.flush();
72+
// close connections: note ASAPEngine does NOT close any connection!!
73+
aliceChannel.close(); bobChannel.close(); Thread.sleep(1000);
74+
75+
///////////////////////////////////////////////////////////////////////////////////////////////////
76+
// test results //
77+
///////////////////////////////////////////////////////////////////////////////////////////////////
78+
79+
// received?
80+
Assert.assertTrue(listenerBob.hasReceivedMessage());
81+
}
82+
83+
@Test
84+
public void onlineTest() throws IOException, ASAPException, InterruptedException {
85+
ASAPEngineFS.removeFolder(TESTS_ROOT_FOLDER);
86+
87+
Collection<CharSequence> formats = new HashSet<>();
88+
formats.add(APP_FORMAT);
89+
90+
// create alice engine
91+
ASAPJavaApplication asapJavaApplicationAlice =
92+
ASAPJavaApplicationFS.createASAPJavaApplication(ALICE, ALICE_ROOT_FOLDER, formats);
93+
4294
// create bob engine
4395
ASAPJavaApplication asapJavaApplicationBob =
4496
ASAPJavaApplicationFS.createASAPJavaApplication(BOB, BOB_ROOT_FOLDER, formats);
4597

98+
// create Bob receiver
4699
ListenerExample listenerBob = new ListenerExample();
47100
asapJavaApplicationBob.setASAPMessageReceivedListener(APP_FORMAT, listenerBob);
48101

102+
103+
///////////////////////////////////////////////////////////////////////////////////////////////////
104+
// create a tcp connection //
105+
///////////////////////////////////////////////////////////////////////////////////////////////////
106+
49107
// create connections for both sides
50108
TCPChannel aliceChannel = new TCPChannel(PORT, true, "a2b");
51109
TCPChannel bobChannel = new TCPChannel(PORT, false, "b2a");
52110

53-
aliceChannel.start();
54-
bobChannel.start();
55-
111+
aliceChannel.start(); bobChannel.start();
56112
// wait to connect
57-
aliceChannel.waitForConnection();
58-
bobChannel.waitForConnection();
113+
aliceChannel.waitForConnection(); bobChannel.waitForConnection();
59114

60115
///////////////////////////////////////////////////////////////////////////////////////////////////
61-
// run asap connection //
116+
// run asap session //
62117
///////////////////////////////////////////////////////////////////////////////////////////////////
63118

64119
// run engine as thread
@@ -70,21 +125,17 @@ public void usageTest() throws IOException, ASAPException, InterruptedException
70125
// let's start communication
71126
asapJavaApplicationBob.handleConnection(bobChannel.getInputStream(), bobChannel.getOutputStream());
72127

73-
// wait until communication probably ends
74-
System.out.flush();
75-
System.err.flush();
76-
Thread.sleep(2000);
77-
System.out.flush();
78-
System.err.flush();
128+
// nothing really spectaculare has happend until now
79129

130+
// create a message and send message from alice to bob over an existing connection
131+
Collection<CharSequence> recipients = new HashSet<>();
132+
recipients.add(BOB);
133+
asapJavaApplicationAlice.sendASAPMessage(APP_FORMAT, "yourSchema://yourURI", recipients, TESTMESSAGE);
134+
135+
// wait until communication probably ends
136+
Thread.sleep(2000); System.out.flush(); System.err.flush();
80137
// close connections: note ASAPEngine does NOT close any connection!!
81-
aliceChannel.close();
82-
bobChannel.close();
83-
System.out.flush();
84-
System.err.flush();
85-
Thread.sleep(1000);
86-
System.out.flush();
87-
System.err.flush();
138+
aliceChannel.close(); bobChannel.close(); Thread.sleep(1000);
88139

89140
///////////////////////////////////////////////////////////////////////////////////////////////////
90141
// test results //

0 commit comments

Comments
 (0)