Search in sources :

Example 1 with LifetimePolicy

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

the class ExchangeSendingDestination method getQueue.

private static Queue<?> getQueue(Exchange<?> exchange, Source source, String subscriptionName, BindingInfo bindingInfo) throws AmqpErrorException {
    boolean isDurable = source.getExpiryPolicy() == TerminusExpiryPolicy.NEVER;
    boolean isShared = hasCapability(source.getCapabilities(), SHARED_CAPABILITY);
    QueueManagingVirtualHost virtualHost;
    if (exchange.getAddressSpace() instanceof QueueManagingVirtualHost) {
        virtualHost = (QueueManagingVirtualHost) exchange.getAddressSpace();
    } else {
        throw new AmqpErrorException(new Error(AmqpError.INTERNAL_ERROR, "Address space of unexpected type"));
    }
    Queue<?> queue;
    final Map<String, Object> attributes = new HashMap<>();
    ExclusivityPolicy exclusivityPolicy;
    if (isShared) {
        exclusivityPolicy = ExclusivityPolicy.SHARED_SUBSCRIPTION;
    } else {
        exclusivityPolicy = ExclusivityPolicy.LINK;
    }
    org.apache.qpid.server.model.LifetimePolicy lifetimePolicy = getLifetimePolicy(source.getExpiryPolicy());
    attributes.put(Queue.ID, UUID.randomUUID());
    attributes.put(Queue.NAME, subscriptionName);
    attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
    attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
    attributes.put(Queue.DURABLE, isDurable);
    Map<String, Map<String, Object>> bindings = bindingInfo.getBindings();
    try {
        queue = virtualHost.getSubscriptionQueue(exchange.getName(), attributes, bindings);
    } catch (NotFoundException e) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, e.getMessage()));
    } catch (IllegalStateException e) {
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, "Subscription is already in use"));
    }
    return queue;
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) NotFoundException(org.apache.qpid.server.model.NotFoundException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LifetimePolicy

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

the class Session_1_0 method convertDynamicNodePropertiesToAttributes.

private Map<String, Object> convertDynamicNodePropertiesToAttributes(final Link_1_0<?, ?> link, final Map properties, final String nodeName) {
    // TODO convert AMQP 1-0 node properties to queue attributes
    LifetimePolicy lifetimePolicy = properties == null ? null : (LifetimePolicy) properties.get(LIFETIME_POLICY);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.ID, UUID.randomUUID());
    attributes.put(ConfiguredObject.NAME, nodeName);
    attributes.put(ConfiguredObject.DURABLE, true);
    if (lifetimePolicy instanceof DeleteOnNoLinks) {
        attributes.put(ConfiguredObject.LIFETIME_POLICY, org.apache.qpid.server.model.LifetimePolicy.DELETE_ON_NO_LINKS);
    } else if (lifetimePolicy instanceof DeleteOnNoLinksOrMessages) {
        attributes.put(ConfiguredObject.LIFETIME_POLICY, org.apache.qpid.server.model.LifetimePolicy.IN_USE);
    } else if (lifetimePolicy instanceof DeleteOnClose) {
        attributes.put(ConfiguredObject.LIFETIME_POLICY, org.apache.qpid.server.model.LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE);
        final CreatingLinkInfo linkInfo = new CreatingLinkInfoImpl(link.getRole() == Role.SENDER, link.getRemoteContainerId(), link.getName());
        attributes.put("creatingLinkInfo", linkInfo);
    } else if (lifetimePolicy instanceof DeleteOnNoMessages) {
        attributes.put(ConfiguredObject.LIFETIME_POLICY, org.apache.qpid.server.model.LifetimePolicy.IN_USE);
    } else {
        attributes.put(ConfiguredObject.LIFETIME_POLICY, org.apache.qpid.server.model.LifetimePolicy.DELETE_ON_CONNECTION_CLOSE);
    }
    return attributes;
}
Also used : LifetimePolicy(org.apache.qpid.server.protocol.v1_0.type.LifetimePolicy) CreatingLinkInfoImpl(org.apache.qpid.server.queue.CreatingLinkInfoImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DeleteOnNoMessages(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoMessages) DeleteOnNoLinksOrMessages(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoLinksOrMessages) DeleteOnClose(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnClose) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) DeleteOnNoLinks(org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoLinks) CreatingLinkInfo(org.apache.qpid.server.queue.CreatingLinkInfo)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 ExclusivityPolicy (org.apache.qpid.server.model.ExclusivityPolicy)1 LifetimePolicy (org.apache.qpid.server.model.LifetimePolicy)1 NotFoundException (org.apache.qpid.server.model.NotFoundException)1 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)1 LifetimePolicy (org.apache.qpid.server.protocol.v1_0.type.LifetimePolicy)1 DeleteOnClose (org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnClose)1 DeleteOnNoLinks (org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoLinks)1 DeleteOnNoLinksOrMessages (org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoLinksOrMessages)1 DeleteOnNoMessages (org.apache.qpid.server.protocol.v1_0.type.messaging.DeleteOnNoMessages)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)1 CreatingLinkInfo (org.apache.qpid.server.queue.CreatingLinkInfo)1 CreatingLinkInfoImpl (org.apache.qpid.server.queue.CreatingLinkInfoImpl)1 QueueManagingVirtualHost (org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)1