Package org.exolab.jms.message

Examples of org.exolab.jms.message.MessageImpl


     * @throws JMSException if the JMS provider fails to create this message due
     *                      to some internal error.
     */
    public Message createMessage() throws JMSException {
        ensureOpen();
        return new MessageImpl();
    }
View Full Code Here


     * @throws JMSException if the message can't be acknowledged
     */
    public void acknowledgeMessage(Message message) throws JMSException {
        ensureOpen();
        if (_ackMode == Session.CLIENT_ACKNOWLEDGE) {
            MessageImpl impl = (MessageImpl) message;
            getServerSession().acknowledgeMessage(impl.getConsumerId(),
                                                  impl.getAckMessageID());
        }
    }
View Full Code Here

     *         if the timeout expires or the consumer concurrently closed
     * @throws JMSException if the next message can't be received
     */
    public MessageImpl receive(long consumerId, long timeout)
            throws JMSException {
        MessageImpl message = null;
        ensureOpen();

        synchronized (_receiveLock) {
            if (_blockingConsumer != -1) {
                throw new IllegalStateException(
                        "Session cannot be accessed concurrently");
            }

            _blockingConsumer = consumerId;

            long start = (timeout != 0) ? System.currentTimeMillis() : 0;
            try {
                while (message == null && !isClosed()) {
                    if (timeout == 0) {
                        message = getServerSession().receive(consumerId, 0);
                    } else {
                        message = getServerSession().receive(consumerId,
                                                             timeout);
                    }
                    if (message == null && !isClosed()) {
                        // no message received in the required time.
                        // Wait for a notification from the server that
                        // a message has become available.
                        try {
                            if (timeout == 0) {
                                _receiveLock.wait();
                            } else {
                                long elapsed = System.currentTimeMillis()
                                        - start;
                                if (elapsed >= timeout) {
                                    // no message received in the required time
                                    break;
                                } else {
                                    // adjust the timeout so that the client
                                    // only waits as long as the original
                                    // timeout
                                    timeout -= elapsed;
                                }
                                _receiveLock.wait(timeout);
                            }
                        } catch (InterruptedException ignore) {
                            // no-op
                        }
                    }
                }

                if (message != null) {
                    message.setSession(this);
                    if (_ackMode == AUTO_ACKNOWLEDGE
                            || _ackMode == DUPS_OK_ACKNOWLEDGE) {
                        getServerSession().acknowledgeMessage(
                                message.getConsumerId(),
                                message.getMessageId().toString());
                    }
                }
            } finally {
                _blockingConsumer = -1;
            }
View Full Code Here

     *         if one is not available
     * @throws JMSException if the next message can't be received
     */
    public MessageImpl receiveNoWait(long consumerId) throws JMSException {
        ensureOpen();
        MessageImpl message = getServerSession().receiveNoWait(consumerId);
        if (message != null) {
            message.setSession(this);
            if (_ackMode == AUTO_ACKNOWLEDGE
                    || _ackMode == DUPS_OK_ACKNOWLEDGE) {
                getServerSession().acknowledgeMessage(
                        message.getConsumerId(),
                        message.getMessageId().toString());
            }
        }
        return message;
    }
View Full Code Here

                if (records[index] instanceof TransactionalObjectWrapper) {
                    TransactionalObjectWrapper wrapper =
                            (TransactionalObjectWrapper) records[index];
                    if (wrapper.isPublishedMessage()) {
                        // send the published message to the message manager
                        MessageImpl message = (MessageImpl) wrapper.getObject();
                        _messages.add(message);

                    } else if (wrapper.isReceivedMessage()) {
                        // if it is a received message handle then simply
                        // delete it and mark it as acknowledged
View Full Code Here

     * @throws PersistenceException - an sql related error
     */
    public MessageImpl get(Connection connection, String messageId)
        throws PersistenceException {

        MessageImpl result = null;
        PreparedStatement select = null;
        ResultSet set = null;
        try {
            select = connection.prepareStatement(
                "select messageBlob, processed from messages where messageId=?");

            select.setString(1, messageId);
            set = select.executeQuery();
            if (set.next()) {
                result = deserialize(set.getBytes(1));
                result.setProcessed((set.getInt(2) == 1 ? true : false));
            }
        } catch (SQLException exception) {
            throw new PersistenceException(
                "Failed to retrieve message, id=" + messageId, exception);
        } finally {
View Full Code Here

            // now iterate through the result set
            int count = 0;
            long lastTimeStamp = time;
            while (set.next()) {
                MessageImpl m = deserialize(set.getBytes(3));
                m.setProcessed((set.getInt(2) == 1 ? true : false));
                messages.add(m);
                if (++count > 200) {
                    // if there are more than two hundred rows then exist
                    // the loop after 200 messages have been retrieved
                    // and the timestamp has changed.
View Full Code Here

            select = connection.prepareStatement(
                "select messageblob from messages where processed=0");
            set = select.executeQuery();
            // now iterate through the result set
            while (set.next()) {
                MessageImpl m = deserialize(set.getBytes(1));
                m.setProcessed(false);
                messages.add(m);
            }
        } catch (SQLException exception) {
            throw new PersistenceException(
                "Failed to retrieve unprocessed messages", exception);
View Full Code Here

     *
     * @param blob the serialized message
     * @return the re-constructed message
     */
    public MessageImpl deserialize(byte[] blob) throws PersistenceException {
        MessageImpl message = null;

        if (blob != null) {
            ObjectInputStream istream = null;
            try {
                ByteArrayInputStream bstream = new ByteArrayInputStream(blob);
View Full Code Here

        while (!cancel.get() && (handle = _handles.removeFirst()) != null) {
            if (_log.isDebugEnabled()) {
                _log.debug("doReceive() - next available=" + handle.getMessageId());
            }
            // ensure that the message still exists
            MessageImpl message = handle.getMessage();
            if (message != null) {
                if (selects(message)) {
                    // got a message which is applicable for the endpoint
                    result = handle;
                    break;
View Full Code Here

TOP

Related Classes of org.exolab.jms.message.MessageImpl

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.