Search in sources :

Example 41 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class SendingLinkEndpoint method receiveFlow.

@Override
public void receiveFlow(final Flow flow) {
    UnsignedInteger receiverDeliveryCount = flow.getDeliveryCount();
    UnsignedInteger receiverLinkCredit = flow.getLinkCredit();
    setDrain(flow.getDrain());
    Map<Symbol, Object> properties = flow.getProperties();
    if (properties != null) {
        final Binary transactionId = (Binary) properties.get(Symbol.valueOf("txn-id"));
        if (transactionId != null) {
            try {
                getSession().getTransaction(transactionId);
            } catch (UnknownTransactionException e) {
                close(new Error(TransactionError.UNKNOWN_ID, e.getMessage()));
                return;
            }
        }
        _transactionId = transactionId;
    }
    if (receiverDeliveryCount == null) {
        setLinkCredit(receiverLinkCredit);
    } else {
        // 2.6.7 Flow Control : link_credit_snd := delivery_count_rcv + link_credit_rcv - delivery_count_snd
        UnsignedInteger limit = receiverDeliveryCount.add(receiverLinkCredit);
        if (limit.compareTo(getDeliveryCount().unsignedIntegerValue()) <= 0) {
            setLinkCredit(UnsignedInteger.valueOf(0));
        } else {
            setLinkCredit(limit.subtract(getDeliveryCount().unsignedIntegerValue()));
        }
    }
    // send flow when echo=true or drain=true but link credit is zero
    boolean sendFlow = Boolean.TRUE.equals(flow.getEcho()) || (Boolean.TRUE.equals(flow.getDrain()) && getLinkCredit().equals(UnsignedInteger.ZERO));
    flowStateChanged();
    if (sendFlow) {
        sendFlow();
    }
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) 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) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 42 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class StandardReceivingLinkEndpoint method receiveDelivery.

@Override
protected Error receiveDelivery(Delivery delivery) {
    ReceiverSettleMode transferReceiverSettleMode = delivery.getReceiverSettleMode();
    if (delivery.getResume()) {
        DeliveryState deliveryState = _unsettled.get(delivery.getDeliveryTag());
        if (deliveryState instanceof Outcome) {
            boolean settled = shouldReceiverSettleFirst(transferReceiverSettleMode);
            updateDisposition(delivery.getDeliveryTag(), deliveryState, settled);
            return null;
        } else {
        // TODO: QPID-7845: create message ?
        }
    } else {
        ServerMessage<?> serverMessage;
        UnsignedInteger messageFormat = delivery.getMessageFormat();
        DeliveryState xfrState = delivery.getState();
        MessageFormat format = MessageFormatRegistry.getFormat(messageFormat.intValue());
        if (format != null) {
            try (QpidByteBuffer payload = delivery.getPayload()) {
                serverMessage = format.createMessage(payload, getAddressSpace().getMessageStore(), getSession().getConnection().getReference());
            } catch (AmqpErrorRuntimeException e) {
                return e.getCause().getError();
            }
        } else {
            final Error err = new Error();
            err.setCondition(AmqpError.NOT_IMPLEMENTED);
            err.setDescription("Unknown message format: " + messageFormat);
            return err;
        }
        MessageReference<?> reference = serverMessage.newReference();
        try {
            Binary transactionId = null;
            if (xfrState != null) {
                if (xfrState instanceof TransactionalState) {
                    transactionId = ((TransactionalState) xfrState).getTxnId();
                }
            }
            final ServerTransaction transaction;
            boolean setRollbackOnly = true;
            if (transactionId != null) {
                try {
                    transaction = getSession().getTransaction(transactionId);
                } catch (UnknownTransactionException e) {
                    return new Error(TransactionError.UNKNOWN_ID, String.format("transaction-id '%s' is unknown.", transactionId));
                }
                if (!(transaction instanceof AutoCommitTransaction)) {
                    transaction.addPostTransactionAction(new ServerTransaction.Action() {

                        @Override
                        public void postCommit() {
                            updateDisposition(delivery.getDeliveryTag(), null, true);
                        }

                        @Override
                        public void onRollback() {
                            updateDisposition(delivery.getDeliveryTag(), null, true);
                        }
                    });
                }
            } else {
                transaction = new AsyncAutoCommitTransaction(getAddressSpace().getMessageStore(), this);
            }
            try {
                Session_1_0 session = getSession();
                session.getAMQPConnection().checkAuthorizedMessagePrincipal(serverMessage.getMessageHeader().getUserId());
                Outcome outcome;
                if (serverMessage.isPersistent() && !getAddressSpace().getMessageStore().isPersistent()) {
                    final Error preconditionFailedError = new Error(AmqpError.PRECONDITION_FAILED, "Non-durable message store cannot accept durable message.");
                    if (_rejectedOutcomeSupportedBySource) {
                        final Rejected rejected = new Rejected();
                        rejected.setError(preconditionFailedError);
                        outcome = rejected;
                    } else {
                        // TODO - disposition not updated for the non-transaction case
                        return preconditionFailedError;
                    }
                } else {
                    try {
                        getReceivingDestination().send(serverMessage, transaction, session.getSecurityToken());
                        outcome = ACCEPTED;
                    } catch (UnroutableMessageException e) {
                        final Error error = new Error();
                        error.setCondition(e.getErrorCondition());
                        error.setDescription(e.getMessage());
                        String targetAddress = getTarget().getAddress();
                        if (targetAddress == null || "".equals(targetAddress.trim())) {
                            error.setInfo(Collections.singletonMap(DELIVERY_TAG, delivery.getDeliveryTag()));
                        }
                        if (!_rejectedOutcomeSupportedBySource || (delivery.isSettled() && !(transaction instanceof LocalTransaction))) {
                            return error;
                        } else {
                            if (delivery.isSettled() && transaction instanceof LocalTransaction) {
                                ((LocalTransaction) transaction).setRollbackOnly();
                            }
                            Rejected rejected = new Rejected();
                            rejected.setError(error);
                            outcome = rejected;
                        }
                    }
                }
                Outcome sourceDefaultOutcome = getSource().getDefaultOutcome();
                boolean defaultOutcome = sourceDefaultOutcome != null && sourceDefaultOutcome.getSymbol().equals(outcome.getSymbol());
                DeliveryState resultantState;
                if (transactionId == null) {
                    resultantState = defaultOutcome ? null : outcome;
                } else {
                    TransactionalState transactionalState = new TransactionalState();
                    transactionalState.setOutcome(defaultOutcome ? null : outcome);
                    transactionalState.setTxnId(transactionId);
                    resultantState = transactionalState;
                }
                boolean settled = shouldReceiverSettleFirst(transferReceiverSettleMode);
                if (transaction instanceof AsyncAutoCommitTransaction) {
                    _pendingDispositions.add(new PendingDispositionHolder(delivery.getDeliveryTag(), resultantState, settled));
                } else {
                    getSession().receivedComplete();
                    updateDisposition(delivery.getDeliveryTag(), resultantState, settled);
                }
                getSession().getAMQPConnection().registerMessageReceived(serverMessage.getSize());
                if (transactionId != null) {
                    getSession().getAMQPConnection().registerTransactedMessageReceived();
                }
                setRollbackOnly = false;
            } catch (AccessControlException e) {
                final Error err = new Error();
                err.setCondition(AmqpError.NOT_ALLOWED);
                err.setDescription(e.getMessage());
                return err;
            } finally {
                if (setRollbackOnly && transaction instanceof LocalTransaction) {
                    ((LocalTransaction) transaction).setRollbackOnly();
                }
            }
        } finally {
            reference.release();
        }
    }
    return null;
}
Also used : AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) ReceiverSettleMode(org.apache.qpid.server.protocol.v1_0.type.transport.ReceiverSettleMode) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) AmqpErrorRuntimeException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorRuntimeException) MessageFormat(org.apache.qpid.server.plugin.MessageFormat) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AccessControlException(java.security.AccessControlException) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 43 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MessageConverter_v1_0_to_InternalTest method doTestDataWithAnnotation.

private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String mimeType, final String expectedMimeType) {
    final Data value = new Data(new Binary(data));
    Message_1_0 sourceMessage;
    if (mimeType != null) {
        Properties properties = new Properties();
        properties.setContentType(Symbol.valueOf(mimeType));
        sourceMessage = createTestMessage(properties, messageAnnotations, value.createEncodingRetainingSection());
    } else {
        sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
    }
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
    assertArrayEquals("Unexpected content", data, ((byte[]) convertedMessage.getMessageBody()));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 44 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project storm by apache.

the class EventHubReceiverMock method receive.

@Override
public EventData receive(long timeoutInMilliseconds) {
    if (isPaused) {
        return null;
    }
    currentOffset++;
    List<Section> body = new ArrayList<Section>();
    //the body of the message is "message" + currentOffset, e.g. "message123"
    body.add(new Data(new Binary(("message" + currentOffset).getBytes())));
    Message m = new Message(body);
    MessageId mid = new MessageId(partitionId, "" + currentOffset, currentOffset);
    EventData ed = new EventData(m, mid);
    return ed;
}
Also used : Message(org.apache.qpid.amqp_1_0.client.Message) ArrayList(java.util.ArrayList) Data(org.apache.qpid.amqp_1_0.type.messaging.Data) EventData(org.apache.storm.eventhubs.spout.EventData) Binary(org.apache.qpid.amqp_1_0.type.Binary) Section(org.apache.qpid.amqp_1_0.type.Section) EventData(org.apache.storm.eventhubs.spout.EventData) MessageId(org.apache.storm.eventhubs.spout.MessageId)

Example 45 with Binary

use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeAmqpList.

public void testDataWithContentTypeAmqpList() throws Exception {
    List<Object> originalMap = Collections.singletonList("testValue");
    byte[] bytes = new ListToAmqpListConverter().toMimeContent(originalMap);
    final Data value = new Data(new Binary(bytes));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf("amqp/list"));
    Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "amqp/list", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
Also used : ListToAmqpListConverter(org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.ListToAmqpListConverter) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Aggregations

Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)104 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)46 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)45 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)43 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)42 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)37 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)29 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)29 Test (org.junit.Test)29 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)28 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)23 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)22 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)19 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)16 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 HashMap (java.util.HashMap)11