Search in sources :

Example 1 with QpidServiceLoader

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

the class AbstractLogger method getSupportedLogInclusionRules.

private static Collection<String> getSupportedLogInclusionRules(Class<? extends ConfiguredObject> clazz) {
    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 (clazz.isAssignableFrom(typeClass)) {
                ManagedObject annotation = typeClass.getAnnotation(ManagedObject.class);
                if (annotation.creatable() && annotation.defaultType().equals("") && LogBackLogInclusionRule.class.isAssignableFrom(typeClass)) {
                    supportedTypes.add(ConfiguredObjectTypeRegistry.getType(typeClass));
                }
            }
        }
    }
    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 2 with QpidServiceLoader

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

the class Main method printVersion.

private void printVersion() {
    final StringBuilder protocol = new StringBuilder("AMQP version(s) [major.minor]: ");
    boolean first = true;
    Set<Protocol> protocols = new TreeSet<>();
    for (ProtocolEngineCreator installedEngine : (new QpidServiceLoader()).instancesOf(ProtocolEngineCreator.class)) {
        protocols.add(installedEngine.getVersion());
    }
    for (Protocol supportedProtocol : protocols) {
        if (first) {
            first = false;
        } else {
            protocol.append(", ");
        }
        protocol.append(supportedProtocol.getProtocolVersion());
    }
    System.out.println(CommonProperties.getVersionString() + " (" + protocol + ")");
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) TreeSet(java.util.TreeSet) ProtocolEngineCreator(org.apache.qpid.server.plugin.ProtocolEngineCreator) Protocol(org.apache.qpid.server.model.Protocol)

Example 3 with QpidServiceLoader

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

the class ConfiguredObjectRecordConverter method readFromJson.

public Collection<ConfiguredObjectRecord> readFromJson(Class<? extends ConfiguredObject> rootClass, ConfiguredObject<?> parent, Reader reader) throws IOException {
    Map<UUID, ConfiguredObjectRecord> objectsById = new HashMap<>();
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
    Map data = objectMapper.readValue(reader, Map.class);
    if (!data.isEmpty()) {
        if (rootClass == null && parent instanceof DynamicModel) {
            String defaultContainerType = ((DynamicModel) parent).getDefaultContainerType();
            String containerTypeName = defaultContainerType;
            if (data.get(ConfiguredObject.TYPE) instanceof String) {
                containerTypeName = data.get(ConfiguredObject.TYPE).toString();
            }
            QpidServiceLoader loader = new QpidServiceLoader();
            Map<String, ContainerType> instancesByType = loader.getInstancesByType(ContainerType.class);
            final ContainerType<?> containerType = instancesByType.get(containerTypeName);
            if (containerType != null) {
                _model = containerType.getModel();
                rootClass = containerType.getCategoryClass();
            } else {
                // fall back to default container type
                final ContainerType<?> defaultContainerTypeInstance = instancesByType.get(defaultContainerType);
                if (defaultContainerTypeInstance != null) {
                    _model = defaultContainerTypeInstance.getModel();
                    rootClass = defaultContainerTypeInstance.getCategoryClass();
                } else {
                    throw new IllegalConfigurationException(String.format("Cannot identify container type for '%s'", containerType));
                }
            }
        }
        Collection<NameToIdResolver> unresolved = loadChild(rootClass, data, parent.getCategoryClass(), parent.getId(), objectsById);
        _rootClass = rootClass;
        Iterator<NameToIdResolver> iterator = unresolved.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().resolve(objectsById)) {
                iterator.remove();
            }
        }
        if (!unresolved.isEmpty()) {
            throw new IllegalArgumentException("Initial configuration has unresolved references");
        }
    }
    return objectsById.values();
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) HashMap(java.util.HashMap) ContainerType(org.apache.qpid.server.model.ContainerType) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DynamicModel(org.apache.qpid.server.model.DynamicModel)

Example 4 with QpidServiceLoader

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

the class JsonFileConfigStore method load.

protected boolean load(final ConfiguredObjectRecord... initialRecords) {
    final File configFile = getConfigFile();
    try {
        LOGGER.debug("Loading file {}", configFile.getCanonicalPath());
        boolean updated = false;
        Collection<ConfiguredObjectRecord> records = Collections.emptyList();
        ConfiguredObjectRecordConverter configuredObjectRecordConverter = new ConfiguredObjectRecordConverter(_parent.getModel());
        records = configuredObjectRecordConverter.readFromJson(_rootClass, _parent, new FileReader(configFile));
        if (_rootClass == null) {
            _rootClass = configuredObjectRecordConverter.getRootClass();
            _classNameMapping = generateClassNameMap(configuredObjectRecordConverter.getModel(), _rootClass);
        }
        if (records.isEmpty()) {
            LOGGER.debug("File contains no records - using initial configuration");
            records = Arrays.asList(initialRecords);
            updated = true;
            if (_rootClass == null) {
                String containerTypeName = ((DynamicModel) _parent).getDefaultContainerType();
                ConfiguredObjectRecord rootRecord = null;
                for (ConfiguredObjectRecord record : records) {
                    if (record.getParents() == null || record.getParents().isEmpty()) {
                        rootRecord = record;
                        break;
                    }
                }
                if (rootRecord != null && rootRecord.getAttributes().get(ConfiguredObject.TYPE) instanceof String) {
                    containerTypeName = rootRecord.getAttributes().get(ConfiguredObject.TYPE).toString();
                }
                QpidServiceLoader loader = new QpidServiceLoader();
                final ContainerType<?> containerType = loader.getInstancesByType(ContainerType.class).get(containerTypeName);
                if (containerType != null) {
                    _rootClass = containerType.getCategoryClass();
                    _classNameMapping = generateClassNameMap(containerType.getModel(), containerType.getCategoryClass());
                }
            }
        }
        for (ConfiguredObjectRecord record : records) {
            LOGGER.debug("Loading record (Category: {} \t Name: {} \t ID: {}", record.getType(), record.getAttributes().get("name"), record.getId());
            _objectsById.put(record.getId(), record);
            List<UUID> idsForType = _idsByType.get(record.getType());
            if (idsForType == null) {
                idsForType = new ArrayList<>();
                _idsByType.put(record.getType(), idsForType);
            }
            if (idsForType.contains(record.getId())) {
                throw new IllegalArgumentException("Duplicate id for record " + record);
            }
            idsForType.add(record.getId());
        }
        if (updated) {
            save();
        }
        return updated;
    } catch (IOException e) {
        throw new StoreException("Cannot construct configuration from the configuration file " + configFile, e);
    }
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) ContainerType(org.apache.qpid.server.model.ContainerType) IOException(java.io.IOException) FileReader(java.io.FileReader) UUID(java.util.UUID) File(java.io.File) DynamicModel(org.apache.qpid.server.model.DynamicModel)

Example 5 with QpidServiceLoader

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

the class AbstractVirtualHost method createLinkRegistry.

LinkRegistryModel createLinkRegistry() {
    LinkRegistryModel linkRegistry;
    Iterator<LinkRegistryFactory> linkRegistryFactories = (new QpidServiceLoader()).instancesOf(LinkRegistryFactory.class).iterator();
    if (linkRegistryFactories.hasNext()) {
        final LinkRegistryFactory linkRegistryFactory = linkRegistryFactories.next();
        if (linkRegistryFactories.hasNext()) {
            throw new RuntimeException("Found multiple implementations of LinkRegistry");
        }
        linkRegistry = linkRegistryFactory.create(this);
    } else {
        linkRegistry = null;
    }
    return linkRegistry;
}
Also used : QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader)

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