Example #1
0
        /**
         * method used by the client for Registering or Adding a callback with the client channel
         *
         * @param CallbackId String
         * @param Callback the class that implements the method "execute"
         * @param OnRegisterCallbackFinish
         */
        public void registerCallback(String CallbackId, DBXCallback Callback, OnRegisterCallbackFinish onRegisterCallbackFinish = null)
        {
            TJSONValue Value = new TJSONTrue();

            if (wThread == null)
            {
                wThread = new WorkerThread(Connection.Clone(true), this);
                thread  = new Thread(new ThreadStart(wThread.run));
                dsadmin.ConsumeClientChannel(ChannelName,
                                             getManagerID(), CallbackId, ChannelName,
                                             getSecurityToken(), Value, (TJSONValue res) =>
                {
                    if (res is TJSONObject && ((TJSONObject)res).has("invoke"))
                    {
                        thread.Start();
                    }
                    if (onRegisterCallbackFinish != null)
                    {
                        onRegisterCallbackFinish();
                    }
                });
            }
            else
            {
                registerClientCallback(CallbackId);
                if (onRegisterCallbackFinish != null)
                {
                    onRegisterCallbackFinish();
                }
            }
            wThread.addCallback(CallbackId, Callback);
        }
Example #2
0
            /**
             * @return JObject
             */
            private TJSONValue channelCallbackExecute()
            {
                Object     o     = new Object();
                TJSONValue Value = new TJSONTrue();
                TJSONValue res   = null;
                long       lastRequestAttempt = 0;
                int        retries            = 0;

                while (!stopped)
                {
                    lastRequestAttempt = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    res = null;
                    Exception raisedException = null;
                    Monitor.Enter(o);
                    try
                    {
                        dsadmin.ConsumeClientChannel(mngr.getChannelName(), mngr
                                                     .getManagerID(), "", mngr.getChannelName(), mngr
                                                     .getSecurityToken(), Value,
                                                     (r) =>
                        {
                            Monitor.Enter(o);
                            try
                            {
                                res = r;
                                Monitor.PulseAll(o);
                            }
                            finally
                            {
                                Monitor.Exit(o);
                            }
                        }, (e) =>
                        {
                            Monitor.Enter(o);
                            try
                            {
                                raisedException = e;
                                Monitor.PulseAll(o);
                            }
                            finally
                            {
                                Monitor.Exit(o);
                            }
                        }
                                                     );
                        Monitor.Wait(o);

                        //analize the callback's results
                        if (raisedException != null)
                        {
                            if ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - lastRequestAttempt >= dsadmin.getConnection().getConnectionTimeout() + 1000)
                            {
                                retries = 0;
                            }
                            if (retries == this.mngr.getMaxRetries())
                            {
                                terminate();
                                res = null;
                                mngr.Connection.syncContext.Send(new SendOrPostCallback(x => mngr.ExCallback.DynamicInvoke(raisedException)), null);
                            }
                            retries++;
                            Thread.Sleep(this.mngr.getRetryDelay());
                        }
                        else
                        {
                            break;
                        }
                    }
                    finally {
                        Monitor.Exit(o);
                    }
                } //while
                return(res);
            }
            /**
             * @return JObject
             */
            private TJSONValue channelCallbackExecute()
            {
                Object o = new Object();
                TJSONValue Value = new TJSONTrue();
                TJSONValue res = null;
                long lastRequestAttempt = 0;
                int retries = 0;
                while (!stopped) {
                    lastRequestAttempt = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    res = null;
                    Exception raisedException = null;
                    Monitor.Enter(o);
                    try
                    {
                        dsadmin.ConsumeClientChannel(mngr.getChannelName(), mngr
                                .getManagerID(), "", mngr.getChannelName(), mngr
                                .getSecurityToken(), Value,
                                (r) =>
                                {
                                    Monitor.Enter(o);
                                    try
                                    {
                                        res = r;
                                        Monitor.PulseAll(o);
                                    }
                                    finally
                                    {
                                        Monitor.Exit(o);
                                    }
                                }, (e) =>
                                {
                                    Monitor.Enter(o);
                                    try
                                    {
                                        raisedException = e;
                                        Monitor.PulseAll(o);
                                    }
                                    finally
                                    {
                                        Monitor.Exit(o);
                                    }
                                }
                        );
                        Monitor.Wait(o);

                        //analize the callback's results
                        if (raisedException != null)
                        {
                            if ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - lastRequestAttempt >= dsadmin.getConnection().getConnectionTimeout() + 1000)
                                retries = 0;
                            if (retries == this.mngr.getMaxRetries())
                            {
                                terminate();
                                res = null;
                                mngr.Connection.syncContext.Send(new SendOrPostCallback(x => mngr.ExCallback.DynamicInvoke(raisedException)), null);
                            }
                            retries++;
                            Thread.Sleep(this.mngr.getRetryDelay());
                        }
                        else
                            break;
                    }
                    finally {
                        Monitor.Exit(o);
                    }
                } //while
                return res;
            }
 /**
  * method used by the client for Registering or Adding a callback with the client channel
  *
  * @param CallbackId String
  * @param Callback the class that implements the method "execute"
  * @param OnRegisterCallbackFinish
  */
 public void registerCallback(String CallbackId, DBXCallback Callback, OnRegisterCallbackFinish onRegisterCallbackFinish = null)
 {
     TJSONValue Value = new TJSONTrue();
     if (wThread == null)
     {
         wThread = new WorkerThread(Connection.Clone(true), this);
         thread = new Thread(new ThreadStart(wThread.run));
         dsadmin.ConsumeClientChannel(ChannelName,
           getManagerID(), CallbackId, ChannelName,
           getSecurityToken(), Value, (TJSONValue res) =>
                 {
                     if (res is TJSONObject && ((TJSONObject)res).has("invoke"))
                     {
                         thread.Start();
                     }
                     if (onRegisterCallbackFinish != null)
                         onRegisterCallbackFinish();
                 });
     }
     else
     {
         registerClientCallback(CallbackId);
         if (onRegisterCallbackFinish != null)
             onRegisterCallbackFinish();
     }
     wThread.addCallback(CallbackId, Callback);
 }