Archived

This forum has been archived. Please start a new discussion on GitHub.

Problem with IceStorm noce more

Like the example[Weather Monitor] in Spec I have written a much more simple test program. There were no problems with Server, Client and IceBox service configuration. But the client could not display the published message.
The code is very simple, but I can not find out why. I'd like to hear some tipps from anyone. Thanks!
Code for SuperNewsServer.java
public class SuperNewsServer extends Application {
	public static void main(String[] args) {
		SuperNewsServer sns = new SuperNewsServer();
		int status = sns.main("SuperNewsServer", args);
		System.exit(status);
	}

	@Override
	public int run(String[] arg0) {
		Communicator ic = communicator();
		ObjectPrx tm$ = ic.stringToProxy("IceStorm/TopicManager:tcp -p 9998");
		TopicManagerPrx tm = TopicManagerPrxHelper.checkedCast(tm$);
		TopicPrx tpp = null;
		try {
			tpp = tm.retrieve("SportNewsCenter");
		} catch (NoSuchTopic e) {
			try {
				tpp = tm.create("SportNewsCenter");
			} catch (TopicExists e1) {
				e1.printStackTrace();
			}
		}
		System.out.println(tpp.getName());
		ObjectPrx pub = tpp.getPublisher();
		NewsCenterPrx ncp = NewsCenterPrxHelper.uncheckedCast(pub);
		NewsServerI ns = new NewsServerI("Sport", ncp);
		System.out.println("super news server ready...");
		int id = 1;
		for (int i = 0; i < 1000; i++) {
			ns.publish("automatic news number: " + id);
			++id;
			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		ic.waitForShutdown();
		return 0;
	}

}

code for NewsServerI.java
public class NewsServerI extends _NewsServerDisp {
	String category;

	NewsCenterPrx newsCenter;

	public NewsServerI(String cat, NewsCenterPrx ncp) {
		category = cat;
		newsCenter = ncp;
	}

	public void publish(String news, Current __current) {
		System.out.println("[to publish]: " + news);
		newsCenter.publishNews("[" + category.toUpperCase() + "]: " + news);
	}
}

code for NewsCenterI.java
public class NewsCenterI extends _NewsCenterDisp {

	public void publishNews(String news, Current __current) {
		System.out.println("[GOT NEWS]: " + news);
	}

}

code for NewsClient.java
public class NewsClient extends Application {
	public static void main(String[] args) {
		NewsClient nc = new NewsClient();
		int status = nc.main("NewsClient", args);
		System.exit(status);
	}

	@Override
	public int run(String[] arg0) {
		Communicator ic = communicator();
		ObjectPrx tm$ = ic.stringToProxy("IceStorm/TopicManager:tcp -p 9998");
		TopicManagerPrx tm = TopicManagerPrxHelper.checkedCast(tm$);
		ObjectAdapter oa = ic.createObjectAdapter("NewsCenterAdapter");
		NewsCenterI nci = new NewsCenterI();
		ObjectPrx np = oa.addWithUUID(nci);
		TopicPrx tpp = null;
		try {
			tpp = tm.retrieve("SportNewsCenter");
		} catch (NoSuchTopic e) {
			e.printStackTrace();
		}
		System.out.println(tpp.getName());
		tpp.subscribe(null, np);
		oa.activate();
		System.out.println("subsribed for sport news");
		ic.waitForShutdown();
		tpp.unsubscribe(np);
		return 0;
	}
}

Comments

  • dwayne
    dwayne St. John's, Newfoundland
    Hi,

    For support, please set your signature as described in this thread.

    Regards,
    Dwayne
  • update of my signature

    I have updated my signature with university and project in the sense of where I am in and what I am listening to.
  • benoit
    benoit Rennes, France
    Hi,

    Your code seems fine. Can you also post the configuration of the your publisher and subscriber? Did you correctly configured the endpoints of your subscriber object adapter (with the property "NewsCenterAdapter.Endpoint=tcp" for example)?

    The best way to investigate these problems is to add tracing to the IceStorm service. Try to run your IceStorm service with the properties IceStorm.Trace.Subscriber=1 and Ice.Trace.Network=2. It should give more information if the IceStorm service fails to establish a network connection to the subscriber.

    Cheers,
    Benoit.
  • Problem still exists

    Hi,
    Thanks for reply. "NewsCenterAdapter.Endpoint=tcp" that's the core solution for my problem. I have changed the code in NewsClient.java to:
    ...
    ObjectAdapter oa = ic.createObjectAdapterWithEndpoints("NewsCenterAdapter", "default -p 11011");
    ...
    
    And this did work.

    Regards