Archived

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

importing Grid in the Demo Chat

I encounter a problem that preventing me from moving forward.
When I attempt to importing Grid in the Glacier2 Chat Demo,I am so boring that I don't know what I should do:( .
What I changed is just adding two configuration files.

application_with_replication.xml
<icegrid>
	<application name="Simple">

		<server-template id="SimpleServer">
			<parameter name="index"/>
			<server id="SimpleServer-${index}" exe="./server" activation="on-demand">
				<adapter name="ChatServer" endpoints="tcp" register-process="true" replica-group="ReplicatedChatAdapter"/>
			</server>
		</server-template>
		<server-template id="Glacier2">
			<parameter name="instance-name" default="Glacier2"/>
			<parameter name="client-endpoints"/> 
			<parameter name="server-endpoints"/>
			<parameter name="session-timeout" default="30"/>
			<server id="${instance-name}" exe="glacier2router" activation="always">
				<properties>
					<property name="Glacier2.Client.Endpoints" value="${client-endpoints}"/>
					<property name="Glacier2.Server.Endpoints" value="${server-endpoints}"/>				
					<property name="Glacier2.InstanceName" value="${instance-name}"/>
					<property name="Glacier2.SessionTimeout" value="${session-timeout}"/>
					<property name="Glacier2.PermissionsVerifier" value="${instance-name}/NullPermissionsVerifier"/>
					<property name="Glacier2.SessionManager" value="ChatSessionManager"/>
					
				</properties>
			</server>
		</server-template>


		<replica-group id="ReplicatedChatAdapter">
			<load-balancing type="round-robin"/>
			<object identity="ChatSessionManager" type="::Demo::ChatSession"/>
		</replica-group>

		<node name="localhost">
			[B]<server-instance template="SimpleServer" index="1"/>
			<server-instance template="SimpleServer" index="2"/>[/B]			
			<server-instance template="Glacier2" client-endpoints="tcp -p 10005" server-endpoints="tcp"/>
		</node>


	</application>

</icegrid>

config.grid
IceGrid.InstanceName=DemoIceGrid

#
# The IceGrid locator proxy.
#
Ice.Default.Locator=DemoIceGrid/Locator:default -h 192.168.1.104 -p 12000
#
# IceGrid registry configuration.
#
IceGrid.Registry.Client.Endpoints=default -p 12000
IceGrid.Registry.Server.Endpoints=default
IceGrid.Registry.Internal.Endpoints=default

IceGrid.Registry.Data=db/registry
IceGrid.Registry.PermissionsVerifier=DemoIceGrid/NullPermissionsVerifier
IceGrid.Registry.AdminPermissionsVerifier=DemoIceGrid/NullPermissionsVerifier
IceGrid.Registry.SSLPermissionsVerifier=DemoIceGrid/NullSSLPermissionsVerifier
IceGrid.Registry.AdminSSLPermissionsVerifier=DemoIceGrid/NullSSLPermissionsVerifier

#
# IceGrid node configuration.
#
IceGrid.Node.Name=localhost
IceGrid.Node.Endpoints=default
IceGrid.Node.Data=db/node
IceGrid.Node.CollocateRegistry=1

#
# Trace properties.
#
IceGrid.Node.Trace.Activator=2
IceGrid.Node.Trace.Adapter=2
IceGrid.Node.Trace.Server=2

#
# Dummy username and password for icegridadmin.
#
IceGridAdmin.Username=foo
IceGridAdmin.Password=bar

When I deploy this project
C:\Ice-3.2.1\demo\Glacier2\chat>icegridnode --Ice.Config=config.grid
[ 10/25/07 20:46:32.546 Server: changed server `Glacier2' state to `Inactive' ]
[ 10/25/07 20:46:32.546 Server: changed server `SimpleServer-1' state to `Inacti
ve' ]
[ 10/25/07 20:46:32.546 Server: changed server `SimpleServer-2' state to `Inacti
ve' ]
[ 10/25/07 20:46:33.046 Activator: activating server `Glacier2'
  path = C:\Ice-3.2.1\bin\glacier2router.exe
  pwd = C:\Ice-3.2.1\demo\Glacier2\chat
  args = C:\Ice-3.2.1\bin\glacier2router.exe --Ice.Config=C:\Ice-3.2.1\demo\Glacier2\chat/db/node/servers/Glacier2/config/config ]
[ 10/25/07 20:46:33.046 Server: changed server `Glacier2' state to `Active' ]
[ 10/25/07 20:46:33.125 Activator: activating server `SimpleServer-1'
  path = ./server
  pwd = C:\Ice-3.2.1\demo\Glacier2\chat
  args = ./server --Ice.Config=C:\Ice-3.2.1\demo\Glacier2\chat/db/node/serv
ers/SimpleServer-1/config/config ]
[ 10/25/07 20:46:33.187 Server: changed server `SimpleServer-1' state to `Active
' ]
[ 10/25/07 20:46:33.187 Adapter: server `SimpleServer-1' adapter `SimpleServer-1
.ChatServer' activated: dummy -t:tcp -h 192.168.1.104 -p 2635 ]
[ 10/25/07 20:47:11.109 Activator: activating server `SimpleServer-2'
  path = ./server
  pwd = D:\Copy of server_chatroom_c++_mobile
  args = ./server --Ice.Config=C:\Ice-3.2.1\demo\Glacier2\chat/db/node/serv
ers/SimpleServer-2/config/config ]
[ 10/25/07 20:47:11.171 Server: changed server `SimpleServer-2' state to `Active
' ]
[ 10/25/07 20:47:11.171 Adapter: server `SimpleServer-2' adapter `SimpleServer-2
.ChatServer' activated: dummy -t:tcp -h 192.168.1.104 -p 2651 ]
C:\Ice-3.2.1\demo\Glacier2\chat>client
This demo accepts any user-id / password combination.
user id: neons
password: neons
client: Outgoing.cpp:388: Ice::ObjectNotExistException:
object does not exist:
identity: `9d0a41ad-1dc3-4d3a-8b2f-f011a6cb7dbc'
facet:
operation: setCallback

----:confused:

But when i just delete a server-instance from application_with_replication.xml, it works well!

application_with_replication.xml (have changed)
<icegrid>
<application name="Simple">
... ...
<node name="localhost">			
[B]<server-instance template="Glacier2" client-endpoints="tcp -p 10005" server-endpoints="tcp"/>[/B]
</node>
</application>
</icegrid>

:) Your answers will do me a good favour.

Comments

  • benoit
    benoit Rennes, France
    Hi,

    I don't see how it could work if you remove the servers from the application, to which server would the client connect to? Could you post the configuration file of the client as well?

    The Ice::ObjectNotExistException indicates that the client setCallback request is rejected by Glacier2. This can happen if the client doesn't have an active session or is using another network connection than the one used to create the session.

    You should enable network tracing in your client (with Ice.Trace.Network=2) and Glacier2 tracing (with Glacier2.Client.Trace.Reject=1) to see if it gives you some hints.

    Cheers,
    Benoit
  • don't see how it could work if you remove the servers from the application, to which server would the client connect to? Could you post the configuration file of the client as well?

    Oh! I lost something in the file application_with_replication.xml (have changed) when I post my thread.

    <server-instance template="SimpleServer" index="1"/>

    is added in the node tab.
    <icegrid>
    <application name="Simple">
    ... ...
    <node name="localhost">

    <server-instance template="SimpleServer" index="1"/>
    <!--
    <server-instance template="SimpleServer" index="2"/>
    -->

    <server-instance template="Glacier2" client-endpoints="tcp -p 10005" server-endpoints="tcp"/>
    </node>
    </application>
    </icegrid>
    That is when i just delete a server-instance from application_with_replication.xml, it works well!

    The configuration file of the client is the config.client which is in the glacier2 chat demo,I changed nothing.

    config.client
    Ice.Default.Router=Glacier2/router:tcp -p 10005 -h 192.168.1.104
    Chat.Client.Router=Glacier2/router:tcp -p 10005 -h 192.168.1.104
    The Ice::ObjectNotExistException indicates that the client setCallback request is rejected by Glacier2. This can happen if the client doesn't have an active session or is using another network connection than the one used to create the session.

    What should I do.I am a beginner to ICE. I need your help so much.
    Thank you!:)
  • matthew
    matthew NL, Canada
    neons wrote: »
    ....
    What should I do.I am a beginner to ICE. I need your help so much.
    Thank you!:)

    If you haven't established a session you should do so. If the problem is the request being blocked by Glacier2 you can discover that by setting Glacier2.Client.Trace.Reject=1 in the Glacier2 configuration file.

    You can find more information on both of these topics in the Ice newsletter (see issue19 which is the latest issue to discuss the Glacier2 filtering). Glacier2 sessions are covered in numerous articles, and Glacier2 demos.

    If you need more assistance I recommend posting a complete, self contained compilable example that demonstrates your problem.
  • :) Thanks,I appreciate your answers. Because my poor English, I post my whole code,actually the main code is supplyed by zeroc.I want to see my code acts as the simple demo in the IceGrid sample directory which is also supplyed by zeroc.

    chat.ice
    #ifndef CHAT_ICE
    #define CHAT_ICE
    
    #include <Glacier2/Session.ice>
    
    module Demo
    {
    
    interface ChatCallback
    {
        void message(string data);
    };
    
    interface ChatSession extends Glacier2::Session
    {
        bool setCallback(ChatCallback* callback);
        void say(string data,string user);
    };
    
    };
    
    #endif
    

    ChatSessionI.h
    #ifndef CHAT_SESSION_I_H
    #define CHAT_SESSION_I_H
    
    #include <Chat.h>
    
    class ChatSessionI : public Demo::ChatSession, public IceUtil::Mutex
    {
    public:
    
        ChatSessionI(const std::string&);
    
        virtual bool setCallback(const Demo::ChatCallbackPrx&, const Ice::Current&);
    	virtual void say(const std::string&, const std::string&,const Ice::Current&);
        virtual void destroy(const Ice::Current&);
    
    private:
    
        const std::string _userId;
        Demo::ChatCallbackPrx _callback;
    };
    
    #endif
    

    ChatSessionI.cpp
    #include <Ice/Ice.h>
    #include <ChatSessionI.h>
    #include <list>
    
    using namespace std;
    using namespace Demo;
    
    class ChatRoom;
    typedef IceUtil::Handle<ChatRoom> ChatRoomPtr;
    
    class ChatRoom : public IceUtil::Mutex, public IceUtil::Shared
    {
    public:
    
        static ChatRoomPtr& instance();
    
        void enter(const Demo::ChatCallbackPrx&);
        void leave(const Demo::ChatCallbackPrx&);
        void message(const string&) const;
    
    private:
        
        list<Demo::ChatCallbackPrx> _members;
    
        static ChatRoomPtr _instance;
        static IceUtil::StaticMutex _instanceMutex;
    };
    
    ChatRoomPtr ChatRoom::_instance;
    IceUtil::StaticMutex ChatRoom::_instanceMutex = ICE_STATIC_MUTEX_INITIALIZER;
    
    ChatRoomPtr&
    ChatRoom::instance()
    {
    ... ...
    }
    
    void
    ChatRoom::enter(const ChatCallbackPrx& callback)
    {
    ... ...
    }
    
    void
    ChatRoom::leave(const ChatCallbackPrx& callback)
    {
    ... ...
    }
    
    void
    ChatRoom::message(const string& data) const
    {
    ... ...
    }
    
    ChatSessionI::ChatSessionI(const string& userId) :
        _userId(userId)
    {
    }
    
    void
    ChatSessionI::setCallback(const ChatCallbackPrx& callback, const Ice::Current& current)
    {
    ... ...
    }
    
    void
    ChatSessionI::say(const string& data, const Ice::Current&)
    {
     ... ...
    }
    
    void
    ChatSessionI::destroy(const Ice::Current& current)
    {
     ... ...
    }
    

    Server.cpp
    #include <Ice/Ice.h>
    #include <Glacier2/PermissionsVerifier.h>
    #include <ChatSessionI.h>
    
    using namespace std;
    using namespace Demo;
    
    class ChatSessionManagerI : public Glacier2::SessionManager
    {
    public:
    
        virtual Glacier2::SessionPrx
        create(const string& userId, const Glacier2::SessionControlPrx&, const Ice::Current& current)
        {
            return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(new ChatSessionI(userId)));
        }
    };
    
    class ChatServer : public Ice::Application
    {
    public:
    
        virtual int
        run(int, char*[])
        {
            Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("ChatServer");
            
            adapter->add(new ChatSessionManagerI, communicator()->stringToIdentity("ChatSessionManager"));
            adapter->activate();
            communicator()->waitForShutdown();
            
            return EXIT_SUCCESS;
        }
    };
    
    int
    main(int argc, char* argv[])
    {
        ChatServer app;
        return app.main(argc, argv, "config.server");
    }
    

    Client.cpp
    #include <IceUtil/IceUtil.h>
    #include <Ice/Ice.h>
    #include <Glacier2/Router.h>
    #include <Chat.h>
    
    using namespace std;
    using namespace Demo;
    
    class SessionPingThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
    {
    ... ...
    };
    typedef IceUtil::Handle<SessionPingThread> SessionPingThreadPtr;
    
    class ChatCallbackI : public ChatCallback
    {
    public:
    
        virtual void
        message(const string& data, const Ice::Current&)
        {
            cout << data << endl;
        }
    };
    
    class ChatClient : public Ice::Application
    {
    public:
    
        virtual int
        run(int argc, char* argv[])
        {
    
            callbackOnInterrupt();
    
            {
                IceUtil::Mutex::Lock sync(_mutex);
                Ice::RouterPrx defaultRouter = communicator()->getDefaultRouter();
                if(!defaultRouter)
                {
                    cerr << argv[0] << ": no default router set" << endl;
                    return EXIT_FAILURE;
                }
                
                _router = Glacier2::RouterPrx::checkedCast(defaultRouter);
                if(!_router)
                {
                    cerr << argv[0] << ": configured router is not a Glacier2 router" << endl;
                    return EXIT_FAILURE;
                }
            }
    
            ChatSessionPrx session;
            while(true)
            {
                cout << "This demo accepts any user-id / password combination.\n";
    
                string id;
                cout << "user id: " << flush;
                getline(cin, id);
                id = trim(id);
    
                string pw;
                cout << "password: " << flush;
                getline(cin, pw);
                pw = trim(pw);
    
                try
                {
                    session = ChatSessionPrx::uncheckedCast(_router->createSession(id, pw));
                    break;
                }
                catch(const Glacier2::PermissionDeniedException& ex)
                {
                    cout << "permission denied:\n" << ex.reason << endl;
                }
            }
    
            {
                IceUtil::Mutex::Lock sync(_mutex);
                _ping = new SessionPingThread(session, (long)_router->getSessionTimeout() / 2);
                _ping->start();
            }
    
            Ice::Identity callbackReceiverIdent;
            callbackReceiverIdent.name = "callbackReceiver";
            callbackReceiverIdent.category = _router->getCategoryForClient();
    
            Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Chat.Client");
            ChatCallbackPrx callback = ChatCallbackPrx::uncheckedCast(
                adapter->add(new ChatCallbackI, callbackReceiverIdent));
            adapter->activate();
    
            session->setCallback(callback);
    
            menu();
    
            try
            {
                do
                {
                    string s;
                    cout << "==> ";
                    getline(cin, s);
                    s = trim(s);
                    if(!s.empty())
                    {
                        if(s[0] == '/')
                        {
                            if(s == "/quit")
                            {
                                break;
                            }
                            menu();
                        }
                        else
                        {
                            session->say(s);
                        }
                    }
                }
                while(cin.good());
    
                cleanup();
            }
            catch(const Ice::Exception& ex)
            {
                cerr << ex << endl;
                cleanup();
    
                return EXIT_FAILURE;
            }
            return EXIT_SUCCESS;
        }
    
        virtual void
        interruptCallback(int)
        {
              ... ...
        }
    
    private:
    
        void
        cleanup()
        {
               ... ...
        }
    
        void
        menu()
        {
            cout << "enter /quit to exit." << endl;
        }
    
        string
        trim(const string& s)
        {
             ... ...
        }
    
        IceUtil::Mutex _mutex;
        Glacier2::RouterPrx _router;
        SessionPingThreadPtr _ping;
    };
    
    int
    main(int argc, char* argv[])
    {
        ChatClient app;
        return app.main(argc, argv, "config.client");
    }
    
  • config.server
    ChatServer.Endpoints=tcp -h localhost -p 10001
    
    Ice.Warn.Connections=1
    
    Ice.Trace.Network=2
    

    config.client
    Ice.Default.Router=Glacier2/router:tcp -p 10005 -h localhost
    
    Chat.Client.Router=Glacier2/router:tcp -p 10005 -h localhost
    
    Ice.ACM.Client=0
    Ice.MonitorConnections=60
    Ice.RetryIntervals=-1
    
    

    config.grid
    IceGrid.InstanceName=DemoIceGrid
    
    #
    # The IceGrid locator proxy.
    #
    Ice.Default.Locator=DemoIceGrid/Locator:default -h localhost -p 12000
    #Ice.Default.Router=Simple.Glacier2/router:tcp -p 12001
    #
    # IceGrid registry configuration.
    #
    IceGrid.Registry.Client.Endpoints=default -p 12000
    IceGrid.Registry.Server.Endpoints=default
    IceGrid.Registry.Internal.Endpoints=default
    #IceGrid.Registry.SessionManager.Endpoints=default
    
    IceGrid.Registry.Data=db/registry
    #IceGrid.Registry.SessionFilters=0
    IceGrid.Registry.PermissionsVerifier=DemoIceGrid/NullPermissionsVerifier
    IceGrid.Registry.AdminPermissionsVerifier=DemoIceGrid/NullPermissionsVerifier
    IceGrid.Registry.SSLPermissionsVerifier=DemoIceGrid/NullSSLPermissionsVerifier
    IceGrid.Registry.AdminSSLPermissionsVerifier=DemoIceGrid/NullSSLPermissionsVerifier
    
    #
    # IceGrid node configuration.
    #
    IceGrid.Node.Name=localhost
    IceGrid.Node.Endpoints=default
    IceGrid.Node.Data=db/node
    IceGrid.Node.CollocateRegistry=1
    #IceGrid.Node.Output=db
    #IceGrid.Node.RedirectErrToOut=1
    
    #
    # Trace properties.
    #
    IceGrid.Node.Trace.Activator=2
    IceGrid.Node.Trace.Adapter=2
    IceGrid.Node.Trace.Server=2
    Ice.Trace.Network=2
    Glacier2.Client.Trace.Reject=1
    
    #
    # Dummy username and password for icegridadmin.
    #
    IceGridAdmin.Username=foo
    IceGridAdmin.Password=bar
    

    application_with_replication.xml
    <icegrid>
    
    <application name="Simple">
    <server-template id="SimpleServer">
    <parameter name="index"/>
    <server id="SimpleServer-${index}" exe="./server" activation="on-demand">
    <adapter name="ChatServer" endpoints="tcp" register-process="true" replica-group="ReplicatedChatAdapter"/>
    </server>
    </server-template>
    <server-template id="Glacier2">
    <parameter name="instance-name" default="Glacier2"/>
    <parameter name="client-endpoints"/> 
    <parameter name="server-endpoints"/>
    <parameter name="session-timeout" default="30"/>
    <server id="${instance-name}" exe="glacier2router" activation="always">
    <properties>
    <property name="Glacier2.Client.Endpoints" value="${client-endpoints}"/>
    <property name="Glacier2.Server.Endpoints" value="${server-endpoints}"/>				
    <property name="Glacier2.InstanceName" value="${instance-name}"/>
    <property name="Glacier2.SessionTimeout" value="${session-timeout}"/>
    <property name="Glacier2.PermissionsVerifier" value="${instance-name}/NullPermissionsVerifier"/>
    <property name="Glacier2.SessionManager" value="ChatSessionManager"/>
    					
    </properties>
    </server>
    </server-template>
    <replica-group id="ReplicatedChatAdapter">
    <load-balancing type="round-robin"/>
    <object identity="ChatSessionManager" type="::Demo::ChatSession"/>
    </replica-group>
    <node name="localhost">
    <server-instance template="SimpleServer" index="1"/>
    <server-instance template="SimpleServer" index="2"/>
    <server-instance template="SimpleServer" index="3"/>	
    <server-instance template="Glacier2" client-endpoints="tcp -p 10005" server-endpoints="tcp"/>
    </node>
    </application>
    
    </icegrid>
    

    :eek:
    I hope I am not bothering you!:)
    I want to know why it doesn't work as supposed.I just want my three service,which is the same,works round-robin.

    Best wishes!:)