コード例 #1
0
        internal void AsyncResultCallTest()
        {
            ManualResetEvent eventa = new ManualResetEvent(false);

            AsyncCallResultDelegate delegateInstance =
                delegate(ISuperPoolClient client, AsyncResultParams parameters)
            {
                if ((parameters.State is int == false) ||
                    (int)parameters.State != 152)
                {
                    Assert.Fail("Parameter fail.");
                }

                if (parameters.Result != null)
                {
                    // Do something with result.
                    string resultString = parameters.Result.ToString();
                }

                eventa.Set();
            };

            Client1.Call <ITestInterface>(Client2.Id, delegateInstance, 152).AsyncResultMethod(1500);

            if (eventa.WaitOne(60000) == false)
            {
                Assert.Fail("Failed to receive async result.");
            }
        }
コード例 #2
0
        internal void AsyncTimeoutResultCallTest()
        {
            ManualResetEvent eventa = new ManualResetEvent(false);

            DateTime start = DateTime.Now;

            AsyncCallResultDelegate delegateInstance =
                delegate(ISuperPoolClient client, AsyncResultParams parameters)
            {
                TimeSpan time = DateTime.Now - start;
                Console.WriteLine("Async call result received in " + time.TotalMilliseconds + "ms.");
                eventa.Set();
                string p = parameters.Result as string;
            };

            Client1.CallAll <ITestInterface>(delegateInstance, 152, TimeSpan.FromSeconds(2)).AsyncResultMethod(500);

            eventa.WaitOne(60000);

            if (Client1.PendingSyncCallsCount != 1)
            {
                throw new Exception("Pending sync calls count not 1.");
            }

            // Allow time for the client GC to gather the call.
            Thread.Sleep(SuperPoolClient.GarbageCollectorIntervalMs * 3);

            if (Client1.PendingSyncCallsCount != 0)
            {
                throw new Exception("Pending sync calls count not 0.");
            }
        }
コード例 #3
0
        /// <summary>
        /// Perform the actual call.
        /// </summary>
        protected TType DoCall <TType>(ComponentId receiverId, TimeSpan?requestConfirmTimeout,
                                       TimeSpan?timeout, AsyncCallResultDelegate asyncResultDelegate, object asyncResultState,
                                       TimeSpan?asyncResultTimeout, SuperPoolProxyCall.ModeEnum callMode, CallOutcome outcome)
            where TType : class
        {
            Matrix.Framework.SuperPool.Core.SuperPool pool = _superPool;
            if (pool == null)
            {
                return(null);
            }

            SuperPoolProxyCall proxyCall;
            TType result;

            if (pool.Call <TType>(this, receiverId, out result, out proxyCall) == false)
            {
                // Call failed.
                return(null);
            }

            proxyCall.AsyncResultDelegate = asyncResultDelegate;
            proxyCall.AsyncResultState    = asyncResultState;
            proxyCall.AsyncResultTimeout  = asyncResultTimeout;

            proxyCall.RequestConfirmTimeout = requestConfirmTimeout;
            proxyCall.Timeout = timeout;

            proxyCall.Mode    = callMode;
            proxyCall.Outcome = outcome;

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// This method shows a few ways to perform calls.
        /// </summary>
        public void PerformCalls(ISuperPoolClient otherClient)
        {
            ISample otherSource = otherClient.Source as ISample;
            string  result;

            ComponentId recipientId = otherClient.Id;

            ComponentId[] recipientsIds = new ComponentId[] { otherClient.Id };

            AsyncCallResultDelegate asyncDelegate = delegate(ISuperPoolClient clientInstance, AsyncResultParams param)
            {
            };

            // Strongly Coupled Synchronous Invocation.
            // This is the typical, strong coupled way of communication, or invocation.
            result = otherSource.MyMethod(12);

            // Decoupled “DirectCall” Invocation (Very fast, Local only)
            // The closest invocation to the classical strongly coupled approach, this
            // method is very fast, synchronous, and loosely coupled.
            client.CallDirectLocal <ISample>(recipientId).MyMethod(12);

            // Decoupled Synchronous Invocation (Local and remote, Timeout configurable)
            client.CallSync <ISample>(recipientId).MyMethod(12);

            // Decoupled Asynchronous Invocation.
            client.Call <ISample>(recipientId).MyMethod(12);

            // Decoupled Asynchronous Invocation with Result.
            client.Call <ISample>(recipientId, asyncDelegate).MyMethod(12);

            // Decoupled Asynchronous Invocation to Multiple Receivers (Addressed or Non-addressed).
            client.Call <ISample>(recipientsIds).MyMethod(12); // Addressed
            client.CallAll <ISample>().MyMethod(12);           // Non-addressed
        }
コード例 #5
0
        internal void AsyncTimeoutResultCallTestException()
        {
            ManualResetEvent eventa = new ManualResetEvent(false);

            AsyncCallResultDelegate delegateInstance =
                delegate(ISuperPoolClient client, AsyncResultParams parameters)
            {
                if (parameters.Exception == null)
                {    // No exception was received, this is not expected.
                }
                else
                {
                    eventa.Set();
                }
            };

            Client1.CallAll <ITestInterface>(delegateInstance, 152, TimeSpan.FromSeconds(2)).ExceptionMethod();

            if (eventa.WaitOne(20000) == false)
            {
                throw new Exception("Test failed due to no exception received.");
            }
        }
コード例 #6
0
 /// <summary>
 /// Call and receive any result that may come with the usage of asyncDelegate; use state to
 /// track any call identification information you may wish to use in the callback.
 ///
 /// Since in this version no direct receiver is identified, make sure to specify a maximum number of
 /// results to accept, as well as how long to wait for results to come.
 /// </summary>
 /// <param name="maxResultCount">Maximum number of accepted results, as a result of this non addressed call.</param>
 /// <param name="resultWaitTimeout">How long to wait for results coming in.</param>
 public TType CallAll <TType>(AsyncCallResultDelegate asyncDelegate, object state, TimeSpan asyncResultTimeout)
     where TType : class
 {
     return(DoCall <TType>(null, null, null, asyncDelegate, state, asyncResultTimeout, SuperPoolProxyCall.ModeEnum.Default, null));
 }
コード例 #7
0
 /// <summary>
 /// Call and receive any result that may come with the usage of asyncDelegate; use state to
 /// track any call identification information you may wish to use in the callback.
 /// </summary>
 public TType Call <TType>(ComponentId receiverId, AsyncCallResultDelegate asyncDelegate) where TType : class
 {
     return(DoCall <TType>(null, null, null, asyncDelegate, null, null, SuperPoolProxyCall.ModeEnum.Default, null));
 }
コード例 #8
0
 public TType CallAll <TType>(AsyncCallResultDelegate asyncDelegate, object state, TimeSpan asyncResultTimeout) where TType : class
 {
     return(this.DoCall <TType>((ComponentId)null, new TimeSpan?(), new TimeSpan?(), asyncDelegate, state, new TimeSpan?(asyncResultTimeout), SuperPoolProxyCall.ModeEnum.Default, (CallOutcome)null));
 }
コード例 #9
0
 public TType Call <TType>(ComponentId receiverId, AsyncCallResultDelegate asyncDelegate) where TType : class
 {
     return(this.DoCall <TType>((ComponentId)null, new TimeSpan?(), new TimeSpan?(), asyncDelegate, (object)null, new TimeSpan?(), SuperPoolProxyCall.ModeEnum.Default, (CallOutcome)null));
 }
コード例 #10
0
        protected TType DoCall <TType>(ComponentId receiverId, TimeSpan?requestConfirmTimeout, TimeSpan?timeout, AsyncCallResultDelegate asyncResultDelegate, object asyncResultState, TimeSpan?asyncResultTimeout, SuperPoolProxyCall.ModeEnum callMode, CallOutcome outcome) where TType : class
        {
            SuperPool superPool = this._superPool;

            if (superPool == null)
            {
                return(default(TType));
            }
            TType result;
            SuperPoolProxyCall call;

            if (!superPool.Call <TType>(this, receiverId, out result, out call))
            {
                return(default(TType));
            }
            call.AsyncResultDelegate   = asyncResultDelegate;
            call.AsyncResultState      = asyncResultState;
            call.AsyncResultTimeout    = asyncResultTimeout;
            call.RequestConfirmTimeout = requestConfirmTimeout;
            call.Timeout = timeout;
            call.Mode    = callMode;
            call.Outcome = outcome;
            return(result);
        }