コード例 #1
0
 public void FoundObjectById(Identity id, IObjectPrx?proxy, Current current) =>
 CompletionSource.SetResult(proxy);
コード例 #2
0
        public static void allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            TextWriter output = helper.GetWriter();

            output.Write("testing communicator operations... ");
            output.Flush();
            {
                // Test: Exercise AddAdminFacet, FindAdminFacet, RemoveAdminFacet with a typical configuration.
                var properties = new Dictionary <string, string>
                {
                    ["Ice.Admin.Endpoints"]    = "tcp -h 127.0.0.1",
                    ["Ice.Admin.InstanceName"] = "Test"
                };
                using var com = new Communicator(properties);
                TestFacets(com, true, false);
            }
            {
                // Test: Verify that the operations work correctly in the presence of facet filters.
                var properties = new Dictionary <string, string>
                {
                    ["Ice.Admin.Endpoints"]    = "tcp -h 127.0.0.1",
                    ["Ice.Admin.InstanceName"] = "Test",
                    ["Ice.Admin.Facets"]       = "Properties"
                };
                using var com = new Communicator(properties);
                TestFacets(com, false, true);
            }
            {
                // Test: Verify that the operations work correctly with the Admin object disabled.
                using var com = new Communicator();
                TestFacets(com, false, false);
            }
            {
                // Test: Verify that the operations work correctly with Ice.Admin.Enabled=1
                var properties = new Dictionary <string, string>()
                {
                    { "Ice.Admin.Enabled", "1" }
                };
                using var com = new Communicator(properties);
                TestHelper.Assert(com.GetAdmin() == null);
                var id = Identity.Parse("test-admin");
                try
                {
                    com.CreateAdmin(null, id);
                    TestHelper.Assert(false);
                }
                catch (InvalidConfigurationException)
                {
                }

                ObjectAdapter adapter = com.CreateObjectAdapter();
                TestHelper.Assert(com.CreateAdmin(adapter, id) != null);
                TestHelper.Assert(com.GetAdmin() != null);

                TestFacets(com, true, false);
            }
            {
                //
                // Test: Verify that the operations work correctly when creation of the Admin object is delayed.
                //
                var properties = new Dictionary <string, string>()
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.DelayCreation", "1" }
                };

                using var com = new Communicator(properties);
                TestFacets(com, true, false);
                com.GetAdmin();
                TestFacets(com, true, false);
            }
            output.WriteLine("ok");

            var factory = IRemoteCommunicatorFactoryPrx.Parse($"factory:{helper.GetTestEndpoint(0)} -t 10000",
                                                              communicator);

            output.Write("testing process facet... ");
            output.Flush();
            {
                //
                // Test: Verify that Process::shutdown() operation shuts down the communicator.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IProcessPrx proc = obj.Clone("Process", IProcessPrx.Factory);
                proc.Shutdown();
                com.waitForShutdown();
                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing properties facet... ");
            output.Flush();
            {
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Prop1", "1" },
                    { "Prop2", "2" },
                    { "Prop3", "3" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IPropertiesAdminPrx pa = obj.Clone("Properties", IPropertiesAdminPrx.Factory);

                //
                // Test: PropertiesAdmin::getProperty()
                //
                TestHelper.Assert(pa.GetProperty("Prop2") == "2");
                TestHelper.Assert(pa.GetProperty("Bogus").Length == 0);

                //
                // Test: PropertiesAdmin::getProperties()
                //
                Dictionary <string, string> pd = pa.GetPropertiesForPrefix("");
                TestHelper.Assert(pd.Count == 6);
                TestHelper.Assert(pd["Ice.ProgramName"] == "server");
                TestHelper.Assert(pd["Ice.Admin.Endpoints"] == "tcp -h 127.0.0.1");
                TestHelper.Assert(pd["Ice.Admin.InstanceName"] == "Test");
                TestHelper.Assert(pd["Prop1"] == "1");
                TestHelper.Assert(pd["Prop2"] == "2");
                TestHelper.Assert(pd["Prop3"] == "3");

                Dictionary <string, string> changes;

                //
                // Test: PropertiesAdmin::setProperties()
                //
                var setProps = new Dictionary <string, string>
                {
                    { "Prop1", "10" }, // Changed
                    { "Prop2", "20" }, // Changed
                    { "Prop3", "" },   // Removed
                    { "Prop4", "4" },  // Added
                    { "Prop5", "5" } // Added
                };
                pa.SetProperties(setProps);
                TestHelper.Assert(pa.GetProperty("Prop1").Equals("10"));
                TestHelper.Assert(pa.GetProperty("Prop2").Equals("20"));
                TestHelper.Assert(pa.GetProperty("Prop3").Length == 0);
                TestHelper.Assert(pa.GetProperty("Prop4").Equals("4"));
                TestHelper.Assert(pa.GetProperty("Prop5").Equals("5"));
                changes = com.getChanges();
                TestHelper.Assert(changes.Count == 5);
                TestHelper.Assert(changes["Prop1"].Equals("10"));
                TestHelper.Assert(changes["Prop2"].Equals("20"));
                TestHelper.Assert(changes["Prop3"].Length == 0);
                TestHelper.Assert(changes["Prop4"].Equals("4"));
                TestHelper.Assert(changes["Prop5"].Equals("5"));
                pa.SetProperties(setProps);
                changes = com.getChanges();
                TestHelper.Assert(changes.Count == 0);

                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing logger facet... ");
            output.Flush();
            {
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "NullLogger", "1" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                com.trace("testCat", "trace");
                com.warning("warning");
                com.error("error");
                com.print("print");

                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                ILoggerAdminPrx logger = obj.Clone("Logger", ILoggerAdminPrx.Factory);

                //
                // Get all
                //
                (LogMessage[] logMessages, string prefix) =
                    logger.GetLog(Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);

                TestHelper.Assert(logMessages.Length == 4);
                TestHelper.Assert(prefix.Equals("NullLogger"));
                TestHelper.Assert(logMessages[0].TraceCategory.Equals("testCat") && logMessages[0].Message.Equals("trace"));
                TestHelper.Assert(logMessages[1].Message.Equals("warning"));
                TestHelper.Assert(logMessages[2].Message.Equals("error"));
                TestHelper.Assert(logMessages[3].Message.Equals("print"));

                //
                // Get only errors and warnings
                //
                com.error("error2");
                com.print("print2");
                com.trace("testCat", "trace2");
                com.warning("warning2");

                LogMessageType[] messageTypes = { LogMessageType.ErrorMessage, LogMessageType.WarningMessage };

                (logMessages, prefix) = logger.GetLog(messageTypes, Array.Empty <string>(), -1);

                TestHelper.Assert(logMessages.Length == 4);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                foreach (LogMessage msg in logMessages)
                {
                    TestHelper.Assert(msg.Type == LogMessageType.ErrorMessage || msg.Type == LogMessageType.WarningMessage);
                }

                //
                // Get only errors and traces with Cat = "testCat"
                //
                com.trace("testCat2", "A");
                com.trace("testCat", "trace3");
                com.trace("testCat2", "B");

                messageTypes = new LogMessageType[] { LogMessageType.ErrorMessage, LogMessageType.TraceMessage };
                string[] categories = { "testCat" };
                (logMessages, prefix) = logger.GetLog(messageTypes, categories, -1);
                TestHelper.Assert(logMessages.Length == 5);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                foreach (LogMessage msg in logMessages)
                {
                    TestHelper.Assert(msg.Type == LogMessageType.ErrorMessage ||
                                      (msg.Type == LogMessageType.TraceMessage && msg.TraceCategory.Equals("testCat")));
                }

                //
                // Same, but limited to last 2 messages(trace3 + error3)
                //
                com.error("error3");

                (logMessages, prefix) = logger.GetLog(messageTypes, categories, 2);
                TestHelper.Assert(logMessages.Length == 2);
                TestHelper.Assert(prefix.Equals("NullLogger"));

                TestHelper.Assert(logMessages[0].Message.Equals("trace3"));
                TestHelper.Assert(logMessages[1].Message.Equals("error3"));

                //
                // Now, test RemoteLogger
                //
                ObjectAdapter adapter = communicator.CreateObjectAdapterWithEndpoints("RemoteLoggerAdapter",
                                                                                      "tcp -h localhost", serializeDispatch: true);

                var remoteLogger = new RemoteLogger();

                IRemoteLoggerPrx myProxy = adapter.AddWithUUID(remoteLogger, IRemoteLoggerPrx.Factory);

                adapter.Activate();

                //
                // No filtering
                //
                (logMessages, prefix) = logger.GetLog(Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);

                logger.AttachRemoteLogger(myProxy, Array.Empty <LogMessageType>(), Array.Empty <string>(), -1);
                remoteLogger.Wait(1);

                foreach (LogMessage m in logMessages)
                {
                    remoteLogger.CheckNextInit(prefix, m.Type, m.Message, m.TraceCategory);
                }

                com.trace("testCat", "rtrace");
                com.warning("rwarning");
                com.error("rerror");
                com.print("rprint");

                remoteLogger.Wait(4);

                remoteLogger.CheckNextLog(LogMessageType.TraceMessage, "rtrace", "testCat");
                remoteLogger.CheckNextLog(LogMessageType.WarningMessage, "rwarning", "");
                remoteLogger.CheckNextLog(LogMessageType.ErrorMessage, "rerror", "");
                remoteLogger.CheckNextLog(LogMessageType.PrintMessage, "rprint", "");

                TestHelper.Assert(logger.DetachRemoteLogger(myProxy));
                TestHelper.Assert(!logger.DetachRemoteLogger(myProxy));

                //
                // Use Error + Trace with "traceCat" filter with 4 limit
                //
                (logMessages, prefix) = logger.GetLog(messageTypes, categories, 4);
                TestHelper.Assert(logMessages.Length == 4);

                logger.AttachRemoteLogger(myProxy, messageTypes, categories, 4);
                remoteLogger.Wait(1);

                foreach (LogMessage m in logMessages)
                {
                    remoteLogger.CheckNextInit(prefix, m.Type, m.Message, m.TraceCategory);
                }

                com.warning("rwarning2");
                com.trace("testCat", "rtrace2");
                com.warning("rwarning3");
                com.error("rerror2");
                com.print("rprint2");

                remoteLogger.Wait(2);

                remoteLogger.CheckNextLog(LogMessageType.TraceMessage, "rtrace2", "testCat");
                remoteLogger.CheckNextLog(LogMessageType.ErrorMessage, "rerror2", "");

                //
                // Attempt reconnection with slightly different proxy
                //
                try
                {
                    logger.AttachRemoteLogger(myProxy.Clone(oneway: true), messageTypes, categories, 4);
                    TestHelper.Assert(false);
                }
                catch (RemoteLoggerAlreadyAttachedException)
                {
                    // expected
                }

                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing custom facet... ");
            output.Flush();
            {
                //
                // Test: Verify that the custom facet is present.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                ITestFacetPrx tf = obj.Clone("TestFacet", ITestFacetPrx.Factory);
                tf.op();
                com.destroy();
            }
            output.WriteLine("ok");

            output.Write("testing facet filtering... ");
            output.Flush();
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the Properties facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Properties" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the Process facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Process" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose only the TestFacet facet,
                // meaning no other facet is available.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "TestFacet" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }

                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose two facets. Use whitespace to separate the
                // facet names.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "Properties TestFacet" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                IPropertiesAdminPrx pa = obj.Clone("Properties", IPropertiesAdminPrx.Factory);
                TestHelper.Assert(pa.GetProperty("Ice.Admin.InstanceName").Equals("Test"));
                var tf = ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                tf !.op();
                try
                {
                    IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                com.destroy();
            }
            {
                //
                // Test: Set Ice.Admin.Facets to expose two facets. Use a comma to separate the
                // facet names.
                //
                var props = new Dictionary <string, string>
                {
                    { "Ice.Admin.Endpoints", "tcp -h 127.0.0.1" },
                    { "Ice.Admin.InstanceName", "Test" },
                    { "Ice.Admin.Facets", "TestFacet, Process" }
                };
                IRemoteCommunicatorPrx?com = factory.createCommunicator(props);
                TestHelper.Assert(com != null);
                IObjectPrx?obj = com.getAdmin();
                TestHelper.Assert(obj != null);
                try
                {
                    IPropertiesAdminPrx.CheckedCast(obj.Clone(facet: "Properties", IObjectPrx.Factory));
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException)
                {
                }
                var tf = ITestFacetPrx.CheckedCast(obj.Clone(facet: "TestFacet", IObjectPrx.Factory));
                TestHelper.Assert(tf != null);
                tf.op();
                var proc = IProcessPrx.CheckedCast(obj.Clone(facet: "Process", IObjectPrx.Factory));
                TestHelper.Assert(proc != null);
                proc.Shutdown();
                com.waitForShutdown();
                com.destroy();
            }
            output.WriteLine("ok");

            factory.shutdown();
        }
コード例 #3
0
 public IObjectPrx?Echo(IObjectPrx?obj, Current c) => obj;
コード例 #4
0
        private async Task <IReadOnlyList <Endpoint> > GetAdapterEndpointsAsync(
            Reference reference,
            CancellationToken cancel)
        {
            if (reference.Communicator.TraceLevels.Location > 0)
            {
                reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                    $"searching for adapter by id\nadapter = {reference.AdapterId}");
            }

            Task <IReadOnlyList <Endpoint> >?task;

            lock (_mutex)
            {
                if (!_adapterRequests.TryGetValue(reference.AdapterId, out task))
                {
                    // If there's no locator request in progress for this adapter, we invoke one and cache it to prevent
                    // making too many requests on the locator. It's removed once the locator response is received.
                    task = PerformGetAdapterEndpointsAsync(reference);
                    if (!task.IsCompleted)
                    {
                        // If PerformGetAdapterEndpointsAsync completed, don't add the task (it would leak since
                        // PerformGetAdapterEndpointsAsync is responsible for removing it).
                        _adapterRequests.Add(reference.AdapterId, task);
                    }
                }
            }

            return(await task.WaitAsync(cancel).ConfigureAwait(false));

            async Task <IReadOnlyList <Endpoint> > PerformGetAdapterEndpointsAsync(Reference reference)
            {
                try
                {
                    // TODO: Fix FindAdapterById to return non-null proxy
                    IObjectPrx?proxy = await Locator.FindAdapterByIdAsync(reference.AdapterId).ConfigureAwait(false);

                    if (proxy != null && !proxy.IceReference.IsIndirect)
                    {
                        // Cache the adapter endpoints.
                        _table.SetAdapterEndpoints(reference.AdapterId, proxy.IceReference.Endpoints);
                        return(proxy.IceReference.Endpoints);
                    }
                    else
                    {
                        return(ImmutableArray <Endpoint> .Empty);
                    }
                }
                catch (AdapterNotFoundException)
                {
                    if (reference.Communicator.TraceLevels.Location > 0)
                    {
                        reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                            $"adapter not found\nadapter = {reference.AdapterId}");
                    }
                    _table.RemoveAdapterEndpoints(reference.AdapterId);
                    throw;
                }
                catch (Exception exception)
                {
                    if (reference.Communicator.TraceLevels.Location > 0)
                    {
                        reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                            "could not contact the locator to retrieve endpoints\n" +
                                                            $"adapter = {reference.AdapterId}\nreason = {exception}");
                    }
                    throw;
                }
                finally
                {
                    lock (_mutex)
                    {
                        _adapterRequests.Remove(reference.AdapterId);
                    }
                }
            }
        }
コード例 #5
0
 opOneOptionalProxy(IObjectPrx?p1, Current current) => new Test.IInitial.OpOneOptionalProxyReturnValue(p1, p1);
コード例 #6
0
ファイル: Instrumentation.cs プロジェクト: sgrzegorz/ice
 public Ice.Instrumentation.IInvocationObserver?GetInvocationObserver(
     IObjectPrx? p, string o, IReadOnlyDictionary <string, string> c) => invocationObserver;
コード例 #7
0
ファイル: PluginI.cs プロジェクト: lmf07120057/ice
        public ValueTask <IObjectPrx?> FindAdapterByIdAsync(string id, Current current)
        {
            IObjectPrx?prx = null;

            return(new ValueTask <IObjectPrx?>(prx));
        }
コード例 #8
0
ファイル: TestI.cs プロジェクト: yuwenyong/ice
 public (IObjectPrx?, IObjectPrx?) opOneOptionalProxy(IObjectPrx?p1, Current current) => (p1, p1);
コード例 #9
0
ファイル: Lookup.cs プロジェクト: nail-lian/ice
 public abstract void Finished(IObjectPrx?proxy);
コード例 #10
0
 public IObjectPrx?Echo(IObjectPrx?obj, Current c, CancellationToken cancel) => obj;
コード例 #11
0
 opOneOptionalProxyAsync(IObjectPrx?p1, Current current)
 {
     return(Task.FromResult(new Test.Initial.OpOneOptionalProxyReturnValue(p1, p1)));
 }
コード例 #12
0
ファイル: Lookup.cs プロジェクト: zhengxiaoming1/ice
 public void FoundObjectById(Identity id, IObjectPrx?proxy, Current current, CancellationToken cancel) =>
 CompletionSource.SetResult(proxy);
コード例 #13
0
ファイル: TestI.cs プロジェクト: xingx001/ice
 opOneOptionalProxy(IObjectPrx?p1, out IObjectPrx?p3, Current current)
 {
     p3 = p1;
     return(p1);
 }
コード例 #14
0
ファイル: MyDerivedClassAMDI.cs プロジェクト: wubo2018/ice
 public ValueTask <IObjectPrx?> EchoAsync(IObjectPrx?obj, Current c, CancellationToken cancel) =>
 new ValueTask <IObjectPrx?>(obj);
コード例 #15
0
 public void AddObject(IObjectPrx?obj, Current current, CancellationToken cancel)
 {
     TestHelper.Assert(obj != null);
     AddObject(obj);
 }
コード例 #16
0
ファイル: InstrumentationI.cs プロジェクト: menghuan341/ice
 public InvocationHelper(IObjectPrx?proxy, string op, Dictionary <string, string> ctx) : base(_attributes)
 {
     _proxy     = proxy;
     _operation = op;
     _context   = ctx;
 }
コード例 #17
0
 public IInvocationObserver?GetInvocationObserver(IObjectPrx?p, string o,
                                                  IReadOnlyDictionary <string, string> c) => _invocationObserver;
コード例 #18
0
 public ValueTask SetReplicatedAdapterDirectProxyAsync(string adapter, string replica, IObjectPrx?obj,
                                                       Current current)
 {
     if (obj != null)
     {
         _adapters[adapter] = obj;
         _adapters[replica] = obj;
     }
     else
     {
         _adapters.Remove(adapter);
         _adapters.Remove(replica);
     }
     return(new ValueTask(Task.CompletedTask));
 }
コード例 #19
0
ファイル: PluginI.cs プロジェクト: lmf07120057/ice
        public ValueTask <IObjectPrx?> FindObjectByIdAsync(Identity id, Current current)
        {
            IObjectPrx?prx = null;

            return(new ValueTask <IObjectPrx?>(prx));
        }
コード例 #20
0
 public void addObject(IObjectPrx?obj, Current current)
 {
     TestHelper.Assert(obj != null);
     AddObject(obj);
 }
コード例 #21
0
ファイル: IObjectPrx.cs プロジェクト: yuweiApp/ice
 // Implements IEquatable<IObjectPrx>:
 /// <summary>Returns whether this proxy equals the given proxy. Two proxies are equal if they are equal in all
 /// respects, that is, if their object identity, endpoints timeout settings, and so on are all equal.</summary>
 /// <param name="other">The proxy to compare this proxy with.</param>
 /// <returns>True if this proxy is equal to other; otherwise, false.</returns>
 public bool Equals(IObjectPrx?other) => other != null && IceReference.Equals(other.IceReference);
コード例 #22
0
 public ValueTask <IObjectPrx?> echoAsync(IObjectPrx?obj, Current c)
 => new ValueTask <IObjectPrx?>(obj);
コード例 #23
0
        private async Task <Reference?> GetObjectReferenceAsync(Reference reference, CancellationToken cancel)
        {
            if (reference.Communicator.TraceLevels.Location > 0)
            {
                reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                    $"searching for well-known object\nwell-known proxy = {reference}");
            }

            Task <Reference?>?task;

            lock (_mutex)
            {
                if (!_objectRequests.TryGetValue(reference.Identity, out task))
                {
                    // If there's no locator request in progress for this object, we make one and cache it to prevent
                    // making too many requests on the locator. It's removed once the locator response is received.
                    task = PerformGetObjectProxyAsync(reference);
                    if (!task.IsCompleted)
                    {
                        // If PerformGetObjectProxyAsync completed, don't add the task (it would leak since
                        // PerformGetObjectProxyAsync is responsible for removing it).
                        _objectRequests.Add(reference.Identity, task);
                    }
                }
            }

            return(await task.WaitAsync(cancel).ConfigureAwait(false));

            async Task <Reference?> PerformGetObjectProxyAsync(Reference reference)
            {
                try
                {
                    // TODO: Fix FindObjectById to return non-null proxy
                    IObjectPrx?proxy = await Locator.FindObjectByIdAsync(reference.Identity).ConfigureAwait(false);

                    if (proxy != null && !proxy.IceReference.IsWellKnown)
                    {
                        // Cache the object reference.
                        _table.SetObjectReference(reference.Identity, proxy.IceReference);
                        return(proxy.IceReference);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (ObjectNotFoundException)
                {
                    if (reference.Communicator.TraceLevels.Location > 0)
                    {
                        reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                            "object not found\n" +
                                                            $"object = {reference.Identity.ToString(reference.Communicator.ToStringMode)}");
                    }
                    _table.RemoveObjectReference(reference.Identity);
                    throw;
                }
                catch (Exception exception)
                {
                    if (reference.Communicator.TraceLevels.Location > 0)
                    {
                        reference.Communicator.Logger.Trace(reference.Communicator.TraceLevels.LocationCategory,
                                                            "could not contact the locator to retrieve endpoints\n" +
                                                            $"well-known proxy = {reference}\nreason = {exception}");
                    }
                    throw;
                }
                finally
                {
                    lock (_mutex)
                    {
                        _objectRequests.Remove(reference.Identity);
                    }
                }
            }
        }
コード例 #24
0
ファイル: Lookup.cs プロジェクト: yzun/ice
 public void Response(IObjectPrx?proxy) => Finished(proxy);