package org.avis.client.examples;
import org.avis.client.Elvin;
import org.avis.client.Notification;
import org.avis.client.NotificationEvent;
import org.avis.client.NotificationListener;
import org.avis.client.Subscription;
public class HelloWorld
{
public static void main (String [] args)
throws Exception
{
String elvinUri = System.getProperty ("elvin", "elvin://localhost");
Elvin listeningClient = new Elvin (elvinUri);
final Subscription greetingSubscription =
listeningClient.subscribe ("require (Greeting)");
greetingSubscription.addListener (new NotificationListener ()
{
public void notificationReceived (NotificationEvent e)
{
System.out.println
("Received greeting: " + e.notification.get ("Greeting"));
synchronized (greetingSubscription)
{
greetingSubscription.notify ();
}
}
});
Elvin sendingClient = new Elvin (elvinUri);
Notification greeting = new Notification ();
greeting.set ("Greeting", "Hello World!");
synchronized (greetingSubscription)
{
sendingClient.send (greeting);
greetingSubscription.wait ();
}
listeningClient.close ();
sendingClient.close ();
}
}