Search in sources :

Example 11 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class TargetLink method handleTransactionRequest.

private void handleTransactionRequest(TransferFrame frame) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, frame=" + frame);
    AMQPMessage msg = null;
    try {
        msg = new AMQPMessage(frame.getPayload());
    } catch (Exception e) {
        e.printStackTrace();
        new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Exception during decode of a message: " + e));
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/handleTransactionRequest, msg=" + msg);
    if (msg.getAmqpValue() == null)
        throw new SessionEndException(AmqpError.NOT_FOUND, new AMQPString("Missing amqp-value message body in transaction request!"));
    AMQPType bare = msg.getAmqpValue().getValue();
    AMQPDescribedConstructor constructor = bare.getConstructor();
    if (constructor == null)
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Missing constructor: " + bare));
    if (!AMQPTypeDecoder.isList(constructor.getFormatCode()))
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Message body is not of a list type, code=0x" + Integer.toHexString(bare.getCode()) + ", bare=" + bare));
    AMQPType descriptor = constructor.getDescriptor();
    int code = descriptor.getCode();
    try {
        if (AMQPTypeDecoder.isULong(code)) {
            long type = ((AMQPUnsignedLong) descriptor).getValue();
            if (type == Declare.DESCRIPTOR_CODE)
                handleDeclare(new Declare(((AMQPList) bare).getValue()));
            else if (type == Discharge.DESCRIPTOR_CODE)
                handleDischarge(new Discharge(((AMQPList) bare).getValue()));
            else
                throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
        } else if (AMQPTypeDecoder.isSymbol(code)) {
            String type = ((AMQPSymbol) descriptor).getValue();
            if (type.equals(Declare.DESCRIPTOR_NAME))
                handleDeclare(new Declare(((AMQPList) bare).getValue()));
            else if (type.equals(Discharge.DESCRIPTOR_NAME))
                handleDischarge(new Discharge(((AMQPList) bare).getValue()));
            else
                throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid descriptor type: " + type + ", bare=" + bare));
        } else
            throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare));
    } catch (Exception e) {
        e.printStackTrace();
        throw new SessionEndException(AmqpError.DECODE_ERROR, new AMQPString(e.toString()));
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Example 12 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method discharge.

public void discharge(TxnIdIF btxnId, boolean rollback) throws EndWithErrorException {
    String txnId = new String(((TransactionId) btxnId).getValue());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", rollback=" + rollback);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.remove(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.inboundTxEntryMap != null) {
            for (Iterator iter = activeTxEntry.inboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                InboundTxEntry inboundTxEntry = (InboundTxEntry) entry.getValue();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", linkName=" + entry.getKey());
                if (rollback)
                    inboundTxEntry.tx.rollback();
                else
                    inboundTxEntry.tx.commit();
                inboundTxEntry.targetLink.setFlowcontrolDelay(inboundTxEntry.tx.getFlowControlDelay());
                inboundTxEntry.targetLink.decreaseActiveTransactions();
                inboundTxEntry.targetLink.closeResource();
            }
            activeTxEntry.inboundTxEntryMap.clear();
        }
        if (activeTxEntry.outboundTxEntryMap != null) {
            for (Iterator iter = activeTxEntry.outboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                long deliveryId = ((Long) entry.getKey()).longValue();
                OutboundTxEntry outboundTxEntry = (OutboundTxEntry) entry.getValue();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", deliveryId=" + deliveryId);
                if (rollback) {
                    if (outboundTxEntry.sourceLink != null)
                        sessionHandler.settleOutbound(deliveryId, RELEASED);
                } else
                    sessionHandler.settleOutbound(deliveryId, outboundTxEntry.deliveryStateIF);
                if (outboundTxEntry.sourceLink != null) {
                    outboundTxEntry.sourceLink.decreaseActiveTransactions();
                    outboundTxEntry.sourceLink.closeResource();
                }
            }
            activeTxEntry.outboundTxEntryMap.clear();
            sessionHandler.sendOutboundDeliveries();
        }
    } catch (QueueException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
    } finally {
        lock.unlock();
    }
}
Also used : AMQPString(com.swiftmq.amqp.v100.types.AMQPString) Iterator(java.util.Iterator) QueueException(com.swiftmq.swiftlet.queue.QueueException) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method addToTransaction.

public void addToTransaction(TxnIdIF btxnId, String linkName, MessageImpl message, TargetLink targetLink) throws EndWithErrorException {
    String txnId = new String(((TransactionId) btxnId).getValue());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", message=" + message);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.inboundTxEntryMap == null)
            activeTxEntry.inboundTxEntryMap = new HashMap();
        InboundTxEntry inboundTxEntry = (InboundTxEntry) activeTxEntry.inboundTxEntryMap.get(linkName);
        try {
            if (inboundTxEntry == null) {
                QueuePushTransaction tx = targetLink.getQueueSender().createTransaction();
                targetLink.increaseActiveTransactions();
                inboundTxEntry = new InboundTxEntry(tx, targetLink);
                activeTxEntry.inboundTxEntryMap.put(linkName, inboundTxEntry);
            }
            ((QueuePushTransaction) inboundTxEntry.tx).putMessage(message);
        } catch (QueueException e) {
            throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
        }
    } finally {
        lock.unlock();
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) HashMap(java.util.HashMap) QueueException(com.swiftmq.swiftlet.queue.QueueException) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString)

Example 14 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class JMSMappingOutboundTransformer method transform.

public void transform(Delivery delivery) throws AMQPException, JMSException {
    jmsTypeProp = getValue(PROP_JMS_TYPE, null);
    MessageImpl message = delivery.getMessage();
    if (message.propertyExists(amqpNative) && message.getBooleanProperty(amqpNative))
        throw new JMSException("Message is an AMQP native transformation");
    try {
        AMQPMessage amqpMessage = new AMQPMessage();
        Header header = new Header();
        int deliveryMode = message.getJMSDeliveryMode();
        header.setDurable(new AMQPBoolean(deliveryMode == DeliveryMode.PERSISTENT));
        header.setPriority(new AMQPUnsignedByte(message.getJMSPriority()));
        header.setDeliveryCount(new AMQPUnsignedInt(delivery.getMessageIndex().getDeliveryCount() - 1));
        long ttl = message.getJMSExpiration();
        if (ttl > 0) {
            if (message.propertyExists(Util.PROP_EXPIRATION_CURRENT_TIME_ADD))
                header.setTtl(new Milliseconds(ttl - message.getLongProperty(Util.PROP_EXPIRATION_CURRENT_TIME_ADD)));
        }
        Properties properties = new Properties();
        String messageId = message.getJMSMessageID();
        if (messageId != null)
            properties.setMessageId(new MessageIdString(message.getJMSMessageID()));
        if (message.propertyExists(Util.PROP_AMQP_TO_ADDRESS))
            properties.setTo(new AddressString(message.getStringProperty(Util.PROP_AMQP_TO_ADDRESS)));
        else
            properties.setTo(new AddressString(message.getJMSDestination().toString()));
        Destination replyTo = message.getJMSReplyTo();
        if (replyTo != null)
            properties.setReplyTo(new AddressString(replyTo.toString()));
        String correlationId = message.getJMSCorrelationID();
        if (correlationId != null)
            properties.setCorrelationId(new MessageIdString(correlationId));
        if (ttl > 0)
            properties.setAbsoluteExpiryTime(new AMQPTimestamp(ttl));
        long timestamp = message.getJMSTimestamp();
        if (timestamp > 0)
            properties.setCreationTime(new AMQPTimestamp(timestamp));
        Map daMap = null;
        Map maMap = null;
        Map ftMap = null;
        Map apMap = null;
        String firstAcquirerName = prefixVendor + "FirstAcquirer";
        String subject = prefixVendor + "Subject";
        String contentType = prefixVendor + "ContentType";
        String contentEncoding = prefixVendor + "ContentEncoding";
        String replyToGroupId = prefixVendor + "ReplyToGroupID";
        for (Enumeration _enum = message.getPropertyNames(); _enum.hasMoreElements(); ) {
            String name = (String) _enum.nextElement();
            if (name.equals(amqpNative) || name.equals(messageFormat) || name.equals(Util.PROP_EXPIRATION_CURRENT_TIME_ADD) || name.equals(Util.PROP_AMQP_TO_ADDRESS))
                continue;
            if (name.equals(firstAcquirerName))
                header.setFirstAcquirer(new AMQPBoolean(message.getBooleanProperty(firstAcquirerName)));
            else if (name.equals(MessageImpl.PROP_USER_ID))
                properties.setUserId(new AMQPBinary(message.getStringProperty(MessageImpl.PROP_USER_ID).getBytes()));
            else if (name.equals(subject))
                properties.setSubject(new AMQPString(message.getStringProperty(subject)));
            else if (name.equals(contentType))
                properties.setContentType(new AMQPSymbol(message.getStringProperty(contentType)));
            else if (name.equals(contentEncoding))
                properties.setContentEncoding(new AMQPSymbol(message.getStringProperty(contentEncoding)));
            else if (name.equals("JMSXGroupID") && message.getObjectProperty(Util.PROP_GROUP_ID) instanceof String)
                properties.setGroupId(new AMQPString(message.getStringProperty(Util.PROP_GROUP_ID)));
            else if (name.equals("JMSXGroupSeq") && message.getObjectProperty(Util.PROP_GROUP_SEQ) instanceof Long)
                properties.setGroupSequence(new SequenceNo(message.getLongProperty(Util.PROP_GROUP_SEQ)));
            else if (name.equals(replyToGroupId))
                properties.setReplyToGroupId(new AMQPString(message.getStringProperty(replyToGroupId)));
            else if (name.startsWith(prefixDA)) {
                if (daMap == null)
                    daMap = new HashMap();
                daMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixDA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else if (name.startsWith(prefixMA)) {
                if (maMap == null)
                    maMap = new HashMap();
                maMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixMA.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else if (name.startsWith(prefixFT)) {
                if (ftMap == null)
                    ftMap = new HashMap();
                ftMap.put(new AMQPSymbol(nameTranslator.translate(name.substring(prefixFT.length()))), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            } else {
                if (apMap == null)
                    apMap = new HashMap();
                apMap.put(new AMQPString(nameTranslator.translate(name)), Util.convertJMStoAMQP(message.getObjectProperty(name)));
            }
        }
        if (message.getJMSType() != null) {
            if (jmsTypeProp != null) {
                if (apMap == null)
                    apMap = new HashMap();
                apMap.put(new AMQPString(jmsTypeProp), Util.convertJMStoAMQP(message.getJMSType()));
            } else {
                if (maMap == null)
                    maMap = new HashMap();
                maMap.put(new AMQPSymbol("x-opt-jms-type"), new AMQPString(message.getJMSType()));
            }
        }
        amqpMessage.setHeader(header);
        amqpMessage.setProperties(properties);
        if (daMap != null)
            amqpMessage.setDeliveryAnnotations(new DeliveryAnnotations(daMap));
        if (maMap != null)
            amqpMessage.setMessageAnnotations(new MessageAnnotations(maMap));
        if (apMap != null)
            amqpMessage.setApplicationProperties(new ApplicationProperties(apMap));
        if (ftMap != null)
            amqpMessage.setFooter(new Footer(ftMap));
        bodyFactory.createBody(message, amqpMessage);
        delivery.setAmqpMessage(amqpMessage);
        dbos.rewind();
        amqpMessage.writeContent(dbos);
        byte[] payload = new byte[dbos.getCount()];
        System.arraycopy(dbos.getBuffer(), 0, payload, 0, dbos.getCount());
        delivery.setData(payload);
        delivery.setMessageFormat(0);
    } catch (IOException e) {
        e.printStackTrace();
        throw new AMQPException(e.toString());
    }
}
Also used : Destination(javax.jms.Destination) SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) HashMap(java.util.HashMap) JMSException(javax.jms.JMSException) Enumeration(java.util.Enumeration) IOException(java.io.IOException) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) MessageImpl(com.swiftmq.jms.MessageImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class AMQPHandler method visit.

public void visit(POSendOpen po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    Entity connectionTemplate = versionedConnection.getConnectionTemplate();
    myIdleTimeout = ((Long) connectionTemplate.getProperty("idle-timeout").getValue()).longValue();
    OpenFrame frame = new OpenFrame(0);
    frame.setContainerId(new AMQPString(SwiftletManager.getInstance().getRouterName()));
    frame.setChannelMax(new AMQPUnsignedShort(((Integer) connectionTemplate.getProperty("max-channel-number").getValue()).intValue()));
    frame.setMaxFrameSize(new AMQPUnsignedInt(((Long) connectionTemplate.getProperty("max-frame-size").getValue()).longValue()));
    try {
        AMQPArray offeredCapas = new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPSymbol[] { new AMQPSymbol(CAPABILITY_NO_LOCAL), new AMQPSymbol(CAPABILITY_SELECTOR) });
        frame.setOfferedCapabilities(offeredCapas);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (myIdleTimeout > 0) {
        frame.setIdleTimeOut(new Milliseconds(myIdleTimeout));
        idleTimeoutChecker = new TimerListener() {

            public void performTimeAction() {
                dispatch(new POCheckIdleTimeout(null));
            }
        };
        ctx.timerSwiftlet.addTimerListener(myIdleTimeout / 2, idleTimeoutChecker);
    }
    versionedConnection.send(AMQPHandlerFactory.AMQP_INIT);
    versionedConnection.send(frame);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : Entity(com.swiftmq.mgmt.Entity) IOException(java.io.IOException) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) TimerListener(com.swiftmq.swiftlet.timer.event.TimerListener)

Aggregations

AMQPString (com.swiftmq.amqp.v100.types.AMQPString)29 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)17 HashMap (java.util.HashMap)14 Map (java.util.Map)14 IOException (java.io.IOException)13 AMQPContext (com.swiftmq.amqp.AMQPContext)9 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)6 QueueException (com.swiftmq.swiftlet.queue.QueueException)5 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)4 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)4 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)4 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)4 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 Iterator (java.util.Iterator)4 Connection (com.swiftmq.amqp.v100.client.Connection)3