Search in sources :

Example 6 with ProduceMessageRequest

use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.

the class MessageProducerImpl method validate.

public void validate(Request request) throws ValidationException {
    if (request instanceof ProduceMessageRequest) {
        try {
            ProduceMessageRequest r = (ProduceMessageRequest) request;
            r.setDispatchId(mySession.dispatchId);
            r.setQueueProducerId(producerId);
            MessageImpl msg = SMQPUtil.getMessage(r);
            Destination dest = msg.getJMSDestination();
            // failover
            if (dest instanceof TemporaryQueue || dest instanceof TemporaryTopic) {
                r.setCancelledByValidator(true);
                return;
            }
            msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
            if (r.getSingleMessage() != null)
                r.setSingleMessage(msg);
            else
                r.setMessageCopy(SMQPUtil.toBytes(msg));
        } catch (Exception e) {
            e.printStackTrace();
            throw new ValidationException(e.toString());
        }
    } else {
        CloseProducerRequest r = (CloseProducerRequest) request;
        r.setDispatchId(mySession.dispatchId);
        r.setQueueProducerId(producerId);
    }
}
Also used : ProduceMessageRequest(com.swiftmq.jms.smqp.v630.ProduceMessageRequest) CloseProducerRequest(com.swiftmq.jms.smqp.v630.CloseProducerRequest)

Example 7 with ProduceMessageRequest

use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.

the class MessageProducerImpl method processSend.

void processSend(int producerId, Message message) throws JMSException {
    boolean transacted = mySession.getTransacted();
    MessageImpl msg = (MessageImpl) message;
    if (transacted) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, storeTransactedMessage");
        }
        mySession.storeTransactedMessage(this, msg);
    } else {
        nSend++;
        ProduceMessageReply reply = null;
        boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
        try {
            ProduceMessageRequest request = null;
            if (!replyRequired) {
                byte[] b;
                synchronized (dbos) {
                    dbos.rewind();
                    msg.writeContent(dbos);
                    b = new byte[dbos.getCount()];
                    System.arraycopy(dbos.getBuffer(), 0, b, 0, b.length);
                }
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, null, b);
            } else
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, msg, null);
            request.setReplyRequired(replyRequired);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend ...");
            }
            reply = (ProduceMessageReply) requestRegistry.request(request);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend done, reply=" + reply);
            }
        } catch (Exception e) {
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, exception=" + e);
            }
            e.printStackTrace();
            throw ExceptionConverter.convert(e);
        }
        if (replyRequired) {
            if (reply == null)
                throw new JMSException("Request was cancelled (reply == null)");
            nSend = 0;
            if (!reply.isOk()) {
                throw ExceptionConverter.convert(reply.getException());
            }
            currentDelay = reply.getDelay();
            if (currentDelay > 0) {
                try {
                    Thread.sleep(currentDelay);
                } catch (Exception ignored) {
                }
            }
        }
    }
    // fix 1.2
    msg.reset();
}
Also used : ProduceMessageReply(com.swiftmq.jms.smqp.v630.ProduceMessageReply) ProduceMessageRequest(com.swiftmq.jms.smqp.v630.ProduceMessageRequest)

Example 8 with ProduceMessageRequest

use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.

the class MessageProducerImpl method processSend.

void processSend(int producerId, Message message) throws JMSException {
    boolean transacted = mySession.getTransacted();
    MessageImpl msg = (MessageImpl) message;
    if (transacted) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, storeTransactedMessage");
        }
        mySession.storeTransactedMessage(this, msg);
    } else {
        nSend++;
        ProduceMessageReply reply = null;
        boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
        try {
            ProduceMessageRequest request = null;
            if (!replyRequired) {
                byte[] b;
                synchronized (dbos) {
                    dbos.rewind();
                    msg.writeContent(dbos);
                    b = new byte[dbos.getCount()];
                    System.arraycopy(dbos.getBuffer(), 0, b, 0, b.length);
                }
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, null, b);
            } else
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, msg, null);
            request.setReplyRequired(replyRequired);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend ...");
            }
            reply = (ProduceMessageReply) requestRegistry.request(request);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend done, reply=" + reply);
            }
        } catch (Exception e) {
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, exception=" + e);
            }
            e.printStackTrace();
            throw ExceptionConverter.convert(e);
        }
        if (replyRequired) {
            if (reply == null)
                throw new JMSException("Request was cancelled (reply == null)");
            nSend = 0;
            if (!reply.isOk()) {
                throw ExceptionConverter.convert(reply.getException());
            }
            currentDelay = reply.getDelay();
            if (currentDelay > 0) {
                try {
                    Thread.sleep(currentDelay);
                } catch (Exception ignored) {
                }
            }
        }
    }
    // fix 1.2
    msg.reset();
}
Also used : ProduceMessageReply(com.swiftmq.jms.smqp.v750.ProduceMessageReply) ProduceMessageRequest(com.swiftmq.jms.smqp.v750.ProduceMessageRequest) IllegalStateException(javax.jms.IllegalStateException)

Example 9 with ProduceMessageRequest

use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.

the class MessageProducerImpl method processSend.

void processSend(int producerId, Message message) throws JMSException {
    boolean transacted = mySession.getTransacted();
    MessageImpl msg = (MessageImpl) message;
    if (transacted) {
        if (MessageTracker.enabled) {
            MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, storeTransactedMessage");
        }
        mySession.storeTransactedMessage(this, msg);
    } else {
        nSend++;
        ProduceMessageReply reply = null;
        boolean replyRequired = nSend == replyThreshold || msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT && !ASYNC_SEND;
        try {
            ProduceMessageRequest request = null;
            if (!replyRequired) {
                dbos.rewind();
                msg.writeContent(dbos);
                byte[] b = new byte[dbos.getCount()];
                System.arraycopy(dbos.getBuffer(), 0, b, 0, b.length);
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, null, b);
            } else
                request = new ProduceMessageRequest(this, mySession.dispatchId, producerId, msg, null);
            request.setReplyRequired(replyRequired);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend ...");
            }
            reply = (ProduceMessageReply) requestRegistry.request(request);
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend done, reply=" + reply);
            }
        } catch (Exception e) {
            if (MessageTracker.enabled) {
                MessageTracker.getInstance().track((MessageImpl) msg, new String[] { mySession.myConnection.toString(), mySession.toString(), toString() }, "processSend, exception=" + e);
            }
            e.printStackTrace();
            throw ExceptionConverter.convert(e);
        }
        if (replyRequired) {
            if (reply == null)
                throw new JMSException("Request was cancelled (reply == null)");
            nSend = 0;
            if (!reply.isOk()) {
                throw ExceptionConverter.convert(reply.getException());
            }
            currentDelay = reply.getDelay();
            if (currentDelay > 0) {
                try {
                    Thread.sleep(currentDelay);
                } catch (Exception ignored) {
                }
            }
        }
    }
    // fix 1.2
    msg.reset();
}
Also used : ProduceMessageReply(com.swiftmq.jms.smqp.v610.ProduceMessageReply) ProduceMessageRequest(com.swiftmq.jms.smqp.v610.ProduceMessageRequest)

Example 10 with ProduceMessageRequest

use of com.swiftmq.jms.smqp.v630.ProduceMessageRequest in project swiftmq-client by iitsoftware.

the class MessageProducerImpl method validate.

public void validate(Request request) throws ValidationException {
    if (request instanceof ProduceMessageRequest) {
        try {
            ProduceMessageRequest r = (ProduceMessageRequest) request;
            r.setDispatchId(mySession.dispatchId);
            r.setQueueProducerId(producerId);
            MessageImpl msg = SMQPUtil.getMessage(r);
            Destination dest = msg.getJMSDestination();
            // failover
            if (dest instanceof TemporaryQueue || dest instanceof TemporaryTopic) {
                r.setCancelledByValidator(true);
                return;
            }
            msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
            if (r.getSingleMessage() != null)
                r.setSingleMessage(msg);
            else
                r.setMessageCopy(SMQPUtil.toBytes(msg));
        } catch (Exception e) {
            e.printStackTrace();
            throw new ValidationException(e.toString());
        }
    } else {
        CloseProducerRequest r = (CloseProducerRequest) request;
        r.setDispatchId(mySession.dispatchId);
        r.setQueueProducerId(producerId);
    }
}
Also used : ProduceMessageRequest(com.swiftmq.jms.smqp.v610.ProduceMessageRequest) CloseProducerRequest(com.swiftmq.jms.smqp.v610.CloseProducerRequest)

Aggregations

ProduceMessageRequest (com.swiftmq.jms.smqp.v600.ProduceMessageRequest)2 ProduceMessageRequest (com.swiftmq.jms.smqp.v610.ProduceMessageRequest)2 ProduceMessageRequest (com.swiftmq.jms.smqp.v630.ProduceMessageRequest)2 ProduceMessageRequest (com.swiftmq.jms.smqp.v750.ProduceMessageRequest)2 IllegalStateException (javax.jms.IllegalStateException)2 ProduceMessageReply (com.swiftmq.jms.smqp.v400.ProduceMessageReply)1 ProduceMessageRequest (com.swiftmq.jms.smqp.v400.ProduceMessageRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v500.ProduceMessageReply)1 ProduceMessageRequest (com.swiftmq.jms.smqp.v500.ProduceMessageRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v510.ProduceMessageReply)1 ProduceMessageRequest (com.swiftmq.jms.smqp.v510.ProduceMessageRequest)1 CloseProducerRequest (com.swiftmq.jms.smqp.v600.CloseProducerRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v600.ProduceMessageReply)1 CloseProducerRequest (com.swiftmq.jms.smqp.v610.CloseProducerRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v610.ProduceMessageReply)1 CloseProducerRequest (com.swiftmq.jms.smqp.v630.CloseProducerRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v630.ProduceMessageReply)1 CloseProducerRequest (com.swiftmq.jms.smqp.v750.CloseProducerRequest)1 ProduceMessageReply (com.swiftmq.jms.smqp.v750.ProduceMessageReply)1