Exemplo n.º 1
0
        private SIF_Ack ProcessPush(SifMessagePayload parsed)
        {
            try {
                //  Dispatch. When the result is an Integer it is an ack code to
                //  return; otherwise it is ack data to return and the code is assumed
                //  to be 1 for an immediate acknowledgement.
                int ackStatus = this.Zone.Dispatcher.dispatch(parsed);

                //  Ask the original message to generate a SIF_Ack for itself
                return(parsed.ackStatus(ackStatus));
            }
            catch (SifException se) {
                return
                    (parsed.AckError(se));
            }
            catch (AdkException adke) {
                return
                    (parsed.AckError
                         (SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_GENERIC_ERROR_1,
                         adke.Message));
            }
            catch (Exception thr) {
                if ((Adk.Debug & AdkDebugFlags.Messaging) != 0)
                {
                    this.Zone.Log.Debug("Uncaught exception dispatching push message: " + thr);
                }

                return
                    (parsed.AckError
                         (SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_GENERIC_ERROR_1,
                         "An unexpected error has occurred", thr.ToString()));
            }
        }
        //public string Send(string msg)
        //{
        //   lock (this)
        //   {
        //      fMessages.AddLast(msg);
        //   }
        //   return makeAck();
        //}

        public IMessageInputStream Send( IMessageOutputStream msg )
        {
            lock ( this )
            {
                try
                {
                    MemoryStream stream = new MemoryStream();
                    msg.CopyTo( stream );
                    stream.Seek( 0, SeekOrigin.Begin );
                    SifParser parser = SifParser.NewInstance();
                    SifMessagePayload smp = (SifMessagePayload) parser.Parse( stream, fZone );

                    fMessages.Add( smp );
                    parser = null;

                    SIF_Ack ack = smp.ackStatus( 0 );
                    SIF_Header hdr = ack.Header;
                    hdr.SIF_Timestamp = DateTime.Now;
                    hdr.SIF_MsgId = Adk.MakeGuid();
                    hdr.SIF_SourceId = fZone.Agent.Id;

                    StringWriter str = new StringWriter();
                    SifWriter writer = new SifWriter( str );
                    writer.Write( ack );
                    writer.Flush();
                    writer.Close();
                    writer = null;
                    return new MessageStreamImpl( str.ToString() );
                }
                catch( Exception ex )
                {
                    // Possible error parsing. Write the message to console out
                    Console.Out.WriteLine(msg.Decode());
                    throw new AdkMessagingException(ex.Message, fZone, ex);
                }
            }
        }
Exemplo n.º 3
0
        /**
	 * Sends a SIF_Ack in response to a pulled message
	 * @param sifGetMessageAck The original SIF_Ack from the SIF_GetMessage. This is sometimes null, when
	 * 						parsing fails
	 * @param pulledMEssage The message delivered inside of the above ack. NOTE that even if parsing fails,
	 *          the SIFParser tries to return what it can, and will return this message payload (in getParsed()),
	 *          instead of the above container message.
	 * @param ackStatus The status to ack (NOTE: This is ignored if the err property is set)
	 * @param err The error to set in the SIF_Ack
	 */
	private void sendPushAck(SIF_Ack sifGetMessageAck,
			SifMessagePayload pulledMEssage, int ackStatus, SifException err) {
		try
		{
			SIF_Ack ack2 = null;
			if( fAckAckOnPull && sifGetMessageAck != null){
				ack2 = sifGetMessageAck.ackStatus( ackStatus );
			} else {
				ack2 = pulledMEssage.ackStatus(ackStatus);
			}


			//  If an error occurred processing the message, return
			//  the details in the SIF_Ack
			if( err != null )
			{
				fZone.Log.Debug( "Handling exception by creating a SIF_Error", err );

				SIF_Error newErr = new SIF_Error();
				newErr.SIF_Category =  (int)err.ErrorCategory;
				newErr.SIF_Code = err.ErrorCode;
				newErr.SIF_Desc = err.ErrorDesc;
				newErr.SIF_ExtendedDesc = err.ErrorExtDesc;
				ack2.SIF_Error = newErr;

				//  Get rid of the <SIF_Status>
				SIF_Status status = ack2.SIF_Status;
				if( status != null ) {
					ack2.RemoveChild( status );
				}
			}

			//  Send the ack
			send(ack2);
		}
		catch( Exception ackEx )
		{
			fZone.Log.Debug( "Failed to send acknowledgement to pulled message: " + ackEx, ackEx );
		}
	}