Esempio n. 1
0
        public void Query(Query query,
                          IMessagingListener listener,
                          string destinationId,
                          AdkQueryOptions queryOptions)
        {
            if (query == null)
            {
                AdkUtils._throw
                    (new ArgumentException("Query object cannot be null"), Agent.GetLog());
            }

            // Validate that the query object type and SIF Context are valid for this Topic
            if (query.ObjectType != fObjType)
            {
                AdkUtils._throw(new ArgumentException("Query object type: {" + query.ObjectTag +
                                                      "} does not match Topic object type: " + fObjType + "}"), log);
            }

            if (!query.SifContext.Equals(fContext))
            {
                AdkUtils._throw(new ArgumentException("Query SIF_Context: {" + query.SifContext +
                                                      "} does not match Topic SIF_Context: " + fContext + "}"), log);
            }

            _checkZones();

            AdkMessagingException err = null;

            //  Send the SIF_Request to each zone
            foreach (ZoneImpl z in fZones)
            {
                try
                {
                    z.Query(query, listener, destinationId, queryOptions);
                }
                catch (Exception th)
                {
                    if (err == null)
                    {
                        err =
                            new AdkMessagingException
                                ("Error querying topic \"" + fObjType + "\"", z);
                    }

                    if (th is AdkException)
                    {
                        err.Add(th);
                    }
                    else
                    {
                        err.Add(new AdkMessagingException(th.ToString(), z));
                    }
                }
            }

            if (err != null)
            {
                AdkUtils._throw(err, Agent.GetLog());
            }
        }
Esempio n. 2
0
        public void PublishEvent(Event data)
        {
            AdkMessagingException err = null;

            _checkZones();

            foreach (ZoneImpl z in fZones)
            {
                try
                {
                    z.fPrimitives.SifEvent(z, data, null, null);
                }
                catch (Exception th)
                {
                    if (err == null)
                    {
                        err =
                            new AdkMessagingException
                                ("Error publishing event to topic \"" + fObjType + "\"", z);
                    }

                    if (th is AdkException)
                    {
                        err.Add(th);
                    }
                    else
                    {
                        err.Add(new AdkMessagingException(th.ToString(), z));
                    }
                }
            }

            if (err != null)
            {
                AdkUtils._throw(err, Agent.GetLog());
            }
        }
Esempio n. 3
0
        private void AssertExceptionHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone,
                                             Type expectedExceptionType)
        {
            Exception exc = null;

            try
            {
                assertNormalHandling(handler, payload, zone);
            }
            catch (Exception ex)
            {
                exc = ex;
                Assert.IsTrue(handler.wasCalled(), "Handler was not called");

                AdkMessagingException adkme = ex as AdkMessagingException;
                Assert.IsNotNull(adkme,
                                 "Expected an ADKMessagingException, but was " + ex.GetType().Name + ":" + ex.ToString());

                Exception source  = adkme;
                Exception innerEx = null;
                while (source.InnerException != null)
                {
                    innerEx = source.InnerException;
                    source  = innerEx;
                }
                Assert.IsNotNull(innerEx, "AdkMessaginException was thrown but inner exception was not set");

                if (innerEx.GetType() != expectedExceptionType)
                {
                    Assert.Fail("Exception thrown was not a " + expectedExceptionType.Name + ", but was " +
                                innerEx.GetType().Name + ":" + innerEx.ToString());
                }
            }

            Assert.IsNotNull(exc, "An exception was not thrown by the handler");
            AssertThreadIsOK();
        }
            /// <summary>  Waits for the EvDisp thread to either signal that an Intermediate
            /// acknowledgement should be returned to the ZIS, signal that processing
            /// has been completed and an Immediate acknowledgement should be
            /// returned, or signal that an exception occurred. If an exception
            /// occurred, it is rethrown by this method.
            /// 
            /// </summary>
            /// <returns> The SIF_Ack code (either 1 or 2) that should be returned to
            /// the ZIS in response to the processing of the SIF_Event
            /// </returns>
            private int waitForAckCode()
            {
                int result = -1;

                try
                {
                    lock (_state)
                    {
                        //  Was it changed because of an exception? If so throw it
                        if (_state._exception != null)
                        {
                            if ((Adk.Debug & AdkDebugFlags.Messaging) != 0)
                            {
                                fDispatcher.fZone.Log.Debug
                                    (
                                    "EvDisp received an exception instead of an acknowledgement code");
                            }
                            if (_state._exception is AdkMessagingException)
                            {
                                AdkUtils._throw
                                    ((AdkMessagingException)_state._exception,
                                      fDispatcher.fZone.Log);
                            }
                            else
                            {
                                AdkMessagingException adkme = new AdkMessagingException
                                    (
                                    "Dispatching SIF_Event: " + _state._exception,
                                    fDispatcher.fZone, _state._exception);
                                if (_state._exception is AdkException)
                                {
                                    // ensure that retry support is always enabled
                                    adkme.Retry = ((AdkException)_state._exception).Retry;
                                }

                                AdkUtils._throw(adkme, fDispatcher.fZone.Log);
                            }
                        }

                        //  Return the SIF_Ack code the caller is waiting for
                        if ((Adk.Debug & AdkDebugFlags.Messaging) != 0)
                        {
                            fDispatcher.fZone.Log.Debug
                                ("EvDisp received acknowledgement code " + _state._ack);
                        }

                        result = _state._ack;
                    }
                }
                catch (ThreadInterruptedException ie)
                {
                    if ((Adk.Debug & AdkDebugFlags.Messaging_Event_Dispatching) != 0)
                    {
                        fDispatcher.fZone.Log.Debug("EvDisp interrupted waiting for ack code");
                    }

                    AdkUtils._throw
                        (new AdkMessagingException(ie.ToString(), fDispatcher.fZone),
                          fDispatcher.fZone.Log);
                }

                return result;
            }
Esempio n. 5
0
        public void Query(Query query,
                                  IMessagingListener listener,
                                  string destinationId,
                                  AdkQueryOptions queryOptions)
        {
            if (query == null)
            {
                AdkUtils._throw
                    (new ArgumentException("Query object cannot be null"), Agent.GetLog());
            }

            // Validate that the query object type and SIF Context are valid for this Topic
            if (query.ObjectType != fObjType)
            {
                AdkUtils._throw(new ArgumentException("Query object type: {" + query.ObjectTag +
                        "} does not match Topic object type: " + fObjType + "}"), log);
            }

            if (!query.SifContext.Equals(fContext))
            {
                AdkUtils._throw(new ArgumentException("Query SIF_Context: {" + query.SifContext +
                        "} does not match Topic SIF_Context: " + fContext + "}"), log);
            }

            _checkZones();

            AdkMessagingException err = null;

            //  Send the SIF_Request to each zone
            foreach (ZoneImpl z in fZones)
            {
                try
                {
                    z.Query(query, listener, destinationId, queryOptions);
                }
                catch (Exception th)
                {
                    if (err == null)
                    {
                        err =
                            new AdkMessagingException
                                ("Error querying topic \"" + fObjType + "\"", z);
                    }

                    if (th is AdkException)
                    {
                        err.Add(th);
                    }
                    else
                    {
                        err.Add(new AdkMessagingException(th.ToString(), z));
                    }
                }
            }

            if (err != null)
            {
                AdkUtils._throw(err, Agent.GetLog());
            }
        }
Esempio n. 6
0
        public void PublishEvent(Event data)
        {
            AdkMessagingException err = null;

                _checkZones();

                foreach (ZoneImpl z in fZones)
                {
                    try
                    {
                        z.fPrimitives.SifEvent(z, data, null, null);
                    }
                    catch (Exception th)
                    {
                        if (err == null)
                        {
                            err =
                                new AdkMessagingException
                                    ("Error publishing event to topic \"" + fObjType + "\"", z);
                        }

                        if (th is AdkException)
                        {
                            err.Add(th);
                        }
                        else
                        {
                            err.Add(new AdkMessagingException(th.ToString(), z));
                        }
                    }
                }

                if (err != null)
                {
                    AdkUtils._throw(err, Agent.GetLog());
                }
        }
Esempio n. 7
0
        /// <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 );
                }
            }
        }