Example #1
0
        public override void runTestCase(RemoteObjectAdapterPrx adapter, TestIntfPrx proxy)
        {
            Ice.Connection con = proxy.ice_getCachedConnection();

            try
            {
                con.setACM(-19, Ice.Util.None, Ice.Util.None);
                test(false);
            }
            catch (ArgumentException)
            {
            }

            Ice.ACM acm;
            acm = con.getACM();
            test(acm.timeout == 15);
            test(acm.close == Ice.ACMClose.CloseOnIdleForceful);
            test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOff);

            con.setACM(Ice.Util.None, Ice.Util.None, Ice.Util.None);
            acm = con.getACM();
            test(acm.timeout == 15);
            test(acm.close == Ice.ACMClose.CloseOnIdleForceful);
            test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatOff);

            con.setACM(1,
                       Ice.ACMClose.CloseOnInvocationAndIdle,
                       Ice.ACMHeartbeat.HeartbeatAlways);
            acm = con.getACM();
            test(acm.timeout == 1);
            test(acm.close == Ice.ACMClose.CloseOnInvocationAndIdle);
            test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatAlways);

            proxy.startHeartbeatCount();
            proxy.waitForHeartbeatCount(2);

            var t1 = new TaskCompletionSource <object>();

            con.setCloseCallback(_ => { t1.SetResult(null); });

            con.close(Ice.ConnectionClose.Gracefully);
            test(t1.Task.Result == null);

            try
            {
                con.throwException();
                test(false);
            }
            catch (Ice.ConnectionManuallyClosedException)
            {
            }

            var t2 = new TaskCompletionSource <object>();

            con.setCloseCallback(_ => { t2.SetResult(null); });
            test(t2.Task.Result == null);

            con.setHeartbeatCallback(_ => { test(false); });
        }
Example #2
0
        connected(RouterPrx router, SessionPrx session)
        {
            //
            // Remote invocation should be done without acquiring a mutex lock.
            //
            Debug.Assert(router != null);
            Ice.Connection conn       = router.ice_getCachedConnection();
            string         category   = router.getCategoryForClient();
            int            acmTimeout = 0;

            try
            {
                acmTimeout = router.getACMTimeout();
            }
            catch (Ice.OperationNotExistException)
            {
            }

            if (acmTimeout <= 0)
            {
                acmTimeout = (int)router.getSessionTimeout();
            }

            //
            // We create the callback object adapter here because createObjectAdapter internally
            // makes synchronous RPCs to the router. We can't create the OA on-demand when the
            // client calls objectAdapter() or addWithUUID() because they can be called from the
            // GUI thread.
            //
            if (_useCallbacks)
            {
                Debug.Assert(_adapter == null);
                _adapter = _communicator.createObjectAdapterWithRouter("", router);
                _adapter.activate();
            }

            lock (_mutex)
            {
                _router = router;

                if (_destroy)
                {
                    //
                    // Run destroyInternal in a thread because it makes remote invocations.
                    //
                    Thread t = new Thread(new ThreadStart(destroyInternal));
                    t.Start();
                    return;
                }

                //
                // Cache the category.
                //
                _category = category;

                //
                // Assign the session after _destroy is checked.
                //
                _session   = session;
                _connected = true;

                if (acmTimeout > 0)
                {
                    Ice.Connection connection = _router.ice_getCachedConnection();
                    Debug.Assert(connection != null);
                    connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
                    connection.setCloseCallback(_ => destroy());
                }
            }

            dispatchCallback(() =>
            {
                try
                {
                    _callback.connected(this);
                }
                catch (SessionNotExistException)
                {
                    destroy();
                }
            }, conn);
        }
Example #3
0
    doMain(string[] args, Ice.InitializationData initData, out int status)
    {
        //
        // Reset internal state variables from Ice.Application. The
        // remainder are reset at the end of this method.
        //
        iceCallbackInProgress = false;
        iceDestroyed = false;
        iceInterrupted = false;

        bool restart = false;
        status = 0;

        try
        {
            iceCommunicator = Ice.Util.initialize(ref args, initData);

            _router = Glacier2.RouterPrxHelper.uncheckedCast(communicator().getDefaultRouter());
            if(_router == null)
            {
                Ice.Util.getProcessLogger().error(iceAppName + ": no Glacier2 router configured");
                status = 1;
            }
            else
            {
                //
                // The default is to destroy when a signal is received.
                //
                if(iceSignalPolicy == Ice.SignalPolicy.HandleSignals)
                {
                    destroyOnInterrupt();
                }

                //
                // If createSession throws, we're done.
                //
                try
                {
                    _session = createSession();
                    _createdSession = true;
                }
                catch(Ice.LocalException ex)
                {
                    Ice.Util.getProcessLogger().error(ex.ToString());
                    status = 1;
                }

                if(_createdSession)
                {
                    int acmTimeout = 0;
                    try
                    {
                        acmTimeout = _router.getACMTimeout();
                    }
                    catch(Ice.OperationNotExistException)
                    {
                    }
                    if(acmTimeout <= 0)
                    {
                        acmTimeout = (int)_router.getSessionTimeout();
                    }
                    if(acmTimeout > 0)
                    {
                        Ice.Connection connection = _router.ice_getCachedConnection();
                        Debug.Assert(connection != null);
                        connection.setACM((int)acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
                        connection.setCloseCallback(_ => sessionDestroyed());
                    }
                    _category = _router.getCategoryForClient();
                    status = runWithSession(args);
                }
            }
        }
        //
        // We want to restart on those exceptions that indicate a
        // break down in communications, but not those exceptions that
        // indicate a programming logic error (i.e., marshal, protocol
        // failure, etc).
        //
        catch(RestartSessionException)
        {
            restart = true;
        }
        catch(Ice.ConnectionRefusedException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            restart = true;
        }
        catch(Ice.ConnectionLostException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            restart = true;
        }
        catch(Ice.UnknownLocalException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            restart = true;
        }
        catch(Ice.RequestFailedException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            restart = true;
        }
        catch(Ice.TimeoutException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            restart = true;
        }
        catch(Ice.LocalException ex)
        {
            Ice.Util.getProcessLogger().error(ex.ToString());
            status = 1;
        }
        catch(System.Exception ex)
        {
            Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString());
            status = 1;
        }

        //
        // Don't want any new interrupt. And at this point
        // (post-run), it would not make sense to release a held
        // signal to run shutdown or destroy.
        //
        if(iceSignalPolicy == Ice.SignalPolicy.HandleSignals)
        {
            ignoreInterrupt();
        }

        lock(iceMutex)
        {
            while(iceCallbackInProgress)
            {
                System.Threading.Monitor.Wait(iceMutex);
            }

            if(iceDestroyed)
            {
                iceCommunicator = null;
            }
            else
            {
                iceDestroyed = true;
                //
                // And iceCommunicator != null, meaning will be
                // destroyed next, iceDestroyed = true also ensures that
                // any remaining callback won't do anything
                //
            }
        }

        if(_createdSession && _router != null)
        {
            try
            {
                _router.destroySession();
            }
            catch(Ice.ConnectionLostException)
            {
                //
                // Expected if another thread invoked on an object from the session concurrently.
                //
            }
            catch(Glacier2.SessionNotExistException)
            {
                //
                // This can also occur.
                //
            }
            catch(System.Exception ex)
            {
                //
                // Not expected.
                //
                Ice.Util.getProcessLogger().error("unexpected exception when destroying the session:\n" +
                                                  ex.ToString());
            }
            _router = null;
        }

        if(iceCommunicator != null)
        {
            try
            {
                iceCommunicator.destroy();
            }
            catch(Ice.LocalException ex)
            {
                Ice.Util.getProcessLogger().error(ex.ToString());
                status = 1;
            }
            catch(System.Exception ex)
            {
                Ice.Util.getProcessLogger().error("unknown exception:\n" + ex.ToString());
                status = 1;
            }
            iceCommunicator = null;
        }

        //
        // Reset internal state. We cannot reset the Application state
        // here, since iceDestroyed must remain true until we re-run
        // this method.
        //
        _adapter = null;
        _router = null;
        _session = null;
        _createdSession = false;
        _category = null;

        return restart;
    }
Example #4
0
    private static int run(Ice.Communicator communicator)
    {
        var router = Glacier2.RouterPrxHelper.checkedCast(communicator.getDefaultRouter());

        Glacier2.SessionPrx session;
        while (true)
        {
            Console.WriteLine("This demo accepts any user-id / password combination.");

            string id;
            string pw;
            try
            {
                Console.Write("user id: ");
                Console.Out.Flush();
                id = Console.In.ReadLine();
                if (id == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }
                id = id.Trim();

                Console.Write("password: "******"permission denied:\n" + ex.reason);
            }
            catch (Glacier2.CannotCreateSessionException ex)
            {
                Console.WriteLine("cannot create session:\n" + ex.reason);
            }
        }

        int acmTimeout = router.getACMTimeout();

        Ice.Connection connection = router.ice_getCachedConnection();
        Debug.Assert(connection != null);
        connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
        connection.setCloseCallback(_ => Console.WriteLine("The Glacier2 session has been destroyed."));

        Ice.Identity callbackReceiverIdent     = new Ice.Identity("callbackReceiver", router.getCategoryForClient());
        Ice.Identity callbackReceiverFakeIdent = new Ice.Identity("fake", "callbackReceiver");

        Ice.ObjectPrx @base       = communicator.propertyToProxy("Callback.Proxy");
        CallbackPrx   twoway      = CallbackPrxHelper.checkedCast(@base);
        CallbackPrx   oneway      = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
        CallbackPrx   batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway());

        var adapter = communicator.createObjectAdapterWithRouter("", router);

        adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent);

        CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
            adapter.add(new CallbackReceiverI(), callbackReceiverIdent));

        adapter.activate();
        CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());

        menu();

        string line      = null;
        string @override = null;
        bool   fake      = false;

        do
        {
            Console.Write("==> ");
            Console.Out.Flush();
            line = Console.In.ReadLine();
            if (line == null)
            {
                break;
            }
            if (line.Equals("t"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "t";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                twoway.initiateCallback(twowayR, context);
            }
            else if (line.Equals("o"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "o";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                oneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("O"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "O";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                batchOneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("f"))
            {
                batchOneway.ice_flushBatchRequests();
            }
            else if (line.Equals("v"))
            {
                if (@override == null)
                {
                    @override = "some_value";
                    Console.WriteLine("override context field is now `" + @override + "'");
                }
                else
                {
                    @override = null;
                    Console.WriteLine("override context field is empty");
                }
            }
            else if (line.Equals("F"))
            {
                fake = !fake;

                if (fake)
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverFakeIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverFakeIdent));
                }
                else
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverIdent));
                }

                Console.WriteLine("callback receiver identity: " +
                                  Ice.Util.identityToString(twowayR.ice_getIdentity()));
            }
            else if (line.Equals("s"))
            {
                twoway.shutdown();
            }
            else if (line.Equals("x"))
            {
                // Nothing to do
            }
            else if (line.Equals("?"))
            {
                menu();
            }
            else
            {
                Console.WriteLine("unknown command `" + line + "'");
                menu();
            }
        }while(!line.Equals("x"));

        return(0);
    }
Example #5
0
    private static int run(Ice.Communicator communicator)
    {
        var router = Glacier2.RouterPrxHelper.checkedCast(communicator.getDefaultRouter());

        Glacier2.SessionPrx session;
        //
        // Loop until we have successfully create a session.
        //
        while (true)
        {
            //
            // Prompt the user for the credentials to create the session.
            //
            Console.WriteLine("This demo accepts any user-id / password combination.");

            string id;
            string pw;
            try
            {
                Console.Write("user id: ");
                Console.Out.Flush();
                id = Console.In.ReadLine();
                if (id == null)
                {
                    throw new Ice.CommunicatorDestroyedException();
                }
                id = id.Trim();

                Console.Write("password: "******"permission denied:\n" + ex.reason);
            }
            catch (Glacier2.CannotCreateSessionException ex)
            {
                Console.WriteLine("cannot create session:\n" + ex.reason);
            }
        }

        int acmTimeout = router.getACMTimeout();

        Ice.Connection connection = router.ice_getCachedConnection();
        Debug.Assert(connection != null);
        connection.setACM(acmTimeout, Ice.Util.None, Ice.ACMHeartbeat.HeartbeatAlways);
        connection.setCloseCallback(_ => Console.WriteLine("The Glacier2 session has been destroyed."));

        //
        // The Glacier2 router routes bidirectional calls to objects in the client only
        // when these objects have the correct Glacier2-issued category. The purpose of
        // the callbackReceiverFakeIdent is to demonstrate this.
        //
        // The Identity name is not checked by the server any value can be used.
        //
        Ice.Identity callbackReceiverIdent =
            new Ice.Identity(System.Guid.NewGuid().ToString(), router.getCategoryForClient());
        Ice.Identity callbackReceiverFakeIdent =
            new Ice.Identity(System.Guid.NewGuid().ToString(), "fake");

        Ice.ObjectPrx @base       = communicator.propertyToProxy("Callback.Proxy");
        CallbackPrx   twoway      = CallbackPrxHelper.checkedCast(@base);
        CallbackPrx   oneway      = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
        CallbackPrx   batchOneway = CallbackPrxHelper.uncheckedCast(twoway.ice_batchOneway());

        var adapter = communicator.createObjectAdapterWithRouter("", router);

        //
        // Callback will never be called for a fake identity.
        //
        adapter.add(new CallbackReceiverI(), callbackReceiverFakeIdent);

        CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast(
            adapter.add(new CallbackReceiverI(), callbackReceiverIdent));

        adapter.activate();
        CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());

        menu();

        //
        // Client REPL
        //
        string line      = null;
        string @override = null;
        bool   fake      = false;

        do
        {
            Console.Write("==> ");
            Console.Out.Flush();
            line = Console.In.ReadLine();
            if (line == null)
            {
                break;
            }
            if (line.Equals("t"))
            {
                twoway.initiateCallback(twowayR);
            }
            else if (line.Equals("o"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                oneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("O"))
            {
                Dictionary <string, string> context = new Dictionary <string, string>();
                context["_fwd"] = "O";
                if (@override != null)
                {
                    context["_ovrd"] = @override;
                }
                batchOneway.initiateCallback(onewayR, context);
            }
            else if (line.Equals("f"))
            {
                batchOneway.ice_flushBatchRequests();
            }
            else if (line.Equals("v"))
            {
                if (@override == null)
                {
                    @override = "some_value";
                    Console.WriteLine("override context field is now `" + @override + "'");
                }
                else
                {
                    @override = null;
                    Console.WriteLine("override context field is empty");
                }
            }
            else if (line.Equals("F"))
            {
                fake = !fake;

                if (fake)
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverFakeIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverFakeIdent));
                }
                else
                {
                    twowayR = CallbackReceiverPrxHelper.uncheckedCast(
                        twowayR.ice_identity(callbackReceiverIdent));
                    onewayR = CallbackReceiverPrxHelper.uncheckedCast(
                        onewayR.ice_identity(callbackReceiverIdent));
                }

                Console.WriteLine("callback receiver identity: " +
                                  Ice.Util.identityToString(twowayR.ice_getIdentity()));
            }
            else if (line.Equals("s"))
            {
                twoway.shutdown();
            }
            else if (line.Equals("x"))
            {
                // Nothing to do
            }
            else if (line.Equals("?"))
            {
                menu();
            }
            else
            {
                Console.WriteLine("unknown command `" + line + "'");
                menu();
            }
        }while(!line.Equals("x"));

        return(0);
    }