Home Help Center

a problem about facet and IceStorm

first of all,my english is very poor,so I am very sorry.If the problem isn't described clearly,you can tell me and I will do best to it.

when I integrate facet and IceStorm ,I have a problem.It is described like this:

I added some facets in server and in client my codes is:

Ice.Communicator communicator = null;
System.out.println("Facet storm client is starting....");

communicator =Ice.Util.initialize(args);

//get the TopicManager object
Ice.ObjectPrx obj = communicator.stringToProxy
("IceStorm/TopicManager:tcp -p 10000");

IceStorm.TopicManagerPrx topicManager =
IceStorm.TopicManagerPrxHelper.checkedCast(obj);
IceStorm.TopicPrx topic = null;

//get a "Trap" topic
try {
topic = topicManager.retrieve("Trap");
}
catch(IceStorm.NoSuchTopic ex)
{
try {
topic = topicManager.create("Trap");
} catch (TopicExists e) { e.printStackTrace();
}

}

Ice.ObjectPrx pub = topic.getPublisher();

if(!pub.ice_isDatagram())
pub = pub.ice_oneway();



machine = receiveEventPrxHelper.checkedCast(machine,"facet");
machine.manageEvent(event);

@",the exception is:

Ice.TwowayOnlyException
operation = "ice_isA"
at Ice.ObjectPrxHelperBase.__checkTwowayOnly(ObjectPrxHelperBase.java:597)
at Ice.ObjectPrxHelperBase.ice_isA(ObjectPrxHelperBase.java:40)
at Ice.ObjectPrxHelperBase.ice_isA(ObjectPrxHelperBase.java:29)
at ice.eventGenerated.receiveEventPrxHelper.checkedCast(receiveEventPrxHelper.java:62)
at iceEvent.SendEvent.manageEvent(SendEvent.java:135)
at iceEvent.SendEvent.main(SendEvent.java:94)

so how can I do? what is the reason?

Thank you very much,I am very sorry about my English level

BTW,what are the differences about checkedCast and uncheckedCast

Comments

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

    The checkedCast operation invokes a remote twoway operation (ice_isA). Since this is a twoway operation, it cannot be invoked on a oneway proxy, therefore the TwowayOnlyException is raised. There are two ways to avoid this exception: you can use an uncheckedCast instead, which does not make a remote invocation but does not guarantee that the remote object implements the requested type, or you can alter the sequence of statements in your code so that checkedCast is invoked on a twoway proxy first.

    Take care,
    - Mark
  • freshmanfreshman Member ✭✭
    Thank you very much

    I will try it.
    If there are some new problems ,I will be back.Thank you.
  • freshmanfreshman Member ✭✭
    I failed

    hello everyone. I modified the "checkedCast" as "uncheckedCast",so the codes is

    receiveEventPrx machine = receiveEventPrxHelper.uncheckedCast(pub);
    receiveEventPrx machine1 = receiveEventPrxHelper.uncheckedCast(machine,"facet");
    machine1.manageEvent(event);

    I have some questions: Is machine a object and is machine1 is a facet of machine?
    I have a trial ,"machine.manageEvent(event);" can work well and "machine1.manageEvent(event) can't work well"

    and in the server the codes is:

    Ice.Object receiveEvent = new receiveEventI();
    Ice.ObjectPrx proxy = adapter.add(receiveEvent, Ice.Util.stringToIdentity("receiveEvent"));
    adapter.addFacet(receiveEvent, Ice.Util.stringToIdentity("receiveEvent"), "facet");

    so what happened? how to do it?



    another question:

    what is the exception "Ice.UnmarshalOutOfBoundsException"? who causes it?
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Re: I failed

    Hi,

    IceStorm currently does not preserve the facet when forwarding events to subscribers, therefore you cannot use IceStorm to publish events to facet servants. We will investigate this further.
    Originally posted by freshman
    another question:

    what is the exception "Ice.UnmarshalOutOfBoundsException"? who causes it?
    This exception can occur when the client and server are not using the same Slice definitions. In this case the receiver is attempting to unmarshal an incorrect type, which could cause it to unmarshal garbage or attempt to unmarshal more data than is actually available.

    Take care,
    - Mark
  • freshmanfreshman Member ✭✭
    Thank you mes

    two more questions:

    1. so is it impossible to make IceStorm and facet together ?
    2. my teacher doubted that IceStorm cann't use chackedCast, because it doesn't check in the server ,is it ?
    3. if cann't make IceStorm and facet together ,what's the reason? Is it described in question 2?


    I am very sorry to disturbe you, thank you very much for helping me!!
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Re: Thank you mes
    Originally posted by freshman
    1. so is it impossible to make IceStorm and facet together ?
    Yes, currently it is not possible to use IceStorm to publish messages to facets.
    2. my teacher doubted that IceStorm cann't use chackedCast, because it doesn't check in the server ,is it ?
    That is correct, you should not call checkedCast on the topic's publisher object.
    3. if cann't make IceStorm and facet together ,what's the reason?
    We haven't implemented it yet.

    Take care,
    - Mark
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Sorry, I was wrong. It is possible to use IceStorm to publish messages to facets, you just have to make sure that the subscriber's proxy contains the desired facet.

    Note that we just discovered that the object adapter operations addFacet and addFacetWithUUID return a proxy that does not contain the facet. If you are obtaining your subscriber's proxy from one of these operations, you need to obtain a new proxy by calling ice_newFacet("myFacet") and then pass the new proxy to IceStorm.

    Take care,
    - Mark
  • freshmanfreshman Member ✭✭
    Thank you very much

    I'll try it. If I have problems,pls help me,thank you
  • freshmanfreshman Member ✭✭
    I am sorry,I failed again

    in the subscribe,the code is:

    Ice.Object receiveEvent = new receiveEventI();
    Ice.ObjectPrx proxy = adapter.add(receiveEvent, Ice.Util.stringToIdentity("receiveEvent"));

    Ice.ObjectPrx proxyFacet = adapter.addFacet(receiveEvent, Ice.Util.stringToIdentity("receiveEvent"), "facet");

    Ice.Object receiveEventEx = new receiveEventExI();
    Ice.ObjectPrx proxyFacetEx = adapter.addFacet(receiveEventEx, Ice.Util.stringToIdentity("receiveEvent"), "facetEx");
    //is it?


    //is it ?
    adapter.activate();

    IceStorm.TopicPrx topic = null;

    try
    {
    topic = topicManager.retrieve("Trap");
    java.util.Map qos = null;
    // topic.subscribe(qos,proxy);
    topic.subscribe(qos,proxyFacet1);
    topic.subscribe(qos,proxyFacetEx1);
    }
    catch (IceStorm.NoSuchTopic ex)
    {
    ex.printStackTrace();
    }
    communicator.waitForShutdown();
    topic.unsubscribe(proxy);
    return 0;



    and in publisher,the code is:

    receiveEventPrx machine = receiveEventPrxHelper.uncheckedCast(pub);

    receiveEventPrx machine1 = receiveEventPrxHelper.uncheckedCast(machine,"facet");
    receiveEventExPrx machineEx = receiveEventExPrxHelper.uncheckedCast(machine,"facetEx");

    // machine.manageEvent(event);
    machine1.manageEvent(event);
    machineEx.manageEventEx(event);

    but nothing happened, it should print "oh yeah" in console

    PLS help me,what's wrong with my code
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Your subscriber code looks correct, but your publisher should not be publishing to a facet proxy. An IceStorm publisher is not aware of its subscribers, and therefore it should not be attempting to publish messages to subscriber facets. If a publisher needs to publish messages to a certain group of subscribers, it should create a topic for that group.

    Take care,
    - Mark
  • freshmanfreshman Member ✭✭
    I am sorry to ask you again

    in publisher :

    I have a topic
    try {
    topic = topicManager.retrieve("Trap");
    }
    catch(IceStorm.NoSuchTopic ex) {
    try {
    topic = topicManager.create("Trap");
    } catch (TopicExists e) {
    e.printStackTrace();
    }

    }


    and then I think receiveEventPrx is a proxy,is it?
    because "public interface receiveEventPrx extends Ice.ObjectPrx"

    and what the codes in publisher should be? Could you give me a example?
    Thank you mes!!
  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    What I mean is that your publisher must do this:

    receiveEventPrx machine = receiveEventPrxHelper.uncheckedCast(pub);

    Your publisher must NOT pass a facet to uncheckedCast.

    Invoking on machine will send a message to all of the topic's subscribers (including those subscribers with facet proxies).

    You cannot publish to a particular facet, but IceStorm will forward messages to facet proxies without problems.

    - Mark
  • freshmanfreshman Member ✭✭
    Oh ,I see

    Thank you very much.
    I love you.
Sign In or Register to comment.