org.apache.activemq.util.IntrospectionSupport Java Examples

The following examples show how to use org.apache.activemq.util.IntrospectionSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActiveMQConnectionFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public boolean buildFromMap(Map<String, Object> properties) {
   boolean rc = false;

   ActiveMQPrefetchPolicy p = new ActiveMQPrefetchPolicy();
   if (IntrospectionSupport.setProperties(p, properties, "prefetchPolicy.")) {
      setPrefetchPolicy(p);
      rc = true;
   }

   RedeliveryPolicy rp = new RedeliveryPolicy();
   if (IntrospectionSupport.setProperties(rp, properties, "redeliveryPolicy.")) {
      setRedeliveryPolicy(rp);
      rc = true;
   }

   BlobTransferPolicy blobTransferPolicy = new BlobTransferPolicy();
   if (IntrospectionSupport.setProperties(blobTransferPolicy, properties, "blobTransferPolicy.")) {
      setBlobTransferPolicy(blobTransferPolicy);
      rc = true;
   }

   rc |= IntrospectionSupport.setProperties(this, properties);

   return rc;
}
 
Example #2
Source File: TcpTransportFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public TransportServer doBind(final URI location) throws IOException {
   try {
      Map<String, String> options = new HashMap<>(URISupport.parseParameters(location));

      ServerSocketFactory serverSocketFactory = createServerSocketFactory();
      TcpTransportServer server = createTcpTransportServer(location, serverSocketFactory);
      server.setWireFormatFactory(createWireFormatFactory(options));
      IntrospectionSupport.setProperties(server, options);
      Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
      server.setTransportOption(transportOptions);
      server.bind();

      return server;
   } catch (URISyntaxException e) {
      throw IOExceptionSupport.create(e);
   }
}
 
Example #3
Source File: TcpFaultyTransportFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public TransportServer doBind(final URI location) throws IOException {
   try {
      Map<String, String> options = new HashMap<>(URISupport.parseParameters(location));

      ServerSocketFactory serverSocketFactory = createServerSocketFactory();
      TcpFaultyTransportServer server = createTcpFaultyTransportServer(location, serverSocketFactory);
      server.setWireFormatFactory(createWireFormatFactory(options));
      IntrospectionSupport.setProperties(server, options);
      Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
      server.setTransportOption(transportOptions);
      server.bind();

      return server;
   } catch (URISyntaxException e) {
      throw IOExceptionSupport.create(e);
   }
}
 
Example #4
Source File: ActiveMQ5Factory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private BrokerService newPatchedBrokerService() {
    return new BrokerService() {
        @Override
        public NetworkConnector addNetworkConnector(final URI discoveryAddress) throws Exception {
            final NetworkConnector connector = new DiscoveryNetworkConnector(discoveryAddress);
            try { // try to set properties to broker too
                final Map<String, String> props = URISupport.parseParameters(discoveryAddress);
                if (!props.containsKey("skipConnector")) {
                    IntrospectionSupport.setProperties(connector, props);
                }
            } catch (final URISyntaxException e) {
                // low level cause not supported by AMQ by default
                Logger.getInstance(LogCategory.OPENEJB_STARTUP, ActiveMQ5Factory.class).getChildLogger("service")
                        .debug(e.getMessage());
            }
            return addNetworkConnector(connector);
        }
    };
}
 
Example #5
Source File: KubernetesDiscoveryAgentFactory.java    From activemq-k8s-discovery with Apache License 2.0 5 votes vote down vote up
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        Map<String, String> options = URISupport.parseParameters(uri);
        KubernetesDiscoveryAgent rc = new KubernetesDiscoveryAgent();
        IntrospectionSupport.setProperties(rc, options);
        LOG.info("Succesfully created Kubernetes discovery agent from URI: {}", uri);

        return rc;
        
    } catch (Throwable e) {
        LOG.error("Could not create Kubernetes discovery agent: " + uri, e);
        throw IOExceptionSupport.create("Could not create Kubernetes discovery agent: " + uri, e);
    }
}
 
Example #6
Source File: KubeDiscoveryAgentFactory.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
@Override
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        LOGGER.info("Creating Kubernetes discovery agent for {}.", uri.toString());
        final Map<String, String> options = URISupport.parseParameters(uri);
        uri = URISupport.removeQuery(uri);
        final OpenShiftDiscoveryAgent agent = new OpenShiftDiscoveryAgent(new KubePeerAddressResolver(
                uri.getHost(), uri.getPort()));
        IntrospectionSupport.setProperties(agent, options);
        return agent;
    } catch (Throwable e) {
        throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
    }
}
 
Example #7
Source File: DNSDiscoveryAgentFactory.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
@Override
protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException {
    try {
        LOGGER.info("Creating DNS discovery agent for {}.", uri.toString());
        final Map<String, String> options = URISupport.parseParameters(uri);
        uri = URISupport.removeQuery(uri);
        final OpenShiftDiscoveryAgent agent = new OpenShiftDiscoveryAgent(new DNSPeerResolver(uri.getHost(), uri.getPort()));
        IntrospectionSupport.setProperties(agent, options);
        return agent;
    } catch (Throwable e) {
        throw IOExceptionSupport.create("Could not create discovery agent: " + uri, e);
    }
}
 
Example #8
Source File: TcpTransportFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public Transport compositeConfigure(Transport transport, WireFormat format, Map options) {

   TcpTransport tcpTransport = transport.narrow(TcpTransport.class);
   IntrospectionSupport.setProperties(tcpTransport, options);

   Map<String, Object> socketOptions = IntrospectionSupport.extractProperties(options, "socket.");
   tcpTransport.setSocketOptions(socketOptions);

   if (tcpTransport.isTrace()) {
      try {
         transport = TransportLoggerSupport.createTransportLogger(transport, tcpTransport.getLogWriterName(), tcpTransport.isDynamicManagement(), tcpTransport.isStartLogging(), tcpTransport.getJmxPort());
      } catch (Throwable e) {
         LOG.error("Could not create TransportLogger object for: " + tcpTransport.getLogWriterName() + ", reason: " + e, e);
      }
   }

   boolean useInactivityMonitor = "true".equals(getOption(options, "useInactivityMonitor", "true"));
   if (useInactivityMonitor && isUseInactivityMonitor(transport)) {
      transport = createInactivityMonitor(transport, format);
      IntrospectionSupport.setProperties(transport, options);
   }

   // Only need the WireFormatNegotiator if using openwire
   if (format instanceof OpenWireFormat) {
      transport = new WireFormatNegotiator(transport, (OpenWireFormat) format, tcpTransport.getMinmumWireFormatVersion());
   }

   return super.compositeConfigure(transport, format, options);
}
 
Example #9
Source File: FailoverStaticNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(String scheme,
                                     String listenPort,
                                     String[] networkToPorts,
                                     HashMap<String, String> networkProps) throws Exception {
   BrokerService broker = new BrokerService();
   broker.getManagementContext().setCreateConnector(false);
   broker.setSslContext(sslContext);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setBrokerName("Broker_" + listenPort);
   // lazy init listener on broker start
   TransportConnector transportConnector = new TransportConnector();
   transportConnector.setUri(new URI(scheme + "://localhost:" + listenPort));
   List<TransportConnector> transportConnectors = new ArrayList<>();
   transportConnectors.add(transportConnector);
   broker.setTransportConnectors(transportConnectors);
   if (networkToPorts != null && networkToPorts.length > 0) {
      StringBuilder builder = new StringBuilder("static:(failover:(" + scheme + "://localhost:");
      builder.append(networkToPorts[0]);
      for (int i = 1; i < networkToPorts.length; i++) {
         builder.append("," + scheme + "://localhost:" + networkToPorts[i]);
      }
      // limit the reconnects in case of initial random connection to slave
      // leaving randomize on verifies that this config is picked up
      builder.append(")?maxReconnectAttempts=0)?useExponentialBackOff=false");
      NetworkConnector nc = broker.addNetworkConnector(builder.toString());
      if (networkProps != null) {
         IntrospectionSupport.setProperties(nc, networkProps);
      }
   }
   return broker;
}
 
Example #10
Source File: ActiveMQ5Factory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private BrokerService newDefaultBroker(final URI uri) throws Exception {
    final URISupport.CompositeData compositeData = URISupport.parseComposite(uri);
    final Map<String, String> params = new HashMap<>(compositeData.getParameters());

    final BrokerService brokerService = newPatchedBrokerService();

    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());
    }

    for (final URI component : compositeData.getComponents()) {
        if ("network".equals(component.getScheme())) {
            brokerService.addNetworkConnector(component.getSchemeSpecificPart());
        } else if ("proxy".equals(component.getScheme())) {
            brokerService.addProxyConnector(component.getSchemeSpecificPart());
        } else {
            brokerService.addConnector(component);
        }
    }
    return brokerService;
}
 
Example #11
Source File: ActiveMQConnectionFactory.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
public void populateProperties(Properties props) {
   props.setProperty("dispatchAsync", Boolean.toString(isDispatchAsync()));

   if (getBrokerURL() != null) {
      props.setProperty(Context.PROVIDER_URL, getBrokerURL());
      props.setProperty("brokerURL", getBrokerURL());
   }

   if (getClientID() != null) {
      props.setProperty("clientID", getClientID());
   }

   IntrospectionSupport.getProperties(getPrefetchPolicy(), props, "prefetchPolicy.");
   IntrospectionSupport.getProperties(getRedeliveryPolicy(), props, "redeliveryPolicy.");
   IntrospectionSupport.getProperties(getBlobTransferPolicy(), props, "blobTransferPolicy.");

   props.setProperty("copyMessageOnSend", Boolean.toString(isCopyMessageOnSend()));
   props.setProperty("disableTimeStampsByDefault", Boolean.toString(isDisableTimeStampsByDefault()));
   props.setProperty("objectMessageSerializationDefered", Boolean.toString(isObjectMessageSerializationDefered()));
   props.setProperty("optimizedMessageDispatch", Boolean.toString(isOptimizedMessageDispatch()));

   if (getPassword() != null) {
      props.setProperty("password", getPassword());
   }

   props.setProperty("useAsyncSend", Boolean.toString(isUseAsyncSend()));
   props.setProperty("useCompression", Boolean.toString(isUseCompression()));
   props.setProperty("useRetroactiveConsumer", Boolean.toString(isUseRetroactiveConsumer()));
   props.setProperty("watchTopicAdvisories", Boolean.toString(isWatchTopicAdvisories()));

   if (getUserName() != null) {
      props.setProperty("userName", getUserName());
   }

   props.setProperty("closeTimeout", Integer.toString(getCloseTimeout()));
   props.setProperty("alwaysSessionAsync", Boolean.toString(isAlwaysSessionAsync()));
   props.setProperty("optimizeAcknowledge", Boolean.toString(isOptimizeAcknowledge()));
   props.setProperty("statsEnabled", Boolean.toString(isStatsEnabled()));
   props.setProperty("alwaysSyncSend", Boolean.toString(isAlwaysSyncSend()));
   props.setProperty("producerWindowSize", Integer.toString(getProducerWindowSize()));
   props.setProperty("sendTimeout", Integer.toString(getSendTimeout()));
   props.setProperty("sendAcksAsync", Boolean.toString(isSendAcksAsync()));
   props.setProperty("auditDepth", Integer.toString(getAuditDepth()));
   props.setProperty("auditMaximumProducerNumber", Integer.toString(getAuditMaximumProducerNumber()));
   props.setProperty("checkForDuplicates", Boolean.toString(isCheckForDuplicates()));
   props.setProperty("messagePrioritySupported", Boolean.toString(isMessagePrioritySupported()));
   props.setProperty("transactedIndividualAck", Boolean.toString(isTransactedIndividualAck()));
   props.setProperty("nonBlockingRedelivery", Boolean.toString(isNonBlockingRedelivery()));
   props.setProperty("maxThreadPoolSize", Integer.toString(getMaxThreadPoolSize()));
   props.setProperty("nestedMapAndListEnabled", Boolean.toString(isNestedMapAndListEnabled()));
   props.setProperty("consumerFailoverRedeliveryWaitPeriod", Long.toString(getConsumerFailoverRedeliveryWaitPeriod()));
   props.setProperty("rmIdFromConnectionId", Boolean.toString(isRmIdFromConnectionId()));
   props.setProperty("consumerExpiryCheckEnabled", Boolean.toString(isConsumerExpiryCheckEnabled()));
}
 
Example #12
Source File: CommandLineSupport.java    From chipster with MIT License 4 votes vote down vote up
/**
 * Sets the properties of an object given the command line args.
 * 
 * if args contains: --ack-mode=AUTO --url=tcp://localhost:61616 --persistent 
 * 
 * then it will try to call the following setters on the target object.
 * 
 * target.setAckMode("AUTO");
 * target.setURL(new URI("tcp://localhost:61616") );
 * target.setPersistent(true);
 * 
 * Notice the the proper conversion for the argument is determined by examining the 
 * setter arguement type.  
 * 
 * @param target the object that will have it's properties set
 * @param args the commline options
 * @return any arguments that are not valid options for the target
 */
public static String[] setOptions(Object target, String[] args) {
    ArrayList<String> rc = new ArrayList<String>();

    for (int i = 0; i < args.length; i++) {
        if (args[i] == null) {
            continue;
        }

        if (args[i].startsWith("--")) {

            // --options without a specified value are considered boolean
            // flags that are enabled.
            String value = "true";
            String name = args[i].substring(2);

            // if --option=value case
            int p = name.indexOf("=");
            if (p > 0) {
                value = name.substring(p + 1);
                name = name.substring(0, p);
            }

            // name not set, then it's an unrecognized option
            if (name.length() == 0) {
                rc.add(args[i]);
                continue;
            }

            String propName = convertOptionToPropertyName(name);
            if (!IntrospectionSupport.setProperty(target, propName, value)) {
                rc.add(args[i]);
                continue;
            }
        }

    }

    String r[] = new String[rc.size()];
    rc.toArray(r);
    return r;
}