Search in sources :

Example 26 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQPConnection_0_8Impl method receiveConnectionOpen.

@Override
public void receiveConnectionOpen(AMQShortString virtualHostName, AMQShortString capabilities, boolean insist) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV ConnectionOpen[" + " virtualHost: " + virtualHostName + " capabilities: " + capabilities + " insist: " + insist + " ]");
    }
    assertState(ConnectionState.AWAIT_OPEN);
    String virtualHostStr = AMQShortString.toString(virtualHostName);
    if ((virtualHostStr != null) && virtualHostStr.charAt(0) == '/') {
        virtualHostStr = virtualHostStr.substring(1);
    }
    NamedAddressSpace addressSpace = ((AmqpPort) getPort()).getAddressSpace(virtualHostStr);
    if (addressSpace == null) {
        sendConnectionClose(ErrorCodes.NOT_FOUND, "Unknown virtual host: '" + virtualHostName + "'", 0);
    } else {
        // Check virtualhost access
        if (!addressSpace.isActive()) {
            String redirectHost = addressSpace.getRedirectHost(getPort());
            if (redirectHost != null) {
                sendConnectionClose(0, new AMQFrame(0, new ConnectionRedirectBody(getProtocolVersion(), AMQShortString.valueOf(redirectHost), null)));
            } else {
                sendConnectionClose(ErrorCodes.CONNECTION_FORCED, "Virtual host '" + addressSpace.getName() + "' is not active", 0);
            }
        } else {
            try {
                addressSpace.registerConnection(this, new NoopConnectionEstablishmentPolicy());
                setAddressSpace(addressSpace);
                if (addressSpace.authoriseCreateConnection(this)) {
                    MethodRegistry methodRegistry = getMethodRegistry();
                    AMQMethodBody responseBody = methodRegistry.createConnectionOpenOkBody(virtualHostName);
                    writeFrame(responseBody.generateFrame(0));
                    _state = ConnectionState.OPEN;
                } else {
                    sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Connection refused", 0);
                }
            } catch (AccessControlException | VirtualHostUnavailableException e) {
                sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), 0);
            }
        }
    }
}
Also used : VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) AmqpPort(org.apache.qpid.server.model.port.AmqpPort)

Example 27 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQPConnection_0_8Impl method closed.

@Override
public void closed() {
    try {
        try {
            if (!_orderlyClose.get()) {
                completeAndCloseAllChannels();
            }
        } finally {
            performDeleteTasks();
            final NamedAddressSpace virtualHost = getAddressSpace();
            if (virtualHost != null) {
                virtualHost.deregisterConnection(this);
            }
        }
    } catch (ConnectionScopedRuntimeException | TransportException e) {
        LOGGER.error("Could not close protocol engine", e);
    } finally {
        markTransportClosed();
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) TransportException(org.apache.qpid.server.transport.TransportException)

Example 28 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class AMQPConnection_0_8Impl method receiveChannelOpen.

@Override
public void receiveChannelOpen(final int channelId) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + channelId + "] ChannelOpen");
    }
    assertState(ConnectionState.OPEN);
    // Protect the broker against out of order frame request.
    final NamedAddressSpace virtualHost = getAddressSpace();
    if (virtualHost == null) {
        sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Virtualhost has not yet been set. ConnectionOpen has not been called.", channelId);
    } else if (getChannel(channelId) != null || channelAwaitingClosure(channelId)) {
        sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Channel " + channelId + " already exists", channelId);
    } else if (channelId > getSessionCountLimit()) {
        sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Channel " + channelId + " cannot be created as the max allowed channel id is " + getSessionCountLimit(), channelId);
    } else {
        LOGGER.debug("Connecting to: {}", virtualHost.getName());
        final AMQChannel channel = new AMQChannel(this, channelId, virtualHost.getMessageStore());
        channel.create();
        addChannel(channel);
        ChannelOpenOkBody response;
        response = getMethodRegistry().createChannelOpenOkBody();
        writeFrame(response.generateFrame(channelId));
    }
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace)

Example 29 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace in project qpid-broker-j by apache.

the class SendingLinkEndpoint method recoverLink.

@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
    Source source = getSource();
    if (source == null && attach.getDesiredCapabilities() != null) {
        List<Symbol> capabilities = Arrays.asList(attach.getDesiredCapabilities());
        if (capabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && capabilities.contains(Session_1_0.SHARED_CAPABILITY) && getLinkName().endsWith("|global")) {
            NamedAddressSpace namedAddressSpace = getSession().getConnection().getAddressSpace();
            Collection<Link_1_0<? extends BaseSource, ? extends BaseTarget>> links = namedAddressSpace.findSendingLinks(ANY_CONTAINER_ID, Pattern.compile("^" + Pattern.quote(getLinkName()) + "$"));
            for (Link_1_0<? extends BaseSource, ? extends BaseTarget> link : links) {
                BaseSource baseSource = link.getSource();
                if (baseSource instanceof Source) {
                    Source linkSource = (Source) baseSource;
                    source = new Source(linkSource);
                    getLink().setSource(source);
                    break;
                }
            }
        }
    }
    if (source == null) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, ""));
    }
    attach.setSource(source);
    receiveAttach(attach);
}
Also used : BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) 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) 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) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Example 30 with NamedAddressSpace

use of org.apache.qpid.server.model.NamedAddressSpace 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)

Aggregations

NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)42 AccessControlException (java.security.AccessControlException)22 HashMap (java.util.HashMap)12 MessageSource (org.apache.qpid.server.message.MessageSource)8 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)8 Queue (org.apache.qpid.server.model.Queue)6 Collection (java.util.Collection)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4 MessageDestination (org.apache.qpid.server.message.MessageDestination)4 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Exchange (org.apache.qpid.server.model.Exchange)3 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)3 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)3 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)3