当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleStrategy类代码示例

本文整理汇总了Java中org.apache.camel.spi.LifecycleStrategy的典型用法代码示例。如果您正苦于以下问题:Java LifecycleStrategy类的具体用法?Java LifecycleStrategy怎么用?Java LifecycleStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LifecycleStrategy类属于org.apache.camel.spi包,在下文中一共展示了LifecycleStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addComponent

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public void addComponent(String componentName, final Component component) {
    ObjectHelper.notNull(component, "component");
    synchronized (components) {
        if (components.containsKey(componentName)) {
            throw new IllegalArgumentException("Cannot add component as its already previously added: " + componentName);
        }
        component.setCamelContext(this);
        components.put(componentName, component);
        for (LifecycleStrategy strategy : lifecycleStrategies) {
            strategy.onComponentAdd(componentName, component);
        }

        // keep reference to properties component up to date
        if (component instanceof PropertiesComponent && "properties".equals(componentName)) {
            propertiesComponent = (PropertiesComponent) component;
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:DefaultCamelContext.java

示例2: removeComponent

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public Component removeComponent(String componentName) {
    synchronized (components) {
        Component oldComponent = components.remove(componentName);
        if (oldComponent != null) {
            try {
                stopServices(oldComponent);
            } catch (Exception e) {
                log.warn("Error stopping component " + oldComponent + ". This exception will be ignored.", e);
            }
            for (LifecycleStrategy strategy : lifecycleStrategies) {
                strategy.onComponentRemove(componentName, oldComponent);
            }
        }
        // keep reference to properties component up to date
        if (oldComponent != null && "properties".equals(componentName)) {
            propertiesComponent = null;
        }
        return oldComponent;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:DefaultCamelContext.java

示例3: testService

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public void testService() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    // must enable always as CamelContext has been started
    // and we add the service manually below
    context.getManagementStrategy().getManagementAgent().setRegisterAlways(true);

    MyService service = new MyService();
    for (LifecycleStrategy strategy : context.getLifecycleStrategies()) {
        strategy.onServiceAdd(context, service, null);
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
    assertEquals(9, set.size());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:ManagedNonManagedServiceTest.java

示例4: testNonManagedService

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public void testNonManagedService() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }

    // must enable always as CamelContext has been started
    // and we add the service manually below
    context.getManagementStrategy().getManagementAgent().setRegisterAlways(true);

    MyNonService service = new MyNonService();
    for (LifecycleStrategy strategy : context.getLifecycleStrategies()) {
        strategy.onServiceAdd(context, service, null);
    }

    MBeanServer mbeanServer = getMBeanServer();

    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
    assertEquals(8, set.size());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:ManagedNonManagedServiceTest.java

示例5: wrapInErrorHandler

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
/**
 * Wraps the given output in an error handler
 *
 * @param routeContext the route context
 * @param output the output
 * @return the output wrapped with the error handler
 * @throws Exception can be thrown if failed to create error handler builder
 */
protected Processor wrapInErrorHandler(RouteContext routeContext, Processor output) throws Exception {
    ErrorHandlerFactory builder = routeContext.getRoute().getErrorHandlerBuilder();
    // create error handler
    Processor errorHandler = builder.createErrorHandler(routeContext, output);

    // invoke lifecycles so we can manage this error handler builder
    for (LifecycleStrategy strategy : routeContext.getCamelContext().getLifecycleStrategies()) {
        strategy.onErrorHandlerAdd(routeContext, errorHandler, builder);
    }

    return errorHandler;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:ProcessorDefinition.java

示例6: addEndpoint

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public Endpoint addEndpoint(String uri, Endpoint endpoint) throws Exception {
    Endpoint oldEndpoint;

    startService(endpoint);
    oldEndpoint = endpoints.remove(getEndpointKey(uri));
    for (LifecycleStrategy strategy : lifecycleStrategies) {
        strategy.onEndpointAdd(endpoint);
    }
    addEndpointToRegistry(uri, endpoint);
    if (oldEndpoint != null) {
        stopServices(oldEndpoint);
    }

    return oldEndpoint;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DefaultCamelContext.java

示例7: removeEndpoints

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public Collection<Endpoint> removeEndpoints(String uri) throws Exception {
    Collection<Endpoint> answer = new ArrayList<Endpoint>();
    Endpoint oldEndpoint = endpoints.remove(getEndpointKey(uri));
    if (oldEndpoint != null) {
        answer.add(oldEndpoint);
        stopServices(oldEndpoint);
    } else {
        for (Map.Entry<EndpointKey, Endpoint> entry : endpoints.entrySet()) {
            oldEndpoint = entry.getValue();
            if (EndpointHelper.matchEndpoint(this, oldEndpoint.getEndpointUri(), uri)) {
                try {
                    stopServices(oldEndpoint);
                } catch (Exception e) {
                    log.warn("Error stopping endpoint " + oldEndpoint + ". This exception will be ignored.", e);
                }
                answer.add(oldEndpoint);
                endpoints.remove(entry.getKey());
            }
        }
    }

    // notify lifecycle its being removed
    for (Endpoint endpoint : answer) {
        for (LifecycleStrategy strategy : lifecycleStrategies) {
            strategy.onEndpointRemove(endpoint);
        }
    }

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:DefaultCamelContext.java

示例8: removeService

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public boolean removeService(Object object) throws Exception {
    if (object instanceof Endpoint) {
        removeEndpoint((Endpoint) object);
        return true;
    }
    if (object instanceof Service) {
        Service service = (Service) object;
        for (LifecycleStrategy strategy : lifecycleStrategies) {
            strategy.onServiceRemove(this, service, null);
        }
        return servicesToStop.remove(service);
    }
    return false;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:DefaultCamelContext.java

示例9: startChildService

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
protected void startChildService(Route route, List<Service> services) throws Exception {
    for (Service service : services) {
        LOG.debug("Starting child service on route: {} -> {}", route.getId(), service);
        for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
            strategy.onServiceAdd(camelContext, service, route);
        }
        ServiceHelper.startService(service);
        addChildService(service);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:RouteService.java

示例10: doShutdownNow

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
private List<Runnable> doShutdownNow(ExecutorService executorService, boolean failSafe) {
    ObjectHelper.notNull(executorService, "executorService");

    List<Runnable> answer = null;
    if (!executorService.isShutdown()) {
        if (failSafe) {
            // log as warn, as we shutdown as fail-safe, so end user should see more details in the log.
            LOG.warn("Forcing shutdown of ExecutorService: {}", executorService);
        } else {
            LOG.debug("Forcing shutdown of ExecutorService: {}", executorService);
        }
        answer = executorService.shutdownNow();
        if (LOG.isTraceEnabled()) {
            LOG.trace("Shutdown of ExecutorService: {} is shutdown: {} and terminated: {}.",
                executorService, executorService.isShutdown(), executorService.isTerminated());
        }
    }

    // let lifecycle strategy be notified as well which can let it be managed in JMX as well
    ThreadPoolExecutor threadPool = null;
    if (executorService instanceof ThreadPoolExecutor) {
        threadPool = (ThreadPoolExecutor) executorService;
    } else if (executorService instanceof SizedScheduledExecutorService) {
        threadPool = ((SizedScheduledExecutorService) executorService).getScheduledThreadPoolExecutor();
    }
    if (threadPool != null) {
        for (LifecycleStrategy lifecycle : camelContext.getLifecycleStrategies()) {
            lifecycle.onThreadPoolRemove(camelContext, threadPool);
        }
    }

    // remove reference as its shutdown (do not remove if fail-safe)
    if (!failSafe) {
        executorServices.remove(executorService);
    }

    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:DefaultExecutorServiceManager.java

示例11: doAddService

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
private void doAddService(Object object, boolean stopOnShutdown, boolean forceStart) throws Exception {

        // inject CamelContext
        if (object instanceof CamelContextAware) {
            CamelContextAware aware = (CamelContextAware) object;
            aware.setCamelContext(this);
        }

        if (object instanceof Service) {
            Service service = (Service) object;

            for (LifecycleStrategy strategy : lifecycleStrategies) {
                if (service instanceof Endpoint) {
                    // use specialized endpoint add
                    strategy.onEndpointAdd((Endpoint) service);
                } else {
                    strategy.onServiceAdd(this, service, null);
                }
            }

            if (!forceStart) {
                // now start the service (and defer starting if CamelContext is starting up itself)
                deferStartService(object, stopOnShutdown);
            } else {
                // only add to services to close if its a singleton
                // otherwise we could for example end up with a lot of prototype scope endpoints
                boolean singleton = true; // assume singleton by default
                if (object instanceof IsSingleton) {
                    singleton = ((IsSingleton) service).isSingleton();
                }
                // do not add endpoints as they have their own list
                if (singleton && !(service instanceof Endpoint)) {
                    // only add to list of services to stop if its not already there
                    if (stopOnShutdown && !hasService(service)) {
                        servicesToStop.add(service);
                    }
                }
                ServiceHelper.startService(service);
            }
        }
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:42,代码来源:DefaultCamelContext.java

示例12: getLifecycleStrategies

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public List<LifecycleStrategy> getLifecycleStrategies() {
    return lifecycleStrategies;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:DefaultCamelContext.java

示例13: setLifecycleStrategies

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public void setLifecycleStrategies(List<LifecycleStrategy> lifecycleStrategies) {
    this.lifecycleStrategies = lifecycleStrategies;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:DefaultCamelContext.java

示例14: addLifecycleStrategy

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
public void addLifecycleStrategy(LifecycleStrategy lifecycleStrategy) {
    this.lifecycleStrategies.add(lifecycleStrategy);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:DefaultCamelContext.java

示例15: doStop

import org.apache.camel.spi.LifecycleStrategy; //导入依赖的package包/类
protected void doStop() throws Exception {

        // if we are stopping CamelContext then we are shutting down
        boolean isShutdownCamelContext = camelContext.isStopping();

        if (isShutdownCamelContext || isRemovingRoutes()) {
            // need to call onRoutesRemove when the CamelContext is shutting down or Route is shutdown
            for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
                strategy.onRoutesRemove(routes);
            }
        }
        
        for (Route route : routes) {
            LOG.debug("Stopping services on route: {}", route.getId());

            // gather list of services to stop as we need to start child services as well
            Set<Service> services = gatherChildServices(route, true);

            // stop services
            stopChildService(route, services, isShutdownCamelContext);

            // stop the route itself
            if (isShutdownCamelContext) {
                ServiceHelper.stopAndShutdownServices(route);
            } else {
                ServiceHelper.stopServices(route);
            }

            // invoke callbacks on route policy
            if (route.getRouteContext().getRoutePolicyList() != null) {
                for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                    routePolicy.onStop(route);
                }
            }
            // fire event
            EventHelper.notifyRouteStopped(camelContext, route);
        }
        if (isRemovingRoutes()) {
            camelContext.removeRouteCollection(routes);
        }
        // need to warm up again
        warmUpDone.set(false);
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:44,代码来源:RouteService.java


注:本文中的org.apache.camel.spi.LifecycleStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。