Archived

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

Can't set icegrid observers in python

Hello,

I'm trying to monitor IceGrid servers through the Observers mechanism. I'm interested in the NodeOberver so I've written an implementation of the IceGrid.NodeObserver interface (see below). When I call the setObserver through the call
session.setObservers(None, observer, None, None, None, None), a ValueError exception is raised:

jlafaye@jlafaye:~/workspace/cruise-yacht/yacht/tools/rtcollector/python$ python server_wrapper.py
Traceback (most recent call last):
File "/home/jlafaye/opt/Ice-3.3.1/python/Ice.py", line 766, in main
status = self.run(args)
File "server_wrapper.py", line 46, in run
session.setObservers(None, observer, None, None, None, None)
File "/home/jlafaye/opt/Ice-3.3.1/python/IceGrid_Admin_ice.py", line 1006, in setObservers
return _M_IceGrid.AdminSession._op_setObservers.invoke(self, ((registryObs, nodeObs, appObs, adptObs, objObs), _ctx))
ValueError: invalid value for argument 2 in operation `setObservers'

Any idea or comments ?

#!/usr/bin/python

import Ice
import IceGrid
import sys

class MyObserver(IceGrid.NodeObserver):

def __init__(self):
pass

def nodeInit(self, nodes, curr):
print "nodeInit"
pass

def nodeUp(self, nodes, curr):
print "nodeUp"
pass

def nodeDown(self, name, curr):
print "nodeDown"
pass

def updateServer(self, node, updatedInfo, curr):
print "updateServer"
pass

def updateAdapter(self, node, updatedInfo, curr):
print "updateAdapter"
pass

class IceServerWrapper(Ice.Application):
"""
"""
def run(self, args):
"""
"""
prx = self.communicator().stringToProxy("IceGrid/Registry");
registry = IceGrid.RegistryPrx.checkedCast(prx)
username = "user"
password = "password"
session = registry.createAdminSession(username, password)
observer = MyObserver()
session.setObservers(None, observer, None, None, None, None)


if __name__ == "__main__":
isw = IceServerWrapper()
status = isw.main(sys.argv)
sys.exit(status)

Comments

  • mes
    mes California
    Hi Julien,

    The problem is that you are attempting to pass an instance of the Slice class NodeObserver when the setObservers operation expects a proxy to a NodeObserver object (the observer facility makes callbacks using remote Ice invocations). You should create an object adapter and add your observer as a servant to that adapter, then you'll have the proxy you need.

    Regards,
    Mark
  • Thank you for your quick reply.

    I added the following lines to my script but still got the same error:
    observer = MyObserver()
    oa = self.communicator().createObjectAdapterWithEndpoints('NodeObserverOA', 'default')
    observerPrx = oa.addWithUUID(observer)
    session.setObservers(None, observerPrx, None, None, None, None)


    Julien
  • mes
    mes California
    You need to downcast the proxy to the correct type:
    observer = MyObserver()
    oa = self.communicator().createObjectAdapterWithEndpoints('NodeObserverOA', 'default')
    observerPrx = IceGrid.NodeObserverPrx.uncheckedCast(oa.addWithUUID(observer))
    session.setObservers(None, observerPrx, None, None, None, None)
    
  • That did the trick. Thank you.

    Julien
  • Question about setObserver with python

    Hello,
    I saw that in your code there is an "curr" parameter in each method, but I found that in Ice Manual the methods of these interfaces do not have this parameter. So what are they for? And
    in my code I also did print message in methods, however, I could not see any output while there was not any error notice.
    Thank you for your attention.
    lafayej wrote: »
    Hello,

    I'm trying to monitor IceGrid servers through the Observers mechanism. I'm interested in the NodeOberver so I've written an implementation of the IceGrid.NodeObserver interface (see below). When I call the setObserver through the call
    session.setObservers(None, observer, None, None, None, None), a ValueError exception is raised:

    jlafaye@jlafaye:~/workspace/cruise-yacht/yacht/tools/rtcollector/python$ python server_wrapper.py
    Traceback (most recent call last):
    File "/home/jlafaye/opt/Ice-3.3.1/python/Ice.py", line 766, in main
    status = self.run(args)
    File "server_wrapper.py", line 46, in run
    session.setObservers(None, observer, None, None, None, None)
    File "/home/jlafaye/opt/Ice-3.3.1/python/IceGrid_Admin_ice.py", line 1006, in setObservers
    return _M_IceGrid.AdminSession._op_setObservers.invoke(self, ((registryObs, nodeObs, appObs, adptObs, objObs), _ctx))
    ValueError: invalid value for argument 2 in operation `setObservers'

    Any idea or comments ?

    #!/usr/bin/python

    import Ice
    import IceGrid
    import sys

    class MyObserver(IceGrid.NodeObserver):

    def __init__(self):
    pass

    def nodeInit(self, nodes, curr):
    print "nodeInit"
    pass

    def nodeUp(self, nodes, curr):
    print "nodeUp"
    pass

    def nodeDown(self, name, curr):
    print "nodeDown"
    pass

    def updateServer(self, node, updatedInfo, curr):
    print "updateServer"
    pass

    def updateAdapter(self, node, updatedInfo, curr):
    print "updateAdapter"
    pass

    class IceServerWrapper(Ice.Application):
    """
    """
    def run(self, args):
    """
    """
    prx = self.communicator().stringToProxy("IceGrid/Registry");
    registry = IceGrid.RegistryPrx.checkedCast(prx)
    username = "user"
    password = "password"
    session = registry.createAdminSession(username, password)
    observer = MyObserver()
    session.setObservers(None, observer, None, None, None, None)


    if __name__ == "__main__":
    isw = IceServerWrapper()
    status = isw.main(sys.argv)
    sys.exit(status)
  • benoit
    benoit Rennes, France
    Hi,

    The curr parameter is the Ice::Current parameter provided by the Ice server runtime to all servants methods, see Parameter Passing in Python and The Current Object for details.

    Cheers,
    Benoit.
  • Question about setObserver with python

    Thanks for your reply. I have added that parameter in my methods, yet I cannot see any output when the node is activated. Below is my code:

    def IceGridAdmin():
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties()
    initData.properties.setProperty('Ice.Default.Locator', 'DataProcessGrid/Locator:default -p 4061')
    communicator = Ice.initialize(initData)
    base = communicator.stringToProxy("DataProcessGrid/Registry")
    registry = IceGrid.RegistryPrx.checkedCast(base)
    username = "zslong"
    password = ""
    session = None

    try:
    session = registry.createAdminSession(username, password)
    observer = NodeObs()
    oa = communicator.createObjectAdapterWithEndpoints('NodeObserverOA', 'default')
    observerPrx = IceGrid.NodeObserverPrx.uncheckedCast(oa.addWithUUID(observer))
    regObs = RegistryObs()
    roa = communicator.createObjectAdapterWithEndpoints('RegistryObserverOA', 'default')
    roaPrx = IceGrid.RegistryObserverPrx.uncheckedCast(roa.addWithUUID(regObs))
    appObs = ApplicationObs()
    appoa = communicator.createObjectAdapterWithEndpoints('ApplicationObsOA', 'default')
    appoaPrx = IceGrid.ApplicationObserverPrx.uncheckedCast(appoa.addWithUUID(appObs))
    adpObs = AdapterObs()
    adpoa = communicator.createObjectAdapterWithEndpoints('AdapterObserverOA', 'default')
    adpoaPrx = IceGrid.AdapterObserverPrx.uncheckedCast(adpoa.addWithUUID(adpObs))
    objObs = ObjectObs()
    objoa = communicator.createObjectAdapterWithEndpoints('ObjectObserverOA', 'default')
    objoaPrx = IceGrid.ObjectObserverPrx.uncheckedCast(objoa.addWithUUID(objObs))
    session.setObservers(roaPrx, observerPrx, appoaPrx, adpoaPrx, objoaPrx)
    print "!!!!!!!", session
    except IceGrid.PermissionDeniedException, e:
    print "permission denied:\n" + str(e.reason)
    pass

    class RegistryObs(IceGrid.RegistryObserver):
    def registryInit(self, registryList, curr):
    print "registryList: " + registryList

    def registryUp(self, node, curr):
    print "node: " + node

    def registryDown(self, nodeName, curr):
    print "node name: " + nodeName

    class NodeObs(IceGrid.NodeObserver):
    #curr参数应该是类似C++中的Ice current那个参数
    def nodeInit(self, nodes, curr):
    print "nodes: " + nodes

    def nodeUp(self, node, curr):
    print "nodeUp: " + node

    def nodeDown(self, name, curr):
    print "nodeDown: " + name

    def updateServer(self, node, updatedInfo, curr):
    print "updateServer: " + node + ' ' + updatedInfo

    def updateAdapter(self, node, updatedInfo, curr):
    print "updateAdapter: " + node + " " + updatedInfo

    class ApplicationObs(IceGrid.ApplicationObserver):
    def applicationInit(self, serial, applications, curr):
    print "applicationInit: " + serial + " " + applications

    def applicationAdded(self, serial, desc, curr):
    print "applicationAdded: " + serial + desc
    pass

    def applicationRemoved(self, serial, name, curr):
    print "applicationRemoved: " + serial + name
    pass

    def applicationUpdated(self, serial, desc, curr):
    print "applicationUpdated: " + serial + desc
    pass

    class AdapterObs(IceGrid.AdapterObserver):
    def adapterInit(self, adpts, curr):
    print "adapterInit: " + adpts
    pass

    def adapterAdded(self, info, curr):
    print "adapterAdded: " + info
    pass

    def adapterUpdated(self, info, curr):
    print "adapterUpdated: " + info
    pass

    def adapterRemoved(self, id, curr):
    print "adapterRemoved: " + id
    pass

    class ObjectObs(IceGrid.ObjectObserver):
    def objectInit(self, objects, curr):
    print "objectInit: " + objects

    def objectAdded(self, info, curr):
    print "objectAdded: " + info
    pass

    def objectUpdated(self, info, curr):
    print "objectUpdated: " + info
    pass

    def objectRemoved(self, id, curr):
    print "objectRemoved: " + id
    pass

    if __name__ == "__main__":
    #Main()
    IceGridAdmin()
    benoit wrote: »
    Hi,

    The curr parameter is the Ice::Current parameter provided by the Ice server runtime to all servants methods, see Parameter Passing in Python and The Current Object for details.

    Cheers,
    Benoit.
  • benoit
    benoit Rennes, France
    Hi,

    You need to active the object adapters (by calling active() on the object adapter object). Note also that you don't need to create one object adapter per observer. You should create a single object adapter, you can multiple servants to the same object adapter.

    Cheers,
    Benoit.
  • I get confused with these concepts

    Thank you for your answers. But I am afraid now that I am really confused with this problem.
    First I want to know this observer application is kind of a server-side or client-side. Since it has many proxies, I think it is a client side. While there also needs a adapter and the adapter needs to be active, I think it is a server side. Sorry, I really got confused with these concepts.
    Now I want to talk about my needs and hope someone can give me a suggestion, maybe I should not use these observers at all.
    I have a client side generating data, and call the data handle function in server side, then this server dispatch the data to a cluster of servers which can further handle the data. To make my application more rapid, each server have a queue. When client calls the server function, it just put data in queue, and the server has a thread check the queue and pop data from queue if there are any. All the servers and the client is developed in C++. To monitor the size of each server's queue, I need an GUI application and I plan to use python to do this. If I just make this python application a client side, it may need to load lots of slice files, and the number of servers may vary from time to time, so it will be hard to make the python application load the slice of servers dynamically. As a result, I want to develop an application that can get the information of servers in the cluster dynamically. All the servers have the API to get the size of their queues.
    I am not quite sure whether I describe my question clear since I am not an English native speaker.
    Thanks for your attention. I really need your help because my progress get stuck now. Thank you very much!
    benoit wrote: »
    Hi,

    You need to active the object adapters (by calling active() on the object adapter object). Note also that you don't need to create one object adapter per observer. You should create a single object adapter, you can multiple servants to the same object adapter.

    Cheers,
    Benoit.
  • benoit
    benoit Rennes, France
    Shilong wrote: »
    Thank you for your answers. But I am afraid now that I am really confused with this problem.
    First I want to know this observer application is kind of a server-side or client-side. Since it has many proxies, I think it is a client side. While there also needs a adapter and the adapter needs to be active, I think it is a server side. Sorry, I really got confused with these concepts.

    See the definition of "Clients and Servers" in the terminology section in the Ice manual. Here, your application would both be a client (it calls on the IceGrid registry to establish a session, etc) and server (it receives requests from IceGrid for observers).
    Now I want to talk about my needs and hope someone can give me a suggestion, maybe I should not use these observers at all.
    I have a client side generating data, and call the data handle function in server side, then this server dispatch the data to a cluster of servers which can further handle the data. To make my application more rapid, each server have a queue. When client calls the server function, it just put data in queue, and the server has a thread check the queue and pop data from queue if there are any. All the servers and the client is developed in C++. To monitor the size of each server's queue, I need an GUI application and I plan to use python to do this. If I just make this python application a client side, it may need to load lots of slice files, and the number of servers may vary from time to time, so it will be hard to make the python application load the slice of servers dynamically. As a result, I want to develop an application that can get the information of servers in the cluster dynamically. All the servers have the API to get the size of their queues.
    I am not quite sure whether I describe my question clear since I am not an English native speaker.
    Thanks for your attention. I really need your help because my progress get stuck now. Thank you very much!

    It's not clear to me why your GUI application would need to load the Slice files from the servers.

    From your description, I don't think you need to register observers with IceGrid.

    A simpler method would be to register a well-known Ice object for each of the server and your GUI could periodically retrieve the list of well-known objects matching the Slice type implemented by your servers to handle the data. For example, consider your server provides an object that implements the following Slice interface:
    // Slice
    module MyApp
    {
    interface Queue
    {
        void handle(Ice::ByteSeq data);
    
        int getSize();
    };
    };
    

    Each server could register a well-known Ice object as follow:
    <icegrid>
      <application name="Simple">
        <server-template id="SimpleServer">
          <parameter name="index"/>
          <server id="SimpleServer-${index}" exe="./server" activation="on-demand">
            <adapter name="MyAdapter" endpoints="tcp -h localhost">
              <object identity="queue-${index}" type="::MyApp::Queue" property="Identity"/>
          </server>
        </server-template>
        <node name="node1">
          <server-instance template="SimpleServer" index="1"/>
          <server-instance template="SimpleServer" index="2"/>
        </node>
      </application>
    </icegrid>
    

    Your GUI application can then use the IceGrid::Query interface to obtain the list of the available "::MyApp::Queue" objects:
    // Python
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties()
    initData.properties.setProperty('Ice.Default.Locat or', 'DataProcessGrid/Locator:default -p 4061')
    communicator = Ice.initialize(initData)
    base = communicator.stringToProxy("DataProcessGrid/Query")
    query = IceGrid.QueryPrx.checkedCast(base)
    
    queues = query.findAllObjectsByType("::MyApp::Queue")
    for q in queues:
         try:
            print q.getSize()
         except:
            pass
    

    I recommend you to go through the IceGrid demos for more examples and get a better idea on how you can discover servers with IceGrid.

    Cheers,
    Benoit.
  • Thanks, that is what I want

    Thanks very much, especially for the examples you gave me. In fact, I have used well-known object in my application.xml, but I do not know the way using query to get all these objects. I just load the server's slice and call its getSize() in my GUI application. That is why I said I have to load the slice files. Thanks very much. And I am sorry for the troublesome I brought because of my unfamiliar with the IceGrid Manual. I will try this method as soon as possible. It is so brilliant.
    benoit wrote: »
    See the definition of "Clients and Servers" in the terminology section in the Ice manual. Here, your application would both be a client (it calls on the IceGrid registry to establish a session, etc) and server (it receives requests from IceGrid for observers).



    It's not clear to me why your GUI application would need to load the Slice files from the servers.

    From your description, I don't think you need to register observers with IceGrid.

    A simpler method would be to register a well-known Ice object for each of the server and your GUI could periodically retrieve the list of well-known objects matching the Slice type implemented by your servers to handle the data. For example, consider your server provides an object that implements the following Slice interface:
    // Slice
    module MyApp
    {
    interface Queue
    {
        void handle(Ice::ByteSeq data);
    
        int getSize();
    };
    };
    

    Each server could register a well-known Ice object as follow:
    <icegrid>
      <application name="Simple">
        <server-template id="SimpleServer">
          <parameter name="index"/>
          <server id="SimpleServer-${index}" exe="./server" activation="on-demand">
            <adapter name="MyAdapter" endpoints="tcp -h localhost">
              <object identity="queue-${index}" type="::MyApp::Queue" property="Identity"/>
          </server>
        </server-template>
        <node name="node1">
          <server-instance template="SimpleServer" index="1"/>
          <server-instance template="SimpleServer" index="2"/>
        </node>
      </application>
    </icegrid>
    

    Your GUI application can then use the IceGrid::Query interface to obtain the list of the available "::MyApp::Queue" objects:
    // Python
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties()
    initData.properties.setProperty('Ice.Default.Locat or', 'DataProcessGrid/Locator:default -p 4061')
    communicator = Ice.initialize(initData)
    base = communicator.stringToProxy("DataProcessGrid/Query")
    query = IceGrid.QueryPrx.checkedCast(base)
    
    queues = query.findAllObjectsByType("::MyApp::Queue")
    for q in queues:
         try:
            print q.getSize()
         except:
            pass
    

    I recommend you to go through the IceGrid demos for more examples and get a better idea on how you can discover servers with IceGrid.

    Cheers,
    Benoit.
  • IcePy.ObjectPrx has no attribute "GetCacheSize"

    Hello,
    I tried to use queryPrx to get all objects' information, but there is a problem telling:
    Traceback (most recent call last):
    File "D:\graduation_project\prj\src\TMProcess\PyGuiClt\src\view_controller\MainFraim.py", line 156, in <module>
    Main()
    File "D:\graduation_project\prj\src\TMProcess\PyGuiClt\src\view_controller\MainFraim.py", line 26, in Main
    print "dp cache size is: " + str(dp.GetCacheSize())
    AttributeError: 'IcePy.ObjectPrx' object has no attribute 'GetCacheSize'

    Here is my slice:
    #ifndef MPDU2EPDU_ICE
    #define MPDU2EPDU_ICE

    module DataProcess
    {
    sequence<byte> ByteArray;
    sequence<ByteArray> BigFrame;
    interface DecodeCADU
    {
    ByteArray decode(BigFrame bf);
    int GetCacheSize();
    int GetCacheMaxSize();
    };
    };

    #endif

    Here is my application.xml:
    <!--
    **********************************************************************

    Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.

    This copy of Ice is licensed to you under the terms described in the
    ICE_LICENSE file included in this distribution.

    **********************************************************************
    -->

    <icegrid>

    <application name="DataProcess">
    <server-template id="DataProcessServer">
    <parameter name="index"/>
    <parameter name="exepath" default="./server"/>
    <server id="DataProcessServer${index}" exe="${exepath}" activation="on-demand">
    <adapter name="DecodeCaduAdp" endpoints="tcp" replica-group="ReplicatedDecodeCaduAdapter"/>
    <property name="Identity" value="decodeCadu"/>
    </server>
    </server-template>

    <replica-group id="ReplicatedDecodeCaduAdapter">
    <load-balancing type="round-robin"/>
    <object identity="decodeCadu" type="::DataProcess::DecodeCADU"/>
    </replica-group>


    <node name="node1">
    <server-instance template="DataProcessServer" index="1" exepath="../debug/TMProcess"/>
    </node>

    <node name="node2">
    <server-instance template="DataProcessServer" index="2"/>
    </node>

    </application>

    </icegrid>

    Here is my python code:
    import Ice, IceGrid, os
    import time
    import wx
    import sys

    #Ice.loadSlice("../../config/DataProcess.ice")
    #import DataProcess

    def Main():
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties()
    initData.properties.setProperty('Ice.Default.Locator', 'DataProcessGrid/Locator:default -p 4061')
    communicator = Ice.initialize(initData)
    query = IceGrid.QueryPrx.checkedCast(communicator.stringToProxy("DataProcessGrid/Query"))
    decodeCaduPrxs = query.findAllObjectsByType("::DataProcess::DecodeCADU")
    while(True):
    for dp in decodeCaduPrxs:
    print "dp cache size is: " + str(dp.GetCacheSize())
    time.sleep(1)
    if __name__ == "__main__":
    Main()

    I used to load the slice file and initialize the proxy explicitly, it worked. But now it seems that query did not find the exact proxy.

    Thank you.
    benoit wrote: »
    See the definition of "Clients and Servers" in the terminology section in the Ice manual. Here, your application would both be a client (it calls on the IceGrid registry to establish a session, etc) and server (it receives requests from IceGrid for observers).



    It's not clear to me why your GUI application would need to load the Slice files from the servers.

    From your description, I don't think you need to register observers with IceGrid.

    A simpler method would be to register a well-known Ice object for each of the server and your GUI could periodically retrieve the list of well-known objects matching the Slice type implemented by your servers to handle the data. For example, consider your server provides an object that implements the following Slice interface:
    // Slice
    module MyApp
    {
    interface Queue
    {
        void handle(Ice::ByteSeq data);
    
        int getSize();
    };
    };
    

    Each server could register a well-known Ice object as follow:
    <icegrid>
      <application name="Simple">
        <server-template id="SimpleServer">
          <parameter name="index"/>
          <server id="SimpleServer-${index}" exe="./server" activation="on-demand">
            <adapter name="MyAdapter" endpoints="tcp -h localhost">
              <object identity="queue-${index}" type="::MyApp::Queue" property="Identity"/>
          </server>
        </server-template>
        <node name="node1">
          <server-instance template="SimpleServer" index="1"/>
          <server-instance template="SimpleServer" index="2"/>
        </node>
      </application>
    </icegrid>
    

    Your GUI application can then use the IceGrid::Query interface to obtain the list of the available "::MyApp::Queue" objects:
    // Python
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties()
    initData.properties.setProperty('Ice.Default.Locat or', 'DataProcessGrid/Locator:default -p 4061')
    communicator = Ice.initialize(initData)
    base = communicator.stringToProxy("DataProcessGrid/Query")
    query = IceGrid.QueryPrx.checkedCast(base)
    
    queues = query.findAllObjectsByType("::MyApp::Queue")
    for q in queues:
         try:
            print q.getSize()
         except:
            pass
    

    I recommend you to go through the IceGrid demos for more examples and get a better idea on how you can discover servers with IceGrid.

    Cheers,
    Benoit.
  • benoit
    benoit Rennes, France
    You need to cast the proxy with either the proxy checkedCast or uncheckedCast method after obtaining it from the IceGrid::Query object:
    query = IceGrid.QueryPrx.checkedCast(communicator.stringTo Proxy("DataProcessGrid/Query"))
    decodeCaduPrxs = query.findAllObjectsByType("::DataProcess::DecodeCADU")
    while(True):
         for dp in decodeCaduPrxs:
              dp = DataProcess.DecodeCADUPrx.uncheckedCast(dp)
              print "dp cache size is: " + str(dp.GetCacheSize())
         time.sleep(1)
    

    See Python Mapping for Interfaces - Ice 3.5 - ZeroC and the Python demos for details.

    Benoit.
  • So I have to load slice file

    Hi,
    Thanks for your quick answer, but I am afraid we come back to the origin. If I have to use DataProcess.DecodeCADUPrx.uncheckedCast or checkedCast, I must first import DataProcess, like
    Ice.load("DataProcess.ice")
    import DataProcess
    If I do not, there is no DataProcess at all.
    That is why I said I have to load servers' slice files. Because now I have only one server, but if there are many servers and I will call function of them I have to load their slice file one by one. This is not a good way because it cannot adapt to the change of grid dynamically.
    By the way, if I have import DataProcess, I can get DecodeCADUPrx directly using DataProcess.DecodeCADUPrx.checkedCast(xxx) instead of using IceGrid.QueryPrx.
    benoit wrote: »
    You need to cast the proxy with either the proxy checkedCast or uncheckedCast method after obtaining it from the IceGrid::Query object:
    query = IceGrid.QueryPrx.checkedCast(communicator.stringTo Proxy("DataProcessGrid/Query"))
    decodeCaduPrxs = query.findAllObjectsByType("::DataProcess::DecodeCADU")
    while(True):
         for dp in decodeCaduPrxs:
              dp = DataProcess.DecodeCADUPrx.uncheckedCast(dp)
              print "dp cache size is: " + str(dp.GetCacheSize())
         time.sleep(1)
    

    See Python Mapping for Interfaces - Ice 3.5 - ZeroC and the Python demos for details.

    Benoit.
  • Maybe I did not describe my questions clearly

    In my scene, different servers have different slice, one may like
    module DataProcess
    {
    interface DecodeCADU
    {
    int GetCacheSize();
    };
    };
    others may like this,
    module DataProcess
    {
    interface DecodeVCDU
    {
    int GetCacheSize();
    };
    };
    And there may other slice files.
    So I think if I want to call different server's function, I must first use Ice.load(xx.ice) first and if there are different slice files changing from time to time, I do not know a good way to handle that.
    benoit wrote: »
    You need to cast the proxy with either the proxy checkedCast or uncheckedCast method after obtaining it from the IceGrid::Query object:
    query = IceGrid.QueryPrx.checkedCast(communicator.stringTo Proxy("DataProcessGrid/Query"))
    decodeCaduPrxs = query.findAllObjectsByType("::DataProcess::DecodeCADU")
    while(True):
         for dp in decodeCaduPrxs:
              dp = DataProcess.DecodeCADUPrx.uncheckedCast(dp)
              print "dp cache size is: " + str(dp.GetCacheSize())
         time.sleep(1)
    

    See Python Mapping for Interfaces - Ice 3.5 - ZeroC and the Python demos for details.

    Benoit.
  • benoit
    benoit Rennes, France
    Don't forget the object oriented nature of the Slice language :)

    You could instead define a base interface and have your server interfaces inherit from it:
    // Base.ice
    module DataProcess {
      interface BaseDecoder {
         int GetCacheSize();
      };
    };
    
    // DecodeCADU.ice
    #include <Base.ice>
    module DataProcess {
        interface DecodeCADU extends BaseDecoder {
        };
    };
    
    // DecodeVCDU.ice
    #include <Base.ice>
    module DataProcess {
        interface DecodeVCDU extends BaseDecoder {
        };
    };
    

    Your Python utility can then just include <Base.ice> and doesn't need to depend on each server Slice file. I recommend you to go through the Ice manual and in particular checkout The Slice Language - Ice 3.5 - ZeroC, this will provide you a better idea on what's possible to do with Ice.

    Cheers,
    Benoit.
  • I will try to use the nature

    Thanks, I think I can try this way.
    benoit wrote: »
    Don't forget the object oriented nature of the Slice language :)

    You could instead define a base interface and have your server interfaces inherit from it:
    // Base.ice
    module DataProcess {
      interface BaseDecoder {
         int GetCacheSize();
      };
    };
    
    // DecodeCADU.ice
    #include <Base.ice>
    module DataProcess {
        interface DecodeCADU extends BaseDecoder {
        };
    };
    
    // DecodeVCDU.ice
    #include <Base.ice>
    module DataProcess {
        interface DecodeVCDU extends BaseDecoder {
        };
    };
    

    Your Python utility can then just include <Base.ice> and doesn't need to depend on each server Slice file. I recommend you to go through the Ice manual and in particular checkout The Slice Language - Ice 3.5 - ZeroC, this will provide you a better idea on what's possible to do with Ice.

    Cheers,
    Benoit.