@Override public void buildFromProperties(Properties properties) { if (properties == null) { properties = new Properties(); } IntrospectionSupport.setProperties(this, properties); }
location = new URI("vm://" + host); } else { options = URISupport.parseParameters(location); String config = options.remove("brokerConfig"); if (config != null) { brokerURI = new URI(config); } else { Map<String, Object> brokerOptions = IntrospectionSupport.extractProperties(options, "broker."); throw IOExceptionSupport.create(e1); broker = BrokerFactory.createBroker(brokerURI); broker.start(); MDC.put("activemq.broker", broker.getBrokerName()); } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); IntrospectionSupport.setProperties(vmtransport.peer, new HashMap<String,String>(options)); IntrospectionSupport.setProperties(vmtransport, options); Transport transport = vmtransport; if (vmtransport.isMarshal()) {
private void storeMetaData() throws IOException { // Convert the metadata into a property format metaData.metaDataTxId++; Properties p = new Properties(); IntrospectionSupport.getProperties(metaData, p, null); ByteArrayOutputStream os = new ByteArrayOutputStream(PAGE_FILE_HEADER_SIZE); p.store(os, ""); if (os.size() > PAGE_FILE_HEADER_SIZE / 2) { throw new IOException("Configuation is larger than: " + PAGE_FILE_HEADER_SIZE / 2); } // Fill the rest with space... byte[] filler = new byte[(PAGE_FILE_HEADER_SIZE / 2) - os.size()]; Arrays.fill(filler, (byte) ' '); os.write(filler); os.flush(); byte[] d = os.toByteArray(); // So we don't loose it.. write it 2 times... writeFile.seek(0); writeFile.write(d); writeFile.sync(); writeFile.seek(PAGE_FILE_HEADER_SIZE / 2); writeFile.write(d); writeFile.sync(); }
private PersistenceAdapter kahaDBFromTemplate(PersistenceAdapter template) throws IOException { try { Map<String, Object> configuration = new HashMap<String, Object>(); IntrospectionSupport.getProperties(template, configuration, null); PersistenceAdapter adapter = template.getClass().newInstance(); IntrospectionSupport.setProperties(adapter, configuration); return adapter; } catch (Exception e) { throw IOExceptionSupport.create(e); } }
public FailoverTransport createTransport(Map<String, String> parameters) throws IOException { FailoverTransport transport = new FailoverTransport(); Map<String, Object> nestedExtraQueryOptions = IntrospectionSupport.extractProperties(parameters, "nested."); IntrospectionSupport.setProperties(transport, parameters); try { transport.setNestedExtraQueryOptions(URISupport.createQueryString(nestedExtraQueryOptions)); } catch (URISyntaxException e) { } return transport; }
public static boolean setProperty(Object target, String name, Object value) { try { Class<?> clazz = target.getClass(); if (target instanceof SSLServerSocket) { // overcome illegal access issues with internal implementation class clazz = SSLServerSocket.class; } Method setter = findSetterMethod(clazz, name); if (setter == null) { return false; } // If the type is null or it matches the needed type, just use the // value directly if (value == null || value.getClass() == setter.getParameterTypes()[0]) { setter.invoke(target, value); } else { // We need to convert it setter.invoke(target, convert(value, setter.getParameterTypes()[0])); } return true; } catch (Exception e) { LOG.error(String.format("Could not set property %s on %s", name, target), e); return false; } }
MetaData v2 = new MetaData(); try { Properties p = new Properties(); byte[] d = new byte[PAGE_FILE_HEADER_SIZE / 2]; readFile.seek(0); readFile.readFully(d); is = new ByteArrayInputStream(d); p.load(is); IntrospectionSupport.setProperties(v1, p); } catch (IOException e) { v1 = null; Properties p = new Properties(); byte[] d = new byte[PAGE_FILE_HEADER_SIZE / 2]; readFile.seek(PAGE_FILE_HEADER_SIZE / 2); is = new ByteArrayInputStream(d); p.load(is); IntrospectionSupport.setProperties(v2, p); } catch (IOException e) { v2 = null;
brokerInfo.setDuplexConnection(configuration.isDuplex()); Properties props = new Properties(); IntrospectionSupport.getProperties(configuration, props, null); props.put(dynamicallyIncludedDestinationsKey, StringToListOfActiveMQDestinationConverter. convertFromActiveMQDestination(configuration.getDynamicallyIncludedDestinations(), true)); props.put(staticallyIncludedDestinationsKey, StringToListOfActiveMQDestinationConverter. convertFromActiveMQDestination(configuration.getStaticallyIncludedDestinations(), true)); demandConsumerInfo = new ConsumerInfo(remoteSessionInfo, 1); demandConsumerInfo.setDispatchAsync(true); String advisoryTopic = configuration.getDestinationFilter(); if (configuration.isBridgeTempDestinations()) { advisoryTopic += "," + AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC; demandConsumerInfo.setDestination(new ActiveMQTopic(advisoryTopic)); configureConsumerPrefetch(demandConsumerInfo); remoteBroker.oneway(demandConsumerInfo);
@Override public BrokerService createBroker(URI brokerURI) throws Exception { BrokerService service = new BrokerService(); IntrospectionSupport.setProperties(service, brokerOptions); service.setBrokerName(finalBroker); TransportConnector c = service.addConnector("tcp://0.0.0.0:0"); c.setDiscoveryUri(new URI("multicast://default?group=" + finalGroup)); service.addNetworkConnector("multicast://default?group=" + finalGroup); return service; } });
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException { try { if (LOG.isTraceEnabled()) { LOG.trace("doCreateDiscoveryAgent: uri = " + uri.toString()); } MulticastDiscoveryAgent mda = new MulticastDiscoveryAgent(); mda.setDiscoveryURI(uri); // allow MDA's params to be set via query arguments // (e.g., multicast://default?group=foo Map options = URISupport.parseParameters(uri); IntrospectionSupport.setProperties(mda, options); return mda; } catch (Throwable e) { throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e); } } }
private NetworkConnector createNetworkConnector(URI uri,Properties properties) throws URISyntaxException, IOException { NetworkConnector nc = new DiscoveryNetworkConnector(uri); Map<String, Object> networkProperties = new HashMap<String, Object>(); // use default credentials for network connector (if none was specified) networkProperties.put("network.userName", "admin"); networkProperties.put("network.password", properties.getProperty("zookeeper.password")); for (String k : properties.stringPropertyNames()) { networkProperties.put(k, properties.getProperty(k)); } IntrospectionSupport.setProperties(nc, networkProperties, "network."); return nc; }
public BrokerService createBroker(URI brokerURI) throws Exception { CompositeData compositeData = URISupport.parseComposite(brokerURI); Map<String, String> params = new HashMap<String, String>(compositeData.getParameters()); BrokerService brokerService = new BrokerService(); IntrospectionSupport.setProperties(brokerService, params); if (!params.isEmpty()) { String msg = "There are " + params.size() + " Broker options that couldn't be set on the BrokerService." + " Check the options are spelled correctly." + " Unknown parameters=[" + params + "]." + " This BrokerService cannot be started."; throw new IllegalArgumentException(msg); } if (compositeData.getPath() != null) { brokerService.setBrokerName(compositeData.getPath()); } URI[] components = compositeData.getComponents(); for (int i = 0; i < components.length; i++) { if ("network".equals(components[i].getScheme())) { brokerService.addNetworkConnector(components[i].getSchemeSpecificPart()); } else if ("proxy".equals(components[i].getScheme())) { brokerService.addProxyConnector(components[i].getSchemeSpecificPart()); } else { brokerService.addConnector(components[i]); } } return brokerService; }
@Override public void populateProperties(Properties props) { props.setProperty("dispatchAsync", Boolean.toString(isDispatchAsync())); props.setProperty(Context.PROVIDER_URL, getBrokerURL()); props.setProperty("brokerURL", getBrokerURL()); IntrospectionSupport.getProperties(getPrefetchPolicy(), props, "prefetchPolicy."); IntrospectionSupport.getProperties(getRedeliveryPolicy(), props, "redeliveryPolicy."); IntrospectionSupport.getProperties(getBlobTransferPolicy(), props, "blobTransferPolicy."); props.setProperty("copyMessageOnSend", Boolean.toString(isCopyMessageOnSend()));
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException { try { Map options = URISupport.parseParameters(uri); ZeroconfDiscoveryAgent rc = new ZeroconfDiscoveryAgent(); rc.setGroup(uri.getHost()); IntrospectionSupport.setProperties(rc, options); return rc; } catch (Throwable e) { throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e); } } }
public Transport doConnect(URI location) throws Exception { try { Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location)); if( !options.containsKey("wireFormat.host") ) { options.put("wireFormat.host", location.getHost()); } WireFormat wf = createWireFormat(options); Transport transport = createTransport(location, wf); Transport rc = configure(transport, wf, options); //remove auto IntrospectionSupport.extractProperties(options, "auto."); if (!options.isEmpty()) { throw new IllegalArgumentException("Invalid connect parameters: " + options); } return rc; } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); } }
/** * Connect to a remote node such as a Broker. * * @param wireFormat The WireFormat to be used. * @param socketFactory The socket factory to be used. Forcing SSLSockets * for obvious reasons. * @param remoteLocation The remote location. * @param localLocation The local location. * @param needClientAuth If set to true, the underlying socket will need * client certificate authentication. * @throws UnknownHostException If TcpTransport throws. * @throws IOException If TcpTransport throws. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public SslTransport(WireFormat wireFormat, SSLSocketFactory socketFactory, URI remoteLocation, URI localLocation, boolean needClientAuth) throws IOException { super(wireFormat, socketFactory, remoteLocation, localLocation); if (this.socket != null) { ((SSLSocket)this.socket).setNeedClientAuth(needClientAuth); // Lets try to configure the SSL SNI field. Handy in case your using // a single proxy to route to different messaging apps. // On java 1.7 it seems like it can only be configured via reflection. // TODO: find out if this will work on java 1.8 HashMap props = new HashMap(); props.put("host", remoteLocation.getHost()); IntrospectionSupport.setProperties(this.socket, props); } }
protected void buildFromProperties(Properties props) { ActiveMQConnectionFactory activeMQConnectionFactory = props.containsKey("xaAckMode") ? new ActiveMQXAConnectionFactory() : new ActiveMQConnectionFactory(); activeMQConnectionFactory.buildFromProperties(props); setConnectionFactory(activeMQConnectionFactory); IntrospectionSupport.setProperties(this, new HashMap(props), POOL_PROPS_PREFIX); }
if (this.brokerURL.getQuery() != null) { Map<String,String> map = URISupport.parseQuery(this.brokerURL.getQuery()); Map<String,Object> jmsOptionsMap = IntrospectionSupport.extractProperties(map, "jms."); if (buildFromMap(jmsOptionsMap)) { if (!jmsOptionsMap.isEmpty()) { this.brokerURL = URISupport.createRemainingURI(this.brokerURL, map); CompositeData data = URISupport.parseComposite(this.brokerURL); Map<String,Object> jmsOptionsMap = IntrospectionSupport.extractProperties(data.getParameters(), "jms."); if (buildFromMap(jmsOptionsMap)) { if (!jmsOptionsMap.isEmpty()) {
public BrokerService createBroker(URI config) throws Exception { String uri = config.getSchemeSpecificPart(); if (uri.lastIndexOf('?') != -1) { IntrospectionSupport.setProperties(this, URISupport.parseQuery(uri)); uri = uri.substring(0, uri.lastIndexOf('?')); springBrokerContext.setApplicationContext(context); springBrokerContext.setConfigurationUrl(uri); broker.setBrokerContext(springBrokerContext);
public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, ServerSessionPool sessionPool, int maxMessages, boolean noLocal) throws JMSException { checkClosedOrFailed(); ensureConnectionInfoSent(); ConsumerId consumerId = createConsumerId(); ConsumerInfo consumerInfo = new ConsumerInfo(consumerId); consumerInfo.setDestination(ActiveMQMessageTransformation.transformDestination(destination)); consumerInfo.setSelector(messageSelector); consumerInfo.setPrefetchSize(maxMessages); consumerInfo.setNoLocal(noLocal); consumerInfo.setDispatchAsync(isDispatchAsync()); // Allows the options on the destination to configure the consumerInfo if (consumerInfo.getDestination().getOptions() != null) { Map<String, String> options = new HashMap<>(consumerInfo.getDestination().getOptions()); IntrospectionSupport.setProperties(consumerInfo, options, "consumer."); } return new ActiveMQConnectionConsumer(this, sessionPool, consumerInfo); }