Search in sources :

Example 6 with ActiveMQIOErrorException

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

the class ServerSessionImpl method send.

@Override
public synchronized RoutingStatus send(Transaction tx, Message msg, final boolean direct, boolean noAutoCreateQueue) throws Exception {
    final Message message;
    if ((msg.getEncodeSize() > storageManager.getMaxRecordSize()) && !msg.isLargeMessage()) {
        message = messageToLargeMessage(msg);
    } else {
        message = msg;
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeSend(this, tx, message, direct, noAutoCreateQueue));
    }
    // If the protocol doesn't support flow control, we have no choice other than fail the communication
    if (!this.getRemotingConnection().isSupportsFlowControl() && pagingManager.isDiskFull()) {
        ActiveMQIOErrorException exception = ActiveMQMessageBundle.BUNDLE.diskBeyondLimit();
        this.getRemotingConnection().fail(exception);
        throw exception;
    }
    final RoutingStatus result;
    // case the id header already generated.
    if (!message.isLargeMessage()) {
        long id = storageManager.generateID();
        // This will re-encode the message
        message.setMessageID(id);
    }
    SimpleString address = message.getAddressSimpleString();
    if (defaultAddress == null && address != null) {
        defaultAddress = address;
    }
    if (address == null) {
        // We don't want to force a re-encode when the message gets sent to the consumer
        message.setAddress(defaultAddress);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("send(message=" + message + ", direct=" + direct + ") being called");
    }
    if (message.getAddress() == null) {
        // This could happen with some tests that are ignoring messages
        throw ActiveMQMessageBundle.BUNDLE.noAddress();
    }
    if (message.getAddressSimpleString().equals(managementAddress)) {
        // It's a management message
        result = handleManagementMessage(tx, message, direct);
    } else {
        result = doSend(tx, message, address, direct, noAutoCreateQueue);
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterSend(this, tx, message, direct, noAutoCreateQueue, result));
    }
    return result;
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingStatus(org.apache.activemq.artemis.core.postoffice.RoutingStatus)

Example 7 with ActiveMQIOErrorException

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

the class LargeServerMessageImpl method getBodySize.

private long getBodySize() throws ActiveMQException {
    try {
        if (bodySize < 0) {
            if (file != null) {
                bodySize = file.size();
            } else {
                SequentialFile tmpFile = createFile();
                bodySize = tmpFile.size();
                tmpFile.close();
            }
        }
        return bodySize;
    } catch (Exception e) {
        ActiveMQIOErrorException errorException = new ActiveMQIOErrorException();
        errorException.initCause(e);
        throw errorException;
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) 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 8 with ActiveMQIOErrorException

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

the class ServerSessionPacketHandler method onSessionSend.

private void onSessionSend(Packet packet) {
    this.storageManager.setContext(session.getSessionContext());
    try {
        Packet response = null;
        boolean requiresResponse = false;
        try {
            final SessionSendMessage message = (SessionSendMessage) packet;
            requiresResponse = message.isRequiresResponse();
            this.session.send(EmbedMessageUtil.extractEmbedded(message.getMessage()), this.direct);
            if (requiresResponse) {
                response = new NullResponseMessage();
            }
        } catch (ActiveMQIOErrorException e) {
            response = onActiveMQIOErrorExceptionWhileHandlePacket(e, requiresResponse, response, this.session);
        } catch (ActiveMQXAException e) {
            response = onActiveMQXAExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQQueueMaxConsumerLimitReached e) {
            response = onActiveMQQueueMaxConsumerLimitReachedWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQException e) {
            response = onActiveMQExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (Throwable t) {
            response = onCatchThrowableWhileHandlePacket(t, requiresResponse, response, this.session);
        }
        sendResponse(packet, response, false, false);
    } finally {
        this.storageManager.clearContext();
    }
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) NullResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NullResponseMessage) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQQueueMaxConsumerLimitReached(org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)

Example 9 with ActiveMQIOErrorException

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

the class ServerSessionPacketHandler method onSessionConsumerFlowCredit.

private void onSessionConsumerFlowCredit(Packet packet) {
    this.storageManager.setContext(session.getSessionContext());
    try {
        Packet response = null;
        boolean requiresResponse = false;
        try {
            SessionConsumerFlowCreditMessage message = (SessionConsumerFlowCreditMessage) packet;
            session.receiveConsumerCredits(message.getConsumerID(), message.getCredits());
        } catch (ActiveMQIOErrorException e) {
            response = onActiveMQIOErrorExceptionWhileHandlePacket(e, requiresResponse, response, this.session);
        } catch (ActiveMQXAException e) {
            response = onActiveMQXAExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQQueueMaxConsumerLimitReached e) {
            response = onActiveMQQueueMaxConsumerLimitReachedWhileHandlePacket(e, requiresResponse, response);
        } catch (ActiveMQException e) {
            response = onActiveMQExceptionWhileHandlePacket(e, requiresResponse, response);
        } catch (Throwable t) {
            response = onCatchThrowableWhileHandlePacket(t, requiresResponse, response, this.session);
        }
        sendResponse(packet, response, false, false);
    } finally {
        this.storageManager.clearContext();
    }
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SessionConsumerFlowCreditMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionConsumerFlowCreditMessage) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQQueueMaxConsumerLimitReached(org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)

Example 10 with ActiveMQIOErrorException

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

the class JournalImplTestUnit method testVersionCheck.

@Test
public void testVersionCheck() throws Exception {
    setup(10, 10 * 1024, true);
    createJournal();
    startJournal();
    load();
    stopJournal();
    fileFactory.start();
    List<String> files = fileFactory.listFiles(fileExtension);
    for (String fileStr : files) {
        SequentialFile file = fileFactory.createSequentialFile(fileStr);
        ByteBuffer buffer = fileFactory.newBuffer(JournalImpl.SIZE_HEADER);
        for (int i = 0; i < JournalImpl.SIZE_HEADER; i++) {
            buffer.put(Byte.MAX_VALUE);
        }
        buffer.rewind();
        file.open();
        file.position(0);
        file.writeDirect(buffer, sync);
        file.close();
    }
    fileFactory.stop();
    startJournal();
    boolean exceptionHappened = false;
    try {
        load();
    } catch (ActiveMQIOErrorException ioe) {
        exceptionHappened = true;
    } catch (ActiveMQException e) {
        Assert.fail("invalid exception type:" + e.getType());
    }
    Assert.assertTrue("Exception was expected", exceptionHappened);
    stopJournal();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)13 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 ActiveMQQueueMaxConsumerLimitReached (org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)5 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)5 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 NullResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NullResponseMessage)3 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)2 Test (org.junit.Test)2 ByteBuf (io.netty.buffer.ByteBuf)1 RandomAccessFile (java.io.RandomAccessFile)1 List (java.util.List)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Message (org.apache.activemq.artemis.api.core.Message)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1