Archived

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

Can anyone tell me the difference of those two Snippet codes

//////////////////////===first ===//////////////////////////////

ObjectPrx myOP = Ice.Util.initialize().propertyToProxy("TopicManager.Proxy");
///////////////////////////////////////////////////////////////////


//////////////////////===second===//////////////////////////////

ObjectPrx myOP = Ice.Application.communicator().propertyToProxy("TopicManager.Proxy");
//////////////////////////////////////////////////////////////////////

Comments

  • xdm
    xdm La Coruña, Spain
    Hi,

    propertyToProxy retrieves the configuration property with the given name and converts its value into a proxy. A null proxy is returned if no property is found with the specified name.

    In first case you create a communicator without configuration and then call propertyToProxy on in, so propertyToProxy will return a null proxy.

    In the second case you access the application communicator, and call propertyToProxy on it, this communicator is initialized as part of Ice::Application startup, if your application use a configuration file that defines "TopicManager.Proxy" property, the call will return a non null proxy.


    Note that in first case you are not destroying the communicator, and you must always call destroy on a communicator before leaving the main function. When you use Ice::Application, it takes care to destroy the communicator for you.

    see also Communicators - Ice 3.4 - ZeroC
  • C# IceStrom exception error.

    But how I know the second one is being configured ? Since they are both the first line of code called to create an object proxy?

    I looked at this code it returns an object
    Ice.ObjectPrx op = Ice.Application.communicator().propertyToProxy("TopicManager.Proxy");
    The debug trace shows it is not null.
    op {DemoIceStorm/TopicManager -t:tcp -h 127.0.0.1 -p 10000} Ice.ObjectPrx {Ice.ObjectPrxHelperBase}

    Notice that it is "DemoIceStorm/TopicManager -t:tcp -h 127.0.0.1 -p 10000"
    And there is "-t" there.

    The code below causes exception
    IceStorm.TopicManagerPrx tmp = IceStorm.TopicManagerPrxHelper.checkedCast(op);
    It returns null. Basically the code I am testing is from clock demo. I could not figure out any wrong.

    My config file for icebox is :
    IceBox.InstanceName=DemoIceStrom
    TopicManager.Proxy=DemoIceStorm/TopicManager:default -h 127.0.0.1 -p 10000

    and the config file for publisher is :
    TopicManager.Proxy=DemoIceStorm/TopicManager:default -h 127.0.0.1 -p 10000

    the exception error code is:
    /////////////////////////////////////////////////////////////////////
    Ice.ObjectNotExistException was unhandled by user code
    Message=Exception of type 'Ice.ObjectNotExistException' was thrown.
    Source=Ice
    StackTrace:
    at IceInternal.ProxyFactory.checkRetryAfterException(LocalException ex, Reference ref, Boolean sleep, Int32& cnt)
    at Ice.ObjectPrxHelperBase.handleException__(ObjectDel_ delegate, LocalException ex, Boolean sleep, Int32& cnt)
    at Ice.ObjectPrxHelperBase.ice_isA(String id__, Dictionary`2 context__, Boolean explicitContext__)
    at Ice.ObjectPrxHelperBase.ice_isA(String id__)
    at IceStorm.TopicManagerPrxHelper.checkedCast(ObjectPrx b)
    at Publisher.App.run(String[] args) in E:\Program Files (x86)\ZeroC\Ice-3.4.2\src\cs\demo\IceStorm\clock\Publisher.cs:line 59
    at Ice.Application.doMain(String[] args, InitializationData initData)
    InnerException:
    //////////////////////////////////////////////////
    The iceBox log is:

    02/24/12 09:44:38.201 icebox: Network: attempting to bind to tcp socket 0.0.0.0:9998
    02/24/12 09:44:38.220 icebox: Network: accepting tcp connections at 0.0.0.0:9998
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.239 icebox: Network: published endpoints for object adapter `IceBox.ServiceManager':
    tcp -h 128.100.128.99 -p 9998
    02/24/12 09:44:38.280 icebox-IceStorm: Network: accepting tcp connections at 0.0.0.0:10000
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.299 icebox-IceStorm: Network: published endpoints for object adapter `IceStorm.TopicManager':
    tcp -h 128.100.128.99 -p 10000
    02/24/12 09:44:38.322 icebox-IceStorm: Network: accepting tcp connections at 0.0.0.0:10001
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.340 icebox-IceStorm: Network: starting to receive udp packets
    local address = 0.0.0.0:10001
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.357 icebox-IceStorm: Network: published endpoints for object adapter `IceStorm.Publish':
    tcp -h 128.100.128.99 -p 10001:udp -h 128.100.128.99 -p 10001
    02/24/12 09:45:06.887 icebox-IceStorm: Network: accepted tcp connection
    local address = 127.0.0.1:10000
    remote address = 127.0.0.1:65071
  • bernard
    bernard Jupiter, FL
    Hi Chang,

    Can you run the clock demo successfully on your computer?

    I can't spot the problem in your description but I can explain what's happening:
    But how I know the second one is being configured ? Since they are both the first line of code called to create an object proxy?

    You provide the configuration when you create your Ice communicator. When you use an application, you provide this configuration in the application configuration. For example, with the clock demo publisher (in Java), it's:
        public static void
        main(String[] args)
        {
            Publisher app = new Publisher();
            int status = app.main("Publisher", args, "config.pub"); // communicator will use config.pub config file
            System.exit(status);
        }
    
    The debug trace shows it is not null.
    op {DemoIceStorm/TopicManager -t:tcp -h 127.0.0.1 -p 10000} Ice.ObjectPrx {Ice.ObjectPrxHelperBase}

    Notice that it is "DemoIceStorm/TopicManager -t:tcp -h 127.0.0.1 -p 10000"
    And there is "-t" there.

    This means you are correctly retrieving the configuration from your config file (good). Don't worry about the "-t": it just means your proxy is configured for two-way invocations, which is the default.
    the exception error code is:
    /////////////////////////////////////////////////////////////////////
    Ice.ObjectNotExistException was unhandled by user code
    Message=Exception of type 'Ice.ObjectNotExistException' was thrown.
    Source=Ice
    StackTrace:
    at IceInternal.ProxyFactory.checkRetryAfterException( LocalException ex, Reference ref, Boolean sleep, Int32& cnt)

    ObjectNotExistException means that your client (publisher) was able to connect to port 10,000 for the server running on localhost, but this server could not find the object ID you requested ("DemoIceStorm/TopicManager").

    Are you using exactly the same config files as the clock demo? If not, please post your complete config files for both IceBox and IceStorm.
    The iceBox log is:

    02/24/12 09:44:38.201 icebox: Network: attempting to bind to tcp socket 0.0.0.0:9998
    02/24/12 09:44:38.220 icebox: Network: accepting tcp connections at 0.0.0.0:9998
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.239 icebox: Network: published endpoints for object adapter `IceBox.ServiceManager':
    tcp -h 128.100.128.99 -p 9998
    02/24/12 09:44:38.280 icebox-IceStorm: Network: accepting tcp connections at 0.0.0.0:10000
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.299 icebox-IceStorm: Network: published endpoints for object adapter `IceStorm.TopicManager':
    tcp -h 128.100.128.99 -p 10000
    02/24/12 09:44:38.322 icebox-IceStorm: Network: accepting tcp connections at 0.0.0.0:10001
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.340 icebox-IceStorm: Network: starting to receive udp packets
    local address = 0.0.0.0:10001
    local interfaces: 128.100.128.99, 127.0.0.1
    02/24/12 09:44:38.357 icebox-IceStorm: Network: published endpoints for object adapter `IceStorm.Publish':
    tcp -h 128.100.128.99 -p 10001:udp -h 128.100.128.99 -p 10001
    02/24/12 09:45:06.887 icebox-IceStorm: Network: accepted tcp connection
    local address = 127.0.0.1:10000
    remote address = 127.0.0.1:65071

    Everything looks fine here; the last log entry shows your publisher connecting to IceStorm.

    Best regards,
    Bernard
  • C# IceStrom exception error.

    I think I find the problem. It is in config files that port numbers cause conflicting in config.icebox, config.service and config.pub