Search in sources :

Example 6 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class BDBHARemoteReplicationNodeTest method testUpdateRole.

public void testUpdateRole() throws Exception {
    String remoteReplicationName = getName();
    BDBHARemoteReplicationNode remoteReplicationNode = createRemoteReplicationNode(remoteReplicationName);
    // Simulate an election that put the node in REPLICA state
    ((BDBHARemoteReplicationNodeImpl) remoteReplicationNode).setRole(NodeRole.REPLICA);
    Future<Void> future = mock(Future.class);
    when(_facade.transferMasterAsynchronously(remoteReplicationName)).thenReturn(future);
    remoteReplicationNode.setAttributes(Collections.singletonMap(BDBHARemoteReplicationNode.ROLE, NodeRole.MASTER));
    verify(_facade).transferMasterAsynchronously(remoteReplicationName);
    remoteReplicationNode = createRemoteReplicationNode(remoteReplicationName);
    ((BDBHARemoteReplicationNodeImpl) remoteReplicationNode).setRole(NodeRole.REPLICA);
    doThrow(new ExecutionException(new RuntimeException("Test"))).when(future).get(anyLong(), any(TimeUnit.class));
    try {
        remoteReplicationNode.setAttributes(Collections.singletonMap(BDBHARemoteReplicationNode.ROLE, NodeRole.MASTER));
        fail("ConnectionScopedRuntimeException is expected");
    } catch (ConnectionScopedRuntimeException e) {
    // pass
    }
    remoteReplicationNode = createRemoteReplicationNode(remoteReplicationName);
    ((BDBHARemoteReplicationNodeImpl) remoteReplicationNode).setRole(NodeRole.REPLICA);
    doThrow(new ExecutionException(new ServerScopedRuntimeException("Test"))).when(future).get(anyLong(), any(TimeUnit.class));
    try {
        remoteReplicationNode.setAttributes(Collections.singletonMap(BDBHARemoteReplicationNode.ROLE, NodeRole.MASTER));
        fail("ServerScopedRuntimeException is expected");
    } catch (ServerScopedRuntimeException e) {
    // pass
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) TimeUnit(java.util.concurrent.TimeUnit) ExecutionException(java.util.concurrent.ExecutionException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 7 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method createMessage.

@Override
public AMQMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    try {
        AMQShortString exchange = readShortString(payload);
        AMQShortString routingKey = readShortString(payload);
        byte flags = payload.get();
        final MessagePublishInfo publishBody = new MessagePublishInfo(exchange, (flags & IMMEDIATE_MASK) != 0, (flags & MANDATORY_MASK) != 0, routingKey);
        final ContentHeaderBody contentHeaderBody = readContentBody(payload);
        MessageMetaData mmd = new MessageMetaData(publishBody, contentHeaderBody);
        final MessageHandle<MessageMetaData> handle = store.addMessage(mmd);
        handle.addContent(payload);
        final StoredMessage<MessageMetaData> storedMessage = handle.allContentAdded();
        return new AMQMessage(storedMessage, connectionReference);
    } catch (AMQFrameDecodingException | BufferUnderflowException e) {
        throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-9-1 message format", e);
    }
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 8 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.

private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
    // TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
    _destination = destination;
    final Source source = getSource();
    EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
    boolean noLocal = false;
    JMSSelectorFilter messageFilter = null;
    if (destination instanceof ExchangeSendingDestination) {
        options.add(ConsumerOption.ACQUIRES);
        options.add(ConsumerOption.SEES_REQUEUES);
    } else if (destination instanceof StandardSendingDestination) {
        MessageSource messageSource = _destination.getMessageSource();
        if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
            source.setDistributionMode(StdDistMode.COPY);
        }
        Map<Symbol, Filter> filters = source.getFilter();
        Map<Symbol, Filter> actualFilters = new HashMap<>();
        if (filters != null) {
            for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
                if (entry.getValue() instanceof NoLocalFilter) {
                    actualFilters.put(entry.getKey(), entry.getValue());
                    noLocal = true;
                } else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
                    org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
                    try {
                        messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
                        actualFilters.put(entry.getKey(), entry.getValue());
                    } catch (ParseException | SelectorParsingException | TokenMgrError e) {
                        Error error = new Error();
                        error.setCondition(AmqpError.INVALID_FIELD);
                        error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
                        error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
                        throw new AmqpErrorException(error);
                    }
                }
            }
        }
        source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
        if (source.getDistributionMode() != StdDistMode.COPY) {
            options.add(ConsumerOption.ACQUIRES);
            options.add(ConsumerOption.SEES_REQUEUES);
        }
    } else {
        throw new ConnectionScopedRuntimeException("Unknown destination type");
    }
    if (noLocal) {
        options.add(ConsumerOption.NO_LOCAL);
    }
    FilterManager filters = null;
    if (messageFilter != null) {
        filters = new FilterManager();
        filters.add(messageFilter.getName(), messageFilter);
    }
    _consumerOptions = options;
    _consumerFilters = filters;
}
Also used : ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) FilterManager(org.apache.qpid.server.filter.FilterManager) SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue) JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) NoLocalFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) ParseException(org.apache.qpid.server.filter.selector.ParseException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 9 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class TxnCoordinatorReceivingLinkEndpoint method receiveDelivery.

@Override
protected Error receiveDelivery(Delivery delivery) {
    // Only interested in the amqp-value section that holds the message to the coordinator
    try (QpidByteBuffer payload = delivery.getPayload()) {
        List<EncodingRetainingSection<?>> sections = getSectionDecoder().parseAll(payload);
        boolean amqpValueSectionFound = false;
        for (EncodingRetainingSection section : sections) {
            try {
                if (section instanceof AmqpValueSection) {
                    if (amqpValueSectionFound) {
                        throw new ConnectionScopedRuntimeException("Received more than one AmqpValue sections");
                    }
                    amqpValueSectionFound = true;
                    Object command = section.getValue();
                    Session_1_0 session = getSession();
                    AMQPConnection_1_0<?> connection = session.getConnection();
                    connection.receivedComplete();
                    if (command instanceof Declare) {
                        final IdentifiedTransaction txn = connection.createIdentifiedTransaction();
                        _createdTransactions.put(txn.getId(), txn.getServerTransaction());
                        long notificationRepeatPeriod = getSession().getContextValue(Long.class, Session.TRANSACTION_TIMEOUT_NOTIFICATION_REPEAT_PERIOD);
                        connection.registerTransactionTickers(txn.getServerTransaction(), this::doTimeoutAction, notificationRepeatPeriod);
                        Declared state = new Declared();
                        state.setTxnId(Session_1_0.integerToTransactionId(txn.getId()));
                        updateDisposition(delivery.getDeliveryTag(), state, true);
                    } else if (command instanceof Discharge) {
                        Discharge discharge = (Discharge) command;
                        Error error = discharge(discharge.getTxnId(), Boolean.TRUE.equals(discharge.getFail()));
                        final DeliveryState outcome;
                        if (error == null) {
                            outcome = new Accepted();
                        } else if (Arrays.asList(getSource().getOutcomes()).contains(Rejected.REJECTED_SYMBOL)) {
                            final Rejected rejected = new Rejected();
                            rejected.setError(error);
                            outcome = rejected;
                            error = null;
                        } else {
                            outcome = null;
                        }
                        if (error == null) {
                            updateDisposition(delivery.getDeliveryTag(), outcome, true);
                        }
                        return error;
                    } else {
                        throw new ConnectionScopedRuntimeException(String.format("Received unknown command '%s'", command.getClass().getSimpleName()));
                    }
                }
            } finally {
                section.dispose();
            }
        }
        if (!amqpValueSectionFound) {
            throw new ConnectionScopedRuntimeException("Received no AmqpValue section");
        }
    } catch (AmqpErrorException e) {
        return e.getError();
    }
    return null;
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Declared(org.apache.qpid.server.protocol.v1_0.type.transaction.Declared) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 10 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class MessageFormat_0_10 method createMessage.

@Override
public MessageTransferMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    try {
        ServerDecoder serverDecoder = new ServerDecoder(payload);
        int headerCount = serverDecoder.readInt32();
        DeliveryProperties deliveryProperties = null;
        MessageProperties messageProperties = null;
        List<Struct> nonStandard = null;
        for (int i = 0; i < headerCount; i++) {
            final Struct struct = serverDecoder.readStruct32();
            switch(struct.getStructType()) {
                case DeliveryProperties.TYPE:
                    deliveryProperties = (DeliveryProperties) struct;
                    break;
                case MessageProperties.TYPE:
                    messageProperties = (MessageProperties) struct;
                    break;
                default:
                    if (nonStandard == null) {
                        nonStandard = new ArrayList<>();
                    }
                    nonStandard.add(struct);
            }
        }
        Header header = new Header(deliveryProperties, messageProperties, nonStandard);
        MessageMetaData_0_10 metaData = new MessageMetaData_0_10(header, payload.remaining(), System.currentTimeMillis());
        final MessageHandle<MessageMetaData_0_10> handle = store.addMessage(metaData);
        handle.addContent(payload);
        final StoredMessage<MessageMetaData_0_10> storedMessage = handle.allContentAdded();
        return new MessageTransferMessage(storedMessage, connectionReference);
    } catch (BufferUnderflowException e) {
        throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-10 message format", e);
    }
}
Also used : DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)32 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)9 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)6 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)3 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2 ObjectOutputStream (java.io.ObjectOutputStream)2 BufferUnderflowException (java.nio.BufferUnderflowException)2