org.apache.camel.support.service.ServiceHelper Java Examples

The following examples show how to use org.apache.camel.support.service.ServiceHelper. 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: ReactiveStreamsRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStop() throws Exception {
    ServiceHelper.stopService(this.reactiveStreamService);
    this.reactiveStreamService = null;

    super.doStop();
}
 
Example #2
Source File: KnativeComponent.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() throws Exception {
    super.doStart();

    if (this.transport != null && managedTransport) {
        ServiceHelper.startService(this.transport);
    }
}
 
Example #3
Source File: KnativeComponent.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStop() throws Exception {
    super.doStop();

    if (this.transport != null && managedTransport) {
        ServiceHelper.stopService(this.transport);
    }
}
 
Example #4
Source File: CamelPropertiesHelper.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the properties on the target bean.
 * <p/>
 * This method uses {@link PropertyBindingSupport} and therefore offers its capabilities such as:
 * <ul>
 *     <li>property placeholders - Keys and values using Camels property placeholder will be resolved</li>
 *     <li>nested - Properties can be nested using the dot syntax (OGNL and builder pattern using with as prefix), eg foo.bar=123</li>
 *     <li>map</li> - Properties can lookup in Map's using map syntax, eg foo[bar] where foo is the name of the property that is a Map instance, and bar is the name of the key.</li>
 *     <li>list</li> - Properties can refer or add to in List's using list syntax, eg foo[0] where foo is the name of the property that is a
 *                     List instance, and 0 is the index. To refer to the last element, then use last as key.</li>
 * </ul>
 * This implementation sets the properties using the following algorithm in the given order:
 * <ul>
 *     <li>reference by bean id - Values can refer to other beans in the registry by prefixing with with # or #bean: eg #myBean or #bean:myBean</li>
 *     <li>reference by type - Values can refer to singleton beans by their type in the registry by prefixing with #type: syntax, eg #type:com.foo.MyClassType</li>
 *     <li>autowire by type - Values can refer to singleton beans by auto wiring by setting the value to #autowired</li>
 *     <li>reference new class - Values can refer to creating new beans by their class name by prefixing with #class, eg #class:com.foo.MyClassType</li>
 *     <li>value as lookup - The value is used as-is (eg like #value) to lookup in the Registry if there is a bean then its set on the target</li>
 * </ul>
 * When an option has been set on the target bean, then its removed from the given properties map. If all the options has been set, then the map will be empty.
 * The implementation ignores case for the property keys.
 *
 * @param context        the CamelContext
 * @param target         the target bean
 * @param properties     the properties
 * @param failIfNotSet   whether to fail if an option either does not exists on the target bean or if the option cannot be due no suitable setter methods with the given type
 * @return <tt>true</tt> if at least one option was configured
 * @throws IllegalArgumentException is thrown if an option cannot be configured on the bean because there is no suitable setter method and failOnNoSet is true.
 * @throws Exception for any other kind of error
 */
public static boolean setCamelProperties(CamelContext context, Object target, Map<String, Object> properties, boolean failIfNotSet) throws Exception {
    ObjectHelper.notNull(context, "context");
    ObjectHelper.notNull(target, "target");
    ObjectHelper.notNull(properties, "properties");
    boolean rc = false;

    PropertyConfigurer configurer = null;
    if (target instanceof Component) {
        // the component needs to be initialized to have the configurer ready
        ServiceHelper.initService(target);
        configurer = ((Component) target).getComponentPropertyConfigurer();
    }

    Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Object> entry = it.next();
        String name = entry.getKey();
        Object value = entry.getValue();
        String stringValue = value != null ? value.toString() : null;
        boolean hit = false;
        try {
            hit = PropertyBindingSupport.build()
                    .withConfigurer(configurer)
                    .withIgnoreCase(true)
                    .bind(context, target, name, value);
        } catch (PropertyBindingException e) {
            // no we could not and this would be thrown if we attempted to set a value on a property which we cannot do type conversion as
            // then maybe the value refers to a spring bean in the registry so try this
            if (stringValue != null) {
                if (stringValue.startsWith("#")) {
                    stringValue = stringValue.substring(1);
                }
                // use #bean: to lookup
                stringValue = "#bean:" + stringValue;
                hit = PropertyBindingSupport.build().withIgnoreCase(true).bind(context, target, name, stringValue);
            }
        }

        if (hit) {
            // must remove as its a valid option and we could configure it
            it.remove();
            rc = true;
        } else if (failIfNotSet) {
            throw new IllegalArgumentException("Cannot configure option [" + name + "] with value [" + stringValue
                + "] as the bean class [" + ObjectHelper.classCanonicalName(target)
                + "] has no suitable setter method, or not possible to lookup a bean with the id [" + stringValue + "] in Spring Boot registry");
        }
    }

    return rc;
}
 
Example #5
Source File: KnativeProducer.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@Override
protected void doStart() throws Exception {
    ServiceHelper.startService(processor);
}
 
Example #6
Source File: KnativeProducer.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@Override
protected void doStop() throws Exception {
    ServiceHelper.stopService(processor);
}
 
Example #7
Source File: KnativeProducer.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@Override
protected void doSuspend() throws Exception {
    ServiceHelper.suspendService(processor);
}
 
Example #8
Source File: KnativeProducer.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@Override
protected void doResume() throws Exception {
    ServiceHelper.resumeService(processor);
}
 
Example #9
Source File: KnativeProducer.java    From camel-k-runtime with Apache License 2.0 4 votes vote down vote up
@Override
protected void doShutdown() throws Exception {
    ServiceHelper.stopAndShutdownService(processor);
}
 
Example #10
Source File: ComponentProxyEndpoint.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doStart() throws Exception {
    super.doStart();
    ServiceHelper.startService(endpoint);
}
 
Example #11
Source File: ComponentProxyEndpoint.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doStop() throws Exception {
    ServiceHelper.stopService(endpoint);
    super.doStop();
}
 
Example #12
Source File: ComponentProxyProducer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doStart() throws Exception {
    ServiceHelper.startService(processor);
}
 
Example #13
Source File: ComponentProxyProducer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doStop() throws Exception {
    ServiceHelper.stopService(processor);
}
 
Example #14
Source File: ComponentProxyProducer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doSuspend() throws Exception {
    ServiceHelper.suspendService(processor);
}
 
Example #15
Source File: ComponentProxyProducer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doResume() throws Exception {
    ServiceHelper.resumeService(processor);
}
 
Example #16
Source File: ComponentProxyProducer.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void doShutdown() throws Exception {
    ServiceHelper.stopAndShutdownServices(processor);
}