Search in sources :

Example 21 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class Session_1_0Test method createAttach.

private Attach createAttach(final boolean durable, final String linkName, final String address, final Symbol destinationTypeCapability, final boolean isGlobal, final boolean isShared) {
    Attach attach = new Attach();
    Source source = new Source();
    List<Symbol> capabilities = new ArrayList<>();
    if (isGlobal) {
        capabilities.add(Symbol.getSymbol("global"));
    }
    if (isShared) {
        capabilities.add(Symbol.getSymbol("shared"));
    }
    capabilities.add(destinationTypeCapability);
    source.setCapabilities(capabilities.toArray(new Symbol[capabilities.size()]));
    if (durable) {
        source.setDurable(TerminusDurability.CONFIGURATION);
        source.setExpiryPolicy(TerminusExpiryPolicy.NEVER);
    } else {
        source.setDurable(TerminusDurability.NONE);
        source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
    }
    attach.setSource(source);
    Target target = new Target();
    attach.setTarget(target);
    attach.setHandle(new UnsignedInteger(_handle++));
    attach.setIncompleteUnsettled(false);
    attach.setName(linkName);
    attach.setRole(Role.RECEIVER);
    source.setAddress(address);
    return attach;
}
Also used : Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ArrayList(java.util.ArrayList) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Example 22 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class LinkStoreTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _linkStore = createLinkStore();
    _source = new Source();
    _target = new Target();
    _source.setAddress(ADDRESS);
    _source.setCapabilities(new Symbol[] { Symbol.getSymbol(CAPABILITY) });
    _source.setDefaultOutcome(new Rejected());
    _source.setDistributionMode(StdDistMode.COPY);
    _source.setDurable(TerminusDurability.UNSETTLED_STATE);
    _source.setDynamic(Boolean.TRUE);
    _source.setExpiryPolicy(TerminusExpiryPolicy.CONNECTION_CLOSE);
    _source.setFilter(Collections.singletonMap(Symbol.valueOf("foo"), NoLocalFilter.INSTANCE));
    _source.setOutcomes(new Accepted().getSymbol());
    _source.setDynamicNodeProperties(Collections.singletonMap(Symbol.valueOf("dynamicProperty"), "dynamicPropertyValue"));
    _source.setTimeout(new UnsignedInteger(1));
    _target.setTimeout(new UnsignedInteger(2));
    _target.setDynamicNodeProperties(Collections.singletonMap(Symbol.valueOf("targetDynamicProperty"), "targetDynamicPropertyValue"));
    _target.setDynamic(Boolean.TRUE);
    _target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
    _target.setAddress("bar");
    _target.setCapabilities(new Symbol[] { Symbol.getSymbol(CAPABILITY) });
    _target.setDurable(TerminusDurability.CONFIGURATION);
}
Also used : Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)

Example 23 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class SendingLinkEndpoint method attachReceived.

@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
    super.attachReceived(attach);
    Target target = (Target) attach.getTarget();
    Source source = getSource();
    if (source == null) {
        source = new Source();
        Source attachSource = (Source) attach.getSource();
        final Modified defaultOutcome = new Modified();
        defaultOutcome.setDeliveryFailed(true);
        source.setDefaultOutcome(defaultOutcome);
        source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Released.RELEASED_SYMBOL, Rejected.REJECTED_SYMBOL);
        source.setAddress(attachSource.getAddress());
        source.setDynamic(attachSource.getDynamic());
        if (Boolean.TRUE.equals(attachSource.getDynamic()) && attachSource.getDynamicNodeProperties() != null) {
            Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
            if (attachSource.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
                dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachSource.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
            }
            source.setDynamicNodeProperties(dynamicNodeProperties);
        }
        source.setDurable(TerminusDurability.min(attachSource.getDurable(), getLink().getHighestSupportedTerminusDurability()));
        source.setExpiryPolicy(attachSource.getExpiryPolicy());
        source.setDistributionMode(attachSource.getDistributionMode());
        source.setFilter(attachSource.getFilter());
        source.setCapabilities(attachSource.getCapabilities());
        final SendingDestination destination = getSession().getSendingDestination(getLink(), source);
        source.setCapabilities(destination.getCapabilities());
        getLink().setSource(source);
        prepareConsumerOptionsAndFilters(destination);
    }
    getLink().setTarget(target);
    final MessageInstanceConsumer oldConsumer = getConsumer();
    createConsumerTarget();
    _resumeAcceptedTransfers.clear();
    _resumeFullTransfers.clear();
    final NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
    // TODO: QPID-7845 : Resuming links is unsupported at the moment. Thus, cleaning up unsettled deliveries unconditionally.
    cleanUpUnsettledDeliveries();
    getSession().addDeleteTask(_cleanUpUnsettledDeliveryTask);
    Map<Binary, OutgoingDelivery> unsettledCopy = new HashMap<>(_unsettled);
    Map<Binary, DeliveryState> remoteUnsettled = attach.getUnsettled() == null ? Collections.emptyMap() : new HashMap<>(attach.getUnsettled());
    final boolean isUnsettledComplete = !Boolean.TRUE.equals(attach.getIncompleteUnsettled());
    for (Map.Entry<Binary, OutgoingDelivery> entry : unsettledCopy.entrySet()) {
        Binary deliveryTag = entry.getKey();
        final MessageInstance queueEntry = entry.getValue().getMessageInstance();
        if (!remoteUnsettled.containsKey(deliveryTag) && isUnsettledComplete) {
            queueEntry.setRedelivered();
            queueEntry.release(oldConsumer);
            _unsettled.remove(deliveryTag);
        } else if (remoteUnsettled.get(deliveryTag) instanceof Outcome) {
            Outcome outcome = (Outcome) remoteUnsettled.get(deliveryTag);
            if (outcome instanceof Accepted) {
                if (oldConsumer.acquires()) {
                    AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
                    if (queueEntry.acquire() || queueEntry.isAcquired()) {
                        txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {

                            @Override
                            public void postCommit() {
                                queueEntry.delete();
                            }

                            @Override
                            public void onRollback() {
                            }
                        });
                    }
                }
            } else if (outcome instanceof Released) {
                if (oldConsumer.acquires()) {
                    AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
                    txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {

                        @Override
                        public void postCommit() {
                            queueEntry.release(oldConsumer);
                        }

                        @Override
                        public void onRollback() {
                        }
                    });
                }
            }
            // TODO: QPID-7845: Handle rejected and modified outcome
            remoteUnsettled.remove(deliveryTag);
            _resumeAcceptedTransfers.add(deliveryTag);
        } else {
            _resumeFullTransfers.add(queueEntry);
        // TODO:QPID-7845: exists in receivers map, but not yet got an outcome ... should resend with resume = true
        }
    }
    getConsumerTarget().updateNotifyWorkDesired();
}
Also used : AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) Action(org.apache.qpid.server.util.Action) Modified(org.apache.qpid.server.protocol.v1_0.type.messaging.Modified) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) 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) MessageInstance(org.apache.qpid.server.message.MessageInstance) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Released(org.apache.qpid.server.protocol.v1_0.type.messaging.Released) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 24 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class Session_1_0 method getReceivingDestination.

public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
    final ReceivingDestination destination;
    if (target != null) {
        if (Boolean.TRUE.equals(target.getDynamic())) {
            MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
            if (tempDestination != null) {
                target.setAddress(_primaryDomain + tempDestination.getName());
            } else {
                throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
            }
        }
        String addr = target.getAddress();
        if (addr == null || "".equals(addr.trim())) {
            destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
        } else {
            DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
            MessageDestination messageDestination = destinationAddress.getMessageDestination();
            if (messageDestination != null) {
                destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
            } else {
                destination = null;
            }
        }
    } else {
        destination = null;
    }
    if (destination == null) {
        throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
    }
    return destination;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 25 with Target

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Target in project qpid-broker-j by apache.

the class StandardReceivingLinkEndpoint method attachReceived.

@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
    super.attachReceived(attach);
    Source source = (Source) attach.getSource();
    Target target = new Target();
    Target attachTarget = (Target) attach.getTarget();
    setDeliveryCount(new SequenceNumber(attach.getInitialDeliveryCount().intValue()));
    target.setAddress(attachTarget.getAddress());
    target.setDynamic(attachTarget.getDynamic());
    if (Boolean.TRUE.equals(attachTarget.getDynamic()) && attachTarget.getDynamicNodeProperties() != null) {
        Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
        if (attachTarget.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
            dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachTarget.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
        }
        target.setDynamicNodeProperties(dynamicNodeProperties);
    }
    target.setDurable(TerminusDurability.min(attachTarget.getDurable(), getLink().getHighestSupportedTerminusDurability()));
    final List<Symbol> targetCapabilities = new ArrayList<>();
    if (attachTarget.getCapabilities() != null) {
        final List<Symbol> desiredCapabilities = Arrays.asList(attachTarget.getCapabilities());
        if (desiredCapabilities.contains(Symbol.valueOf("temporary-topic"))) {
            targetCapabilities.add(Symbol.valueOf("temporary-topic"));
        }
        if (desiredCapabilities.contains(Symbol.valueOf("topic"))) {
            targetCapabilities.add(Symbol.valueOf("topic"));
        }
        target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
    }
    target.setExpiryPolicy(attachTarget.getExpiryPolicy());
    final ReceivingDestination destination = getSession().getReceivingDestination(getLink(), target);
    targetCapabilities.addAll(Arrays.asList(destination.getCapabilities()));
    target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
    setCapabilities(targetCapabilities);
    setDestination(destination);
    if (!Boolean.TRUE.equals(attach.getIncompleteUnsettled())) {
        Map remoteUnsettled = attach.getUnsettled();
        Map<Binary, DeliveryState> unsettledCopy = new HashMap<>(_unsettled);
        for (Map.Entry<Binary, DeliveryState> entry : unsettledCopy.entrySet()) {
            Binary deliveryTag = entry.getKey();
            if (remoteUnsettled == null || !remoteUnsettled.containsKey(deliveryTag)) {
                _unsettled.remove(deliveryTag);
            }
        }
    }
    getLink().setTermini(source, target);
    _rejectedOutcomeSupportedBySource = source.getOutcomes() != null && Arrays.asList(source.getOutcomes()).contains(Rejected.REJECTED_SYMBOL);
}
Also used : HashMap(java.util.HashMap) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ArrayList(java.util.ArrayList) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)11 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)11 Test (org.junit.Test)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)10 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)9 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 StoreException (org.apache.qpid.server.store.StoreException)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)6 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)6 PreparedStatement (java.sql.PreparedStatement)5 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)5 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)4 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)4 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)4