Search in sources :

Example 61 with Attach

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

the class AbstractLinkEndpoint method handleOversizedUnsettledMapIfNecessary.

private Attach handleOversizedUnsettledMapIfNecessary(final Attach attachToSend) {
    final AMQPDescribedTypeRegistry describedTypeRegistry = getSession().getConnection().getDescribedTypeRegistry();
    final ValueWriter<Attach> valueWriter = describedTypeRegistry.getValueWriter(attachToSend);
    if (valueWriter.getEncodedSize() + 8 > getSession().getConnection().getMaxFrameSize()) {
        _localIncompleteUnsettled = true;
        attachToSend.setIncompleteUnsettled(true);
        final int targetSize = getSession().getConnection().getMaxFrameSize();
        int lowIndex = 0;
        Map<Binary, DeliveryState> localUnsettledMap = attachToSend.getUnsettled();
        if (localUnsettledMap == null) {
            localUnsettledMap = Collections.emptyMap();
        }
        int highIndex = localUnsettledMap.size();
        int currentIndex = (highIndex - lowIndex) / 2;
        int oldIndex;
        HashMap<Binary, DeliveryState> unsettledMap = null;
        int totalSize;
        do {
            HashMap<Binary, DeliveryState> partialUnsettledMap = new HashMap<>(currentIndex);
            final Iterator<Map.Entry<Binary, DeliveryState>> iterator = localUnsettledMap.entrySet().iterator();
            for (int i = 0; i < currentIndex; ++i) {
                final Map.Entry<Binary, DeliveryState> entry = iterator.next();
                partialUnsettledMap.put(entry.getKey(), entry.getValue());
            }
            attachToSend.setUnsettled(partialUnsettledMap);
            totalSize = describedTypeRegistry.getValueWriter(attachToSend).getEncodedSize() + FRAME_HEADER_SIZE;
            if (totalSize > targetSize) {
                highIndex = currentIndex;
            } else if (totalSize < targetSize) {
                lowIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            } else {
                lowIndex = highIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            }
            oldIndex = currentIndex;
            currentIndex = lowIndex + (highIndex - lowIndex) / 2;
        } while (oldIndex != currentIndex);
        if (unsettledMap == null || unsettledMap.isEmpty()) {
            final End endWithError = new End();
            endWithError.setError(new Error(AmqpError.FRAME_SIZE_TOO_SMALL, "Cannot fit a single unsettled delivery into Attach frame."));
            getSession().end(endWithError);
        }
        attachToSend.setUnsettled(unsettledMap);
    } else {
        _localIncompleteUnsettled = false;
    }
    return attachToSend;
}
Also used : AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) HashMap(java.util.HashMap) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with Attach

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

the class AbstractLinkEndpoint method sendAttach.

@Override
public void sendAttach() {
    Attach attachToSend = new Attach();
    attachToSend.setName(getLinkName());
    attachToSend.setRole(getRole());
    attachToSend.setHandle(getLocalHandle());
    attachToSend.setSource(getSource());
    attachToSend.setTarget(getTarget());
    attachToSend.setSndSettleMode(getSendingSettlementMode());
    attachToSend.setRcvSettleMode(getReceivingSettlementMode());
    attachToSend.setUnsettled(getLocalUnsettled());
    attachToSend.setProperties(_properties);
    attachToSend.setOfferedCapabilities(_capabilities);
    if (getRole() == Role.SENDER) {
        attachToSend.setInitialDeliveryCount(_deliveryCount.unsignedIntegerValue());
    } else {
        final long maxMessageSize = getSession().getConnection().getMaxMessageSize();
        if (maxMessageSize != Long.MAX_VALUE) {
            attachToSend.setMaxMessageSize(UnsignedLong.valueOf(maxMessageSize));
        }
    }
    attachToSend = handleOversizedUnsettledMapIfNecessary(attachToSend);
    switch(_state) {
        case DETACHED:
            _state = State.ATTACH_SENT;
            break;
        case ATTACH_RECVD:
            _state = State.ATTACHED;
            break;
        default:
            throw new UnsupportedOperationException(_state.toString());
    }
    getSession().sendAttach(attachToSend);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach)

Example 63 with Attach

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

the class ErrantLinkEndpoint method sendAttach.

@Override
public void sendAttach() {
    Attach attachToSend = new Attach();
    attachToSend.setName(_link.getName());
    attachToSend.setRole(getRole());
    attachToSend.setHandle(getLocalHandle());
    attachToSend.setSource(getSource());
    attachToSend.setTarget(getTarget());
    _session.sendAttach(attachToSend);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach)

Example 64 with Attach

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

the class Session_1_0Test method testReceiveAttachTopicNonDurableWithContainer.

public void testReceiveAttachTopicNonDurableWithContainer() throws Exception {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createTopicAttach(false, linkName, address, false);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach)

Example 65 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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)

Aggregations

Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)85 Test (org.junit.Test)84 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)82 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)82 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)70 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)37 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)32 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)32 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)27 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)23 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)17 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)17 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)14 InetSocketAddress (java.net.InetSocketAddress)13 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11