Example #1
0
 internal void addObjectReference(Ice.Identity id, Reference reference)
 {
     lock (this)
     {
         _objectTable[id] = new ReferenceTableEntry(Time.currentMonotonicTimeMillis(), reference);
     }
 }
Example #2
0
        private void btndynamicDetect_Click(object sender, RoutedEventArgs e)
        {
            //回调EndPoint的写法
            //1."default -h 192.168.1.116 -p 9991"
            //2."default"
            string endpoints = "default -h 192.168.1.116 -p 9991";

            callbackAdapter = ic.createObjectAdapterWithEndpoints("callback-client", endpoints);

            Ice.Object servant = new ClientCallbackI(Item);
            callbackAdapter.add(servant, ic.stringToIdentity("callbackReceiver"));
            callbackAdapter.activate();

            ClientCallbackReceiverPrx receiverPrx = null;

            Ice.Identity identity = ic.stringToIdentity("callbackReceiver");
            //代理一定要通过adapter对象创建
            Ice.ObjectPrx pxy = callbackAdapter.createProxy(identity);
            receiverPrx = ClientCallbackReceiverPrxHelper.uncheckedCast(pxy);


            var result = facePxy.dynamicDetect("rtspPath", receiverPrx, 0.4f, 100, 4);

            lbResult.Items.Clear();
            Item("code:" + result.code);
            Item("message:" + result.message);
        }
Example #3
0
 addObject(string oaName, string id, Ice.Current current)
 {
     Debug.Assert(_adapters.ContainsKey(oaName));
     Ice.Identity identity = new Ice.Identity();
     identity.name = id;
     _adapters[oaName].add(new TestIntfI(), identity);
 }
Example #4
0
 removeObject(string oaName, string id, Ice.Current current)
 {
     Debug.Assert(_adapters.ContainsKey(oaName));
     Ice.Identity identity = new Ice.Identity();
     identity.name = id;
     _adapters[oaName].remove(identity);
 }
Example #5
0
        internal Task <Ice.IObjectPrx> findObject(Ice.Identity id)
        {
            lock (this)
            {
                ObjectRequest request;
                if (!_objectRequests.TryGetValue(id, out request))
                {
                    request = new ObjectRequest(this, id, _retryCount);
                    _objectRequests.Add(id, request);
                }

                var task = new TaskCompletionSource <Ice.IObjectPrx>();
                if (request.addCallback(task))
                {
                    try
                    {
                        request.invoke(_domainId, _lookups);
                        _timer.schedule(request, _timeout);
                    }
                    catch (LocalException)
                    {
                        request.finished(null);
                        _objectRequests.Remove(id);
                    }
                }
                return(task.Task);
            }
        }
Example #6
0
        internal static Ice.Current CreateCurrent(int requestId, Ice.InputStream requestFrame,
                                                  Ice.ObjectAdapter adapter, Ice.Connection?connection = null)
        {
            var identity = new Ice.Identity(requestFrame);

            // For compatibility with the old FacetPath.
            string[] facetPath = requestFrame.ReadStringArray();
            if (facetPath.Length > 1)
            {
                throw new Ice.MarshalException();
            }
            string facet     = facetPath.Length == 0 ? "" : facetPath[0];
            string operation = requestFrame.ReadString();
            var    mode      = requestFrame.ReadByte();

            if (mode > 2)
            {
                throw new Ice.MarshalException(
                          $"received invalid operation mode `{mode}' with operation `{operation}'");
            }
            bool idempotent = mode > 0;
            var  context    = requestFrame.ReadContext();

            Ice.EncodingVersion encoding = requestFrame.StartEncapsulation();

            return(new Ice.Current(adapter, identity, facet, operation, idempotent, context,
                                   requestId, connection, encoding));
        }
Example #7
0
        public override int run(string[] args)
        {
            if(args.Length > 0)
            {
                Console.Error.WriteLine(appName() + ": too many arguments");
                return 1;
            }

            var server = CallbackSenderPrxHelper.checkedCast(communicator().propertyToProxy("CallbackSender.Proxy"));
            if(server == null)
            {
                Console.Error.WriteLine("invalid proxy");
                return 1;
            }

            var adapter = communicator().createObjectAdapter("");
            var ident = new Ice.Identity();
            ident.name = Guid.NewGuid().ToString();
            ident.category = "";
            adapter.add(new CallbackReceiverI(), ident);
            adapter.activate();
            server.ice_getConnection().setAdapter(adapter);
            server.addClient(ident);
            communicator().waitForShutdown();

            return 0;
        }
Example #8
0
 public FileI(string name, DirectoryI parent)
 {
     _name = name;
     _parent = parent;
     _destroyed = false;
     _id = new Identity();
     _id.name = Guid.NewGuid().ToString();
 }
Example #9
0
 public void invoke(string domainId, Dictionary <LookupPrx, LookupReplyPrx?> lookups)
 {
     _lookupCount  = lookups.Count;
     _failureCount = 0;
     Ice.Identity id = new Ice.Identity(_requestId, "");
     foreach (var entry in lookups)
     {
         invokeWithLookup(domainId, entry.Key, LookupReplyPrx.UncheckedCast(entry.Value.Clone(id)));
     }
 }
Example #10
0
        public void Invoke(string domainId, Dictionary <ILookupPrx, ILookupReplyPrx?> lookups)
        {
            LookupCount  = lookups.Count;
            FailureCount = 0;
            var id = new Ice.Identity(_requestId, "");

            foreach (KeyValuePair <ILookupPrx, ILookupReplyPrx?> entry in lookups)
            {
                InvokeWithLookup(domainId, entry.Key, ILookupReplyPrx.UncheckedCast(entry.Value.Clone(id)));
            }
        }
Example #11
0
    // DirectoryI constructor
    public DirectoryI(Ice.Communicator communicator, string name, DirectoryI parent)
    {
        _name = name;
        _parent = parent;

        //
        // Create an identity. The root directory has the fixed identity "RootDir"
        //
        _id = new Ice.Identity();
        _id.name = _parent != null ? System.Guid.NewGuid().ToString() : "RootDir";
    }
Example #12
0
 internal Reference removeObjectReference(Ice.Identity id)
 {
     lock (this)
     {
         ReferenceTableEntry entry = null;
         if (_objectTable.TryGetValue(id, out entry))
         {
             _objectTable.Remove(id);
             return(entry.reference);
         }
         return(null);
     }
 }
Example #13
0
    // FileI constructor
    public FileI(Ice.Communicator communicator, string name, DirectoryI parent)
    {
        _name = name;
        _parent = parent;

        Debug.Assert(_parent != null);

        //
        // Create an identity
        //
        _id = new Ice.Identity();
        _id.name = System.Guid.NewGuid().ToString();
    }
Example #14
0
 internal void foundObject(Ice.Identity id, string requestId, Ice.IObjectPrx proxy)
 {
     lock (this)
     {
         ObjectRequest request;
         if (_objectRequests.TryGetValue(id, out request) && request.getRequestId() == requestId)
         {
             request.response(proxy);
             _timer.cancel(request);
             _objectRequests.Remove(id);
         }
         // else ignore responses from old requests
     }
 }
Example #15
0
        public async Task Connect(string[] args)
        {
            await Task.Yield();

            communicator = Ice.Util.initialize(ref args);
            Ice.Identity id    = new Ice.Identity();
            var          proxy = communicator.stringToProxy("Server:default -h localhost -p 10000");

            _server = ServerPrxHelper.checkedCast(proxy);
            adapter = communicator.createObjectAdapterWithEndpoints("TreeDiagramClient", "default -p 10008");
            adapter.activate();
            serverEvent = ServerEventPrxHelper.uncheckedCast(
                adapter.addWithUUID(
                    lib.Provider.serviceProvider.GetRequiredService <lib.IceBridge.ServerEvent>()));
            _server.initEvent(uuid, serverEvent);
        }
        // DirectoryI constructor. parent == null indicates root directory.
        public DirectoryI(string name, DirectoryI parent)
        {
            _name = name;
            _parent = parent;
            _id = new Identity();
            _destroyed = false;
            _contents = new Dictionary<string, NodeI>();

            if(parent == null)
            {
                _id.name = "RootDir";
            }
            else
            {
                _id.name = Guid.NewGuid().ToString();
            }
        }
Example #17
0
        internal Ice.IObjectPrx findObject(Ice.Identity id)
        {
            lock (this)
            {
                if (id.name.Length == 0)
                {
                    return(null);
                }

                Ice.IObjectPrx prx = _wellKnownProxy.Clone(id);

                List <string> adapterIds = new List <string>();
                foreach (KeyValuePair <string, HashSet <string> > entry in _replicaGroups)
                {
                    try
                    {
                        prx.Clone(adapterId: entry.Key).IcePing();
                        adapterIds.Add(entry.Key);
                    }
                    catch (Ice.Exception)
                    {
                    }
                }
                if (adapterIds.Count == 0)
                {
                    foreach (KeyValuePair <string, Ice.IObjectPrx> entry in _adapters)
                    {
                        try
                        {
                            prx.Clone(adapterId: entry.Key).IcePing();
                            adapterIds.Add(entry.Key);
                        }
                        catch (Ice.Exception)
                        {
                        }
                    }
                }

                if (adapterIds.Count == 0)
                {
                    return(null);
                }
                //adapterIds.Suffle();
                return(prx.Clone(adapterId: adapterIds[0]));
            }
        }
Example #18
0
        internal Reference getObjectReference(Ice.Identity id, int ttl, out bool cached)
        {
            if (ttl == 0) // Locator cache disabled.
            {
                cached = false;
                return(null);
            }

            lock (this)
            {
                ReferenceTableEntry entry = null;
                if (_objectTable.TryGetValue(id, out entry))
                {
                    cached = checkTTL(entry.time, ttl);
                    return(entry.reference);
                }
                cached = false;
                return(null);
            }
        }
Example #19
0
        public override int run(string[] args)
        {
            //
            // Terminate cleanly on receipt of a signal.
            //
            shutdownOnInterrupt();

            //
            // Create an object adapter
            //
            Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints(
                "LifecycleFilesystem", "default -h localhost -p 10000");

            //
            // Create the root directory.
            //
            DirectoryI root = new DirectoryI();
            Ice.Identity id = new Ice.Identity();
            id.name = "RootDir";
            adapter.add(root, id);

            //
            // All objects are created, allow client requests now.
            //
            adapter.activate();

            //
            // Wait until we are done.
            //
            communicator().waitForShutdown();
            if(interrupted())
            {
                System.Console.Error.WriteLine(appName() + ": received signal, shutting down");
            }

            return 0;
        }
Example #20
0
        private static void PrintIdentityFacetOperation(System.IO.StringWriter s, Ice.InputStream str)
        {
            try
            {
                Ice.ToStringMode toStringMode = str.Communicator.ToStringMode;

                var identity = new Ice.Identity(str);
                s.Write("\nidentity = " + identity.ToString(toStringMode));

                string[] facet = str.ReadStringArray();
                s.Write("\nfacet = ");
                if (facet.Length > 0)
                {
                    s.Write(IceUtilInternal.StringUtil.EscapeString(facet[0], "", toStringMode));
                }

                string operation = str.ReadString();
                s.Write("\noperation = " + operation);
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
            }
        }
Example #21
0
        public void findObjectById(string domainId, Ice.Identity id, LookupReplyPrx reply,
                                   Ice.Current current)
        {
            if (!domainId.Equals(_domainId))
            {
                return; // Ignore
            }

            Ice.IObjectPrx proxy = _registry.findObject(id);
            if (proxy != null)
            {
                //
                // Reply to the mulicast request using the given proxy.
                //
                try
                {
                    reply.foundObjectByIdAsync(id, proxy);
                }
                catch (Ice.LocalException)
                {
                    // Ignore.
                }
            }
        }
Example #22
0
        public Dictionary<string, Ice.Object> removeAllFacets(Identity ident)
        {
            lock(this)
            {
                checkForDeactivation();
                checkIdentity(ident);

                return _servantManager.removeAllFacets(ident);
            }
        }
Example #23
0
 findObjectByIdAsync(Ice.Identity id, Ice.Current current)
 {
     _controller.checkCallPause(current);
     return(Task.FromResult(current.Adapter.CreateDirectProxy(id)));
 }
Example #24
0
        public ObjectPrx addFacetWithUUID(Ice.Object obj, string facet)
        {
            Identity ident = new Identity();
            ident.category = "";
            ident.name = Guid.NewGuid().ToString();

            return addFacet(obj, ident, facet);
        }
Example #25
0
 public Ice.Object find(Identity ident)
 {
     return findFacet(ident, "");
 }
Example #26
0
 private ObjectPrx newIndirectProxy(Identity ident, string facet, string id)
 {
     //
     // Create a reference with the adapter id and return a
     // proxy for the reference.
     //
     Reference reference = instance_.referenceFactory().create(ident, facet, _reference, id);
     return instance_.proxyFactory().referenceToProxy(reference);
 }
Example #27
0
 public ObjectPrx add(Ice.Object obj, Identity ident)
 {
     return addFacet(obj, ident, "");
 }
Example #28
0
 public ObjectPrx createProxy(Identity ident)
 {
     //
     // Create a reference and return a reverse proxy for this
     // reference.
     //
     return _instance.proxyFactory().referenceToProxy(_instance.referenceFactory().create(ident, this));
 }
Example #29
0
 /// <summary>
 /// Creates a new proxy that is identical to this proxy, except for the per-proxy context.
 /// <param name="newIdentity">The identity for the new proxy.</param>
 /// <returns>The proxy with the new identity.</returns>
 /// </summary>
 public ObjectPrx ice_identity(Identity newIdentity)
 {
     if(newIdentity.name.Length == 0)
     {
         throw new IllegalIdentityException();
     }
     if(newIdentity.Equals(_reference.getIdentity()))
     {
         return this;
     }
     else
     {
         ObjectPrxHelperBase proxy = new ObjectPrxHelperBase();
         proxy.setup(_reference.changeIdentity(newIdentity));
         return proxy;
     }
 }
Example #30
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:default -p 12347");
                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:default -p 12347"));
                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:tcp -p 12010");
                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");
            }

            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(communicator().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(communicator().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(communicator().stringToIdentity("_userid/callback")));
                otherCategoryTwoway.initiateCallback(twowayR, context);
                callbackReceiverImpl.callbackOK();
                Console.Out.WriteLine("ok");
            }

            {
                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:tcp -h 127.0.0.1 -p 12348");
                    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 #31
0
    public static void allTests(Ice.Communicator communicator)
    {
        Console.Out.Write("testing stringToProxy... ");
        Console.Out.Flush();
        String rf = "test @ TestAdapter";
        Ice.ObjectPrx @base = communicator.stringToProxy(rf);
        test(@base != null);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing IceGrid.Locator is present... ");
        IceGrid.LocatorPrx locator = IceGrid.LocatorPrxHelper.uncheckedCast(@base);
        test(locator != null);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing checked cast... ");
        Console.Out.Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);
        test(obj != null);
        test(obj.Equals(@base));
        Console.Out.WriteLine("ok");

        Console.Out.Write("pinging server... ");
        Console.Out.Flush();
        obj.ice_ping();
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing locator finder... ");
        Ice.Identity finderId = new Ice.Identity();
        finderId.category = "Ice";
        finderId.name = "LocatorFinder";
        Ice.LocatorFinderPrx finder = Ice.LocatorFinderPrxHelper.checkedCast(
            communicator.getDefaultLocator().ice_identity(finderId));
        test(finder.getLocator() != null);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing discovery... ");
        {
            // Add test well-known object
            IceGrid.RegistryPrx registry = IceGrid.RegistryPrxHelper.checkedCast(
                communicator.stringToProxy(communicator.getDefaultLocator().ice_getIdentity().category + "/Registry"));
            test(registry != null);
            
            try
            {
                IceGrid.AdminSessionPrx session = registry.createAdminSession("foo", "bar");
                session.getAdmin().addObjectWithType(@base, "::Test");
                session.destroy();
            }
            catch(Ice.UserException)
            {
                test(false);
            }

            //
            // Ensure the IceGrid discovery locator can discover the
            // registries and make sure locator requests are forwarded.
            //
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().ice_clone_();
            initData.properties.setProperty("Ice.Default.Locator", "");
            initData.properties.setProperty("Ice.Plugin.IceGridDiscovery", "IceGrid:IceGrid.DiscoveryPluginFactoryI");
            if(IceInternal.AssemblyUtil.osx_ && 
               initData.properties.getPropertyAsInt("Ice.PreferIPv6Address") > 0)
            {
                initData.properties.setProperty("IceGridDiscovery.Interface", "::1");
            }
            initData.properties.setProperty("AdapterForDiscoveryTest.AdapterId", "discoveryAdapter");
            initData.properties.setProperty("AdapterForDiscoveryTest.Endpoints", "default");
        
            Ice.Communicator com =  Ice.Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            com.stringToProxy("test @ TestAdapter").ice_ping();
            com.stringToProxy("test").ice_ping();

            test(com.getDefaultLocator().getRegistry() != null);
            test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry() != null);
            test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalQuery() != null);

            Ice.ObjectAdapter adapter = com.createObjectAdapter("AdapterForDiscoveryTest");
            adapter.activate();
            adapter.deactivate();
            com.destroy();

            //
            // Now, ensure that the IceGrid discovery locator correctly
            // handles failure to find a locator.
            // 
            initData.properties.setProperty("IceGridDiscovery.InstanceName", "unknown");
            initData.properties.setProperty("IceGridDiscovery.RetryCount", "1");
            initData.properties.setProperty("IceGridDiscovery.Timeout", "100");
            com = Ice.Util.initialize(initData);
            test(com.getDefaultLocator() != null);
            try
            {
                com.stringToProxy("test @ TestAdapter").ice_ping();
            }
            catch(Ice.NoEndpointException)
            {
            }
            try
            {
                com.stringToProxy("test").ice_ping();
            }
            catch(Ice.NoEndpointException)
            {
            }
            test(com.getDefaultLocator().getRegistry() == null);
            test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalRegistry() == null);
            test(IceGrid.LocatorPrxHelper.uncheckedCast(com.getDefaultLocator()).getLocalQuery() == null);

            adapter = com.createObjectAdapter("AdapterForDiscoveryTest");
            adapter.activate();
            adapter.deactivate();

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

        System.Console.Out.Write("shutting down server... ");
        System.Console.Out.Flush();
        obj.shutdown();
        System.Console.Out.WriteLine("ok");
    }
Example #32
0
        attachRemoteLogger(RemoteLoggerPrx prx, LogMessageType[] messageTypes, string[] categories,
                           int messageMax, Current current)
        {
            if (prx == null)
            {
                return; // can't send this null RemoteLogger anything!
            }

            var remoteLogger = prx.Clone(oneway: false);

            Filters filters = new Filters(messageTypes, categories);
            LinkedList <LogMessage> initLogMessages = null;

            lock (this)
            {
                if (_sendLogCommunicator == null)
                {
                    if (_destroyed)
                    {
                        throw new ObjectNotExistException();
                    }

                    _sendLogCommunicator =
                        createSendLogCommunicator(current.Adapter.Communicator, _logger.getLocalLogger());
                }

                Ice.Identity remoteLoggerId = remoteLogger.Identity;

                if (_remoteLoggerMap.ContainsKey(remoteLoggerId))
                {
                    if (_traceLevel > 0)
                    {
                        _logger.trace(_traceCategory, "rejecting `" + remoteLogger.ToString() +
                                      "' with RemoteLoggerAlreadyAttachedException");
                    }

                    throw new Ice.RemoteLoggerAlreadyAttachedException();
                }

                _remoteLoggerMap.Add(remoteLoggerId,
                                     new RemoteLoggerData(changeCommunicator(remoteLogger, _sendLogCommunicator), filters));

                if (messageMax != 0)
                {
                    initLogMessages = new LinkedList <Ice.LogMessage>(_queue); // copy
                }
                else
                {
                    initLogMessages = new LinkedList <Ice.LogMessage>();
                }
            }

            if (_traceLevel > 0)
            {
                _logger.trace(_traceCategory, "attached `" + remoteLogger.ToString() + "'");
            }

            if (initLogMessages.Count > 0)
            {
                filterLogMessages(initLogMessages, filters.messageTypes, filters.traceCategories, messageMax);
            }

            try
            {
                remoteLogger.initAsync(_logger.getPrefix(), initLogMessages.ToArray()).ContinueWith(
                    (t) =>
                {
                    try
                    {
                        t.Wait();
                        if (_traceLevel > 1)
                        {
                            _logger.trace(_traceCategory, "init on `" + remoteLogger.ToString()
                                          + "' completed successfully");
                        }
                    }
                    catch (System.AggregateException ae)
                    {
                        Debug.Assert(ae.InnerException is Ice.LocalException);
                        deadRemoteLogger(remoteLogger, _logger, (Ice.LocalException)ae.InnerException, "init");
                    }
                },
                    System.Threading.Tasks.TaskScheduler.Current);
            }
            catch (Ice.LocalException ex)
            {
                deadRemoteLogger(remoteLogger, _logger, ex, "init");
                throw;
            }
        }
Example #33
0
    public static void allTests(Ice.Communicator communicator)
#endif
    {
        ServerManagerPrx manager = ServerManagerPrxHelper.checkedCast(
                                        communicator.stringToProxy("ServerManager :default -p 12010"));
        test(manager != null);
        TestLocatorPrx locator = TestLocatorPrxHelper.uncheckedCast(communicator.getDefaultLocator());
        test(locator != null);
        TestLocatorRegistryPrx registry = TestLocatorRegistryPrxHelper.checkedCast(locator.getRegistry());
        test(registry != null);
        
        Write("testing stringToProxy... ");
        Flush();
        Ice.ObjectPrx @base = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base2 = communicator.stringToProxy("test @ TestAdapter");
        Ice.ObjectPrx base3 = communicator.stringToProxy("test");
        Ice.ObjectPrx base4 = communicator.stringToProxy("ServerManager");
        Ice.ObjectPrx base5 = communicator.stringToProxy("test2");
        Ice.ObjectPrx base6 = communicator.stringToProxy("test @ ReplicatedAdapter");
        WriteLine("ok");
        
        Write("testing ice_locator and ice_getLocator... ");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0);
        Ice.LocatorPrx anotherLocator = 
            Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("anotherLocator"));
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getLocator() == null);
        @base = @base.ice_locator(anotherLocator);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), anotherLocator) == 0);
        communicator.setDefaultLocator(locator);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getLocator(), communicator.getDefaultLocator()) == 0); 
        
        //
        // We also test ice_router/ice_getRouter (perhaps we should add a
        // test/Ice/router test?)
        //
        test(@base.ice_getRouter() == null);
        Ice.RouterPrx anotherRouter = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("anotherRouter"));
        @base = @base.ice_router(anotherRouter);
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), anotherRouter) == 0);
        Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("dummyrouter"));
        communicator.setDefaultRouter(router);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(Ice.Util.proxyIdentityCompare(@base.ice_getRouter(), communicator.getDefaultRouter()) == 0);
        communicator.setDefaultRouter(null);
        @base = communicator.stringToProxy("test @ TestAdapter");
        test(@base.ice_getRouter() == null);
        WriteLine("ok");

        Write("starting server... ");
        Flush();
        manager.startServer();
        WriteLine("ok");
        
        Write("testing checked cast... ");
        Flush();
        TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base);
        test(obj != null);
        TestIntfPrx obj2 = TestIntfPrxHelper.checkedCast(base2);
        test(obj2 != null);
        TestIntfPrx obj3 = TestIntfPrxHelper.checkedCast(base3);
        test(obj3 != null);
        ServerManagerPrx obj4 = ServerManagerPrxHelper.checkedCast(base4);
        test(obj4 != null);
        TestIntfPrx obj5 = TestIntfPrxHelper.checkedCast(base5);
        test(obj5 != null);
        TestIntfPrx obj6 = TestIntfPrxHelper.checkedCast(base6);
        test(obj6 != null);
        WriteLine("ok");
        
        Write("testing id@AdapterId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing id@ReplicaGroupId indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {       
            obj6.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");
        
        Write("testing identity indirect proxy... ");
        Flush();
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj2.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        try
        {
            obj3.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj2.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj3.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        obj.shutdown();
        manager.startServer();
        try
        {
            obj5 = TestIntfPrxHelper.checkedCast(base5);
            obj5.ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing proxy with unknown identity... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("unknown/unknown");
            @base.ice_ping();
            test(false);
        }
        catch(Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object"));
            test(ex.id.Equals("unknown/unknown"));
        }
        WriteLine("ok");
        
        Write("testing proxy with unknown adapter... ");
        Flush();
        try
        {
            @base = communicator.stringToProxy("test @ TestAdapterUnknown");
            @base.ice_ping();
            test(false);
        }
        catch(Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject.Equals("object adapter"));
            test(ex.id.Equals("TestAdapterUnknown"));
        }
        WriteLine("ok");
        
        Write("testing locator cache timeout... ");
        Flush();
        
        int count = locator.getRequestCount();
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200); // 1200ms
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
        test(++count == locator.getRequestCount());
        
        communicator.stringToProxy("test").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
        count += 2;
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        test(count == locator.getRequestCount());
        System.Threading.Thread.Sleep(1200); // 1200ms
        communicator.stringToProxy("test").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout
        count += 2;
        test(count == locator.getRequestCount());
        
        communicator.stringToProxy("test@TestAdapter").ice_locatorCacheTimeout(-1).ice_ping(); 
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_locatorCacheTimeout(-1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter").ice_ping(); 
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test").ice_ping();
        test(count == locator.getRequestCount());

        test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() == 99);

        WriteLine("ok");

        Write("testing proxy from server... ");
        Flush();
        obj = TestIntfPrxHelper.checkedCast(communicator.stringToProxy("test@TestAdapter"));
        HelloPrx hello = obj.getHello();
        test(hello.ice_getAdapterId().Equals("TestAdapter"));
        hello.sayHello();
        hello = obj.getReplicatedHello();
        test(hello.ice_getAdapterId().Equals("ReplicatedAdapter"));
        hello.sayHello();
        WriteLine("ok");
        
        Write("testing locator request queuing... ");
        Flush();
        hello = (HelloPrx)obj.getReplicatedHello().ice_locatorCacheTimeout(0).ice_connectionCached(false);
        count = locator.getRequestCount();
        hello.ice_ping();
        test(++count == locator.getRequestCount());
        List<Ice.AsyncResult<Test.Callback_Hello_sayHello> > results =
            new List<Ice.AsyncResult<Test.Callback_Hello_sayHello> >();
        for(int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult<Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                whenCompleted(
                    () =>
                    {
                    },
                    (Ice.Exception ex) =>
                    {
                      test(false);
                    });
            results.Add(result);
        }
        foreach(Ice.AsyncResult<Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 999);
        if(locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        count = locator.getRequestCount();
        hello = (HelloPrx)hello.ice_adapterId("unknown");
        for(int i = 0; i < 1000; i++)
        {
            Ice.AsyncResult<Test.Callback_Hello_sayHello> result = hello.begin_sayHello().
                whenCompleted(
                    () =>
                    {
                        test(false);
                    },
                    (Ice.Exception ex) =>
                    {
                        test(ex is Ice.NotRegisteredException);
                    });
            results.Add(result);
        }
        foreach(Ice.AsyncResult<Test.Callback_Hello_sayHello> result in results)
        {
            result.waitForCompleted();
        }
        results.Clear();
        // XXX:
        // Take into account the retries.
        test(locator.getRequestCount() > count && locator.getRequestCount() < count + 1999);
        if(locator.getRequestCount() > count + 800)
        {
            Write("queuing = " + (locator.getRequestCount() - count));
        }
        WriteLine("ok");

        Write("testing adapter locator cache... ");
        Flush();
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch(Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestAdapter3"));
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            registry.setAdapterDirectProxy("TestAdapter3", communicator.stringToProxy("dummy:tcp"));
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
    
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {   
        }
        registry.setAdapterDirectProxy("TestAdapter3", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test@TestAdapter3").ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        WriteLine("ok");

        Write("testing well-known object locator cache... ");
        Flush();
        registry.addObject(communicator.stringToProxy("test3@TestUnknown"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch(Ice.NotRegisteredException ex)
        {
            test(ex.kindOfObject == "object adapter");
            test(ex.id.Equals("TestUnknown"));
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter4")); // Update
        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        registry.setAdapterDirectProxy("TestAdapter4", locator.findAdapterById("TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }

        registry.setAdapterDirectProxy("TestAdapter4", communicator.stringToProxy("dummy:tcp"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }

        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_locatorCacheTimeout(0).ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        try
        {
            communicator.stringToProxy("test@TestAdapter4").ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {   
        }
        try
        {
            communicator.stringToProxy("test3").ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        registry.addObject(communicator.stringToProxy("test3@TestAdapter"));
        try
        {
            communicator.stringToProxy("test3").ice_ping();
        }
        catch(Ice.LocalException)
        {
            test(false);
        }
        
        registry.addObject(communicator.stringToProxy("test4"));
        try
        {
            communicator.stringToProxy("test4").ice_ping();
            test(false);
        }
        catch(Ice.NoEndpointException)
        {
        }
        WriteLine("ok");
        
        Write("testing locator cache background updates... ");
        Flush();
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().ice_clone_();
            initData.properties.setProperty("Ice.BackgroundLocatorCacheUpdates", "1");
            Ice.Communicator ic = Ice.Util.initialize(initData);

            registry.setAdapterDirectProxy("TestAdapter5", locator.findAdapterById("TestAdapter"));
            registry.addObject(communicator.stringToProxy("test3@TestAdapter"));

            count = locator.getRequestCount();
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(0).ice_ping(); // No locator cache.
            count += 3;
            test(count == locator.getRequestCount());
            registry.setAdapterDirectProxy("TestAdapter5", null);
            registry.addObject(communicator.stringToProxy("test3:tcp"));
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(10).ice_ping(); // 10s timeout.
            test(count == locator.getRequestCount());
            System.Threading.Thread.Sleep(1200);

            // The following request should trigger the background
            // updates but still use the cached endpoints and
            // therefore succeed.
            ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
            ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.

            try
            {
                while(true)
                {
                    ic.stringToProxy("test@TestAdapter5").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch(Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            try
            {
                while(true)
                {
                    ic.stringToProxy("test3").ice_locatorCacheTimeout(1).ice_ping(); // 1s timeout.
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch(Ice.LocalException)
            {
                // Expected to fail once they endpoints have been updated in the background.
            }
            ic.destroy();
        }
        WriteLine("ok");

        Write("testing proxy from server after shutdown... ");
        Flush();
        hello = obj.getReplicatedHello();
        obj.shutdown();
        manager.startServer();
        hello.sayHello();
        WriteLine("ok");

        Write("testing object migration... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        obj.migrateHello();
        hello.ice_getConnection().close(false);
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        obj.migrateHello();
        hello.sayHello();
        WriteLine("ok");

        Write("testing locator encoding resolution... ");
        Flush();
        hello = HelloPrxHelper.checkedCast(communicator.stringToProxy("hello"));
        count = locator.getRequestCount();
        communicator.stringToProxy("test@TestAdapter").ice_encodingVersion(Ice.Util.Encoding_1_1).ice_ping();
        test(count == locator.getRequestCount());
        communicator.stringToProxy("test@TestAdapter10").ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        test(++count == locator.getRequestCount());
        communicator.stringToProxy("test -e 1.0@TestAdapter10-2").ice_ping();
        test(++count == locator.getRequestCount());
        WriteLine("ok");

        Write("shutdown server... ");
        Flush();
        obj.shutdown();
        WriteLine("ok");

        Write("testing whether server is gone... ");
        Flush();
        try
        {
            obj2.ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        try
        {
            obj3.ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        try
        {
            obj5.ice_ping();
            test(false);
        }
        catch(Ice.LocalException)
        {
        }
        WriteLine("ok");
        
#if !SILVERLIGHT
        Write("testing indirect proxies to collocated objects... ");
        Flush();

        //
        // Set up test for calling a collocated object through an
        // indirect, adapterless reference.
        //
        Ice.Properties properties = communicator.getProperties();
        properties.setProperty("Ice.PrintAdapterReady", "0");
        Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("Hello", "default");
        adapter.setLocator(locator);

        Ice.Identity id = new Ice.Identity();
        id.name = Guid.NewGuid().ToString();
        registry.addObject(adapter.add(new HelloI(), id));
        adapter.activate();

        HelloPrx helloPrx = HelloPrxHelper.checkedCast(
            communicator.stringToProxy("\"" + communicator.identityToString(id) + "\""));
        test(helloPrx.ice_getConnection() == null);

        adapter.deactivate();
        WriteLine("ok");

        Write("shutdown server manager... ");
        Flush();
        manager.shutdown();
        WriteLine("ok");
#else
        manager.shutdown();
#endif
    }
Example #34
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: " +
                                      communicator().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 #35
0
        public override bool Sent() => base.SentImpl(!Proxy.IsTwoway); // done = true if it's not a two-way proxy

        public override bool Response()
        {
            Debug.Assert(Is != null);
            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //
            Debug.Assert(Proxy.IsTwoway); // Can only be called for twoways.

            if (ChildObserver != null)
            {
                ChildObserver.Reply(Is.Size - Protocol.headerSize - 4);
                ChildObserver.Detach();
                ChildObserver = null;
            }

            byte replyStatus;

            try
            {
                replyStatus = Is.ReadByte();

                switch (replyStatus)
                {
                case ReplyStatus.replyOK:
                    {
                        break;
                    }

                case ReplyStatus.replyUserException:
                {
                    if (Observer != null)
                    {
                        Observer.UserException();
                    }
                    break;
                }

                case ReplyStatus.replyObjectNotExist:
                case ReplyStatus.replyFacetNotExist:
                case ReplyStatus.replyOperationNotExist:
                {
                    var ident = new Ice.Identity(Is);

                    //
                    // For compatibility with the old FacetPath.
                    //
                    string[] facetPath = Is.ReadStringArray();
                    string   facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.MarshalException();
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = Is.ReadString();

                    Ice.RequestFailedException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyObjectNotExist:
                    {
                        ex = new Ice.ObjectNotExistException();
                        break;
                    }

                    case ReplyStatus.replyFacetNotExist:
                    {
                        ex = new Ice.FacetNotExistException();
                        break;
                    }

                    case ReplyStatus.replyOperationNotExist:
                    {
                        ex = new Ice.OperationNotExistException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Id        = ident;
                    ex.Facet     = facet;
                    ex.Operation = operation;
                    throw ex;
                }

                case ReplyStatus.replyUnknownException:
                case ReplyStatus.replyUnknownLocalException:
                case ReplyStatus.replyUnknownUserException:
                {
                    string unknown = Is.ReadString();

                    Ice.UnknownException ex;
                    switch (replyStatus)
                    {
                    case ReplyStatus.replyUnknownException:
                    {
                        ex = new Ice.UnknownException();
                        break;
                    }

                    case ReplyStatus.replyUnknownLocalException:
                    {
                        ex = new Ice.UnknownLocalException();
                        break;
                    }

                    case ReplyStatus.replyUnknownUserException:
                    {
                        ex = new Ice.UnknownUserException();
                        break;
                    }

                    default:
                    {
                        Debug.Assert(false);
                        throw new System.InvalidOperationException();
                    }
                    }

                    ex.Unknown = unknown;
                    throw ex;
                }

                default:
                {
                    throw new Ice.UnknownReplyStatusException();
                }
                }

                return(ResponseImpl(false, replyStatus == ReplyStatus.replyOK, true));
            }
            catch (Ice.Exception ex)
            {
                return(Exception(ex));
            }
        }
Example #36
0
 private static void checkIdentity(Identity ident)
 {
     if(ident.name == null || ident.name.Length == 0)
     {
         throw new IllegalIdentityException(ident);
     }
     if(ident.category == null)
     {
         ident.category = "";
     }
 }
Example #37
0
 /// <summary>
 /// Converts an object identity to a string.
 /// </summary>
 /// <param name="ident">The object identity to convert.</param>
 /// <returns>The string representation of the object identity.</returns>
 public static string identityToString(Identity ident)
 {
     if(ident.category == null || ident.category.Length == 0)
     {
         return IceUtilInternal.StringUtil.escapeString(ident.name, "/");
     }
     else
     {
         return IceUtilInternal.StringUtil.escapeString(ident.category, "/") + '/' +
             IceUtilInternal.StringUtil.escapeString(ident.name, "/");
     }
 }
Example #38
0
    public static void allTests(Test.TestHelper helper)
    {
        Ice.Communicator communicator = helper.communicator();
        Console.Out.Write("testing stringToProxy... ");
        Console.Out.Flush();
        string rf    = "test @ TestAdapter";
        var    @base = IObjectPrx.Parse(rf, communicator);

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing IceGrid.Locator is present... ");
        IceGrid.ILocatorPrx locator = IceGrid.ILocatorPrx.UncheckedCast(@base);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing checked cast... ");
        Console.Out.Flush();
        ITestIntfPrx obj = ITestIntfPrx.CheckedCast(@base);

        test(obj.Equals(@base));
        Console.Out.WriteLine("ok");

        Console.Out.Write("pinging server... ");
        Console.Out.Flush();
        obj.IcePing();
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing locator finder... ");
        Ice.Identity finderId = new Ice.Identity();
        finderId.category = "Ice";
        finderId.name     = "LocatorFinder";
        Ice.ILocatorFinderPrx finder = Ice.ILocatorFinderPrx.CheckedCast(communicator.getDefaultLocator().Clone(finderId));
        test(finder.GetLocator() != null);
        Console.Out.WriteLine("ok");

        Console.Out.Write("testing discovery... ");
        {
            // Add test well-known object
            IceGrid.IRegistryPrx registry = IceGrid.IRegistryPrx.Parse(
                communicator.getDefaultLocator().Identity.category + "/Registry", communicator);

            IceGrid.IAdminSessionPrx session = registry.CreateAdminSession("foo", "bar");
            session.GetAdmin().AddObjectWithType(@base, "::Test");
            session.Destroy();

            //
            // Ensure the IceGrid discovery locator can discover the
            // registries and make sure locator requests are forwarded.
            //
            var properties = communicator.GetProperties();
            properties.Remove("Ice.Default.Locator");
            properties["Ice.Plugin.IceLocatorDiscovery"]    = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            properties["IceLocatorDiscovery.Port"]          = helper.getTestPort(99).ToString();
            properties["AdapterForDiscoveryTest.AdapterId"] = "discoveryAdapter";
            properties["AdapterForDiscoveryTest.Endpoints"] = "default";

            Communicator com = new Communicator(properties);
            test(com.getDefaultLocator() != null);
            IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            IObjectPrx.Parse("test", com).IcePing();

            test(com.getDefaultLocator().GetRegistry() != null);
            test(IceGrid.ILocatorPrx.UncheckedCast(com.getDefaultLocator()).GetLocalRegistry() != null);
            test(IceGrid.ILocatorPrx.UncheckedCast(com.getDefaultLocator()).GetLocalQuery() != null);

            Ice.ObjectAdapter adapter = com.createObjectAdapter("AdapterForDiscoveryTest");
            adapter.Activate();
            adapter.Deactivate();
            com.destroy();

            //
            // Now, ensure that the IceGrid discovery locator correctly
            // handles failure to find a locator.
            //
            properties["IceLocatorDiscovery.InstanceName"] = "unknown";
            properties["IceLocatorDiscovery.RetryCount"]   = "1";
            properties["IceLocatorDiscovery.Timeout"]      = "100";
            com = new Communicator(properties);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            }
            catch (Ice.NoEndpointException)
            {
            }
            try
            {
                IObjectPrx.Parse("test", com).IcePing();
            }
            catch (Ice.NoEndpointException)
            {
            }
            test(com.getDefaultLocator().GetRegistry() == null);
            test(IceGrid.ILocatorPrx.CheckedCast(com.getDefaultLocator()) == null);
            try
            {
                IceGrid.ILocatorPrx.UncheckedCast(com.getDefaultLocator()).GetLocalRegistry();
            }
            catch (Ice.OperationNotExistException)
            {
            }

            adapter = com.createObjectAdapter("AdapterForDiscoveryTest");
            adapter.Activate();
            adapter.Deactivate();

            com.destroy();

            string multicast;
            if (communicator.GetProperty("Ice.IPv6") == "1")
            {
                multicast = "\"ff15::1\"";
            }
            else
            {
                multicast = "239.255.0.1";
            }

            //
            // Test invalid lookup endpoints
            //
            properties = communicator.GetProperties();
            properties.Remove("Ice.Default.Locator");
            properties["Ice.Plugin.IceLocatorDiscovery"] = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            properties["IceLocatorDiscovery.Lookup"]     = $"udp -h {multicast} --interface unknown";
            com = new Communicator(properties);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
            com.destroy();

            properties = communicator.GetProperties();
            properties.Remove("Ice.Default.Locator");
            properties["IceLocatorDiscovery.RetryCount"] = "0";
            properties["Ice.Plugin.IceLocatorDiscovery"] = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            properties["IceLocatorDiscovery.Lookup"]     = $"udp -h {multicast} --interface unknown";
            com = new Communicator(properties);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
                test(false);
            }
            catch (NoEndpointException)
            {
            }
            com.destroy();

            properties = communicator.GetProperties();
            properties.Remove("Ice.Default.Locator");
            properties["IceLocatorDiscovery.RetryCount"] = "1";
            properties["Ice.Plugin.IceLocatorDiscovery"] = "IceLocatorDiscovery:IceLocatorDiscovery.PluginFactory";
            {
                string intf = communicator.GetProperty("IceLocatorDiscovery.Interface") ?? "";
                if (intf != "")
                {
                    intf = $" --interface \"{intf}\"";
                }
                string port = helper.getTestPort(99).ToString();
                properties["IceLocatorDiscovery.Lookup"] =
                    $"udp -h {multicast} --interface unknown:udp -h {multicast} -p {port}{intf}";
            }
            com = new Communicator(properties);
            test(com.getDefaultLocator() != null);
            try
            {
                IObjectPrx.Parse("test @ TestAdapter", com).IcePing();
            }
            catch (NoEndpointException)
            {
                test(false);
            }
            com.destroy();
        }
        Console.Out.WriteLine("ok");

        Console.Out.Write("shutting down server... ");
        Console.Out.Flush();
        obj.shutdown();
        Console.Out.WriteLine("ok");
    }
Example #39
0
 FindObjectByIdAsync(Ice.Identity id, Current current)
 {
     return(null);
 }
Example #40
0
 FindObjectByIdAsync(Ice.Identity id, Current current) => null;
Example #41
0
        private ObjectPrx newDirectProxy(Identity ident, string facet)
        {
            EndpointI[] endpoints;

            //
            // Use the published endpoints, otherwise use the endpoints from all
            // incoming connection factories.
            //
            int sz = _publishedEndpoints.Count;
            endpoints = new EndpointI[sz + _routerEndpoints.Count];
            for(int i = 0; i < sz; ++i)
            {
                endpoints[i] = _publishedEndpoints[i];
            }

            //
            // Now we also add the endpoints of the router's server proxy, if
            // any. This way, object references created by this object adapter
            // will also point to the router's server proxy endpoints.
            //
            for(int i = 0; i < _routerEndpoints.Count; ++i)
            {
                endpoints[sz + i] = _routerEndpoints[i];
            }

            //
            // Create a reference and return a proxy for this reference.
            //
            Reference reference = instance_.referenceFactory().create(ident, facet, _reference, endpoints);
            return instance_.proxyFactory().referenceToProxy(reference);
        }
Example #42
0
    allTests(TestCommon.Application app)
    {
        Ice.Communicator  communicator = app.communicator();
        Ice.ObjectAdapter oa           = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");
        oa.activate();

        Ice.Object servant = new MyObjectI();

        //
        // Register default servant with category "foo"
        //
        oa.addDefaultServant(servant, "foo");

        //
        // Start test
        //
        Console.Out.Write("testing single category... ");
        Console.Out.Flush();

        Ice.Object r = oa.findDefaultServant("foo");
        test(r == servant);

        r = oa.findDefaultServant("bar");
        test(r == null);

        Ice.Identity identity = new Ice.Identity();
        identity.category = "foo";

        string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" };

        Test.MyObjectPrx prx = null;
        for (int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        identity.name = "ObjectNotExist";
        prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        identity.name = "FacetNotExist";
        prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch (Ice.FacetNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch (Ice.FacetNotExistException)
        {
            // Expected
        }

        identity.category = "bar";
        for (int idx = 0; idx < 5; idx++)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));

            try
            {
                prx.ice_ping();
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                // Expected
            }

            try
            {
                prx.getName();
                test(false);
            }
            catch (Ice.ObjectNotExistException)
            {
                // Expected
            }
        }

        oa.removeDefaultServant("foo");
        identity.category = "foo";
        prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
        }
        catch (Ice.ObjectNotExistException)
        {
            // Expected
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing default category... ");
        Console.Out.Flush();

        oa.addDefaultServant(servant, "");

        r = oa.findDefaultServant("bar");
        test(r == null);

        r = oa.findDefaultServant("");
        test(r == servant);

        for (int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx           = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        Console.Out.WriteLine("ok");
    }
Example #43
0
 private ObjectPrx newProxy(Identity ident, string facet)
 {
     if(_id.Length == 0)
     {
         return newDirectProxy(ident, facet);
     }
     else if(_replicaGroupId.Length == 0)
     {
         return newIndirectProxy(ident, facet, _id);
     }
     else
     {
         return newIndirectProxy(ident, facet, _replicaGroupId);
     }
 }
Example #44
0
        public void activate()
        {
            LocatorInfo locatorInfo       = null;
            bool        printAdapterReady = false;

            lock (this)
            {
                checkForDeactivation();

                //
                // If we've previously been initialized we just need to activate the
                // incoming connection factories and we're done.
                //
                if (_state != StateUninitialized)
                {
                    foreach (IncomingConnectionFactory icf in _incomingConnectionFactories)
                    {
                        icf.activate();
                    }
                    return;
                }

                //
                // One off initializations of the adapter: update the
                // locator registry and print the "adapter ready"
                // message. We set set state to StateActivating to prevent
                // deactivation from other threads while these one off
                // initializations are done.
                //
                _state = StateActivating;

                locatorInfo = _locatorInfo;
                if (!_noConfig)
                {
                    Properties properties = _instance.initializationData().properties;
                    printAdapterReady = properties.getPropertyAsInt("Ice.PrintAdapterReady") > 0;
                }
            }

            try
            {
                Identity dummy = new Identity();
                dummy.name = "dummy";
                updateLocatorRegistry(locatorInfo, createDirectProxy(dummy));
            }
            catch (LocalException)
            {
                //
                // If we couldn't update the locator registry, we let the
                // exception go through and don't activate the adapter to
                // allow to user code to retry activating the adapter
                // later.
                //
                lock (this)
                {
                    _state = StateUninitialized;
                    System.Threading.Monitor.PulseAll(this);
                }
                throw;
            }

            if (printAdapterReady)
            {
                Console.Out.WriteLine(_name + " ready");
            }

            lock (this)
            {
                Debug.Assert(_state == StateActivating);

                foreach (IncomingConnectionFactory icf in _incomingConnectionFactories)
                {
                    icf.activate();
                }

                _state = StateActive;
                System.Threading.Monitor.PulseAll(this);
            }
        }
Example #45
0
        public ObjectPrx addFacet(Ice.Object obj, Identity ident, string facet)
        {
            lock(this)
            {
                checkForDeactivation();
                checkIdentity(ident);
                checkServant(obj);

                //
                // Create a copy of the Identity argument, in case the caller
                // reuses it.
                //
                Identity id = new Identity();
                id.category = ident.category;
                id.name = ident.name;

                _servantManager.addServant(obj, id, facet);

                return newProxy(id, facet);
            }
        }
Example #46
0
 public ObjectPrx add(Object obj, Identity ident)
 {
     return(addFacet(obj, ident, ""));
 }
Example #47
0
        public ObjectPrx createProxy(Identity ident)
        {
            lock(this)
            {
                checkForDeactivation();
                checkIdentity(ident);

                return newProxy(ident, "");
            }
        }
Example #48
0
 public Object find(Identity ident)
 {
     return(findFacet(ident, ""));
 }
Example #49
0
 public Ice.Object remove(Identity ident)
 {
     return removeFacet(ident, "");
 }
Example #50
0
    allTests(Ice.Communicator communicator)
    {
        Ice.ObjectAdapter oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");
        oa.activate();

        Ice.Object servant = new MyObjectI();

        //
        // Register default servant with category "foo"
        //
        oa.addDefaultServant(servant, "foo");

        //
        // Start test
        //
        Console.Out.Write("testing single category... ");
        Console.Out.Flush();

        Ice.Object r = oa.findDefaultServant("foo");
        test(r == servant);

        r = oa.findDefaultServant("bar");
        test(r == null);

        Ice.Identity identity = new Ice.Identity();
        identity.category = "foo";

        string[] names = new string[] { "foo", "bar", "x", "y", "abcdefg" };

        Test.MyObjectPrx prx = null;
        for(int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        identity.name = "ObjectNotExist";
        prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch(Ice.ObjectNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch(Ice.ObjectNotExistException)
        {
            // Expected
        }

        identity.name = "FacetNotExist";
        prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
            test(false);
        }
        catch(Ice.FacetNotExistException)
        {
            // Expected
        }

        try
        {
            prx.getName();
            test(false);
        }
        catch(Ice.FacetNotExistException)
        {
            // Expected
        }

        identity.category = "bar";
        for(int idx = 0; idx < 5; idx++)
        {
            identity.name = names[idx];
            prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));

            try
            {
                prx.ice_ping();
                test(false);
            }
            catch(Ice.ObjectNotExistException)
            {
                // Expected
            }

            try
            {
                prx.getName();
                test(false);
            }
            catch(Ice.ObjectNotExistException)
            {
                // Expected
            }
        }

        oa.removeDefaultServant("foo");
        identity.category = "foo";
        prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
        try
        {
            prx.ice_ping();
        }
        catch(Ice.ObjectNotExistException)
        {
            // Expected
        }

        Console.Out.WriteLine("ok");

        Console.Out.Write("testing default category... ");
        Console.Out.Flush();

        oa.addDefaultServant(servant, "");

        r = oa.findDefaultServant("bar");
        test(r == null);

        r = oa.findDefaultServant("");
        test(r == servant);

        for(int idx = 0; idx < 5; ++idx)
        {
            identity.name = names[idx];
            prx = Test.MyObjectPrxHelper.uncheckedCast(oa.createProxy(identity));
            prx.ice_ping();
            test(prx.getName() == names[idx]);
        }

        Console.Out.WriteLine("ok");
    }
Example #51
0
        public Ice.Object removeFacet(Identity ident, string facet)
        {
            lock(this)
            {
                checkForDeactivation();
                checkIdentity(ident);

                return _servantManager.removeServant(ident, facet);
            }
        }
Example #52
0
        /// <summary>
        /// Converts a string to an object identity.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns>The converted object identity.</returns>
        public static Identity stringToIdentity(string s)
        {
            Identity ident = new Identity();

            //
            // Find unescaped separator; note that the string may contain an escaped
            // backslash before the separator.
            //
            int slash = -1, pos = 0;
            while((pos = s.IndexOf((System.Char) '/', pos)) != -1)
            {
                int escapes = 0;
                while(pos - escapes > 0 && s[pos - escapes - 1] == '\\')
                {
                    escapes++;
                }

                //
                // We ignore escaped escapes
                //
                if(escapes % 2 == 0)
                {
                    if(slash == -1)
                    {
                        slash = pos;
                    }
                    else
                    {
                        //
                        // Extra unescaped slash found.
                        //
                        IdentityParseException ex = new IdentityParseException();
                        ex.str = "unescaped backslash in identity `" + s + "'";
                        throw ex;
                    }
                }
                pos++;
            }

            if(slash == -1)
            {
                ident.category = "";
                try
                {
                    ident.name = IceUtilInternal.StringUtil.unescapeString(s, 0, s.Length);
                }
                catch(System.ArgumentException e)
                {
                    IdentityParseException ex = new IdentityParseException();
                    ex.str = "invalid identity name `" + s + "': " + e.Message;
                    throw ex;
                }
            }
            else
            {
                try
                {
                    ident.category = IceUtilInternal.StringUtil.unescapeString(s, 0, slash);
                }
                catch(System.ArgumentException e)
                {
                    IdentityParseException ex = new IdentityParseException();
                    ex.str = "invalid category in identity `" + s + "': " + e.Message;
                    throw ex;
                }
                if(slash + 1 < s.Length)
                {
                    try
                    {
                        ident.name = IceUtilInternal.StringUtil.unescapeString(s, slash + 1, s.Length);
                    }
                    catch(System.ArgumentException e)
                    {
                        IdentityParseException ex = new IdentityParseException();
                        ex.str = "invalid name in identity `" + s + "': " + e.Message;
                        throw ex;
                    }
                }
                else
                {
                    ident.name = "";
                }
            }

            return ident;
        }
Example #53
0
 public Ice.ObjectPrx createAdmin(ObjectAdapter adminAdapter, Identity adminIdentity)
 {
     return(instance_.createAdmin(adminAdapter, adminIdentity));
 }
Example #54
0
        public override bool Sent() => base.SentImpl(IsOneway); // done = true

        public override bool Response()
        {
            Debug.Assert(Is != null);
            //
            // NOTE: this method is called from ConnectionI.parseMessage
            // with the connection locked. Therefore, it must not invoke
            // any user callbacks.
            //
            Debug.Assert(!IsOneway); // Can only be called for twoways.

            if (ChildObserver != null)
            {
                ChildObserver.Reply(Is.Size - Ice1Definitions.HeaderSize - 4);
                ChildObserver.Detach();
                ChildObserver = null;
            }

            ReplyStatus replyStatus;

            try
            {
                replyStatus = (ReplyStatus)Is.ReadByte();

                switch (replyStatus)
                {
                case ReplyStatus.OK:
                {
                    break;
                }

                case ReplyStatus.UserException:
                {
                    if (Observer != null)
                    {
                        Observer.RemoteException();
                    }
                    break;
                }

                case ReplyStatus.ObjectNotExistException:
                case ReplyStatus.FacetNotExistException:
                case ReplyStatus.OperationNotExistException:
                {
                    var identity = new Ice.Identity(Is);

                    // For compatibility with the old FacetPath.
                    string[] facetPath = Is.ReadStringArray();
                    string   facet;
                    if (facetPath.Length > 0)
                    {
                        if (facetPath.Length > 1)
                        {
                            throw new Ice.InvalidDataException(
                                      $"invalid facet path length: {facetPath.Length}");
                        }
                        facet = facetPath[0];
                    }
                    else
                    {
                        facet = "";
                    }

                    string operation = Is.ReadString();

                    if (replyStatus == ReplyStatus.OperationNotExistException)
                    {
                        throw new Ice.OperationNotExistException(identity, facet, operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(identity, facet, operation);
                    }
                }

                case ReplyStatus.UnknownException:
                case ReplyStatus.UnknownLocalException:
                case ReplyStatus.UnknownUserException:
                {
                    throw new UnhandledException(Is.ReadString(), Ice.Identity.Empty, "", "");
                }

                default:
                {
                    throw new InvalidDataException(
                              $"received ice1 response frame with unknown reply status `{replyStatus}'");
                }
                }

                return(ResponseImpl(false, replyStatus == ReplyStatus.OK, true));
            }
            catch (System.Exception ex)
            {
                return(Exception(ex));
            }
        }
Example #55
0
 findObjectByIdAsync(Ice.Identity id, Ice.Current current)
 {
     return(_lookup.findObject(id));
 }
Example #56
0
File: Util.cs Project: zmyer/ice
        /// <summary>
        /// Converts a string to an object identity.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns>The converted object identity.</returns>
        public static Identity stringToIdentity(string s)
        {
            Identity ident = new Identity();

            //
            // Find unescaped separator; note that the string may contain an escaped
            // backslash before the separator.
            //
            int slash = -1, pos = 0;

            while ((pos = s.IndexOf((System.Char) '/', pos)) != -1)
            {
                int escapes = 0;
                while (pos - escapes > 0 && s[pos - escapes - 1] == '\\')
                {
                    escapes++;
                }

                //
                // We ignore escaped escapes
                //
                if (escapes % 2 == 0)
                {
                    if (slash == -1)
                    {
                        slash = pos;
                    }
                    else
                    {
                        //
                        // Extra unescaped slash found.
                        //
                        IdentityParseException ex = new IdentityParseException();
                        ex.str = "unescaped backslash in identity `" + s + "'";
                        throw ex;
                    }
                }
                pos++;
            }

            if (slash == -1)
            {
                ident.category = "";
                try
                {
                    ident.name = IceUtilInternal.StringUtil.unescapeString(s, 0, s.Length, "/");
                }
                catch (ArgumentException e)
                {
                    IdentityParseException ex = new IdentityParseException();
                    ex.str = "invalid identity name `" + s + "': " + e.Message;
                    throw ex;
                }
            }
            else
            {
                try
                {
                    ident.category = IceUtilInternal.StringUtil.unescapeString(s, 0, slash, "/");
                }
                catch (ArgumentException e)
                {
                    IdentityParseException ex = new IdentityParseException();
                    ex.str = "invalid category in identity `" + s + "': " + e.Message;
                    throw ex;
                }
                if (slash + 1 < s.Length)
                {
                    try
                    {
                        ident.name = IceUtilInternal.StringUtil.unescapeString(s, slash + 1, s.Length, "/");
                    }
                    catch (ArgumentException e)
                    {
                        IdentityParseException ex = new IdentityParseException();
                        ex.str = "invalid name in identity `" + s + "': " + e.Message;
                        throw ex;
                    }
                }
                else
                {
                    ident.name = "";
                }
            }

            return(ident);
        }
Example #57
0
File: Client.cs Project: motuii/ice
    public override void run(string[] args)
    {
        Ice.Properties properties = createTestProperties(ref args);
        //
        // We must disable connection warnings, because we attempt to
        // ping the router before session establishment, as well as
        // after session destruction. Both will cause a
        // ConnectionLostException.
        //
        properties.setProperty("Ice.Warn.Connections", "0");
        using (var communicator = initialize(properties))
        {
            IObjectPrx routerBase;
            {
                Console.Out.Write("testing stringToProxy for router... ");
                Console.Out.Flush();
                routerBase = IObjectPrx.Parse($"Glacier2/router:{getTestEndpoint(50)}", communicator);
                Console.Out.WriteLine("ok");
            }

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

            {
                Console.Out.Write("testing router finder... ");
                Console.Out.Flush();
                RouterFinderPrx finder = RouterFinderPrx.Parse($"Ice/RouterFinder:{getTestEndpoint(50)}", communicator);
                test(finder.getRouter().Identity.Equals(router.Identity));
                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");
            }

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

            {
                Console.Out.Write("trying to ping server before session creation... ");
                Console.Out.Flush();
                try
                {
                    @base.IcePing();
                    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.IcePing();
                Console.Out.WriteLine("ok");
            }

            {
                Console.Out.Write("pinging object with client endpoint... ");
                IObjectPrx baseC = IObjectPrx.Parse($"collocated:{getTestEndpoint(50)}", communicator);
                try
                {
                    baseC.IcePing();
                }
                catch (Ice.ObjectNotExistException)
                {
                }
                Console.Out.WriteLine("ok");
            }

            CallbackPrx twoway;

            {
                Console.Out.Write("testing checked cast for server object... ");
                Console.Out.Flush();
                twoway = CallbackPrx.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;
            CallbackReceiver    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 = adapter.Add(callbackReceiver, callbackReceiverIdent);
                Ice.Identity fakeCallbackReceiverIdent = new Ice.Identity();
                fakeCallbackReceiverIdent.name     = "callbackReceiver";
                fakeCallbackReceiverIdent.category = "dummy";
                fakeTwowayR = adapter.Add(callbackReceiver, fakeCallbackReceiverIdent);
                Console.Out.WriteLine("ok");
            }

            {
                Console.Out.Write("testing oneway callback... ");
                Console.Out.Flush();
                CallbackPrx                 oneway  = twoway.Clone(oneway: true);
                CallbackReceiverPrx         onewayR = twowayR.Clone(oneway: true);
                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 =
                    CallbackPrx.UncheckedCast(twoway.Clone(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 =
                        CallbackPrx.UncheckedCast(twoway.Clone(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 =
                    CallbackPrx.UncheckedCast(twoway.Clone(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.IcePing();
                 * 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.IcePing();
                    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");
                }

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

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

                ProcessPrx process;
                {
                    Console.Out.Write("testing checked cast for process object... ");
                    process = ProcessPrx.CheckedCast(processBase);
                    process.IcePing();
                    Console.Out.WriteLine("ok");
                }

                Console.Out.Write("testing Glacier2 shutdown... ");
                process.shutdown();
                try
                {
                    process.IcePing();
                    test(false);
                }
                catch (LocalException)
                {
                    Console.Out.WriteLine("ok");
                }
            }
        }
    }
Example #58
0
 public Object remove(Identity ident)
 {
     return(removeFacet(ident, ""));
 }
Example #59
0
        public override int run(string[] args)
        {
            args = communicator().getProperties().parseCommandLineOptions("Clock", args);

            string topicName = "time";
            string option = "None";
            bool batch = false;
            string id = null;
            string retryCount = null;
            int i;
            for(i = 0; i < args.Length; ++i)
            {
                String oldoption = option;
                if(args[i].Equals("--datagram"))
                {
                    option = "Datagram";
                }
                else if(args[i].Equals("--twoway"))
                {
                    option = "Twoway";
                }
                else if(args[i].Equals("--ordered"))
                {
                    option = "Ordered";
                }
                else if(args[i].Equals("--oneway"))
                {
                    option = "Oneway";
                }
                else if(args[i].Equals("--batch"))
                {
                    batch = true;
                }
                else if(args[i].Equals("--id"))
                {
                    ++i;
                    if(i >= args.Length)
                    {
                        usage();
                        return 1;
                    }
                    id = args[i];
                }
                else if(args[i].Equals("--retryCount"))
                {
                    ++i;
                    if(i >= args.Length)
                    {
                        usage();
                        return 1;
                    }
                    retryCount = args[i];
                }
                else if(args[i].StartsWith("--"))
                {
                    usage();
                    return 1;
                }
                else
                {
                    topicName = args[i++];
                    break;
                }

                if(!oldoption.Equals(option) && !oldoption.Equals("None"))
                {
                    usage();
                    return 1;
                }
            }

            if(i != args.Length)
            {
                usage();
                return 1;
            }

            if(retryCount != null)
            {
                if(option.Equals("None"))
                {
                    option = "Twoway";
                }
                else if(!option.Equals("Twoway") && !option.Equals("Ordered"))
                {
                    usage();
                    return 1;
                }
            }

            if(batch && (option.Equals("Twoway") || option.Equals("Ordered")))
            {
                Console.WriteLine(appName() + ": batch can only be set with oneway or datagram");
                return 1;
            }

            IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(
                communicator().propertyToProxy("TopicManager.Proxy"));
            if(manager == null)
            {
                Console.WriteLine("invalid proxy");
                return 1;
            }

            //
            // Retrieve the topic.
            //
            IceStorm.TopicPrx topic;
            try
            {
                topic = manager.retrieve(topicName);
            }
            catch(IceStorm.NoSuchTopic)
            {
                try
                {
                    topic = manager.create(topicName);
                }
                catch(IceStorm.TopicExists)
                {
                    Console.WriteLine("temporary error. try again.");
                    return 1;
                }
            }

            Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Clock.Subscriber");
            //
            // Add a servant for the Ice object. If --id is used the
            // identity comes from the command line, otherwise a UUID is
            // used.
            //
            // id is not directly altered since it is used below to
            // detect whether subscribeAndGetPublisher can raise
            // AlreadySubscribed.
            //
            Ice.Identity subId = new Ice.Identity(id, "");
            if(subId.name == null)
            {
                subId.name = Guid.NewGuid().ToString();
            }
            Ice.ObjectPrx subscriber = adapter.add(new ClockI(), subId);

            //
            // Activate the object adapter before subscribing.
            //
            adapter.activate();

            Dictionary<string, string> qos = new Dictionary<string, string>();
            if(retryCount != null)
            {
                qos["retryCount"] = retryCount;
            }
            //
            // Set up the proxy.
            //
            if(option.Equals("Datagram"))
            {
                if(batch)
                {
                    subscriber = subscriber.ice_batchDatagram();
                }
                else
                {
                    subscriber = subscriber.ice_datagram();
                }
            }
            else if(option.Equals("Twoway"))
            {
                // Do nothing to the subscriber proxy. Its already twoway.
            }
            else if(option.Equals("Ordered"))
            {
                // Do nothing to the subscriber proxy. Its already twoway.
                qos["reliability"] = "ordered";
            }
            else if(option.Equals("Oneway") || option.Equals("None"))
            {
                if(batch)
                {
                    subscriber = subscriber.ice_batchOneway();
                }
                else
                {
                    subscriber = subscriber.ice_oneway();
                }
            }

            try
            {
                topic.subscribeAndGetPublisher(qos, subscriber);
            }
            catch(IceStorm.AlreadySubscribed)
            {
                // If we're manually setting the subscriber id ignore.
                if(id == null)
                {
                    throw;
                }
                System.Console.Out.WriteLine("reactivating persistent subscriber");
            }

            shutdownOnInterrupt();
            communicator().waitForShutdown();

            topic.unsubscribe(subscriber);

            return 0;
        }
Example #60
0
    internal static void batchOneways(Test.MyClassPrx p)
    {
        byte[] bs1 = new byte[10 * 1024];

        Test.MyClassPrx batch = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());
        batch.ice_flushBatchRequests(); // Empty flush

        p.opByteSOnewayCallCount();     // Reset the call count

        for (int i = 0; i < 30; ++i)
        {
            try
            {
                batch.opByteSOneway(bs1);
                test(true);
            }
            catch (Ice.MemoryLimitException)
            {
                test(false);
            }
        }

        int count = 0;

        while (count < 27) // 3 * 9 requests auto-flushed.
        {
            count += p.opByteSOnewayCallCount();
            System.Threading.Thread.Sleep(10);
        }

        if (batch.ice_getConnection() != null)
        {
            Test.MyClassPrx batch1 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());
            Test.MyClassPrx batch2 = Test.MyClassPrxHelper.uncheckedCast(p.ice_batchOneway());

            batch1.ice_ping();
            batch2.ice_ping();
            batch1.ice_flushBatchRequests();
            batch1.ice_getConnection().close(false);
            batch1.ice_ping();
            batch2.ice_ping();

            batch1.ice_getConnection();
            batch2.ice_getConnection();

            batch1.ice_ping();
            batch1.ice_getConnection().close(false);
            batch1.ice_ping();
            batch2.ice_ping();
        }

        Ice.Identity identity = new Ice.Identity();
        identity.name = "invalid";
        Ice.ObjectPrx batch3 = batch.ice_identity(identity);
        batch3.ice_ping();
        batch3.ice_flushBatchRequests();

        // Make sure that a bogus batch request doesn't cause troubles to other ones.
        batch3.ice_ping();
        batch.ice_ping();
        batch.ice_flushBatchRequests();
        batch.ice_ping();

        if (batch.ice_getConnection() != null)
        {
            Ice.InitializationData initData = new Ice.InitializationData();
            initData.properties = p.ice_getCommunicator().getProperties().ice_clone_();
            BatchRequestInterceptorI interceptor = new BatchRequestInterceptorI();
            initData.batchRequestInterceptor = interceptor;
            Ice.Communicator ic = Ice.Util.initialize(initData);

            batch = Test.MyClassPrxHelper.uncheckedCast(ic.stringToProxy(p.ToString()).ice_batchOneway());

            test(interceptor.count() == 0);
            batch.ice_ping();
            batch.ice_ping();
            batch.ice_ping();
            test(interceptor.count() == 0);

            interceptor.setEnqueue(true);
            batch.ice_ping();
            batch.ice_ping();
            batch.ice_ping();
            test(interceptor.count() == 3);

            batch.ice_flushBatchRequests();
            batch.ice_ping();
            test(interceptor.count() == 1);

            batch.opByteSOneway(bs1);
            test(interceptor.count() == 2);
            batch.opByteSOneway(bs1);
            test(interceptor.count() == 3);

            batch.opByteSOneway(bs1); // This should trigger the flush
            batch.ice_ping();
            test(interceptor.count() == 2);

            ic.destroy();
        }
    }