Package ca.uhn.hl7v2.protocol

Examples of ca.uhn.hl7v2.protocol.Transportable


    /**
     * @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


        String appAckNeeded = t.get("/MSH-16");
        String msgId = t.get("/MSH-10");
       
        String messageText = getParser().encode(theMessage);
        Map 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.info("Received: " + (message == null ? null : message.getMessage()));
            
        return message;
    }
View Full Code Here

        if ( !(theMessage instanceof TextMessage)) {
            throw new TransportException("This implementation expects getMessage() to return "
                + " a TextMessage.  Override this method if another message type is to be used");
        }
       
        Transportable result = null;
        try {
            String text = ((TextMessage) theMessage).getText();
            result = new TransportableImpl(text);
            result.getMetadata().putAll(getCommonMetadata());
        } catch (JMSException e) {
            throw new TransportException(e);
        }

        return result;
View Full Code Here

   
    /**
     * @see ca.uhn.hl7v2.protocol.AbstractTransport#doReceive()
     */
    public Transportable doReceive() throws TransportException {
        Transportable result = null;
        try {
            Message message = myInbound.receive();
            result = toTransportable(message);
        } catch (JMSException e) {
            throw new TransportException(e);           
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 (log.isDebugEnabled()) {
          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)) {
                     
                      if (log.isDebugEnabled()) {
                        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 {

                      if (log.isDebugEnabled()) {
                        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

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.