public override int run(string[] args) { string option = "None"; string topicName = "time"; int i; for (i = 0; i < args.Length; ++i) { String oldoption = option; if (args[i].Equals("--datagram")) { option = "Datagram"; } else if (args[i].Equals("--twoway")) { option = "Twoway"; } else if (args[i].Equals("--oneway")) { option = "Oneway"; } else if (args[i].StartsWith("--")) { usage(); return(1); } else { topicName = args[i++]; break; } if (!oldoption.Equals(option) && !oldoption.Equals("None")) { usage(); return(1); } } if (i != args.Length) { usage(); return(1); } IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( communicator().propertyToProxy("TopicManager.Proxy")); if (manager == null) { Console.WriteLine("invalid proxy"); return(1); } // // Retrieve the topic. // IceStorm.TopicPrx topic; try { topic = manager.retrieve(topicName); } catch (IceStorm.NoSuchTopic) { try { topic = manager.create(topicName); } catch (IceStorm.TopicExists) { Console.WriteLine("temporary error. try again."); return(1); } } // // Get the topic's publisher object, and create a Clock proxy with // the mode specified as an argument of this application. // Ice.ObjectPrx publisher = topic.getPublisher(); if (option.Equals("Datagram")) { publisher = publisher.ice_datagram(); } else if (option.Equals("Twoway")) { // Do nothing. } else // if(oneway) { publisher = publisher.ice_oneway(); } ClockPrx clock = ClockPrxHelper.uncheckedCast(publisher); Console.WriteLine("publishing tick events. Press ^C to terminate the application."); try { while (true) { clock.tick(System.DateTime.Now.ToString("G", DateTimeFormatInfo.InvariantInfo)); System.Threading.Thread.Sleep(1000); } } catch (Ice.CommunicatorDestroyedException) { // Ignore } return(0); }
public override int run(string[] args) { args = communicator().getProperties().parseCommandLineOptions("Clock", args); string topicName = "time"; string option = "None"; bool batch = false; string id = null; string retryCount = null; int i; for (i = 0; i < args.Length; ++i) { String oldoption = option; if (args[i].Equals("--datagram")) { option = "Datagram"; } else if (args[i].Equals("--twoway")) { option = "Twoway"; } else if (args[i].Equals("--ordered")) { option = "Ordered"; } else if (args[i].Equals("--oneway")) { option = "Oneway"; } else if (args[i].Equals("--batch")) { batch = true; } else if (args[i].Equals("--id")) { ++i; if (i >= args.Length) { usage(); return(1); } id = args[i]; } else if (args[i].Equals("--retryCount")) { ++i; if (i >= args.Length) { usage(); return(1); } retryCount = args[i]; } else if (args[i].StartsWith("--")) { usage(); return(1); } else { topicName = args[i++]; break; } if (!oldoption.Equals(option) && !oldoption.Equals("None")) { usage(); return(1); } } if (i != args.Length) { usage(); return(1); } if (retryCount != null) { if (option.Equals("None")) { option = "Twoway"; } else if (!option.Equals("Twoway") && !option.Equals("Ordered")) { usage(); return(1); } } if (batch && (option.Equals("Twoway") || option.Equals("Ordered"))) { Console.WriteLine(appName() + ": batch can only be set with oneway or datagram"); return(1); } IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( communicator().propertyToProxy("TopicManager.Proxy")); if (manager == null) { Console.WriteLine("invalid proxy"); return(1); } // // Retrieve the topic. // IceStorm.TopicPrx topic; try { topic = manager.retrieve(topicName); } catch (IceStorm.NoSuchTopic) { try { topic = manager.create(topicName); } catch (IceStorm.TopicExists) { Console.WriteLine("temporary error. try again."); return(1); } } Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Clock.Subscriber"); // // Add a servant for the Ice object. If --id is used the // identity comes from the command line, otherwise a UUID is // used. // // id is not directly altered since it is used below to // detect whether subscribeAndGetPublisher can raise // AlreadySubscribed. // Ice.Identity subId = new Ice.Identity(id, ""); if (subId.name == null) { subId.name = Guid.NewGuid().ToString(); } Ice.ObjectPrx subscriber = adapter.add(new ClockI(), subId); // // Activate the object adapter before subscribing. // adapter.activate(); Dictionary <string, string> qos = new Dictionary <string, string>(); if (retryCount != null) { qos["retryCount"] = retryCount; } // // Set up the proxy. // if (option.Equals("Datagram")) { if (batch) { subscriber = subscriber.ice_batchDatagram(); } else { subscriber = subscriber.ice_datagram(); } } else if (option.Equals("Twoway")) { // Do nothing to the subscriber proxy. Its already twoway. } else if (option.Equals("Ordered")) { // Do nothing to the subscriber proxy. Its already twoway. qos["reliability"] = "ordered"; } else if (option.Equals("Oneway") || option.Equals("None")) { if (batch) { subscriber = subscriber.ice_batchOneway(); } else { subscriber = subscriber.ice_oneway(); } } try { topic.subscribeAndGetPublisher(qos, subscriber); } catch (IceStorm.AlreadySubscribed) { // If we're manually setting the subscriber id ignore. if (id == null) { throw; } System.Console.Out.WriteLine("reactivating persistent subscriber"); } shutdownOnInterrupt(); communicator().waitForShutdown(); topic.unsubscribe(subscriber); return(0); }
public IceManager(string adapterName, string host, int port, bool catchSignals = true) { IceGridHost = host; IceGridPort = port; Name = adapterName; logger = log4net.LogManager.GetLogger(this.GetType().Name + "::" + Name); _ServantIds = new List <Ice.Identity>(); //keep track of servants for emergency cleanup string myIP = findLocalIPAddress(); logger.Info("My IPAddress is: " + myIP); //initialize Ice Ice.Properties prop = Ice.Util.createProperties(); prop.setProperty("hms.AdapterId", adapterName); prop.setProperty("hms.Endpoints", "tcp -h " + myIP + ":udp -h " + myIP); prop.setProperty("Ice.Default.Locator", "IceGrid/Locator:tcp -p " + IceGridPort + " -h " + IceGridHost); prop.setProperty("Ice.ThreadPool.Server.Size", "5"); prop.setProperty("Ice.ThreadPool.Server.SizeMax", "100000"); prop.setProperty("Ice.ThreadPool.Client.Size", "5"); prop.setProperty("Ice.ThreadPool.Client.SizeMax", "100000"); Ice.InitializationData iceidata = new Ice.InitializationData(); iceidata.properties = prop; Communicator = Ice.Util.initialize(iceidata); // could add sys.argv try { _Adapter = Communicator.createObjectAdapter("hms"); _Adapter.activate(); } catch (Exception ex) { logger.Fatal("Network error, check configuration: " + ex.Message); logger.Fatal("Endpoint(should be local machine): " + prop.getProperty("hms.Endpoints")); logger.Fatal("Locator (should be IceGrid Server): " + prop.getProperty("Ice.Default.Locator")); throw (ex); // we are dead anyway } //Now are we ready to communicate with others //getting usefull proxies try { // proxy to icegrid to register our vc devices Query = IceGrid.QueryPrxHelper.checkedCast(Communicator.stringToProxy("IceGrid/Query")); if (Query == null) { logger.Error("invalid ICeGrid proxy"); } // proxy to icestorm to publish events EventMgr = IceStorm.TopicManagerPrxHelper.checkedCast(Communicator.stringToProxy("EventServer/TopicManager")); if (EventMgr == null) { logger.Error("invalid IceStorm proxy"); } //these 2 objects are only needed to get the IceGrid admin object in order to register _Registry = IceGrid.RegistryPrxHelper.uncheckedCast(Communicator.stringToProxy("IceGrid/Registry")); updateIceGridAdmin(); } catch (Ice.NotRegisteredException e) { logger.Fatal("If we fail here it is probably because the Icebox objects are not registered: " + e.Message); } catch (Exception e) { logger.Fatal("IceGrid Server not found!!!!!: " + e.Message); throw (e);//without yellow page system, there is no need to start } if (catchSignals) { setupSignals(); } }
public IceManager(string adapterName, string host, int port, bool catchSignals = true) { IceGridHost = host; IceGridPort = port; Name = adapterName; logger = log4net.LogManager.GetLogger(this.GetType().Name + "::" + Name); _ServantIds = new List<Ice.Identity>(); //keep track of servants for emergency cleanup string myIP = findLocalIPAddress(); logger.Info("My IPAddress is: " + myIP); //initialize Ice Ice.Properties prop = Ice.Util.createProperties(); prop.setProperty("hms.AdapterId", adapterName); prop.setProperty("hms.Endpoints", "tcp -h " + myIP + ":udp -h " + myIP); prop.setProperty("Ice.Default.Locator", "IceGrid/Locator:tcp -p " + IceGridPort + " -h " + IceGridHost); prop.setProperty("Ice.ThreadPool.Server.Size", "5"); prop.setProperty("Ice.ThreadPool.Server.SizeMax", "100000"); prop.setProperty("Ice.ThreadPool.Client.Size", "5"); prop.setProperty("Ice.ThreadPool.Client.SizeMax", "100000"); Ice.InitializationData iceidata = new Ice.InitializationData(); iceidata.properties = prop; Communicator = Ice.Util.initialize(iceidata); // could add sys.argv try { _Adapter = Communicator.createObjectAdapter("hms"); _Adapter.activate(); } catch (Exception ex) { logger.Fatal("Network error, check configuration: " + ex.Message); logger.Fatal("Endpoint(should be local machine): " + prop.getProperty("hms.Endpoints")); logger.Fatal("Locator (should be IceGrid Server): " + prop.getProperty("Ice.Default.Locator")); throw (ex); // we are dead anyway } //Now are we ready to communicate with others //getting usefull proxies try { // proxy to icegrid to register our vc devices Query = IceGrid.QueryPrxHelper.checkedCast(Communicator.stringToProxy("IceGrid/Query")); if (Query == null) { logger.Error("invalid ICeGrid proxy"); } // proxy to icestorm to publish events EventMgr = IceStorm.TopicManagerPrxHelper.checkedCast(Communicator.stringToProxy("EventServer/TopicManager")); if (EventMgr == null) { logger.Error("invalid IceStorm proxy"); } //these 2 objects are only needed to get the IceGrid admin object in order to register _Registry = IceGrid.RegistryPrxHelper.uncheckedCast(Communicator.stringToProxy("IceGrid/Registry")); updateIceGridAdmin(); } catch (Ice.NotRegisteredException e) { logger.Fatal("If we fail here it is probably because the Icebox objects are not registered: " + e.Message); } catch (Exception e) { logger.Fatal("IceGrid Server not found!!!!!: " + e.Message); throw (e);//without yellow page system, there is no need to start } if (catchSignals) { setupSignals(); } }