/// <summary> Wakes up all connected zones if currently in sleep mode. /// /// For each connected zone, a SIF_Wakeup message is sent to the IZone /// Integration Server to request that sleep mode be removed from this agent's /// queue for that zone. 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 cleared so that the Adk /// will no longer return a Status Code 8 ("Receiver is sleeping") in response /// to messages received by the ZIS. /// /// /// </summary> /// <exception cref="AdkException"> thrown if the SIF_Wakeup message is unsuccessful. /// The Adk will attempt to send a SIF_Wakeup to all connected zones; the /// exception describes the zone or zones that failed /// </exception> public virtual void Wakeup() { lock (this) { _checkInit(); AdkMessagingException err = null; IZone[] zones = fZoneFactory.GetAllZones(); for (int i = 0; i < zones.Length; i++) { try { zones[i].WakeUp(); } catch (AdkMessagingException ex) { if (err == null) { err = new AdkMessagingException ("An error occurred sending SIF_Wakeup to zone \"" + zones[i].ZoneId + "\"", zones[i]); } err.Add(ex); } } if (err != null) { AdkUtils._throw(err, Log); } } }
/// <summary> Initialize the agent.</summary> /// <remarks> /// An application must call this method to initialize the class framework /// and runtime. No other methods can be called until the agent has been /// successfully initialized. When the agent exits it is important that the /// <c>shutdown</c> method be called to safely release the resources /// allocated by the runtime. /// /// If an application overrides this method, it should call the superclass /// implementation <i>after</i> performing its own initialization. /// </remarks> /// <seealso cref="Shutdown()"></seealso> /// <exception cref="Exception">If the agent is unable to initialize due to a file or resource exception</exception> /// <exception cref="AdkException">Thrown if the agent has already /// been initialized /// </exception> public virtual void Initialize() { lock (this) { if (fInit) { AdkUtils._throw(new AdkException("Agent is already initialized", null), Log); } if (fShutdownInProgress) { AdkUtils._throw (new AdkException("Agent is in the process of shutting down", null), Log); } #if EVAL try { new E(this); } catch (Exception) { Console.WriteLine("Corrupt ADK Evaluation Edition or internal error. Please report this notice to OpenADK Tech Support."); Environment.Exit(0); } #endif if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Initializing agent..."); } // Verify home directory exists and can be written to AssertDirectoryExists(HomeDir, "Home"); // Verify work directory exists and can be written to AssertDirectoryExists(WorkDir, "Work"); #if PROFILED { // TODO: Implement Support for Profiling System.out.println("SIF Profiling Harness support enabled in ADK"); // Establish the SIFProfilerClient name (i.e. "sourceId_ADK") ProfilerUtils.setProfilerName(getId() + "_ADK"); } #endif //Initialize the TransportManager fTransportManager.Activate(this); fShutdownInProgress = false; fInit = true; if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Agent initialized"); } } }
/// <summary> Helper routine to check that the <c>initialize</c> method has been called /// @throws AdkException if not initialized /// </summary> private void _checkInit() { if (fShutdown) { throw new LifecycleException("Agent has been shutdown"); } if (!fInit) { Console.Out.WriteLine(new StackTrace(true).ToString()); AdkUtils._throw(new LifecycleException("Agent not initialized"), Log); } }
/// <summary>Constructor</summary> /// <param name="agentId">The string name that uniquely identifies this agent in SIF Zones. /// This string is used as the <c>SourceId</c> in all SIF message /// headers created by the agent. /// </param> public Agent(string agentId) { if (agentId == null || agentId.Trim().Length == 0) { AdkUtils._throw (new ArgumentException("Agent ID cannot be null or a blank string"), Log); } fSourceId = agentId; ObjectFactory factory = ObjectFactory.GetInstance(); fZoneFactory = (IZoneFactory)factory.CreateInstance(ObjectFactory.ADKFactoryType.ZONE, this); fTopicFactory = (ITopicFactory)factory.CreateInstance(ObjectFactory.ADKFactoryType.TOPIC, this); fTransportManager = new TransportManagerImpl(); }
/// <summary> Register a global IQueryResults message handler object with this /// agent for the specified SIF object type in the default SIF Context /// /// Note agents typically register message handlers with Topics or with /// Zones instead of with the Agent. The message fDispatcher first /// delivers messages to Topics, then to Zones, and finally to the Agent /// itself. /// /// </summary> /// <param name="queryResults">An object that implements the <c>IQueryResults</c> /// interface to respond to SIF_Response query results received by the agent, /// where the SIF object type referenced by the request matches the /// specified objectType. This IQueryResults object will be called whenever /// a SIF_Response is received and no other object in the message /// dispatching chain has processed the message. /// /// </param> /// <param name="objectType">A constant from the SifDtd class that identifies the /// type of SIF Data Object this IQueryResults message handler will /// respond to. /// </param> public virtual void SetQueryResults(IQueryResults queryResults, IElementDef objectType) { if (queryResults == null) { AdkUtils._throw (new ArgumentException("IQueryResults object cannot be null"), GetLog()); } if (objectType == null) { fQueryResults[SifDtd.SIF_MESSAGE] = queryResults; } else { fQueryResults[objectType] = queryResults; } }
/// <summary> Register a global ISubscriber message handler with this agent /// for the specified SIF object type in the default SIF Context. /// /// Note agents typically register message handlers with Topics or with Zones /// instead of with the Agent. The message fDispatcher first /// delivers messages to Topics, then to Zones, and finally to the Agent /// itself. /// /// In order to receive SIF_Event messages, the agent is expected to be /// registered as a ISubscriber of one or more object types in at least one /// zone. This method does not send SIF_Subscribe messages to any zones. /// /// </summary> /// <param name="subscriber">An object that implements the <c>ISubscriber</c> /// interface to respond to SIF_Event notifications received by the agent, /// where the SIF object type referenced by the request matches the /// specified objectType. This ISubscriber will be called whenever a /// SIF_Event is received and no other object in the message dispatching /// chain has processed the message. /// /// </param> /// <param name="objectType">A constant from the SifDtd class that identifies the /// type of SIF Data Object this ISubscriber will respond to. /// </param> public virtual void SetSubscriber(ISubscriber subscriber, IElementDef objectType) { if (subscriber == null) { AdkUtils._throw (new ArgumentException("ISubscriber object cannot be null"), GetLog()); } if (objectType == null) { fSubs[SifDtd.SIF_MESSAGE] = subscriber; } else { fSubs[objectType] = subscriber; } }
private void AssertDirectoryExists(string path, string logName) { DirectoryInfo dir = new DirectoryInfo(path); if (!dir.Exists) { if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Debug (string.Format("Creating {0} directory: {1}", logName, dir.FullName)); } dir.Create(); } if (!Directory.Exists(dir.FullName)) { AdkUtils._throw (new AdkException (string.Format ("The {0} directory is not a directory: {1}", logName, path), null), Log); } }