示例#1
0
        /// <summary>  Puts all connected zones into sleep mode.
        ///
        /// For each zone in the connected state, a SIF_Sleep message is sent to the
        /// IZone Integration Server to request that this agent's queue be put into
        /// sleep mode for that zone. If successful, the ZIS should not deliver
        /// further messages to this agent until it is receives a SIF_Register or
        /// SIF_Wakeup message from the agent. Note the Adk keeps an internal sleep
        /// flag for each zone, which is initialized when the <c>connect</c>
        /// method is called by sending a SIF_Ping to the ZIS. This flag is set so
        /// that the Adk will return a Status Code 8 ("Receiver is sleeping") in
        /// response to any message received by the ZIS for the duration of the
        /// session.
        ///
        ///
        /// </summary>
        /// <exception cref="AdkException">  thrown if the SIF_Sleep message is unsuccessful.
        /// The Adk will attempt to send a SIF_Sleep to all connected zones; the
        /// exception describes the zone or zones that failed
        /// </exception>
        public virtual void Sleep()
        {
            lock (this)
            {
                _checkInit();

                AdkMessagingException err = null;

                IZone[] zones = fZoneFactory.GetAllZones();
                for (int i = 0; i < zones.Length; i++)
                {
                    try
                    {
                        zones[i].Sleep();
                    }
                    catch (AdkMessagingException ex)
                    {
                        if (err == null)
                        {
                            err =
                                new AdkMessagingException
                                    ("An error occurred sending SIF_Sleep to zone \"" +
                                    zones[i].ZoneId + "\"", zones[i]);
                        }
                        err.Add(ex);
                    }
                }

                if (err != null)
                {
                    AdkUtils._throw(err, Log);
                }
            }
        }
示例#2
0
        public virtual void Shutdown(ProvisioningFlags provisioningOptions)
        {
            if (!fInit)
            {
                return;
            }

            fShutdownInProgress = true;
            if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0)
            {
                Log.Info("Shutting down agent...");
            }

            //	Close the SIFProfilerClient if supported
#if PROFILED
            {
                // TODO: Implement Support for Profiling
                com.OpenADK.sifprofiler.SIFProfilerClient prof =
                    com.OpenADK.sifprofiler.SIFProfilerClient.getInstance(ProfilerUtils.getProfilerName());
                if (prof != null)
                {
                    try
                    {
                        prof.close();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
#endif

            try
            {
                //  JAVA_TODO:  Unsubscribe, Unprovide topics

                //  Disconnect and shutdown each zone...
                IZoneFactory zf    = IZoneFactory;
                IZone[]      zones = zf.GetAllZones();
                for (int i = 0; i < zones.Length; i++)
                {
                    zones[i].Disconnect(provisioningOptions);
                    ((ZoneImpl)zones[i]).Shutdown();
                }

                if (fTransportManager != null)
                {
                    //  Shutdown transports
                    if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0)
                    {
                        Log.Info("Shutting down Transports...");
                    }
                    fTransportManager.Shutdown();
                }

                //  Close RequestCache
                try
                {
                    RequestCache rc = RequestCache.GetInstance(this);
                    if (rc != null)
                    {
                        rc.Close();
                    }
                }
                catch
                {
                    // Do nothing
                }

                if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0)
                {
                    Log.Debug("Agent shutdown complete");
                }
            }
            finally
            {
                fInit     = false;
                fShutdown = true;
            }
        }