import org.openspaces.core.GigaSpace;
import org.openspaces.core.GigaSpaceConfigurer;
import org.openspaces.core.space.UrlSpaceConfigurer;
import org.openspaces.events.SpaceDataEventListener;
import org.openspaces.events.notify.SimpleNotifyContainerConfigurer;
import org.openspaces.events.notify.SimpleNotifyEventListenerContainer;
import org.springframework.transaction.TransactionStatus;
import com.j_spaces.core.IJSpace;
public class NotifiedReader {
private static SimpleNotifyEventListenerContainer notifyContainer;
/**
* Connect to space and register for notifications
* @param args
*/
public static void listen(String url){
IJSpace space = new UrlSpaceConfigurer(url).space(); GigaSpace gigaSpace = new GigaSpaceConfigurer(space).gigaSpace();
notifyContainer = new SimpleNotifyContainerConfigurer(gigaSpace)
.template(new Account()).fifo(true).notifyWrite(true)
.eventListener(new SpaceDataEventListener<Account>() {
public void onEvent(Account account, GigaSpace gigaSpace,
TransactionStatus txStatus, Object source) {
System.out.println("Read account info ["+account.toString()+"]");
}
}).notifyContainer();
System.out.println("Listening...");
}
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: <URL>");
System.out.println("<protocol>:);
System.exit(1);
}
try {
System.out.println("\nWelcome to GigaSpaces Data_Grid Topologies Example");
System.out.println("Registering for account write notifications");
NotifiedReader.listen(args[0]);
Thread.sleep(2000000); notifyContainer.destroy();
} catch (Throwable e) {
e.printStackTrace();
}
}
}