Search in sources :

Example 1 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class AbstractAMQPConnection method registerTransactionTickers.

@Override
public void registerTransactionTickers(final ServerTransaction serverTransaction, final Action<String> closeAction, final long notificationRepeatPeriod) {
    NamedAddressSpace addressSpace = getAddressSpace();
    if (addressSpace instanceof QueueManagingVirtualHost) {
        final QueueManagingVirtualHost<?> virtualhost = (QueueManagingVirtualHost<?>) addressSpace;
        EventLogger eventLogger = virtualhost.getEventLogger();
        final Set<Ticker> tickers = new LinkedHashSet<>(4);
        if (virtualhost.getStoreTransactionOpenTimeoutWarn() > 0) {
            tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.OPEN_TXN(age))));
        }
        if (virtualhost.getStoreTransactionOpenTimeoutClose() > 0) {
            tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> closeAction.performAction(OPEN_TRANSACTION_TIMEOUT_ERROR)));
        }
        if (virtualhost.getStoreTransactionIdleTimeoutWarn() > 0) {
            tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.IDLE_TXN(age))));
        }
        if (virtualhost.getStoreTransactionIdleTimeoutClose() > 0) {
            tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> closeAction.performAction(IDLE_TRANSACTION_TIMEOUT_ERROR)));
        }
        if (!tickers.isEmpty()) {
            for (Ticker ticker : tickers) {
                getAggregateTicker().addTicker(ticker);
            }
            notifyWork();
        }
        _transactionTickers.put(serverTransaction, tickers);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccessControlContext(java.security.AccessControlContext) SocketAddress(java.net.SocketAddress) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SettableFuture(com.google.common.util.concurrent.SettableFuture) ConnectionMessages(org.apache.qpid.server.logging.messages.ConnectionMessages) ContextProvider(org.apache.qpid.server.model.ContextProvider) TransactionObserver(org.apache.qpid.server.txn.TransactionObserver) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) Map(java.util.Map) Port(org.apache.qpid.server.model.Port) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) InetSocketAddress(java.net.InetSocketAddress) List(java.util.List) Principal(java.security.Principal) Transport(org.apache.qpid.server.model.Transport) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) ConnectionLogSubject(org.apache.qpid.server.logging.subjects.ConnectionLogSubject) AccessController(java.security.AccessController) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) StatisticsGatherer(org.apache.qpid.server.stats.StatisticsGatherer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FlowToDiskTransactionObserver(org.apache.qpid.server.txn.FlowToDiskTransactionObserver) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) EventLogger(org.apache.qpid.server.logging.EventLogger) LogSubject(org.apache.qpid.server.logging.LogSubject) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) FixedKeyMapCreator(org.apache.qpid.server.util.FixedKeyMapCreator) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) TaskExecutorProvider(org.apache.qpid.server.model.TaskExecutorProvider) EventLoggerProvider(org.apache.qpid.server.logging.EventLoggerProvider) NetworkConnection(org.apache.qpid.server.transport.network.NetworkConnection) LinkedHashSet(java.util.LinkedHashSet) Session(org.apache.qpid.server.model.Session) Ticker(org.apache.qpid.server.transport.network.Ticker) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) Action(org.apache.qpid.server.util.Action) Iterator(java.util.Iterator) Broker(org.apache.qpid.server.model.Broker) State(org.apache.qpid.server.model.State) SubjectDomainCombiner(javax.security.auth.SubjectDomainCombiner) Protocol(org.apache.qpid.server.model.Protocol) Connection(org.apache.qpid.server.model.Connection) Subject(javax.security.auth.Subject) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) Ticker(org.apache.qpid.server.transport.network.Ticker) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace)

Example 2 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeImpl method onMaster.

private void onMaster() {
    boolean success = false;
    try {
        boolean firstOpening = false;
        closeVirtualHostIfExist().get();
        getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_START());
        VirtualHostStoreUpgraderAndRecoverer upgraderAndRecoverer = new VirtualHostStoreUpgraderAndRecoverer(this);
        if (getConfigurationStore().isOpen()) {
            upgraderAndRecoverer.reloadAndRecover(getConfigurationStore());
        } else {
            getConfigurationStore().upgradeStoreStructure();
            ConfiguredObjectRecord[] initialRecords = getInitialRecords();
            if (upgraderAndRecoverer.upgradeAndRecover(getConfigurationStore(), initialRecords)) {
                setAttributes(Collections.<String, Object>singletonMap(VIRTUALHOST_INITIAL_CONFIGURATION, "{}"));
                firstOpening = initialRecords.length == 0;
            }
        }
        getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_COMPLETE());
        VirtualHost<?> host = getVirtualHost();
        if (host == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Creating new virtualhost with name : " + getGroupName());
            }
            Map<String, Object> hostAttributes = new HashMap<>();
            hostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
            hostAttributes.put(VirtualHost.NAME, getGroupName());
            hostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
            createChild(VirtualHost.class, hostAttributes);
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Recovered virtualhost with name : " + getGroupName());
            }
            final VirtualHost<?> recoveredHost = host;
            // so the following test should always return true
            if (recoveredHost instanceof QueueManagingVirtualHost) {
                ((QueueManagingVirtualHost<?>) recoveredHost).setFirstOpening(firstOpening);
            }
            Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>() {

                @Override
                public Object run() {
                    recoveredHost.open();
                    return null;
                }
            });
        }
        success = true;
    } catch (Exception e) {
        LOGGER.error("Failed to activate on hearing MASTER change event", e);
    } finally {
        setState(success ? State.ACTIVE : State.ERRORED);
    }
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) LogWriteException(com.sleepycat.je.LogWriteException) DatabaseException(com.sleepycat.je.DatabaseException) StoreException(org.apache.qpid.server.store.StoreException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) VirtualHostStoreUpgraderAndRecoverer(org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord)

Example 3 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost 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 4 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class LegacyAccessControlAdapter method createObjectPropertiesForExchangeBind.

private ObjectProperties createObjectPropertiesForExchangeBind(final Map<String, Object> arguments, final PermissionedObject configuredObject) {
    ObjectProperties properties = new ObjectProperties();
    Exchange<?> exchange = (Exchange<?>) configuredObject;
    final QueueManagingVirtualHost virtualhost = exchange.getVirtualHost();
    properties.setName(exchange.getName());
    final String destination = (String) arguments.get("destination");
    properties.put(ObjectProperties.Property.QUEUE_NAME, destination);
    properties.put(ObjectProperties.Property.ROUTING_KEY, (String) arguments.get("bindingKey"));
    properties.put(ObjectProperties.Property.VIRTUALHOST_NAME, virtualhost.getName());
    MessageDestination dest = virtualhost.getAttainedMessageDestination(destination);
    if (dest != null) {
        // express rules about the binding of temporary queues (whose names cannot be predicted).
        if (dest instanceof ConfiguredObject) {
            ConfiguredObject queue = (ConfiguredObject) dest;
            properties.put(ObjectProperties.Property.TEMPORARY, queue.getLifetimePolicy() != LifetimePolicy.PERMANENT);
        }
        properties.put(ObjectProperties.Property.DURABLE, dest.isDurable());
    }
    return properties;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)

Example 5 with QueueManagingVirtualHost

use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.

the class LinkRegistryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final QueueManagingVirtualHost virtualHost = mock(QueueManagingVirtualHost.class);
    _linkRegistry = new LinkRegistryImpl(virtualHost);
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)

Aggregations

QueueManagingVirtualHost (org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)18 HashMap (java.util.HashMap)12 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)3 AccessControlException (java.security.AccessControlException)2 Principal (java.security.Principal)2 Collection (java.util.Collection)2 Map (java.util.Map)2 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 Queue (org.apache.qpid.server.model.Queue)2 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 LogWriteException (com.sleepycat.je.LogWriteException)1 InetSocketAddress (java.net.InetSocketAddress)1