Java 类org.apache.camel.StatefulService 实例源码

项目:Camel    文件:EventHelper.java   
private static void doNotifyEvent(EventNotifier notifier, EventObject event) {
    // only notify if notifier is started
    boolean started = true;
    if (notifier instanceof StatefulService) {
        started = ((StatefulService) notifier).isStarted();
    }
    if (!started) {
        LOG.debug("Ignoring notifying event {}. The EventNotifier has not been started yet: {}", event, notifier);
        return;
    }

    if (!notifier.isEnabled(event)) {
        LOG.trace("Notifier: {} is not enabled for the event: {}", notifier, event);
        return;
    }

    try {
        notifier.notify(event);
    } catch (Throwable e) {
        LOG.warn("Error notifying event " + event + ". This exception will be ignored. ", e);
    }
}
项目:microservice-bundle    文件:CamelHealthCheck.java   
private Result checkRoute(Route route) {
  LOGGER.debug("Checking route [{}] of type [{}]", route.getId(), route.getClass());
  if (route instanceof StatefulService) {
    StatefulService statefulRoute = (StatefulService) route;
    if (!statefulRoute.isStarted()) {
      return Result.unhealthy(String.format("Route [%s] is not running", route.getId()));
    }
  }
  Consumer consumer = route.getConsumer();
  if (consumer != null) {
    LOGGER.debug("Checking route [{}]'s consumer of type [{}]", route.getId(), consumer.getClass());
    if (consumer instanceof StatefulService) {
      StatefulService statefulConsumer = (StatefulService) consumer;
      if (!statefulConsumer.isStarted()) {
        return Result.unhealthy(String.format("Route [%s]'s consumer is not running", route.getId()));
      }
    }
  }
  return Result.healthy();
}
项目:dropwizard-camel    文件:CamelHealthCheck.java   
private Result checkRoute(Route route) {
    LOGGER.debug("Checking route [{}] of type [{}]", route.getId(), route.getClass());
    if (route instanceof StatefulService) {
        StatefulService statefulRoute = (StatefulService) route;
        if (!statefulRoute.isStarted()) {
            return Result.unhealthy(String.format("Route [%s] is not running", route.getId()));
        }
    }
    Consumer consumer = route.getConsumer();
    if (consumer != null) {
        LOGGER.debug("Checking route [{}]'s consumer of type [{}]", route.getId(), consumer.getClass());
        if (consumer instanceof StatefulService) {
            StatefulService statefulConsumer = (StatefulService) consumer;
            if (!statefulConsumer.isStarted()) {
                return Result.unhealthy(String.format("Route [%s]'s consumer is not running", route.getId()));
            }
        }
    }
    return Result.healthy();
}
项目:cleverbus    文件:AsynchEventHelper.java   
private static void doNotifyEvent(EventNotifier notifier, EventObject event) {
    // only notify if notifier is started
    boolean started = true;
    if (notifier instanceof StatefulService) {
        started = ((StatefulService) notifier).isStarted();
    }

    if (!started) {
        Log.debug("Ignoring notifying event {}. The EventNotifier has not been started yet: {}", event, notifier);
        return;
    }

    if (!notifier.isEnabled(event)) {
        Log.debug("Notification of event is disabled: {}", event);
        return;
    }

    try {
        Log.debug("Event {} arrived to notifier {}", event, notifier.getClass().getName());

        notifier.notify(event);
    } catch (Throwable e) {
        Log.warn("Error notifying event " + event + ". This exception will be ignored. ", e);
    }
}
项目:Camel    文件:AbstractLocalCamelController.java   
private static String getEndpointState(Endpoint endpoint) {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (endpoint instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) endpoint).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:CamelInternalProcessor.java   
/**
 * Strategy to determine if this policy is allowed to run
 *
 * @param policy the policy
 * @return <tt>true</tt> to run
 */
protected boolean isRoutePolicyRunAllowed(RoutePolicy policy) {
    if (policy instanceof StatefulService) {
        StatefulService ss = (StatefulService) policy;
        return ss.isRunAllowed();
    }
    return true;
}
项目:Camel    文件:CamelInternalProcessor.java   
private static boolean isCamelStopping(CamelContext context) {
    if (context instanceof StatefulService) {
        StatefulService ss = (StatefulService) context;
        return ss.isStopping() || ss.isStopped();
    }
    return false;
}
项目:Camel    文件:ManagedService.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (service instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) service).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedDataFormat.java   
@Override
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (dataFormat instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) dataFormat).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedEndpoint.java   
@Override
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (endpoint instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) endpoint).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedComponent.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (component instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) component).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ManagedProcessor.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    if (processor instanceof StatefulService) {
        ServiceStatus status = ((StatefulService) processor).getStatus();
        return status.name();
    }

    // assume started if not a ServiceSupport instance
    return ServiceStatus.Started.name();
}
项目:Camel    文件:ServiceHelper.java   
/**
 * Is the given service stopping or already stopped?
 *
 * @return <tt>true</tt> if stopping or already stopped, <tt>false</tt> otherwise
 * @see StatefulService#isStopping()
 * @see StatefulService#isStopped()
 */
public static boolean isStopped(Object value) {
    if (value instanceof StatefulService) {
        StatefulService service = (StatefulService) value;
        if (service.isStopping() || service.isStopped()) {
            return true;
        }
    }
    return false;
}
项目:Camel    文件:ServiceHelper.java   
/**
 * Is the given service starting or already started?
 *
 * @return <tt>true</tt> if starting or already started, <tt>false</tt> otherwise
 * @see StatefulService#isStarting()
 * @see StatefulService#isStarted()
 */
public static boolean isStarted(Object value) {
    if (value instanceof StatefulService) {
        StatefulService service = (StatefulService) value;
        if (service.isStarting() || service.isStarted()) {
            return true;
        }
    }
    return false;
}
项目:Camel    文件:ServiceHelper.java   
/**
 * Is the given service suspending or already suspended?
 *
 * @return <tt>true</tt> if suspending or already suspended, <tt>false</tt> otherwise
 * @see StatefulService#isSuspending()
 * @see StatefulService#isSuspended()
 */
public static boolean isSuspended(Object value) {
    if (value instanceof StatefulService) {
        StatefulService service = (StatefulService) value;
        if (service.isSuspending() || service.isSuspended()) {
            return true;
        }
    }
    return false;
}
项目:Camel    文件:DefaultRestRegistry.java   
public String getState() {
    // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
    ServiceStatus status = null;
    if (consumer instanceof StatefulService) {
        status = ((StatefulService) consumer).getStatus();
    }
    // if no status exists then its stopped
    if (status == null) {
        status = ServiceStatus.Stopped;
    }
    return status.name();
}
项目:Camel    文件:DefaultCamelContext.java   
/**
 * Starts or resumes the routes
 *
 * @param routeServices  the routes to start (will only start a route if its not already started)
 * @param checkClash     whether to check for startup ordering clash
 * @param startConsumer  whether the route consumer should be started. Can be used to warmup the route without starting the consumer.
 * @param resumeConsumer whether the route consumer should be resumed.
 * @param addingRoutes   whether we are adding new routes
 * @throws Exception is thrown if error starting routes
 */
protected void doStartOrResumeRoutes(Map<String, RouteService> routeServices, boolean checkClash,
                                     boolean startConsumer, boolean resumeConsumer, boolean addingRoutes) throws Exception {
    isStartingRoutes.set(true);
    try {
        // filter out already started routes
        Map<String, RouteService> filtered = new LinkedHashMap<String, RouteService>();
        for (Map.Entry<String, RouteService> entry : routeServices.entrySet()) {
            boolean startable = false;

            Consumer consumer = entry.getValue().getRoutes().iterator().next().getConsumer();
            if (consumer instanceof SuspendableService) {
                // consumer could be suspended, which is not reflected in the RouteService status
                startable = ((SuspendableService) consumer).isSuspended();
            }

            if (!startable && consumer instanceof StatefulService) {
                // consumer could be stopped, which is not reflected in the RouteService status
                startable = ((StatefulService) consumer).getStatus().isStartable();
            } else if (!startable) {
                // no consumer so use state from route service
                startable = entry.getValue().getStatus().isStartable();
            }

            if (startable) {
                filtered.put(entry.getKey(), entry.getValue());
            }
        }

        // the context is in last phase of staring, so lets start the routes
        safelyStartRouteServices(checkClash, startConsumer, resumeConsumer, addingRoutes, filtered.values());

    } finally {
        isStartingRoutes.remove();
    }
}
项目:Camel    文件:RouteSedaStopStartTest.java   
public void testStopStart() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A");

    template.sendBody("seda:foo", "A");

    assertMockEndpointsSatisfied();

    log.info("Stopping");

    // now suspend and dont expect a message to be routed
    resetMocks();
    mock.expectedMessageCount(0);
    context.stopRoute("foo");

    assertEquals("Stopped", context.getRouteStatus("foo").name());
    Route route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Stopped", ((StatefulService) route).getStatus().name());
    }

    template.sendBody("seda:foo", "B");
    mock.assertIsSatisfied(1000);

    log.info("Starting");

    // now resume and expect the previous message to be routed
    resetMocks();
    mock.expectedBodiesReceived("B");
    context.startRoute("foo");
    assertMockEndpointsSatisfied();

    assertEquals("Started", context.getRouteStatus("foo").name());
    route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Started", ((StatefulService) route).getStatus().name());
    }
}
项目:Camel    文件:QuickfixjComponentTest.java   
@Test
public void componentStop() throws Exception {
    setUpComponent();

    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);

    writeSettings();

    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));

    final CountDownLatch latch = new CountDownLatch(1);

    Consumer consumer = endpoint.createConsumer(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = 
                (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionCreated) {
                latch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);

    // Endpoint automatically starts the consumer
    assertThat(((StatefulService)consumer).isStarted(), is(true));

    // will start the component
    camelContext.start();

    assertTrue("Session not created", latch.await(5000, TimeUnit.MILLISECONDS));

    component.stop();

    assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(false));
    // it should still be initialized (ready to start again)
    assertThat(component.getEngines().get(settingsFile.getName()).isInitialized(), is(true));
}
项目:microservice-bundle    文件:CamelHealthCheck.java   
private Result checkComponent(String componentName) {
  Component component = camelContext.getComponent(componentName);
  LOGGER.debug("Checking component [{}] of type [{}]", componentName, component.getClass());
  if (component instanceof StatefulService) {
    StatefulService statefulComponent = (StatefulService) component;
    if (!statefulComponent.isStarted()) {
      return Result.unhealthy(String.format("Component [%s] is not running", componentName));
    }
  }
  return Result.healthy();
}
项目:microservice-bundle    文件:CamelHealthCheck.java   
private Result checkEndpoint(String endpointKey, Endpoint endpoint) {
  LOGGER.debug("Checking endpoint [{}] of type [{}]", endpointKey, endpoint.getClass());
  if (endpoint instanceof StatefulService) {
    StatefulService statefulEndpoint = (StatefulService) endpoint;
    if (!statefulEndpoint.isStarted()) {
      return Result.unhealthy(String.format("Endpoint [%s] is not running", endpointKey));
    }
  }
  return Result.healthy();
}
项目:dropwizard-camel    文件:CamelHealthCheck.java   
private Result checkComponent(String componentName) {
    Component component = camelContext.getComponent(componentName);
    LOGGER.debug("Checking component [{}] of type [{}]", componentName, component.getClass());
    if (component instanceof StatefulService) {
        StatefulService statefulComponent = (StatefulService) component;
        if (!statefulComponent.isStarted()) {
            return Result.unhealthy(String.format("Component [%s] is not running", componentName));
        }
    }
    return Result.healthy();
}
项目:dropwizard-camel    文件:CamelHealthCheck.java   
private Result checkEndpoint(String endpointKey, Endpoint endpoint) {
    LOGGER.debug("Checking endpoint [{}] of type [{}]", endpointKey, endpoint.getClass());
    if (endpoint instanceof StatefulService) {
        StatefulService statefulEndpoint = (StatefulService) endpoint;
        if (!statefulEndpoint.isStarted()) {
            return Result.unhealthy(String.format("Endpoint [%s] is not running", endpointKey));
        }
    }
    return Result.healthy();
}
项目:Camel    文件:RouteSedaSuspendResumeTest.java   
public void testSuspendResume() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A");

    template.sendBody("seda:foo", "A");

    assertMockEndpointsSatisfied();

    log.info("Suspending");

    // now suspend and dont expect a message to be routed
    resetMocks();
    mock.expectedMessageCount(0);
    context.suspendRoute("foo");

    assertEquals("Suspended", context.getRouteStatus("foo").name());
    Route route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Suspended", ((StatefulService) route).getStatus().name());
    }

    // need to give seda consumer thread time to idle
    Thread.sleep(500);

    template.sendBody("seda:foo", "B");
    mock.assertIsSatisfied(1000);

    log.info("Resuming");

    // now resume and expect the previous message to be routed
    resetMocks();
    mock.expectedBodiesReceived("B");
    context.resumeRoute("foo");
    assertMockEndpointsSatisfied();

    assertEquals("Started", context.getRouteStatus("foo").name());
    route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Started", ((StatefulService) route).getStatus().name());
    }
}
项目:Camel    文件:MockEndpointTimeClauseTest.java   
private boolean isStarted(Service service) {
    if (service instanceof StatefulService) {
        return ((StatefulService) service).isStarted();
    }
    return true;
}