Package ca.uhn.hl7v2.protocol

Examples of ca.uhn.hl7v2.protocol.Transportable


            ExpiringTransportable et = myAvailableMessages.get(ackId);
            if (System.currentTimeMillis() > et.expiryTime) {
                it.remove();
               
                //send to an Application
                Transportable out = myContext.getRouter().processMessage(et.transportable);
                sendAppResponse(out);               
            }
        } 
    }
View Full Code Here


    public Transportable receive(String theAckId, long theTimeoutMillis) throws HL7Exception {
        if (!isReserved(theAckId)) {
            reserve(theAckId, theTimeoutMillis);
        }
       
        Transportable in = null;
        long until = System.currentTimeMillis() + theTimeoutMillis;
        do {
            synchronized (this) {
                ExpiringTransportable et = myAvailableMessages.get(theAckId);               
                if (et == null) {
View Full Code Here

        trySend(myContext.getLocallyDrivenTransportLayer(), theMessage);
       
        boolean originalMode = (needAcceptAck == null && needAppAck == null);
        if (originalMode || !needAcceptAck.equals(NE)) {
       
            Transportable response = null;
            int retries = 0;
            do {
                long until = System.currentTimeMillis() + retryIntervalMillis;
                while (response == null && System.currentTimeMillis() < until) {
                    synchronized (this) {
                        ExpiringTransportable et = (ExpiringTransportable) myAcceptAcks.remove(controlId);
                        if (et == null) {
                            cycleIfNeeded(true);
                        } else {
                            response = et.transportable;
                        }
                    }
                    sleepIfNeeded();
                }
               
                if ((response == null && needAcceptAck != null && needAcceptAck.equals(AL))
                        || (response != null && isReject(response))) {
                    log.info("Resending message {}", controlId);
                    trySend(myContext.getLocallyDrivenTransportLayer(), theMessage);
                    response = null;                   
                }
               
                if (response != null && isError(response)) {
                    String[] errMsgPath = {"MSA-3"};
                    String[] errMsg = PreParser.getFields(response.getMessage(), errMsgPath);                   
                    throw new HL7Exception("Error message received: " + errMsg[0]);
                }
               
            } while (response == null && ++retries <= maxRetries);
        }
View Full Code Here

   
    /**
     * Tries to receive a message, and if there is an error reconnects and tries again.
     */
    private Transportable tryReceive(TransportLayer theTransport) throws TransportException {
        Transportable message = null;
        try {
            message = theTransport.receive();           
        } catch (TransportException e) {
            theTransport.disconnect();
            theTransport.connect();
View Full Code Here

     
      cleanReservations();
        cleanAcceptAcks();
        cleanReservedMessages();

        Transportable in = null;
        try {
            if (expectingAck) {
                in = tryReceive(myContext.getLocallyDrivenTransportLayer());
            } else {
                in = tryReceive(myContext.getRemotelyDrivenTransportLayer());
            }
        } catch (TransportException e) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {}
            throw e;
        }
       
        // log
        if (in != null) {
               log.debug("Received message: {}", in.getMessage());
        } else {
          log.debug("Received no message");
        }
       
        // If we have a message, handle it
        if (in != null) {
            String[] fieldPaths = {"MSH-15", "MSH-16", "MSA-1", "MSA-2"};
            String[] fields = PreParser.getFields(in.getMessage(), fieldPaths);        
            String acceptAckNeeded = fields[0];
            String appAckNeeded = fields[1];
            String ackCode = fields[2];
            String ackId = fields[3];
       
            if (ackId != null && ackCode != null && ackCode.startsWith("C")) {
                long expiryTime = System.currentTimeMillis() + 1000 * 60;
                myAcceptAcks.put(ackId, new ExpiringTransportable(in, expiryTime));
            } else {
                AcceptAcknowledger.AcceptACK ack = AcceptAcknowledger.validate(getContext(), in);
           
                if ((acceptAckNeeded != null && acceptAckNeeded.equals(AL))
                    || (acceptAckNeeded != null && acceptAckNeeded.equals(ER) && !ack.isAcceptable())
                    || (acceptAckNeeded != null && acceptAckNeeded.equals(SU) && ack.isAcceptable())) {
                    trySend(myContext.getRemotelyDrivenTransportLayer(), ack.getMessage());   
                }
 
                if (ack.isAcceptable()) {
                    if (isReserved(ackId)) {
                     
                      log.debug("Received expected ACK message with ACK ID: {}", ackId);
                     
                        removeReservation(ackId);
                        long expiryTime = System.currentTimeMillis() + 1000 * 60 * 5;               
                        myAvailableMessages.put(ackId, new ExpiringTransportable(in, expiryTime));
                       
                    } else {

                      log.debug("Sending message to router");
                        Transportable out = myContext.getRouter().processMessage(in);
                        sendAppResponse(out);
                       
                    }
                } else {
                  // TODO: should we do something more here? Might be nice to
View Full Code Here

            ExpiringTransportable et = (ExpiringTransportable) myAvailableMessages.get(ackId);
            if (System.currentTimeMillis() > et.expiryTime) {
                it.remove();
               
                //send to an Application
                Transportable out = myContext.getRouter().processMessage(et.transportable);
                sendAppResponse(out);               
            }
        } 
    }
View Full Code Here

    public Transportable receive(String theAckId, long theTimeoutMillis) throws HL7Exception {
        if (!isReserved(theAckId)) {
            reserve(theAckId, theTimeoutMillis);
        }
       
        Transportable in = null;
        long until = System.currentTimeMillis() + theTimeoutMillis;
        do {
            synchronized (this) {
                ExpiringTransportable et = (ExpiringTransportable) myAvailableMessages.get(theAckId);               
                if (et == null) {
View Full Code Here

  private class MessageHandlerImpl implements IMessageHandler<String> {

    public IResponseSendable<String> messageReceived(IReceivable<String> theMessage) throws MessageProcessingException {

      Transportable received = new TransportableImpl(theMessage.getMessage(), new HashMap<String, Object>(theMessage.getMetadata()));
      Transportable response;
      try {
        response = myApplicationRouter.processMessage(received);
      } catch (HL7Exception e) {
        throw new MessageProcessingException(e);
      }

      return new RawSendable(response.getMessage());
    }
View Full Code Here

    /**
     * @see ca.uhn.hl7v2.protocol.ApplicationRouter#processMessage(ca.uhn.hl7v2.protocol.Transportable)
     */
    public Transportable processMessage(Transportable theMessage) throws HL7Exception {
        String[] result = processMessage(theMessage.getMessage(), theMessage.getMetadata());
        Transportable response = new TransportableImpl(result[0]);
       
        if (result[1] != null) {
            response.getMetadata().put("MSH-18", result[1]);
        }
       
        return response;
    }
View Full Code Here

    public Transportable receive() throws TransportException {
        if (!isConnected()) {
            throw new TransportException("Can't receive because TransportLayer is not connected");
        }
       
        Transportable message = doReceive();
        if (message != null) {
            message.getMetadata().putAll(myCommonMetadata);
        }
       
        log.info("Received: {} ", (message == null ? null : message.getMessage()));
            
        return message;
    }
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.protocol.Transportable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.