Example #1
0
    private static int run(Ice.Communicator communicator)
    {
        var server = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy"));

        if (server == null)
        {
            Console.Error.WriteLine("invalid proxy");
            return(1);
        }

        //
        // Create an object adapter with no name and no endpoints for receiving callbacks
        // over bidirectional connections.
        //
        var adapter = communicator.createObjectAdapter("");

        //
        // Register the callback receiver servant with the object adapter
        //
        var proxy = CallbackReceiverPrxHelper.uncheckedCast(adapter.addWithUUID(new CallbackReceiverI()));

        //
        // Associate the object adapter with the bidirectional connection.
        //
        server.ice_getConnection().setAdapter(adapter);

        //
        // Provide the proxy of the callback receiver object to the server and wait for
        // shutdown.
        //
        server.addClient(proxy);
        communicator.waitForShutdown();
        return(0);
    }
Example #2
0
        public override int runWithSession(string[] args)
        {
            test(router() != null);
            test(categoryForClient() != "");
            test(objectAdapter() != null);

            if (_restart == 0)
            {
                Console.Out.Write("testing Glacier2::Application restart... ");
                Console.Out.Flush();
            }
            Ice.ObjectPrx @base = communicator().stringToProxy("callback:" +
                                                               getTestEndpoint(communicator().getProperties(), 0));
            CallbackPrx callback = CallbackPrxHelper.uncheckedCast(@base);

            if (++_restart < 5)
            {
                CallbackReceiverPrx receiver = CallbackReceiverPrxHelper.uncheckedCast(addWithUUID(_receiver));
                callback.initiateCallback(receiver);
                _receiver.waitForCallback();
                restart();
            }
            Console.Out.WriteLine("ok");

            Console.Out.Write("testing server shutdown... ");
            Console.Out.Flush();
            callback.shutdown();
            Console.Out.WriteLine("ok");
            return(0);
        }
Example #3
0
    public override void addClient(Ice.Identity ident, Ice.Current current)
    {
#if COMPACT
        _m.Lock();
        try
        {
            System.Console.Out.WriteLine("adding client `" + _communicator.identityToString(ident) + "'");

            Ice.ObjectPrx       @base  = current.con.createProxy(ident);
            CallbackReceiverPrx client = CallbackReceiverPrxHelper.uncheckedCast(@base);
            _clients.Add(client);
        }
        finally
        {
            _m.Unlock();
        }
#else
        lock (this)
        {
            System.Console.Out.WriteLine("adding client `" + _communicator.identityToString(ident) + "'");

            Ice.ObjectPrx       @base  = current.con.createProxy(ident);
            CallbackReceiverPrx client = CallbackReceiverPrxHelper.uncheckedCast(@base);
            _clients.Add(client);
        }
#endif
    }
Example #4
0
 public override void addClient(Ice.Identity ident, Ice.Current current)
 {
     lock (this)
     {
         Console.Out.WriteLine("adding client `" + Ice.Util.identityToString(ident) + "'");
         _clients.Add(CallbackReceiverPrxHelper.uncheckedCast(current.con.createProxy(ident)));
     }
 }
Example #5
0
    private static int Init()
    {
        int result = 0;

        try
        {
            Ice.Communicator communicator = Ice.Util.initialize("config.client");

            sender = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy").
                                                         ice_twoway().ice_timeout(-1).ice_secure(false));
            if (sender == null)
            {
                Console.Error.WriteLine("invalid proxy");
                result = 0;
            }

            adapter = communicator.createObjectAdapter("Callback.Client");
            adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver"));
            adapter.activate();

            receiver = CallbackReceiverPrxHelper.uncheckedCast(
                adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver")));

            Console.WriteLine("server connected");

            result = 1;
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);

            Console.WriteLine("connection failed");
            result = 0;
        }

        return(result);
    }
Example #6
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 #7
0
    public override int run(string[] args)
    {
        Ice.ObjectPrx routerBase;
        {
            Console.Out.Write("testing stringToProxy for router... ");
            Console.Out.Flush();
            routerBase = communicator().stringToProxy("Glacier2/router:" + getTestEndpoint(50));
            Console.Out.WriteLine("ok");
        }

        Glacier2.RouterPrx router;
        {
            Console.Out.Write("testing checked cast for router... ");
            Console.Out.Flush();
            router = Glacier2.RouterPrxHelper.checkedCast(routerBase);
            test(router != null);
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("testing router finder... ");
            Console.Out.Flush();
            Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(
                communicator().stringToProxy("Ice/RouterFinder:" + getTestEndpoint(50)));
            test(finder.getRouter().ice_getIdentity().Equals(router.ice_getIdentity()));
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("installing router with communicator... ");
            Console.Out.Flush();
            communicator().setDefaultRouter(router);
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("getting the session timeout... ");
            Console.Out.Flush();
            long timeout = router.getSessionTimeout();
            test(timeout == 30);
            Console.Out.WriteLine("ok");
        }

        Ice.ObjectPrx @base;

        {
            Console.Out.Write("testing stringToProxy for server object... ");
            Console.Out.Flush();
            @base = communicator().stringToProxy("c1/callback:" + getTestEndpoint(0));
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("trying to ping server before session creation... ");
            Console.Out.Flush();
            try
            {
                @base.ice_ping();
                test(false);
            }
            catch (Ice.ConnectionLostException)
            {
                Console.Out.WriteLine("ok");
            }
            catch (Ice.SocketException)
            {
                test(false);
            }
        }

        {
            Console.Out.Write("trying to create session with wrong password... ");
            Console.Out.Flush();
            try
            {
                router.createSession("userid", "xxx");
                test(false);
            }
            catch (Glacier2.PermissionDeniedException)
            {
                Console.Out.WriteLine("ok");
            }
            catch (Glacier2.CannotCreateSessionException)
            {
                test(false);
            }
        }

        {
            Console.Out.Write("trying to destroy non-existing session... ");
            Console.Out.Flush();
            try
            {
                router.destroySession();
                test(false);
            }
            catch (Glacier2.SessionNotExistException)
            {
                Console.Out.WriteLine("ok");
            }
        }

        {
            Console.Out.Write("creating session with correct password... ");
            Console.Out.Flush();
            try
            {
                router.createSession("userid", "abc123");
            }
            catch (Glacier2.PermissionDeniedException)
            {
                test(false);
            }
            catch (Glacier2.CannotCreateSessionException)
            {
                test(false);
            }
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("trying to create a second session... ");
            Console.Out.Flush();
            try
            {
                router.createSession("userid", "abc123");
                test(false);
            }
            catch (Glacier2.PermissionDeniedException)
            {
                test(false);
            }
            catch (Glacier2.CannotCreateSessionException)
            {
                Console.Out.WriteLine("ok");
            }
        }

        {
            Console.Out.Write("pinging server after session creation... ");
            Console.Out.Flush();
            @base.ice_ping();
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("pinging object with client endpoint... ");
            Ice.ObjectPrx baseC = communicator().stringToProxy("collocated:" + getTestEndpoint(50));
            try
            {
                baseC.ice_ping();
            }
            catch (Ice.ObjectNotExistException)
            {
            }
            Console.Out.WriteLine("ok");
        }

        CallbackPrx twoway;

        {
            Console.Out.Write("testing checked cast for server object... ");
            Console.Out.Flush();
            twoway = CallbackPrxHelper.checkedCast(@base);
            test(twoway != null);
            Console.Out.WriteLine("ok");
        }

        Ice.ObjectAdapter adapter;

        {
            Console.Out.Write("creating and activating callback receiver adapter... ");
            Console.Out.Flush();
            communicator().getProperties().setProperty("Ice.PrintAdapterReady", "0");
            adapter = communicator().createObjectAdapterWithRouter("CallbackReceiverAdapter", router);
            adapter.activate();
            Console.Out.WriteLine("ok");
        }

        String category;

        {
            Console.Out.Write("getting category from router... ");
            Console.Out.Flush();
            category = router.getCategoryForClient();
            Console.Out.WriteLine("ok");
        }

        CallbackReceiverI callbackReceiverImpl;

        Ice.Object          callbackReceiver;
        CallbackReceiverPrx twowayR;
        CallbackReceiverPrx fakeTwowayR;

        {
            Console.Out.Write("creating and adding callback receiver object... ");
            Console.Out.Flush();
            callbackReceiverImpl = new CallbackReceiverI();
            callbackReceiver     = callbackReceiverImpl;
            Ice.Identity callbackReceiverIdent = new Ice.Identity();
            callbackReceiverIdent.name     = "callbackReceiver";
            callbackReceiverIdent.category = category;
            twowayR = CallbackReceiverPrxHelper.uncheckedCast(adapter.add(callbackReceiver, callbackReceiverIdent));
            Ice.Identity fakeCallbackReceiverIdent = new Ice.Identity();
            fakeCallbackReceiverIdent.name     = "callbackReceiver";
            fakeCallbackReceiverIdent.category = "dummy";
            fakeTwowayR = CallbackReceiverPrxHelper.uncheckedCast(
                adapter.add(callbackReceiver, fakeCallbackReceiverIdent));
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("testing oneway callback... ");
            Console.Out.Flush();
            CallbackPrx                 oneway  = CallbackPrxHelper.uncheckedCast(twoway.ice_oneway());
            CallbackReceiverPrx         onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway());
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "o";
            oneway.initiateCallback(onewayR, context);
            callbackReceiverImpl.callbackOK();
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("testing twoway callback... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            twoway.initiateCallback(twowayR, context);
            callbackReceiverImpl.callbackOK();
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("ditto, but with user exception... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            try
            {
                twoway.initiateCallbackEx(twowayR, context);
                test(false);
            }
            catch (CallbackException ex)
            {
                test(ex.someValue == 3.14);
                test(ex.someString.Equals("3.14"));
            }
            callbackReceiverImpl.callbackOK();
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("trying twoway callback with fake category... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            try
            {
                twoway.initiateCallback(fakeTwowayR, context);
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                Console.Out.WriteLine("ok");
            }
        }

        {
            Console.Out.Write("testing whether other allowed category is accepted... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            CallbackPrx otherCategoryTwoway = CallbackPrxHelper.uncheckedCast(
                twoway.ice_identity(Ice.Util.stringToIdentity("c2/callback")));
            otherCategoryTwoway.initiateCallback(twowayR, context);
            callbackReceiverImpl.callbackOK();
            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("testing whether disallowed category gets rejected... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            try
            {
                CallbackPrx otherCategoryTwoway = CallbackPrxHelper.uncheckedCast(
                    twoway.ice_identity(Ice.Util.stringToIdentity("c3/callback")));
                otherCategoryTwoway.initiateCallback(twowayR, context);
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                Console.Out.WriteLine("ok");
            }
        }

        {
            Console.Out.Write("testing whether user-id as category is accepted... ");
            Console.Out.Flush();
            Dictionary <string, string> context = new Dictionary <string, string>();
            context["_fwd"] = "t";
            CallbackPrx otherCategoryTwoway = CallbackPrxHelper.uncheckedCast(
                twoway.ice_identity(Ice.Util.stringToIdentity("_userid/callback")));
            otherCategoryTwoway.initiateCallback(twowayR, context);
            callbackReceiverImpl.callbackOK();
            Console.Out.WriteLine("ok");
        }

        if (args.Length >= 1 && args[0].Equals("--shutdown"))
        {
            Console.Out.Write("testing server shutdown... ");
            Console.Out.Flush();
            twoway.shutdown();
            // No ping, otherwise the router prints a warning message if it's
            // started with --Ice.Warn.Connections.
            Console.Out.WriteLine("ok");

            /*
             * try
             * {
             *    base.ice_ping();
             *    test(false);
             * }
             * // If we use the glacier router, the exact exception reason gets
             * // lost.
             * catch(Ice.UnknownLocalException ex)
             * {
             *    Console.Out.WriteLine("ok");
             * }
             */
        }

        {
            Console.Out.Write("destroying session... ");
            Console.Out.Flush();
            try
            {
                router.destroySession();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            Console.Out.WriteLine("ok");
        }

        {
            Console.Out.Write("trying to ping server after session destruction... ");
            Console.Out.Flush();
            try
            {
                @base.ice_ping();
                test(false);
            }
            catch (Ice.ConnectionLostException)
            {
                Console.Out.WriteLine("ok");
            }
            catch (Ice.SocketException)
            {
                test(false);
            }
        }

        if (args.Length >= 1 && args[0].Equals("--shutdown"))
        {
            {
                Console.Out.Write("uninstalling router with communicator... ");
                Console.Out.Flush();
                communicator().setDefaultRouter(null);
                Console.Out.WriteLine("ok");
            }

            Ice.ObjectPrx processBase;

            {
                Console.Out.Write("testing stringToProxy for admin object... ");
                processBase = communicator().stringToProxy("Glacier2/admin -f Process:" + getTestEndpoint(51));
                Console.Out.WriteLine("ok");
            }

/*
 *          {
 *              Console.Out.Write("uninstalling router with process object... ");
 *              processBase.ice_router(null);
 *              Console.Out.WriteLine("ok");
 *          }
 */

            Ice.ProcessPrx process;

            {
                Console.Out.Write("testing checked cast for process object... ");
                process = Ice.ProcessPrxHelper.checkedCast(processBase);
                test(process != null);
                Console.Out.WriteLine("ok");
            }

            Console.Out.Write("testing Glacier2 shutdown... ");
            process.shutdown();
            try
            {
                process.ice_ping();
                test(false);
            }
            catch (Ice.LocalException)
            {
                Console.Out.WriteLine("ok");
            }
        }

        return(0);
    }
Example #8
0
    private static int run(Ice.Communicator communicator)
    {
        var sender = CallbackSenderPrxHelper.checkedCast(communicator.propertyToProxy("CallbackSender.Proxy").
                                                         ice_twoway().ice_timeout(-1).ice_secure(false));

        if (sender == null)
        {
            Console.Error.WriteLine("invalid proxy");
            return(1);
        }

        var adapter = communicator.createObjectAdapter("Callback.Client");

        adapter.add(new CallbackReceiverI(), Ice.Util.stringToIdentity("callbackReceiver"));
        adapter.activate();

        var receiver = CallbackReceiverPrxHelper.uncheckedCast(
            adapter.createProxy(Ice.Util.stringToIdentity("callbackReceiver")));

        menu();

        string line = null;

        do
        {
            try
            {
                Console.Out.Write("==> ");
                Console.Out.Flush();
                line = Console.In.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.Equals("t"))
                {
                    sender.initiateCallback(receiver);
                }
                else if (line.Equals("s"))
                {
                    sender.shutdown();
                }
                else if (line.Equals("x"))
                {
                    // Nothing to do
                }
                else if (line.Equals("?"))
                {
                    menu();
                }
                else
                {
                    Console.Out.WriteLine("unknown command `" + line + "'");
                    menu();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
        }while(!line.Equals("x"));

        return(0);
    }
Example #9
0
        public override int run(string[] args)
        {
            if (args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return(1);
            }

            CallbackSenderPrx sender = CallbackSenderPrxHelper.checkedCast(
                communicator().propertyToProxy("CallbackSender.Proxy").
                ice_twoway().ice_timeout(-1).ice_secure(false));

            if (sender == null)
            {
                Console.Error.WriteLine("invalid proxy");
                return(1);
            }

            Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Client");
            adapter.add(new CallbackReceiverI(), communicator().stringToIdentity("callbackReceiver"));
            adapter.activate();

            CallbackReceiverPrx receiver = CallbackReceiverPrxHelper.uncheckedCast(
                adapter.createProxy(communicator().stringToIdentity("callbackReceiver")));

            menu();

            string line = null;

            do
            {
                try
                {
                    Console.Out.Write("==> ");
                    Console.Out.Flush();
                    line = Console.In.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    if (line.Equals("t"))
                    {
                        sender.initiateCallback(receiver);
                    }
                    else if (line.Equals("s"))
                    {
                        sender.shutdown();
                    }
                    else if (line.Equals("x"))
                    {
                        // Nothing to do
                    }
                    else if (line.Equals("?"))
                    {
                        menu();
                    }
                    else
                    {
                        Console.Out.WriteLine("unknown command `" + line + "'");
                        menu();
                    }
                }
                catch (System.Exception ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }while(!line.Equals("x"));

            return(0);
        }
Example #10
0
 public static CallbackReceiverPrx uncheckedCast(Ice.ObjectPrx b, string f)
 {
     if(b == null)
     {
         return null;
     }
     Ice.ObjectPrx bb = b.ice_facet(f);
     CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
     h.copyFrom__(bb);
     return h;
 }
Example #11
0
 public static CallbackReceiverPrx uncheckedCast(Ice.ObjectPrx b)
 {
     if(b == null)
     {
         return null;
     }
     CallbackReceiverPrx r = b as CallbackReceiverPrx;
     if(r == null)
     {
         CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
         h.copyFrom__(b);
         r = h;
     }
     return r;
 }
Example #12
0
 public static CallbackReceiverPrx checkedCast(Ice.ObjectPrx b, string f, _System.Collections.Generic.Dictionary<string, string> ctx)
 {
     if(b == null)
     {
         return null;
     }
     Ice.ObjectPrx bb = b.ice_facet(f);
     try
     {
         if(bb.ice_isA("::KeeICE::KPlib::CallbackReceiver", ctx))
         {
             CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
             h.copyFrom__(bb);
             return h;
         }
     }
     catch(Ice.FacetNotExistException)
     {
     }
     return null;
 }
Example #13
0
 public static CallbackReceiverPrx checkedCast(Ice.ObjectPrx b, string f)
 {
     if(b == null)
     {
         return null;
     }
     Ice.ObjectPrx bb = b.ice_facet(f);
     try
     {
         if(bb.ice_isA("::KeeICE::KPlib::CallbackReceiver"))
         {
             CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
             h.copyFrom__(bb);
             return h;
         }
     }
     catch(Ice.FacetNotExistException)
     {
     }
     return null;
 }
Example #14
0
 public static CallbackReceiverPrx checkedCast(Ice.ObjectPrx b, _System.Collections.Generic.Dictionary<string, string> ctx)
 {
     if(b == null)
     {
         return null;
     }
     CallbackReceiverPrx r = b as CallbackReceiverPrx;
     if((r == null) && b.ice_isA("::KeeICE::KPlib::CallbackReceiver", ctx))
     {
         CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
         h.copyFrom__(b);
         r = h;
     }
     return r;
 }
Example #15
0
 public static CallbackReceiverPrx checkedCast(Ice.ObjectPrx b)
 {
     if(b == null)
     {
         return null;
     }
     CallbackReceiverPrx r = b as CallbackReceiverPrx;
     if((r == null) && b.ice_isA("::KeeICE::KPlib::CallbackReceiver"))
     {
         CallbackReceiverPrxHelper h = new CallbackReceiverPrxHelper();
         h.copyFrom__(b);
         r = h;
     }
     return r;
 }
Example #16
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);
    }
Example #17
0
        public override int runWithSession(string[] args)
        {
            if (args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return(1);
            }

            Ice.Identity callbackReceiverIdent     = createCallbackIdentity("callbackReceiver");
            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());

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

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

            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("r"))
                {
                    restart();
                }
                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 #18
0
 public static CallbackReceiverPrx read__(IceInternal.BasicStream is__)
 {
     Ice.ObjectPrx proxy = is__.readProxy();
     if(proxy != null)
     {
         CallbackReceiverPrxHelper result = new CallbackReceiverPrxHelper();
         result.copyFrom__(proxy);
         return result;
     }
     return null;
 }