Examples of BridgeMsg


Examples of lt.baltic_amadeus.jqbridge.msg.BridgeMsg

        try {
            do {
                lastFile = queue.receiveFile();
                if (lastFile == null)
                    continue;
                BridgeMsg msg = msgLog.loadMessage(lastFile.getHead(), lastFile.getBody());
                // it's not early receive but we still log it to be compatible with other technologies 
                msgLog.logEarlyReceive(msg.getMessageId());
                return msg;
            } while (!stopping.getValue());
            return null;
        }
        catch (IOException ex) {
View Full Code Here

Examples of lt.baltic_amadeus.jqbridge.msg.BridgeMsg

     * @return reconstructed messages
     * @throws IOException if an I/O error occurs
     */
    public BridgeMsg loadMessage(File head, File body) throws IOException {
        log.debug("loadMessage");
        BridgeMsg msg = new BridgeMsg();
        /* read meta data */
        {
            HeaderReader in = new HeaderReader(new InputStreamReader(new FileInputStream(head), "UTF-8"));
            try {
                while (in.readHeader()) {
                    String name = in.getName();
                    String value = in.getValue();
                    if (name.equalsIgnoreCase(MsgHdr.DUMP_MESSAGE_ID)) {
                        msg.setMessageId(value);
                    }
                    else if (name.equalsIgnoreCase(MsgHdr.DUMP_MESSAGE_TYPE)) {
                        msg.setMsgType(BridgeMsg.getTypeFromMnemonic(value));
                    }
                    else if (name.equalsIgnoreCase(MsgHdr.DUMP_PERSISTENCE)) {
                        msg.setPersistence(BridgePersistence.fromMnemonic(value));
                    }
                    else {
                        // skip
                    }
                }
            }
            finally {
                in.close();
            }
        }
        /* read payload */
        {
            FileInputStream inFile = new FileInputStream(body);
            try {
                switch (msg.getMsgType()) {
                case BridgeMsg.TYPE_BYTES:
                    log.debug("Payload TYPE_BYTES");
                    byte buf[] = new byte[8192];
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    for (;;) {
                        int count = inFile.read(buf);
                        if (count < 0)
                            break;
                        out.write(buf, 0, count);
                    }
                    msg.setByteData(out.toByteArray());
                    break;
                case BridgeMsg.TYPE_TEXT:
                    log.debug("Payload TYPE_TEXT");
                    char cbuf[] = new char[4096];
                    CharArrayWriter cout = new CharArrayWriter();
                    InputStreamReader cin = new InputStreamReader(inFile, "UTF-8");
                    for (;;) {
                        int count = cin.read(cbuf);
                        if (count < 0)
                            break;
                        cout.write(cbuf, 0, count);
                    }
                    msg.setTextData(cout.toString());
                }
            }
            finally {
                inFile.close();
            }
View Full Code Here

Examples of lt.baltic_amadeus.jqbridge.msg.BridgeMsg

                }
            }
            log.debug("queue.get() returned");
            msgLog.logEarlyReceive(createBridgeMessageId(mqMsg.messageId));
            /* build bridge message */
            BridgeMsg msg = new BridgeMsg();
            /* message payload */
            if (mqMsg.format.equals(MQC.MQFMT_STRING)) {
                /* text message */
                msg.setMsgType(BridgeMsg.TYPE_TEXT);
                String textData = mqMsg.readStringOfByteLength(mqMsg.getDataLength());
                msg.setTextData(textData);
            }
            else {
                /* anything other is binary data */
                msg.setMsgType(BridgeMsg.TYPE_BYTES);
                int len = mqMsg.getDataLength();
                byte[] data = new byte[len];
                mqMsg.readFully(data);
                msg.setByteData(data);
            }
            /* message headers */
            msg.setMessageId(createBridgeMessageId(mqMsg.messageId));
            msg.setPersistence(createBridgePersistence(mqMsg.persistence));
            return msg;
        }
        catch (IOException ex) {
            throw new CommunicationException(this, ex);
        }
View Full Code Here

Examples of lt.baltic_amadeus.jqbridge.msg.BridgeMsg

        }
    }

    private BridgeMsg createBridgeMsg(Message jMsg) throws BridgeException, JMSException {
        /* Create message instance */
        BridgeMsg brMsg = new BridgeMsg();
        /* Set message headers */
        brMsg.setMessageId(jMsg.getJMSMessageID());
        brMsg.setPersistence(createPersistence(jMsg.getJMSDeliveryMode()));
        /* Copy payload */
        if (jMsg instanceof TextMessage) {
            brMsg.setMsgType(BridgeMsg.TYPE_TEXT);
            brMsg.setTextData(((TextMessage)jMsg).getText());
        }
        else if (jMsg instanceof BytesMessage) {
            brMsg.setMsgType(BridgeMsg.TYPE_BYTES);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buf = new byte[8192];
            BytesMessage bMsg = (BytesMessage) jMsg;
            for(;;) {
                int amount = bMsg.readBytes(buf);
                if (amount <= 0)
                    break;
                out.write(buf, 0, amount);
                if (amount < buf.length)
                    break;
            }
            brMsg.setByteData(out.toByteArray());
        }
        else {
            brMsg.setMsgType(BridgeMsg.TYPE_NONE);
        }
        /* Return generated message */
        return brMsg;
    }
View Full Code Here

Examples of lt.baltic_amadeus.jqbridge.msg.BridgeMsg

        }
    }

    private BridgeMsg createBridgeMsg(Message jMsg) throws BridgeException, JMSException {
        /* Create message instance */
        BridgeMsg brMsg = new BridgeMsg();
        /* Set message headers */
        brMsg.setMessageId(jMsg.getJMSMessageID());
        brMsg.setPersistence(createPersistence(jMsg.getJMSDeliveryMode()));
        /* Copy payload */
        if (jMsg instanceof TextMessage) {
            brMsg.setMsgType(BridgeMsg.TYPE_TEXT);
            brMsg.setTextData(((TextMessage)jMsg).getText());
        }
        else if (jMsg instanceof BytesMessage) {
            brMsg.setMsgType(BridgeMsg.TYPE_BYTES);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buf = new byte[8192];
            BytesMessage bMsg = (BytesMessage) jMsg;
            for(;;) {
                int amount = bMsg.readBytes(buf);
                if (amount <= 0)
                    break;
                out.write(buf, 0, amount);
                if (amount < buf.length)
                    break;
            }
            brMsg.setByteData(out.toByteArray());
        }
        else {
            brMsg.setMsgType(BridgeMsg.TYPE_NONE);
        }
        /* Return generated message */
        return brMsg;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.