Search in sources :

Example 6 with QpidServiceLoader

use of org.apache.qpid.server.plugin.QpidServiceLoader in project qpid-broker-j by apache.

the class AbstractVirtualHost method onOpen.

@Override
protected void onOpen() {
    super.onOpen();
    registerSystemNodes();
    _messageStore = createMessageStore();
    _messageStoreLogSubject = new MessageStoreLogSubject(getName(), _messageStore.getClass().getSimpleName());
    _messageStore.addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
    _messageStore.addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL);
    _fileSystemMaxUsagePercent = getContextValue(Integer.class, Broker.STORE_FILESYSTEM_MAX_USAGE_PERCENT);
    _flowToDiskCheckPeriod = getContextValue(Long.class, FLOW_TO_DISK_CHECK_PERIOD);
    _isDiscardGlobalSharedSubscriptionLinksOnDetach = getContextValue(Boolean.class, DISCARD_GLOBAL_SHARED_SUBSCRIPTION_LINKS_ON_DETACH);
    QpidServiceLoader serviceLoader = new QpidServiceLoader();
    for (ConnectionValidator validator : serviceLoader.instancesOf(ConnectionValidator.class)) {
        if ((_enabledConnectionValidators.isEmpty() && (_disabledConnectionValidators.isEmpty()) || !_disabledConnectionValidators.contains(validator.getType())) || _enabledConnectionValidators.contains(validator.getType())) {
            _connectionValidators.add(validator);
        }
    }
    PreferencesRoot preferencesRoot = (VirtualHostNode) getParent();
    _preferenceStore = preferencesRoot.createPreferenceStore();
    _linkRegistry = createLinkRegistry();
    createHousekeepingExecutor();
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) PreferencesRoot(org.apache.qpid.server.store.preferences.PreferencesRoot) AtomicLong(java.util.concurrent.atomic.AtomicLong) MessageStoreLogSubject(org.apache.qpid.server.logging.subjects.MessageStoreLogSubject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConnectionValidator(org.apache.qpid.server.plugin.ConnectionValidator)

Example 7 with QpidServiceLoader

use of org.apache.qpid.server.plugin.QpidServiceLoader in project qpid-broker-j by apache.

the class AbstractVirtualHostNode method getSupportedVirtualHostTypes.

protected static Collection<String> getSupportedVirtualHostTypes(boolean includeProvided) {
    final Iterable<ConfiguredObjectRegistration> registrations = (new QpidServiceLoader()).instancesOf(ConfiguredObjectRegistration.class);
    Set<String> supportedTypes = new HashSet<>();
    for (ConfiguredObjectRegistration registration : registrations) {
        for (Class<? extends ConfiguredObject> typeClass : registration.getConfiguredObjectClasses()) {
            if (VirtualHost.class.isAssignableFrom(typeClass)) {
                ManagedObject annotation = typeClass.getAnnotation(ManagedObject.class);
                if (annotation.creatable() && annotation.defaultType().equals("") && !NonStandardVirtualHost.class.isAssignableFrom(typeClass)) {
                    supportedTypes.add(ConfiguredObjectTypeRegistry.getType(typeClass));
                }
            }
        }
    }
    if (includeProvided) {
        supportedTypes.add(ProvidedStoreVirtualHostImpl.VIRTUAL_HOST_TYPE);
    }
    return Collections.unmodifiableCollection(supportedTypes);
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) ConfiguredObjectRegistration(org.apache.qpid.server.plugin.ConfiguredObjectRegistration) ManagedObject(org.apache.qpid.server.model.ManagedObject) HashSet(java.util.HashSet)

Example 8 with QpidServiceLoader

use of org.apache.qpid.server.plugin.QpidServiceLoader in project qpid-broker-j by apache.

the class AbstractQueue method onOpen.

@Override
protected void onOpen() {
    super.onOpen();
    Map<String, Object> attributes = getActualAttributes();
    final LinkedHashMap<String, Object> arguments = new LinkedHashMap<>(attributes);
    arguments.put(Queue.EXCLUSIVE, _exclusive);
    arguments.put(Queue.LIFETIME_POLICY, getLifetimePolicy());
    _arguments = Collections.synchronizedMap(arguments);
    _logSubject = new QueueLogSubject(this);
    _queueHouseKeepingTask = new AdvanceConsumersTask();
    Subject activeSubject = Subject.getSubject(AccessController.getContext());
    Set<SessionPrincipal> sessionPrincipals = activeSubject == null ? Collections.<SessionPrincipal>emptySet() : activeSubject.getPrincipals(SessionPrincipal.class);
    AMQPSession<?, ?> session;
    if (sessionPrincipals.isEmpty()) {
        session = null;
    } else {
        final SessionPrincipal sessionPrincipal = sessionPrincipals.iterator().next();
        session = sessionPrincipal.getSession();
    }
    if (session != null) {
        switch(_exclusive) {
            case PRINCIPAL:
                _exclusiveOwner = session.getAMQPConnection().getAuthorizedPrincipal();
                break;
            case CONTAINER:
                _exclusiveOwner = session.getAMQPConnection().getRemoteContainerName();
                break;
            case CONNECTION:
                _exclusiveOwner = session.getAMQPConnection();
                addExclusivityConstraint(session.getAMQPConnection());
                break;
            case SESSION:
                _exclusiveOwner = session;
                addExclusivityConstraint(session);
                break;
            case NONE:
            case LINK:
            case SHARED_SUBSCRIPTION:
                break;
            default:
                throw new ServerScopedRuntimeException("Unknown exclusivity policy: " + _exclusive + " this is a coding error inside Qpid");
        }
    } else if (_exclusive == ExclusivityPolicy.PRINCIPAL) {
        if (attributes.get(Queue.OWNER) != null) {
            String owner = String.valueOf(attributes.get(Queue.OWNER));
            Principal ownerPrincipal;
            try {
                ownerPrincipal = new GenericPrincipal(owner);
            } catch (IllegalArgumentException e) {
                ownerPrincipal = new GenericPrincipal(owner + "@('')");
            }
            _exclusiveOwner = new AuthenticatedPrincipal(ownerPrincipal);
        }
    } else if (_exclusive == ExclusivityPolicy.CONTAINER) {
        if (attributes.get(Queue.OWNER) != null) {
            _exclusiveOwner = String.valueOf(attributes.get(Queue.OWNER));
        }
    }
    if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CONNECTION_CLOSE) {
        if (session != null) {
            addLifetimeConstraint(session.getAMQPConnection());
        } else {
            throw new IllegalArgumentException("Queues created with a lifetime policy of " + getLifetimePolicy() + " must be created from a connection.");
        }
    } else if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_SESSION_END) {
        if (session != null) {
            addLifetimeConstraint(session);
        } else {
            throw new IllegalArgumentException("Queues created with a lifetime policy of " + getLifetimePolicy() + " must be created from a connection.");
        }
    } else if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE) {
        if (_creatingLinkInfo != null) {
            final LinkModel link;
            if (_creatingLinkInfo.isSendingLink()) {
                link = _virtualHost.getSendingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
            } else {
                link = _virtualHost.getReceivingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
            }
            addLifetimeConstraint(link);
        } else {
            throw new IllegalArgumentException("Queues created with a lifetime policy of " + getLifetimePolicy() + " must be created from a AMQP 1.0 link.");
        }
    }
    // Log the creation of this Queue.
    // The priorities display is toggled on if we set priorities > 0
    getEventLogger().message(_logSubject, getCreatedLogMessage());
    switch(getMessageGroupType()) {
        case NONE:
            _messageGroupManager = null;
            break;
        case STANDARD:
            _messageGroupManager = new AssignedConsumerMessageGroupManager(getMessageGroupKeyOverride(), getMaximumDistinctGroups());
            break;
        case SHARED_GROUPS:
            _messageGroupManager = new DefinedGroupMessageGroupManager(getMessageGroupKeyOverride(), getMessageGroupDefaultGroup(), this);
            break;
        default:
            throw new IllegalArgumentException("Unknown messageGroupType type " + _messageGroupType);
    }
    _mimeTypeToFileExtension = getContextValue(Map.class, MAP_OF_STRING_STRING, MIME_TYPE_TO_FILE_EXTENSION);
    _messageConversionExceptionHandlingPolicy = getContextValue(MessageConversionExceptionHandlingPolicy.class, MESSAGE_CONVERSION_EXCEPTION_HANDLING_POLICY);
    _flowToDiskThreshold = getAncestor(Broker.class).getFlowToDiskThreshold();
    if (_defaultFilters != null) {
        QpidServiceLoader qpidServiceLoader = new QpidServiceLoader();
        final Map<String, MessageFilterFactory> messageFilterFactories = qpidServiceLoader.getInstancesByType(MessageFilterFactory.class);
        for (Map.Entry<String, Map<String, List<String>>> entry : _defaultFilters.entrySet()) {
            String name = String.valueOf(entry.getKey());
            Map<String, List<String>> filterValue = entry.getValue();
            if (filterValue.size() == 1) {
                String filterTypeName = String.valueOf(filterValue.keySet().iterator().next());
                final MessageFilterFactory filterFactory = messageFilterFactories.get(filterTypeName);
                if (filterFactory != null) {
                    final List<String> filterArguments = filterValue.values().iterator().next();
                    // check the arguments are valid
                    filterFactory.newInstance(filterArguments);
                    _defaultFiltersMap.put(name, new Callable<MessageFilter>() {

                        @Override
                        public MessageFilter call() {
                            return filterFactory.newInstance(filterArguments);
                        }
                    });
                } else {
                    throw new IllegalArgumentException("Unknown filter type " + filterTypeName + ", known types are: " + messageFilterFactories.keySet());
                }
            } else {
                throw new IllegalArgumentException("Filter value should be a map with one entry, having the type as key and the value being the filter arguments, not " + filterValue);
            }
        }
    }
    if (isHoldOnPublishEnabled()) {
        _holdMethods.add(new HoldMethod() {

            @Override
            public boolean isHeld(final MessageReference<?> messageReference, final long evaluationTime) {
                return messageReference.getMessage().getMessageHeader().getNotValidBefore() >= evaluationTime;
            }
        });
    }
    if (getAlternateBinding() != null) {
        String alternateDestination = getAlternateBinding().getDestination();
        _alternateBindingDestination = getOpenedMessageDestination(alternateDestination);
        if (_alternateBindingDestination != null) {
            _alternateBindingDestination.addReference(this);
        } else {
            LOGGER.warn("Cannot find alternate binding destination '{}' for queue '{}'", alternateDestination, toString());
        }
    }
    createOverflowPolicyHandlers(_overflowPolicy);
    updateAlertChecks();
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) QueueLogSubject(org.apache.qpid.server.logging.subjects.QueueLogSubject) SessionPrincipal(org.apache.qpid.server.connection.SessionPrincipal) LinkModel(org.apache.qpid.server.protocol.LinkModel) LinkedHashMap(java.util.LinkedHashMap) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MessageFilterFactory(org.apache.qpid.server.plugin.MessageFilterFactory) LogSubject(org.apache.qpid.server.logging.LogSubject) QueueLogSubject(org.apache.qpid.server.logging.subjects.QueueLogSubject) Subject(javax.security.auth.Subject) GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) MessageFilter(org.apache.qpid.server.filter.MessageFilter) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) SessionPrincipal(org.apache.qpid.server.connection.SessionPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 9 with QpidServiceLoader

use of org.apache.qpid.server.plugin.QpidServiceLoader in project qpid-broker-j by apache.

the class AbstractSystemConfig method initiateStoreAndRecovery.

private Container<?> initiateStoreAndRecovery() throws IOException {
    ConfiguredObjectRecord[] initialRecords = convertToConfigurationRecords(getInitialConfigurationLocation());
    final DurableConfigurationStore store = getConfigurationStore();
    store.init(AbstractSystemConfig.this);
    store.upgradeStoreStructure();
    final List<ConfiguredObjectRecord> records = new ArrayList<>();
    boolean isNew = store.openConfigurationStore(new ConfiguredObjectRecordHandler() {

        @Override
        public void handle(final ConfiguredObjectRecord record) {
            records.add(record);
        }
    }, initialRecords);
    String containerTypeName = getDefaultContainerType();
    for (ConfiguredObjectRecord record : records) {
        if (record.getParents() != null && record.getParents().size() == 1 && getId().equals(record.getParents().get(SystemConfig.class.getSimpleName()))) {
            containerTypeName = record.getType();
            break;
        }
    }
    QpidServiceLoader loader = new QpidServiceLoader();
    final ContainerType<?> containerType = loader.getInstancesByType(ContainerType.class).get(containerTypeName);
    if (containerType != null) {
        if (containerType.getModel() != getModel()) {
            updateModel(containerType.getModel());
        }
        containerType.getRecoverer(this).upgradeAndRecover(records);
    } else {
        throw new IllegalConfigurationException("Unknown container type '" + containerTypeName + "'");
    }
    final Class categoryClass = containerType.getCategoryClass();
    return (Container<?>) getContainer(categoryClass);
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) ArrayList(java.util.ArrayList) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 10 with QpidServiceLoader

use of org.apache.qpid.server.plugin.QpidServiceLoader in project qpid-broker-j by apache.

the class AbstractSystemConfig method createPreferenceStore.

@Override
public PreferenceStore createPreferenceStore() {
    PreferenceStoreAttributes preferenceStoreAttributes = getPreferenceStoreAttributes();
    final Map<String, PreferenceStoreFactoryService> preferenceStoreFactories = new QpidServiceLoader().getInstancesByType(PreferenceStoreFactoryService.class);
    String preferenceStoreType;
    Map<String, Object> attributes;
    if (preferenceStoreAttributes == null) {
        preferenceStoreType = NoopPreferenceStoreFactoryService.TYPE;
        attributes = Collections.emptyMap();
    } else {
        preferenceStoreType = preferenceStoreAttributes.getType();
        attributes = preferenceStoreAttributes.getAttributes();
    }
    final PreferenceStoreFactoryService preferenceStoreFactory = preferenceStoreFactories.get(preferenceStoreType);
    return preferenceStoreFactory.createInstance(this, attributes);
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) PreferenceStoreAttributes(org.apache.qpid.server.store.preferences.PreferenceStoreAttributes) NoopPreferenceStoreFactoryService(org.apache.qpid.server.store.preferences.NoopPreferenceStoreFactoryService) PreferenceStoreFactoryService(org.apache.qpid.server.store.preferences.PreferenceStoreFactoryService)

Aggregations

QpidServiceLoader (org.apache.qpid.server.plugin.QpidServiceLoader)22 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)3 ManagedObject (org.apache.qpid.server.model.ManagedObject)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ContainerType (org.apache.qpid.server.model.ContainerType)2 DynamicModel (org.apache.qpid.server.model.DynamicModel)2 Protocol (org.apache.qpid.server.model.Protocol)2 Transport (org.apache.qpid.server.model.Transport)2 ConfiguredObjectRegistration (org.apache.qpid.server.plugin.ConfiguredObjectRegistration)2 File (java.io.File)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 Principal (java.security.Principal)1