import Demo.*; public class BlockSubscriber extends Ice.Application { public class ClockI extends _ClockDisp { public void tick2(Structure date, Ice.Current current) { System.out.println(date.index); System.out.println("size="+date.name.length()); for(int i=0;i<100000;i++) { try { Thread.sleep(5000); } catch (InterruptedException e) { } } } public void tick(String date, Ice.Current current) { System.out.println(date); for(int i=0;i<100000;i++) { try { Thread.sleep(5000); } catch (InterruptedException e) { } } } } public void usage() { System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); } public int run(String[] args) { // get router proxy Ice.RouterPrx defaultRouter; Glacier2.RouterPrx router; defaultRouter = communicator().getDefaultRouter(); router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); // create glacier2 session String id="id"; String pw="pw"; try { router.createSession(id, pw); } catch(Glacier2.PermissionDeniedException ex) { System.out.println("permission denied:\n" + ex.reason); } catch(Glacier2.CannotCreateSessionException ex) { System.out.println("cannot create session:\n" + ex.reason); } //*************************************************** IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper. checkedCast(communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); if (manager == null) { System.err.println("invalid proxy"); return 1; } String topicName = "time"; // get topic IceStorm.TopicPrx topic; try { topic = manager.retrieve(topicName); } catch(IceStorm.NoSuchTopic ee) { try { topic = manager.create(topicName); } catch(IceStorm.TopicExists ex) { System.err.println(appName() + ": temporary failure, try again."); return 1; } } //****************************************************** // create adapter Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Clock.Subscriber"); // add object to subscriber adapter String category = router.getServerProxy().ice_getIdentity().category; Ice.Identity clockerIdent = new Ice.Identity();; clockerIdent.name = Ice.Util.generateUUID(); clockerIdent.category = category; //****************************************************** // // Add a Servant for the Ice Object. // java.util.Map qos = new java.util.HashMap(); Ice.ObjectPrx subscriber= adapter.add(new ClockI(),clockerIdent); //subscriber = subscriber.ice_oneway(); topic.subscribe(qos, subscriber); adapter.activate(); shutdownOnInterrupt(); communicator().waitForShutdown(); topic.unsubscribe(subscriber); return 0; } public static void main(String[] args) { BlockSubscriber app = new BlockSubscriber(); int status = app.main("BlockSubscriber", args, "config.sub.glacier2"); System.exit(status); } }