private URI getUri(ConnectionFactoryConfiguration configuration) { URI attribute = configuration.getAttribute(URI.class, "broker.uri"); if (attribute != null) { return attribute; } return brokerUri; }
private ConnectionFactoryResourceBuilder(String name) { definition = new ConnectionFactoryResource(new ConnectionFactoryConfiguration(name)); }
public ConnectionFactoryConfiguration createDefaultFactory(String name, ConnectionFactoryType type) { ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfiguration(name, "activemq"); configuration.addAttribute("broker.uri", defaultBrokerName); configuration.setType(type); return configuration; } }
public ConnectionFactory create(ConnectionFactoryConfiguration configuration) throws Fabric3Exception { ConnectionFactoryType type = configuration.getType(); String clientId = configuration.getClientId(); switch (type) { case XA: ActiveMQXAConnectionFactory xaFactory = new ActiveMQXAConnectionFactory(getUri(configuration)); xaFactory.setProperties(configuration.getFactoryProperties()); xaFactory.setUserName(configuration.getUsername()); xaFactory.setPassword(configuration.getPassword()); if (clientId != null) { // since a client id is specified (possibly for a durable subscription), create a singleton connection so the connection id is unique setClientId(clientId, xaFactory); return new XaSingletonConnectionFactory(xaFactory, monitor); } return xaFactory; default: // default to local pooled ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(getUri(configuration)); factory.setProperties(configuration.getFactoryProperties()); factory.setUserName(configuration.getUsername()); factory.setPassword(configuration.getPassword()); if (clientId != null) { // since a client id is specified (possibly for a durable subscription), create a singleton connection so the connection id is unique setClientId(clientId, factory); return new SingletonConnectionFactory(factory, monitor); } return factory; } }
public ConnectionFactoryResourceBuilder property(String key, String value) { checkState(); definition.getConfiguration().setFactoryProperty(key, value); return this; }
/** * Sets the client id. The runtime name can be used via the <code>{runtime}</code> parameter. * * @param clientId the client id * @return the builder */ public ConnectionFactoryResourceBuilder clientId(String clientId) { checkState(); definition.getConfiguration().setClientId(clientId); return this; }
public ConnectionFactoryResourceBuilder username(String username) { checkState(); definition.getConfiguration().setUsername(username); return this; }
public ConnectionFactoryResourceBuilder password(String password) { checkState(); definition.getConfiguration().setPassword(password); return this; }
public ConnectionFactoryResourceBuilder attribute(String key, Object value) { checkState(); definition.getConfiguration().addAttribute(key, value); return this; }
public ConnectionFactoryResourceBuilder type(ConnectionFactoryType type) { checkState(); definition.getConfiguration().setType(type); return this; }
public ConnectionFactoryResourceBuilder provider(String provider) { checkState(); definition.getConfiguration().setProvider(provider); return this; }
private Map<String, String> getProperties(ConnectionFactoryConfiguration configuration) { Properties properties = configuration.getFactoryProperties(); Map<String, String> factoryProperties = new HashMap<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { factoryProperties.put(entry.getKey().toString(), entry.getValue().toString()); } return factoryProperties; } }
private void parseFactoryProperties(ConnectionFactoryConfiguration configuration, XMLStreamReader reader) throws XMLStreamException { while (true) { switch (reader.next()) { case XMLStreamConstants.START_ELEMENT: configuration.setFactoryProperty(reader.getName().getLocalPart(), reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if ("factory.properties".equals(reader.getName().getLocalPart())) { return; } break; case XMLStreamConstants.END_DOCUMENT: return; } } }
public PhysicalConnectionFactory generateResource(LogicalResource<ConnectionFactoryResource> resource) { return new PhysicalConnectionFactory(resource.getDefinition().getConfiguration()); } }
public ConnectionFactoryResource load(XMLStreamReader reader, IntrospectionContext context) throws XMLStreamException { if (parsers.isEmpty()) { // skip the resource return null; } String provider = reader.getAttributeValue(null, "provider"); ConnectionFactoryConfigurationParser parser; if (provider == null) { parser = parsers.values().iterator().next(); } else { parser = parsers.get(provider); if (parser == null) { UnrecognizedAttribute error = new UnrecognizedAttribute("JMS provider not installed: " + provider, reader.getLocation()); context.addError(error); return null; } } ConnectionFactoryConfiguration configuration = parser.parse(reader, context); return new ConnectionFactoryResource(configuration); } }
@Destroy public void destroy() throws Fabric3Exception { for (ConnectionFactoryConfiguration configuration : factoryConfigurations) { manager.unregister(configuration.getName()); } Iterator<ConnectionFactory> iterator = factories.iterator(); while (iterator.hasNext()) { ConnectionFactory factory = iterator.next(); creatorRegistry.release(factory); iterator.remove(); } }
@SuppressWarnings({"unchecked"}) public ConnectionFactory create(ConnectionFactoryConfiguration configuration) throws Fabric3Exception { if (creators.isEmpty()) { throw new Fabric3Exception("JMS Provider not installed"); } String provider = configuration.getProvider(); ConnectionFactoryCreator creator = provider == null ? creators.values().iterator().next() : creators.get(provider); if (creator == null) { throw new Fabric3Exception("Provider not found: " + provider); } ConnectionFactory factory = creator.create(configuration); factories.put(factory, creator); return factory; }
private Map<String, String> getProperties(ConnectionFactoryConfiguration configuration) { Properties properties = configuration.getFactoryProperties(); Map<String, String> factoryProperties = new HashMap<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { factoryProperties.put(entry.getKey().toString(), entry.getValue().toString()); } return factoryProperties; }
public void remove(PhysicalConnectionFactory definition) { ConnectionFactory factory = manager.unregister(definition.getConfiguration().getName()); registry.release(factory); }
public void build(PhysicalConnectionFactory physicalFactory) { ConnectionFactoryConfiguration configuration = physicalFactory.getConfiguration(); ConnectionFactory factory = registry.create(configuration); String name = configuration.getName(); Map<String, String> factoryProperties = getProperties(configuration); manager.register(name, factory, factoryProperties); }