Home Help Center

where

hi,
I am working through the publisher/subscriber example in chapter 25, not the clock case for C++ but the weather report , and I am having some trouble. I start the storm service following the steps in the readme for the colock case ,then run the server(subscriber) and start the client(publisher) in eclipse. But i can't see any result in the server side's console window.
It should show the information about the weather but i can't see anything.
:(
following is the config_server and config files.

config_server:
IceBox.Service.IceStorm=IceStormService,13:create --Ice.Config=config
IceBox.DBEnvName.IceStorm=db

config:
IceBox.Service.IceStorm=IceStormService,1.0.0:create
Monitor.Subscriber.Endpoints=tcp
IceBox.DBEnvName.IceStorm=db
IceStorm.TopicManager.Endpoints=tcp -p 9999
IceStorm.Publish.Endpoints=tcp
IceStorm.TopicManager.Proxy=IceStorm/TopicManager:tcp -p 9999

there is part of my code:
public class MonitorI extends _MonitorDisp
{
public void report(Measurement m,Ice.Current current)
{
System.out.println(
"Measurement report:\n"+
"W Spd: " + m.windSpeed + "\n" +
"W Dir: " + m.windDirection + "\n" +
" Temp: " + m.temperature + "\n");
}
}


public class Server_storm
{
private static int
run(String[] args, Ice.Communicator communicator)
{ Ice.ObjectPrx obj = communicator.stringToProxy(
"IceStorm/TopicManager:tcp -p 9999");
IceStorm.TopicManagerPrx topicManager =
IceStorm.TopicManagerPrxHelper.checkedCast(obj);
ObjectAdapter adapter =
communicator.createObjectAdapter("MonitorAdapter");
Monitor monitor = new MonitorI();
Ice.ObjectPrx proxy = adapter.addWithUUID(monitor);
IceStorm.TopicPrx topic = null;
try {
topic = topicManager.retrieve("Weather");
java.util.Map qos = null;
topic.subscribe(qos,proxy);
}
catch (IceStorm.NoSuchTopic ex)
{
ex.printStackTrace();
}
System.out.println(topic);
adapter.activate();
communicator.waitForShutdown();
topic.unsubscribe(proxy); return 0;
}
public static void main(String[] args)
{

System.out.println("ICE_test_storm demo is starting");
int status = 0;
Ice.Communicator communicator = null;
try
{
Ice.Properties properties = Ice.Util.createProperties(args);
properties.load("config");
communicator = Ice.Util.initializeWithProperties(args, properties);
status = run(args, communicator);
}
catch(Ice.LocalException ex)
{
ex.printStackTrace();
status = 1;
} finally {
if(communicator != null)
{
communicator.destroy();
}
}
System.exit(status);

}
}

///////////////////////////////////////////////////////////////////////////
import IceStorm.TopicExists;




public class Client_storm
{
public static void main(String [] args)
{
Ice.Communicator ic = null;
System.out.println("The publisher is starting....");
ic=Ice.Util.initialize(args);
Ice.ObjectPrx obj=ic.stringToProxy("IceStorm/TopicManager:tcp -p 9999");
IceStorm.TopicManagerPrx topicManager =
IceStorm.TopicManagerPrxHelper.checkedCast(obj);
IceStorm.TopicPrx topic=null;
try {
topic = topicManager.retrieve("Weather");
}
catch(IceStorm.NoSuchTopic ex) { try {
topic = topicManager.create("Weather");
} catch (TopicExists e) { e.printStackTrace();
}
}
Ice.ObjectPrx pub=topic.getPublisher();
if(!pub.ice_isDatagram())
pub = pub.ice_oneway(); MonitorPrx monitor = MonitorPrxHelper.uncheckedCast(pub);
int i=0;
while( i<100)
{
Measurement m = getMeasurement();
printor(m);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
monitor.report(m,null);
i++;
}

private static Measurement getMeasurement() {
Measurement temp=new Measurement();
temp.temperature=10+i;
temp.tower="tower"+i+"#";
temp.windSpeed=i;
temp.windDirection=(short) i;
i++;

return temp;
}
private static int i=0;
private static void printor(Measurement m)
{
System.out.println(
"Measurement report:\n"+
"w tower"+m.tower+"\n"+
"W Spd: " + m.windSpeed + "\n" +
"W Dir: " + m.windDirection + "\n" +
" Temp: " + m.temperature + "\n");
}

}

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Welcome!

    The problem is that your subscriber's object adapter has no endpoints, therefore the proxy it sends to the topic manager cannot be used to send messages to the subscriber.

    One way to fix this is to change your subscriber to call createObjectAdapterWithEndpoints, for example:
    Ice.ObjectAdapter adapter =
      communicator.createObjectAdapterWithEndpoints("MonitorAdapter", "tcp");
    
    Take care,
    - Mark
  • lovesunnylovesunny Member
    Ok

    Thanks. Every thing is ok.
Sign In or Register to comment.