Information Technology Reference
In-Depth Information
public class Publisher {
public static void main(String[] args) {
Publisher a = new Publisher();
a.publish(
"This is a test String \ldots{}"
);
System.exit(0);
}
public void publish(String s) {
}
}
Figure 6.2.
Java Publisher class.
public class Subscriber {
public static void main(String[] args) throws InterruptedException {
Subscriber a = new Subscriber();
while (true){
a.subscribe(
"This is not from the producer"
);
Thread.sleep(5000);
}
}
public void subscribe(String message) {
System.out.println(
"Received: "
+ message);
}
}
Figure 6.3.
Java Subscriber class.
The
Publisher
class is altered so that calls to its
publish()
method are
altered to send the
String
parameter as a message on the
REMOTEJ.SEND
topic.
As can be seen in Figure 6.2 and Figure 6.3, the existing code is unaware of the
protocol or recovery scenario that will be applied to it.
Running the applications verifies that the test applications work as expected
with the
Publisher.publish()
method sending
String
objects that are received
by the
Subscriber.subscribe()
method asynchronously.
6.2.4
Summary
In this section we have evaluated the extendibility of the RemoteJ system by
adding two additional protocols,
pub
and
sub
. In contrast to the RMI, REST and
JMS protocols, the
sub
protocol is event-driven as it alters the matched method
to receive data asynchronously. The
pub
protocol alters the matched method to
send its parameter as a message on a topic.
Both protocols are asynchronous and loosely-coupled in nature and are there-
fore decoupled in
time
,
space
and
synchronisation
, and our evaluation has demon-
Search WWH ::
Custom Search