/** * @throws RuntimeException if at least one implementation is not found. */ public <C extends Pluggable> Iterable<C> atLeastOneInstanceOf(Class<C> clazz) { return instancesOf(clazz, true); }
public <C extends Pluggable> Iterable<C> instancesOf(Class<C> clazz) { return instancesOf(clazz, false); }
public <C extends Pluggable> Map<String,C> getInstancesByType(Class<C> clazz) { Map<String,C> instances = new HashMap<>(); for(C instance : instancesOf(clazz)) { instances.put(instance.getType(), instance); } return Collections.unmodifiableMap(instances); }
static Set<TypeControllerFactory> findFactories(String version) { final Iterable<TypeControllerFactory> factories = new QpidServiceLoader().instancesOf(TypeControllerFactory.class); return StreamSupport.stream(factories.spliterator(), false) .filter(f -> version.equals(f.getModelVersion())) .collect(Collectors.toSet()); }
public static Set<Protocol> getInstalledProtocols() { Set<Protocol> protocols = new HashSet<>(); for(ProtocolEngineCreator installedEngine : (new QpidServiceLoader()).instancesOf(ProtocolEngineCreator.class)) { protocols.add(installedEngine.getVersion()); } return protocols; }
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; }
@SuppressWarnings("unused") public static Collection<String> getAllAvailableTransportCombinations() { Set<Set<Transport>> combinations = new HashSet<>(); for(TransportProviderFactory providerFactory : (new QpidServiceLoader()).instancesOf(TransportProviderFactory.class)) { combinations.addAll(providerFactory.getSupportedTransports()); } Set<String> combinationsAsString = new HashSet<>(combinations.size()); ObjectMapper mapper = new ObjectMapper(); for(Set<Transport> combination : combinations) { try(StringWriter writer = new StringWriter()) { mapper.writeValue(writer, combination); combinationsAsString.add(writer.toString()); } catch (IOException e) { throw new IllegalArgumentException("Unexpected IO Exception generating JSON string", e); } } return Collections.unmodifiableSet(combinationsAsString); }
private static Map<String, MimeContentToObjectConverter> buildMimeContentToObjectMap() { final Map<String, MimeContentToObjectConverter> mimeContentToObjectConverters = new HashMap<>(); for(MimeContentToObjectConverter converter : (new QpidServiceLoader()).instancesOf(MimeContentToObjectConverter.class)) { final String mimeType = converter.getMimeType(); final MimeContentToObjectConverter existing = mimeContentToObjectConverters.put(mimeType, converter); if (existing != null) { LOGGER.warn("MIME converter {} for mime type '{}' replaced by {}.", existing.getClass().getName(), existing.getMimeType(), converter.getClass().getName()); } } return Collections.unmodifiableMap(mimeContentToObjectConverters); }
private void registerSystemNodes() { QpidServiceLoader qpidServiceLoader = new QpidServiceLoader(); Iterable<SystemNodeCreator> factories = qpidServiceLoader.instancesOf(SystemNodeCreator.class); for(SystemNodeCreator creator : factories) { creator.register(_systemNodeRegistry); } }
private void registerSystemAddressSpaces() { QpidServiceLoader qpidServiceLoader = new QpidServiceLoader(); Iterable<SystemAddressSpaceCreator> factories = qpidServiceLoader.instancesOf(SystemAddressSpaceCreator.class); for(SystemAddressSpaceCreator creator : factories) { creator.register(_addressSpaceRegistry); } }
@Override public Object perform(Map<String, Object> request, Broker broker) { try { String className = (String) request.get("plugin"); QpidServiceLoader serviceLoader = new QpidServiceLoader(); final Class<Pluggable> clazz = (Class<Pluggable>) Class.forName("org.apache.qpid.server.plugin."+className); List<String> values = new ArrayList<String>(); for(Pluggable instance : serviceLoader.instancesOf(clazz)) { values.add(instance.getType()); } return values; } catch (ClassNotFoundException e) { return Collections.emptyList(); } } }
public MultiVersionProtocolEngineFactory(Broker<?> broker, Set<Protocol> supportedVersions, Protocol defaultSupportedReply, AmqpPort<?> port, Transport transport) { if(defaultSupportedReply != null && !supportedVersions.contains(defaultSupportedReply)) { LOGGER.warn("The configured default reply ({}) to an unsupported protocol version initiation is not" + " supported on this port. Only the following versions are supported: {}", defaultSupportedReply, supportedVersions); defaultSupportedReply = null; } _broker = broker; _supported = supportedVersions; _defaultSupportedReply = defaultSupportedReply; final List<ProtocolEngineCreator> creators = new ArrayList<ProtocolEngineCreator>(); for(ProtocolEngineCreator c : new QpidServiceLoader().instancesOf(ProtocolEngineCreator.class)) { creators.add(c); } Collections.sort(creators, new ProtocolEngineCreatorComparator()); _creators = creators.toArray(new ProtocolEngineCreator[creators.size()]); _port = port; _transport = transport; }
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 + ")"); }
@ManagedObjectFactoryConstructor public JMXManagementPluginImpl(Map<String, Object> attributes, Broker<?> broker) { super(attributes, broker); _changeListener = new ChangeListener(); _pluginMBeanProvider = new PluginMBeansProvider(); _mBeanProviders = new HashSet<>(); QpidServiceLoader qpidServiceLoader = new QpidServiceLoader(); for (MBeanProvider provider : qpidServiceLoader.instancesOf(MBeanProvider.class)) { _mBeanProviders.add(provider); } }
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); }
private static Multimap<Class, ObjectToMimeContentConverter> buildClassToMimeConverters() { Multimap<Class, ObjectToMimeContentConverter> classToMineConverters = HashMultimap.create(); Iterable<ObjectToMimeContentConverter> objectToMimeContentConverters = new QpidServiceLoader().instancesOf(ObjectToMimeContentConverter.class); for(ObjectToMimeContentConverter converter : objectToMimeContentConverters) { Class objectClass = converter.getObjectClass(); for(ObjectToMimeContentConverter existing : classToMineConverters.get(objectClass)) { if (existing.getRank() == converter.getRank()) { LOGGER.warn("MIME converter for object class {} has two or more implementations" + " with the same rank {}. It is undefined which one will be used." + " Implementations are: {} {} ", existing.getObjectClass().getName(), existing.getRank(), existing.getClass().getName(), converter.getClass().getName()); } } classToMineConverters.put(objectClass, converter); } classToMineConverters.put(Void.class, new IdentityConverter()); return ImmutableMultimap.copyOf(classToMineConverters); }
private SystemConfigBootstrapModel() { setRootCategory(SystemConfig.class); _objectFactory = new ConfiguredObjectFactoryImpl(this); _typeRegistry = new ConfiguredObjectTypeRegistry((new QpidServiceLoader()).instancesOf(ConfiguredObjectRegistration.class), (new QpidServiceLoader()).instancesOf(ConfiguredObjectAttributeInjector.class), getSupportedCategories(), _objectFactory); }
@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(); }
LinkRegistryImpl(final NamedAddressSpace addressSpace) { LinkStoreFactory storeFactory = null; Iterable<LinkStoreFactory> linkStoreFactories = new QpidServiceLoader().instancesOf(LinkStoreFactory.class); for (LinkStoreFactory linkStoreFactory : linkStoreFactories) { if (linkStoreFactory.supports(addressSpace) && (storeFactory == null || storeFactory.getPriority() < linkStoreFactory.getPriority())) { storeFactory = linkStoreFactory; } } if (storeFactory == null) { throw new ServerScopedRuntimeException("Cannot find suitable link store"); } _linkStore = storeFactory.create(addressSpace); }
_typeRegistry = new ConfiguredObjectTypeRegistry((new QpidServiceLoader()).instancesOf(ConfiguredObjectRegistration.class), (new QpidServiceLoader()).instancesOf(ConfiguredObjectAttributeInjector.class), getSupportedCategories(), _objectFactory);