Search in sources :

Example 16 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class JournalStorageManager method deleteLargeMessageFile.

// This should be accessed from this package only
void deleteLargeMessageFile(final LargeServerMessage largeServerMessage) throws ActiveMQException {
    if (largeServerMessage.getPendingRecordID() < 0) {
        try {
            // The delete file happens asynchronously
            // And the client won't be waiting for the actual file to be deleted.
            // We set a temporary record (short lived) on the journal
            // to avoid a situation where the server is restarted and pending large message stays on forever
            largeServerMessage.setPendingRecordID(storePendingLargeMessage(largeServerMessage.getMessageID(), largeServerMessage.getPendingRecordID()));
        } catch (Exception e) {
            throw new ActiveMQInternalErrorException(e.getMessage(), e);
        }
    }
    final SequentialFile file = largeServerMessage.getFile();
    if (file == null) {
        return;
    }
    if (largeServerMessage.isDurable() && isReplicated()) {
        readLock();
        try {
            if (isReplicated() && replicator.isSynchronizing()) {
                synchronized (largeMessagesToDelete) {
                    largeMessagesToDelete.add(Long.valueOf(largeServerMessage.getMessageID()));
                    confirmLargeMessage(largeServerMessage);
                }
                return;
            }
        } finally {
            readUnLock();
        }
    }
    Runnable deleteAction = new Runnable() {

        @Override
        public void run() {
            try {
                readLock();
                try {
                    if (replicator != null) {
                        replicator.largeMessageDelete(largeServerMessage.getMessageID(), JournalStorageManager.this);
                    }
                    file.delete();
                    // The confirm could only be done after the actual delete is done
                    confirmLargeMessage(largeServerMessage);
                } finally {
                    readUnLock();
                }
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.journalErrorDeletingMessage(e, largeServerMessage.getMessageID());
            }
        }
    };
    if (executor == null) {
        deleteAction.run();
    } else {
        executor.execute(deleteAction);
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)

Example 17 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class LargeServerMessageImpl method validateFile.

// Private -------------------------------------------------------
public synchronized void validateFile() throws ActiveMQException {
    try {
        if (file == null) {
            if (messageID <= 0) {
                throw new RuntimeException("MessageID not set on LargeMessage");
            }
            file = createFile();
            openFile();
            bodySize = file.size();
        }
    } catch (Exception e) {
        // TODO: There is an IO_ERROR on trunk now, this should be used here instead
        throw new ActiveMQInternalErrorException(e.getMessage(), e);
    }
}
Also used : ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)

Example 18 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class AddressControlImpl method sendMessage.

@Override
public String sendMessage(final Map<String, String> headers, final int type, final String body, boolean durable, final String user, final String password) throws Exception {
    try {
        securityStore.check(addressInfo.getName(), CheckType.SEND, new SecurityAuth() {

            @Override
            public String getUsername() {
                return user;
            }

            @Override
            public String getPassword() {
                return password;
            }

            @Override
            public RemotingConnection getRemotingConnection() {
                return null;
            }
        });
        CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
        if (headers != null) {
            for (String header : headers.keySet()) {
                message.putStringProperty(new SimpleString(header), new SimpleString(headers.get(header)));
            }
        }
        message.setType((byte) type);
        message.setDurable(durable);
        message.setTimestamp(System.currentTimeMillis());
        if (body != null) {
            if (type == Message.TEXT_TYPE) {
                message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body));
            } else {
                message.getBodyBuffer().writeBytes(Base64.decode(body));
            }
        }
        message.setAddress(addressInfo.getName());
        postOffice.route(message, true);
        return "" + message.getMessageID();
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 19 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class QueueControlImpl method sendMessage.

@Override
public String sendMessage(final Map<String, String> headers, final int type, final String body, boolean durable, final String user, final String password) throws Exception {
    try {
        securityStore.check(queue.getAddress(), queue.getName(), CheckType.SEND, new SecurityAuth() {

            @Override
            public String getUsername() {
                return user;
            }

            @Override
            public String getPassword() {
                return password;
            }

            @Override
            public RemotingConnection getRemotingConnection() {
                return null;
            }
        });
        CoreMessage message = new CoreMessage(storageManager.generateID(), 50);
        if (headers != null) {
            for (String header : headers.keySet()) {
                message.putStringProperty(new SimpleString(header), new SimpleString(headers.get(header)));
            }
        }
        message.setType((byte) type);
        message.setDurable(durable);
        message.setTimestamp(System.currentTimeMillis());
        if (body != null) {
            if (type == Message.TEXT_TYPE) {
                message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body));
            } else {
                message.getBodyBuffer().writeBytes(Base64.decode(body));
            }
        }
        message.setAddress(queue.getAddress());
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(queue.getID());
        message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, buffer.array());
        postOffice.route(message, true);
        return "" + message.getMessageID();
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 20 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class QueueControlImpl method expireMessages.

@Override
public int expireMessages(final String filterStr) throws Exception {
    checkStarted();
    clearIO();
    try {
        Filter filter = FilterImpl.createFilter(filterStr);
        return queue.expireReferences(filter);
    } catch (ActiveMQException e) {
        throw new IllegalStateException(e.getMessage());
    } finally {
        blockOnIO();
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Filter(org.apache.activemq.artemis.core.filter.Filter)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)139 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15