Mercurial > hg > blitz_condensed
diff examples/helloworld/Taker.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/helloworld/Taker.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,61 @@ +package helloworld; + +import java.rmi.RMISecurityManager; + +import net.jini.space.JavaSpace; + +import net.jini.core.entry.Entry; + +import net.jini.core.lease.Lease; + +/** + Taker will attempt to take as many entry's as it can find. If any take + blocks longer than 120 seconds, Taker assumes there are no more Entry's + and stops. + */ +public class Taker { + + public void exec() throws Exception { + // Locate a JavaSpace - we will only find those registered + // BEFORE we were started up - doing it properly requires + // ServiceDiscoveryManager - for another time.... + // + System.out.println("Looking for JavaSpace"); + + Lookup myFinder = new Lookup(JavaSpace.class); + + JavaSpace mySpace = (JavaSpace) myFinder.getService(); + + System.out.println("Got space - waiting for Entry's"); + + // We want to find any TestEntry instance so we don't set the + // fields which gives us wildcard match + Entry myTemplate = new TestEntry(); + + while (true) { + Entry myResult = mySpace.take(myTemplate, null, 120 * 1000); + + if (myResult == null) { + System.out.println("No more entry's in the last 120 seconds"); + break; + } + + System.out.println("Took: " + myResult); + } + } + + public static void main(String args[]) { + // We must set the RMI security manager to allow downloading of code + // which, in this case, is the Blitz proxy amongst other things + // + try { + if (System.getSecurityManager() == null) + System.setSecurityManager(new RMISecurityManager()); + + new Taker().exec(); + } catch (Exception anE) { + System.err.println("Whoops"); + anE.printStackTrace(System.err); + } + } +}