Ejemplo n.º 1
0
        /// <seealso cref="Genetibase.NuGenHL7.protocol.Processor.receive(java.lang.String, long)">
        /// </seealso>
        public virtual NuGenTransportable receive(System.String theAckId, long theTimeoutMillis)
        {
            if (!isReserved(theAckId))
            {
                reserve(theAckId, theTimeoutMillis);
            }

            NuGenTransportable in_Renamed = null;
            long until = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + theTimeoutMillis;

            do
            {
                lock (this)
                {
                    ExpiringTransportable et = (ExpiringTransportable)myAvailableMessages[theAckId];
                    if (et == null)
                    {
                        cycleIfNeeded(false);
                    }
                    else
                    {
                        in_Renamed = et.transportable;
                    }
                }
                sleepIfNeeded();
            }while (in_Renamed == null && (System.DateTime.Now.Ticks - 621355968000000000) / 10000 < until);
            return(in_Renamed);
        }
Ejemplo n.º 2
0
        private void  cleanReservedMessages()
        {
            lock (this)
            {
                System.Collections.IEnumerator it     = new SupportClass.HashSetSupport(myAvailableMessages.Keys).GetEnumerator();
                System.Collections.IList       remove = new System.Collections.ArrayList();
                while (it.MoveNext())
                {
                    System.String         ackId = (System.String)it.Current;
                    ExpiringTransportable et    = (ExpiringTransportable)myAvailableMessages[ackId];
                    if ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 > et.expiryTime)
                    {
                        //myAvailableMessages.Remove(it.Current);
                        remove.Add(it.Current);

                        //send to an Application
                        NuGenTransportable out_Renamed = myContext.Router.processMessage(et.transportable);
                        sendAppResponse(out_Renamed);
                    }

                    foreach (object item in remove)
                    {
                        myAvailableMessages.Remove(item);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <seealso cref="Genetibase.NuGenHL7.protocol.Processor.send(Genetibase.NuGenHL7.protocol.Transportable, int, long)">
        /// </seealso>
        public virtual void  send(NuGenTransportable theMessage, int maxRetries, long retryIntervalMillis)
        {
            System.String[] fieldPaths    = new System.String[] { "MSH-10", "MSH-15", "MSH-16" };
            System.String[] fields        = PreParser.getFields(theMessage.Message, fieldPaths);
            System.String   controlId     = fields[0];
            System.String   needAcceptAck = fields[1];
            System.String   needAppAck    = fields[2];

            checkValidAckNeededCode(needAcceptAck);

            trySend(myContext.LocallyDrivenTransportLayer, theMessage);

            bool originalMode = (needAcceptAck == null && needAppAck == null);

            if (originalMode || !needAcceptAck.Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.NE))
            {
                NuGenTransportable response = null;
                int retries = 0;
                do
                {
                    long until = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + retryIntervalMillis;
                    while (response == null && (System.DateTime.Now.Ticks - 621355968000000000) / 10000 < until)
                    {
                        lock (this)
                        {
                            System.Object tempObject;
                            tempObject = myAcceptAcks[controlId];
                            myAcceptAcks.Remove(controlId);
                            ExpiringTransportable et = (ExpiringTransportable)tempObject;
                            if (et == null)
                            {
                                cycleIfNeeded(true);
                            }
                            else
                            {
                                response = et.transportable;
                            }
                        }
                        sleepIfNeeded();
                    }

                    if ((response == null && needAcceptAck != null && needAcceptAck.Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.AL)) || (response != null && isReject(response)))
                    {
                        trySend(myContext.LocallyDrivenTransportLayer, theMessage);
                        response = null;
                    }

                    if (response != null && isError(response))
                    {
                        System.String[] errMsgPath = new System.String[] { "MSA-3" };
                        System.String[] errMsg     = PreParser.getFields(response.Message, errMsgPath);
                        throw new NuGenHL7Exception("Error message received: " + errMsg[0]);
                    }
                }while (response == null && ++retries <= maxRetries);
            }
        }
Ejemplo n.º 4
0
        /// <summary> Discards expired accept acknowledgements (these are used in retry protocol; see send()).   </summary>
        private void  cleanAcceptAcks()
        {
            lock (this)
            {
                System.Collections.IEnumerator it     = new SupportClass.HashSetSupport(myAcceptAcks.Keys).GetEnumerator();
                System.Collections.IList       remove = new System.Collections.ArrayList();
                while (it.MoveNext())
                {
                    System.String         ackId = (System.String)it.Current;
                    ExpiringTransportable et    = (ExpiringTransportable)myAcceptAcks[ackId];
                    if ((System.DateTime.Now.Ticks - 621355968000000000) / 10000 > et.expiryTime)
                    {
                        //myAcceptAcks.Remove(it.Current);
                        remove.Add(it.Current);
                    }
                }

                foreach (object item in remove)
                {
                    myAcceptAcks.Remove(item);
                }
            }
        }
Ejemplo n.º 5
0
        /// <seealso cref="Genetibase.NuGenHL7.protocol.Processor.cycle(boolean)">
        /// </seealso>
        public virtual void  cycle(bool expectingAck)
        {
            cleanReservations();
            cleanAcceptAcks();
            cleanReservedMessages();

            NuGenTransportable in_Renamed = null;

            try
            {
                if (expectingAck)
                {
                    in_Renamed = tryReceive(myContext.LocallyDrivenTransportLayer);
                }
                else
                {
                    in_Renamed = tryReceive(myContext.RemotelyDrivenTransportLayer);
                }
            }
            catch (NuGenTransportException e)
            {
                try
                {
                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 1000));
                }
                catch (System.Threading.ThreadInterruptedException)
                {
                }
                throw e;
            }

            if (in_Renamed != null)
            {
                System.String[] fieldPaths      = new System.String[] { "MSH-15", "MSH-16", "MSA-1", "MSA-2" };
                System.String[] fields          = PreParser.getFields(in_Renamed.Message, fieldPaths);
                System.String   acceptAckNeeded = fields[0];
                System.String   appAckNeeded    = fields[1];
                System.String   ackCode         = fields[2];
                System.String   ackId           = fields[3];

                if (ackId != null && ackCode != null && ackCode.StartsWith("C"))
                {
                    long expiryTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + 1000 * 60;
                    myAcceptAcks[ackId] = new ExpiringTransportable(this, in_Renamed, expiryTime);
                }
                else
                {
                    NuGenAcceptAcknowledger.AcceptACK ack = NuGenAcceptAcknowledger.validate(Context, in_Renamed);

                    if ((acceptAckNeeded != null && acceptAckNeeded.Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.AL)) || (acceptAckNeeded != null && acceptAckNeeded.Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.ER) && !ack.Acceptable) || (acceptAckNeeded != null && acceptAckNeeded.Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.SU) && ack.Acceptable))
                    {
                        trySend(myContext.RemotelyDrivenTransportLayer, ack.Message);
                    }

                    if (ack.Acceptable)
                    {
                        if (isReserved(ackId))
                        {
                            removeReservation(ackId);
                            long expiryTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 + 1000 * 60 * 5;
                            myAvailableMessages[ackId] = new ExpiringTransportable(this, in_Renamed, expiryTime);
                        }
                        else
                        {
                            NuGenTransportable out_Renamed = myContext.Router.processMessage(in_Renamed);
                            sendAppResponse(out_Renamed);
                        }
                    }
                }
            }
            else
            {
                System.String transport = expectingAck?" Locally driven ":"Remotely driven";
            }

            sleepIfNeeded();
        }