/// <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); } }
/// <summary>Returns true if a CE or AE ACK </summary> private static bool isError(NuGenTransportable theMessage) { bool error = false; System.String[] fieldPaths = new System.String[] { "MSA-1" }; System.String[] fields = PreParser.getFields(theMessage.Message, fieldPaths); if (fields[0] != null && (fields[0].Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.CE) || fields[0].Equals(Genetibase.NuGenHL7.protocol.Processor_Fields.AE))) { error = true; } return(error); }
/// <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(); }