Package ca.uhn.hl7v2.protocol

Examples of ca.uhn.hl7v2.protocol.Transportable


        AcceptValidator[] validators = theContext.getValidators();
        for (int i = 0; i < validators.length && ruling == null; i++) {
            AcceptValidator.AcceptRuling vr = validators[i].check(theMessage);           
            if (!vr.isAcceptable()) {
                String description = (vr.getReasons().length > 0) ? vr.getReasons()[0] : null;
                Transportable ack = makeAcceptAck(theMessage, vr.getAckCode(), vr.getErrorCode(), description);
                ruling = new AcceptACK(false, ack);
            }
        }
       
        if (ruling == null) {
            try {
                theContext.getSafeStorage().store(theMessage);
                Transportable ack = makeAcceptAck(theMessage, Processor.CA, HL7Exception.MESSAGE_ACCEPTED, "");
                ruling = new AcceptACK(true, ack);
            } catch (HL7Exception e) {
                log.error(e.getMessage(), e);
                int code = HL7Exception.APPLICATION_INTERNAL_ERROR;
                Transportable ack = makeAcceptAck(theMessage, Processor.CR, code, e.getMessage());
                ruling = new AcceptACK(false, ack);
            }
        }       
       
        return ruling;
View Full Code Here


        trySend(myContext.getLocallyDrivenTransportLayer(), theMessage);
       
        boolean originalMode = (needAcceptAck == null && needAppAck == null);
        if (originalMode || !NE.equals(needAcceptAck)) {
       
            Transportable response = null;
            int retries = 0;
            do {
                long until = System.currentTimeMillis() + retryIntervalMillis;
                while (response == null && System.currentTimeMillis() < until) {
                    synchronized (this) {
                        ExpiringTransportable et = 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 acceptAckNeeded = null;
//            String appAckNeeded = null;
            String ackCode = null;
            String ackId = null;
           
            try {
              String[] fieldPaths = {"MSH-15", "MSH-16", "MSA-1", "MSA-2"};
              String[] fields = PreParser.getFields(in.getMessage(), fieldPaths);        
        acceptAckNeeded = fields[0];
//        appAckNeeded = fields[1];
        ackCode = fields[2];
        ackId = fields[3];
            } catch (HL7Exception e) {
              log.warn("Failed to parse accept ack fields in incoming message", e);
            }
           
            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 = 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

    /**
     * @see ca.uhn.hl7v2.protocol.impl.AbstractTransport#doReceive()
     */
    public Transportable doReceive() throws TransportException {
        Transportable result = null;
        try {
            String message = myReader.getMessage();
            if (message != null) {
                result = new TransportableImpl(message);               
            }
View Full Code Here

   
    Map<String, Object> metadata = new HashMap<String, Object>();
    InetSocketAddress remoteSocketAddress = (InetSocketAddress) inboundSocket.getRemoteSocketAddress();
    metadata.put(ApplicationRouter.METADATA_KEY_SENDING_IP, remoteSocketAddress.getAddress().getHostAddress());
   
    Transportable response = apps.processMessage(new TransportableImpl(incomingMessageString, metadata));
    return response.getMessage();
  }
View Full Code Here

        String appAckNeeded = t.get("/MSH-16");
        String msgId = t.get("/MSH-10");
       
        String messageText = getParser().encode(theMessage);
        Map<String, Object> metadata = getMetadata(theMessage);
        Transportable out = new TransportableImpl(messageText, metadata);
       
        if (needAck(appAckNeeded)) {
            myProcessor.reserve(msgId, getReceiveTimeout());
        }
       
        myProcessor.send(out, getMaxRetries(), getRetryInterval());
       
        Message in = null;
        if (needAck(appAckNeeded)) {
            Transportable received = myProcessor.receive(msgId, getReceiveTimeout());
            if (received != null && received.getMessage() != null) {
                in = getParser().parse(received.getMessage());
            }
        }
       
        return in;
    }
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.debug("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.