Search in sources :

Example 1 with CompositeData

use of org.apache.activemq.util.URISupport.CompositeData in project activemq-artemis by apache.

the class DiscoveryTransportNoBrokerTest method testSetDiscoveredStaticBrokerProperties.

public void testSetDiscoveredStaticBrokerProperties() throws Exception {
    final String extraParameterName = "connectionTimeout";
    final String extraParameterValue = "3000";
    final URI uri = new URI("discovery:(static:tcp://localhost:61616)?initialReconnectDelay=100&" + DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue);
    CompositeData compositeData = URISupport.parseComposite(uri);
    StubCompositeTransport compositeTransport = new StubCompositeTransport();
    DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());
    discoveryTransport.start();
    assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length);
    URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
    Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
    assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
    assertEquals("incorrect value for parameter added to discovered service", parameters.get(extraParameterName), extraParameterValue);
}
Also used : CompositeData(org.apache.activemq.util.URISupport.CompositeData) URI(java.net.URI) StubCompositeTransport(org.apache.activemq.transport.StubCompositeTransport)

Example 2 with CompositeData

use of org.apache.activemq.util.URISupport.CompositeData in project activemq-artemis by apache.

the class DiscoveryTransportNoBrokerTest method testAddRemoveDiscoveredBroker.

public void testAddRemoveDiscoveredBroker() throws Exception {
    final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&connectionTimeout=3000");
    CompositeData compositeData = URISupport.parseComposite(uri);
    StubCompositeTransport compositeTransport = new StubCompositeTransport();
    DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());
    final String serviceName = "tcp://localhost:61616";
    discoveryTransport.onServiceAdd(new DiscoveryEvent(serviceName));
    assertEquals("expected added URI after discovery event", 1, compositeTransport.getTransportURIs().length);
    discoveryTransport.onServiceRemove(new DiscoveryEvent(serviceName));
    assertEquals("expected URI removed after discovery event", 0, compositeTransport.getTransportURIs().length);
}
Also used : CompositeData(org.apache.activemq.util.URISupport.CompositeData) DiscoveryEvent(org.apache.activemq.command.DiscoveryEvent) URI(java.net.URI) StubCompositeTransport(org.apache.activemq.transport.StubCompositeTransport)

Example 3 with CompositeData

use of org.apache.activemq.util.URISupport.CompositeData in project activemq-artemis by apache.

the class ActiveMQConnectionFactory method setBrokerURL.

public void setBrokerURL(String brokerURL) {
    URI uri = null;
    try {
        uri = new URI(brokerURL);
        String scheme = uri.getScheme();
        if ("vm".equals(scheme)) {
            this.vmBrokerUri = uri;
        }
    } catch (URISyntaxException e) {
    }
    this.brokerURL = createURI(brokerURL);
    // options.
    if (this.brokerURL.getQuery() != null) {
        // It might be a standard URI or...
        try {
            Map<String, String> map = URISupport.parseQuery(this.brokerURL.getQuery());
            Map<String, Object> jmsOptionsMap = IntrospectionSupport.extractProperties(map, "jms.");
            if (buildFromMap(jmsOptionsMap)) {
                if (!jmsOptionsMap.isEmpty()) {
                    String msg = "There are " + jmsOptionsMap.size() + " jms options that couldn't be set on the ConnectionFactory." + " Check the options are spelled correctly." + " Unknown parameters=[" + jmsOptionsMap + "]." + " This connection factory cannot be started.";
                    throw new IllegalArgumentException(msg);
                }
                this.brokerURL = URISupport.createRemainingURI(this.brokerURL, map);
            }
        } catch (URISyntaxException e) {
        }
    } else {
        // It might be a composite URI.
        try {
            CompositeData data = URISupport.parseComposite(this.brokerURL);
            Map<String, Object> jmsOptionsMap = IntrospectionSupport.extractProperties(data.getParameters(), "jms.");
            if (buildFromMap(jmsOptionsMap)) {
                if (!jmsOptionsMap.isEmpty()) {
                    String msg = "There are " + jmsOptionsMap.size() + " jms options that couldn't be set on the ConnectionFactory." + " Check the options are spelled correctly." + " Unknown parameters=[" + jmsOptionsMap + "]." + " This connection factory cannot be started.";
                    throw new IllegalArgumentException(msg);
                }
                this.brokerURL = data.toURI();
            }
        } catch (URISyntaxException e) {
        }
    }
}
Also used : CompositeData(org.apache.activemq.util.URISupport.CompositeData) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 4 with CompositeData

use of org.apache.activemq.util.URISupport.CompositeData in project activemq-artemis by apache.

the class DiscoveryTransportNoBrokerTest method testSetDiscoveredBrokerProperties.

public void testSetDiscoveredBrokerProperties() throws Exception {
    final String extraParameterName = "connectionTimeout";
    final String extraParameterValue = "3000";
    final URI uri = new URI("discovery:(multicast://default)?initialReconnectDelay=100&" + DiscoveryListener.DISCOVERED_OPTION_PREFIX + extraParameterName + "=" + extraParameterValue);
    CompositeData compositeData = URISupport.parseComposite(uri);
    StubCompositeTransport compositeTransport = new StubCompositeTransport();
    DiscoveryTransport discoveryTransport = DiscoveryTransportFactory.createTransport(compositeTransport, compositeData, compositeData.getParameters());
    discoveryTransport.onServiceAdd(new DiscoveryEvent("tcp://localhost:61616"));
    assertEquals("expected added URI after discovery event", compositeTransport.getTransportURIs().length, 1);
    URI discoveredServiceURI = compositeTransport.getTransportURIs()[0];
    Map<String, String> parameters = URISupport.parseParameters(discoveredServiceURI);
    assertTrue("unable to add parameter to discovered service", parameters.containsKey(extraParameterName));
    assertEquals("incorrect value for parameter added to discovered service", parameters.get(extraParameterName), extraParameterValue);
}
Also used : CompositeData(org.apache.activemq.util.URISupport.CompositeData) DiscoveryEvent(org.apache.activemq.command.DiscoveryEvent) URI(java.net.URI) StubCompositeTransport(org.apache.activemq.transport.StubCompositeTransport)

Aggregations

URI (java.net.URI)4 CompositeData (org.apache.activemq.util.URISupport.CompositeData)4 StubCompositeTransport (org.apache.activemq.transport.StubCompositeTransport)3 DiscoveryEvent (org.apache.activemq.command.DiscoveryEvent)2 URISyntaxException (java.net.URISyntaxException)1