예제 #1
0
파일: SessionHelper.cs 프로젝트: wandec/ice
        Connected(IRouterPrx router, ISessionPrx session)
        {
            //
            // Remote invocation should be done without acquiring a mutex lock.
            //
            Debug.Assert(router != null);
            Debug.Assert(_communicator != null);
            Connection?conn       = router.GetCachedConnection();
            string     category   = router.GetCategoryForClient();
            int        acmTimeout = 0;

            try
            {
                acmTimeout = router.GetACMTimeout();
            }
            catch (OperationNotExistException)
            {
            }

            if (acmTimeout <= 0)
            {
                acmTimeout = (int)router.GetSessionTimeout();
            }

            //
            // We create the callback object adapter here because createObjectAdapter internally
            // makes synchronous RPCs to the router. We can't create the OA on-demand when the
            // client calls objectAdapter() or addWithUUID() because they can be called from the
            // GUI thread.
            //
            if (_useCallbacks)
            {
                Debug.Assert(_adapter == null);
                _adapter = _communicator.CreateObjectAdapterWithRouter(router);
                _adapter.Activate();
            }

            lock (_mutex)
            {
                _router = router;

                if (_destroy)
                {
                    //
                    // Run destroyInternal in a thread because it makes remote invocations.
                    //
                    var t = new Thread(new ThreadStart(DestroyInternal));
                    t.Start();
                    return;
                }

                //
                // Cache the category.
                //
                _category = category;

                //
                // Assign the session after _destroy is checked.
                //
                _session   = session;
                _connected = true;

                if (acmTimeout > 0)
                {
                    Connection?connection = _router.GetCachedConnection();
                    Debug.Assert(connection != null);
                    connection.SetACM(acmTimeout, null, ACMHeartbeat.HeartbeatAlways);
                    connection.SetCloseCallback(_ => Destroy());
                }
            }

            try
            {
                _callback.Connected(this);
            }
            catch (SessionNotExistException)
            {
                Destroy();
            }
        }
예제 #2
0
        private void Connected(IRouterPrx router, ISessionPrx session)
        {
            // Remote invocation should be done without acquiring a mutex lock.
            Debug.Assert(router != null);
            Debug.Assert(_communicator != null);
            Connection?conn       = router.GetCachedConnection();
            string     category   = router.GetCategoryForClient();
            TimeSpan   acmTimeout = TimeSpan.Zero;

            try
            {
                acmTimeout = TimeSpan.FromSeconds(router.GetACMTimeout());
            }
            catch (OperationNotExistException)
            {
            }

            if (acmTimeout == TimeSpan.Zero)
            {
                acmTimeout = TimeSpan.FromSeconds(router.GetSessionTimeout());
            }

            // We create the callback object adapter here because createObjectAdapter internally makes synchronous
            // RPCs to the router. We can't create the OA on-demand when the client calls ObjectAdapter() or
            // AddWithUUID() because they can be called from the GUI thread.
            if (_useCallbacks)
            {
                Debug.Assert(_adapter == null);
                _adapter = _communicator.CreateObjectAdapterWithRouter(router);
                _adapter.Activate();
            }

            lock (_mutex)
            {
                _router = router;

                if (_destroy)
                {
                    // Run destroyInternal in a thread because it makes remote invocations.
                    var t = new Thread(new ThreadStart(DestroyInternal));
                    t.Start();
                    return;
                }

                // Cache the category.
                _category = category;

                // Assign the session after _destroy is checked.
                _session   = session;
                _connected = true;

                if (acmTimeout != TimeSpan.Zero)
                {
                    Connection?connection = _router.GetCachedConnection();
                    Debug.Assert(connection != null);
                    connection.Acm     = new Acm(acmTimeout, connection.Acm.Close, AcmHeartbeat.Always);
                    connection.Closed += (sender, args) => Destroy();
                }
            }

            try
            {
                _callback.Connected(this);
            }
            catch (SessionNotExistException)
            {
                Destroy();
            }
        }