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


Java AbstractLifeCycle类代码示例

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


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

示例1: getServerState

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
public static ServerComponentEvent getServerState()
{

    ServerComponentEvent sensor = new ServerComponentEvent();

    sensor.setComponentId( EventComponent.RACK.name() );
    sensor.setUnit( EventUnitType.DISCRETE );
    String eventText = null;
    if ( stats != null && AbstractLifeCycle.STARTED.equals( stats.getState() ) )
    {
        sensor.setEventName( NodeEvent.HMS_AGENT_UP );
        eventText = NodeEvent.HMS_AGENT_UP.getEventID().getEventText();
    }
    else
    {
        sensor.setEventName( NodeEvent.HMS_AGENT_DOWN );
        eventText = NodeEvent.HMS_AGENT_DOWN.getEventID().getEventText();
    }
    sensor.setEventId( Constants.HMS_OOBAGENT_STATUS );
    String descreteValue = StringUtils.substringBefore( eventText, HMS_AGENT_STATUS_DESC_SEPARATOR );
    sensor.setDiscreteValue( descreteValue );

    return sensor;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:25,代码来源:JettyMonitorUtil.java

示例2: run

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
public void run(MockConfiguration configuration, Environment environment) throws Exception
{
    AbstractBinder abstractBinder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            bind(new MockHK2Injected()).to(MockHK2Injected.class);
        }
    };
    environment.jersey().register(abstractBinder);
    environment.jersey().register(MockResource.class);
    LifeCycle.Listener listener = new AbstractLifeCycle.AbstractLifeCycleListener()
    {
        @Override
        public void lifeCycleStarted(LifeCycle event)
        {
            System.out.println("Starting...");
            startedLatch.countDown();
        }
    };
    environment.lifecycle().addLifeCycleListener(listener);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:25,代码来源:MockApplication.java

示例3: run

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) throws InvalidKeySpecException, NoSuchAlgorithmException, ServletException, DeploymentException {
    environment.lifecycle().addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {

        @Override
        public void lifeCycleStarted(LifeCycle event) {
            cdl.countDown();
        }
    });
    environment.jersey().register(new MyResource());
    environment.healthChecks().register("alive", new HealthCheck() {
        @Override
        protected HealthCheck.Result check() throws Exception {
            return HealthCheck.Result.healthy();
        }
    });

    // Using ServerEndpointConfig lets you inject objects to the websocket endpoint:
    final ServerEndpointConfig config = ServerEndpointConfig.Builder.create(EchoServer.class, "/extends-ws").build();
    // config.getUserProperties().put(Environment.class.getName(), environment);
    // Then you can get it from the Session object
    // - obj = session.getUserProperties().get("objectName");            
    websocketBundle.addEndpoint(config);
}
 
开发者ID:LivePersonInc,项目名称:dropwizard-websockets,代码行数:25,代码来源:MyApp.java

示例4: before

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
  temp.create();

  Properties properties = new Properties();
  properties.setProperty("jclouds.filesystem.basedir", temp.newFolder("blobStore").getCanonicalPath());

  BlobStoreContext context = ContextBuilder
      .newBuilder("filesystem")
      .credentials("access", "secret")
      .overrides(properties)
      .build(BlobStoreContext.class);

  s3Proxy = s3ProxyBuilder
      .blobStore(context.getBlobStore())
      .endpoint(URI.create(String.format("%s:%d", ENDPOINT_URL, port)))
      .ignoreUnknownHeaders(ignoreUnknownHeaders)
      .build();

  LOG.debug("S3 proxy is starting");
  s3Proxy.start();
  while (!s3Proxy.getState().equals(AbstractLifeCycle.STARTED)) {
    Thread.sleep(10);
  }
  LOG.debug("S3 proxy is running");
  port = s3Proxy.getPort();

  s3ProxyBuilder = null;
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:30,代码来源:S3ProxyRule.java

示例5: getComponentEvents_monitor_HMS_On_STARTED

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Test
public void getComponentEvents_monitor_HMS_On_STARTED()
    throws Exception
{
    insertNodeInNodeMap( getServerNode() );
    addBoardServiceForNode();

    server = initMocks( AbstractLifeCycle.STARTED );

    ComponentEventRestService restService = new ComponentEventRestService();
    List<Event> hmsEvents = restService.getComponentEvents();
    assertNotNull( hmsEvents );
    assertTrue( hmsEvents.size() > 0 );
    Event event = hmsEvents.get( 0 );
    assertNotNull( event );
    Header header = event.getHeader();
    assertEquals( "HMS", header.getAgent() );
    assertEquals( "HMS_AGENT_UP", header.getEventName().name() );
    assertEquals( "NORMAL", header.getEventType().name() );
    assertEquals( "[MANAGEMENT, SOFTWARE]", header.getEventCategoryList().toString() );
    assertEquals( "INFORMATIONAL", header.getSeverity().name() );
    // assertEquals("?", header.getComponentIdentifier());

    Body body = event.getBody();
    Map<String, String> data = body.getData();
    assertEquals( "DISCRETE", data.get( "unit" ) );
    assertEquals( "HMS_OOBAGENT_STATUS", data.get( "eventId" ) );
    assertEquals( "HMS Agent is up", data.get( "value" ) );
    // assertEquals("Hms Agent is Up", data.get("value"));
    assertEquals( "HMS_AGENT_UP", data.get( "eventName" ) );
    assertEquals( "HMS Agent is up - rack {RACK_NAME}", body.getDescription() );

    resetMocks( server );

}
 
开发者ID:vmware,项目名称:OHMS,代码行数:36,代码来源:ComponentEventRestServiceTest.java

示例6: getComponentEvents_monitor_HMS_On_NOT_STARTED

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Test
public void getComponentEvents_monitor_HMS_On_NOT_STARTED()
    throws Exception
{
    insertNodeInNodeMap( getServerNode() );
    addBoardServiceForNode();

    server = initMocks( AbstractLifeCycle.FAILED );

    ComponentEventRestService restService = new ComponentEventRestService();
    List<Event> hmsEvents = restService.getComponentEvents();
    assertNotNull( hmsEvents );
    assertTrue( hmsEvents.size() > 0 );
    Event event = hmsEvents.get( 0 );
    assertNotNull( event );
    Header header = event.getHeader();
    assertEquals( "HMS", header.getAgent() );
    assertEquals( "HMS_AGENT_DOWN", header.getEventName().name() );
    assertEquals( "NORMAL", header.getEventType().name() );
    assertEquals( "[MANAGEMENT, SOFTWARE]", header.getEventCategoryList().toString() );
    assertEquals( "CRITICAL", header.getSeverity().name() );
    // assertEquals("?", header.getComponentIdentifier());

    Body body = event.getBody();
    Map<String, String> data = body.getData();
    assertEquals( "DISCRETE", data.get( "unit" ) );
    assertEquals( "HMS_OOBAGENT_STATUS", data.get( "eventId" ) );
    assertEquals( "HMS Agent is down", data.get( "value" ) );
    // assertEquals("Hms Agent is Down", data.get("value"));
    assertEquals( "HMS_AGENT_DOWN", data.get( "eventName" ) );
    assertEquals( "HMS Agent is down - rack {RACK_NAME}", body.getDescription() );

    resetMocks( server );
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:35,代码来源:ComponentEventRestServiceTest.java

示例7: run

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) throws Exception
{
    LifeCycle.Listener listener = new AbstractLifeCycle.AbstractLifeCycleListener()
    {
        @Override
        public void lifeCycleStarted(LifeCycle event)
        {
            System.out.println("Starting...");
            startedLatch.countDown();
        }
    };
    environment.lifecycle().addLifeCycleListener(listener);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:15,代码来源:MockOldStyleApplication.java

示例8: initialize

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
public void initialize(final GuiceyBootstrap bootstrap) {
    // use  listener to work properly for both guicey only test and normal app (to show hk stats)
    bootstrap.environment().lifecycle().addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
        @Override
        public void lifeCycleStarted(final LifeCycle event) {
            report(bootstrap.application());
        }
    });
    bootstrap.modules(new DiagnosticModule());
}
 
开发者ID:xvik,项目名称:dropwizard-guicey,代码行数:12,代码来源:DiagnosticBundle.java

示例9: startApp

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
private void startApp() throws Exception {
    app.useRandomPorts();
    synchronized (BounceApplication.class) {
        app.run(new String[]{"server", webConfig});
    }

    Utils.waitUntil(() -> app.getS3ProxyState().equals(AbstractLifeCycle.STARTED) || app.isSwiftProxyStarted());
}
 
开发者ID:bouncestorage,项目名称:bouncestorage,代码行数:9,代码来源:BounceApplicationTest.java

示例10: doStart

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
protected void doStart() {
  try {
    Preconditions.checkState(jetty == null);
    Preconditions.checkState(httpPort != 0);

    // ResourceConfig rc = new PackagesResourceConfig(WebModule.class.getPackage().getName());
    // IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(rc, injector);

    // this.selector = GrizzlyServerFactory.create(baseUri, rc, ioc);

    this.jetty = new Server(httpPort);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    jetty.setHandler(context);

    configureContext(context);

    jetty.start();
    while (true) {
      String state = jetty.getState();
      if (state.equals(AbstractLifeCycle.STARTED)) {
        break;
      } else if (state.equals(AbstractLifeCycle.STARTING)) {
        log.debug("Waiting for jetty; state={}", state);
        Thread.sleep(500);
      } else {
        throw new IllegalStateException("Jetty reached unexpected state: " + state);
      }
    }

    this.notifyStarted();
  } catch (Exception e) {
    this.notifyFailed(e);
  }

}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:39,代码来源:JettyService.java

示例11: doStop

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Override
protected void doStop() {
  try {
    if (jetty != null) {
      log.debug("Stopping jetty");
      jetty.stop();
      while (true) {
        String state = jetty.getState();
        if (state.equals(AbstractLifeCycle.STOPPED)) {
          log.debug("Stopped jetty");
          break;
        } else if (state.equals(AbstractLifeCycle.STOPPING)) {
          log.debug("Waiting for jetty; state={}", state);
          Thread.sleep(500);
        } else {
          throw new IllegalStateException("Jetty reached unexpected state: " + state);
        }
      }

      jetty = null;
    }

    this.notifyStopped();
  } catch (Exception e) {
    this.notifyFailed(e);
  }
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:28,代码来源:JettyService.java

示例12: run

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
/**
 * Runs the scheduler. Don't forget to call this!
 * This should never exit, instead the entire process will be terminated internally.
 */
@Override
public void run() {
    CuratorLocker locker = new CuratorLocker(schedulerBuilder.getServiceSpec());

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        LOGGER.info("Shutdown initiated, releasing curator lock");
        locker.unlock();
    }));
    locker.lock();

    SchedulerConfig schedulerConfig = SchedulerConfig.fromEnv();
    Metrics.configureStatsd(schedulerConfig);
    AbstractScheduler scheduler = schedulerBuilder.build();
    scheduler.start();
    Optional<Scheduler> mesosScheduler = scheduler.getMesosScheduler();
    if (mesosScheduler.isPresent()) {
        runScheduler(
                mesosScheduler.get(),
                schedulerBuilder.getServiceSpec(),
                schedulerBuilder.getSchedulerConfig(),
                schedulerBuilder.getStateStore());
    } else {
        /**
         * If no MesosScheduler is provided this scheduler has been deregistered and should report itself healthy
         * and provide an empty COMPLETE deploy plan so it may complete its UNINSTALL.
         *
         * See {@link UninstallScheduler#getMesosScheduler()}.
         */
        Plan emptyDeployPlan = new Plan() {
            @Override
            public List<Phase> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public Strategy<Phase> getStrategy() {
                return new SerialStrategy<>();
            }

            @Override
            public UUID getId() {
                return UUID.randomUUID();
            }

            @Override
            public String getName() {
                return Constants.DEPLOY_PLAN_NAME;
            }

            @Override
            public List<String> getErrors() {
                return Collections.emptyList();
            }
        };

        PlanManager emptyPlanManager = DefaultPlanManager.createProceeding(emptyDeployPlan);
        PlansResource emptyPlanResource = new PlansResource();
        emptyPlanResource.setPlanManagers(Arrays.asList(emptyPlanManager));

        schedulerBuilder.getStateStore().clearAllData();

        SchedulerApiServer apiServer = new SchedulerApiServer(
                schedulerConfig,
                Arrays.asList(
                        emptyPlanResource,
                        new HealthResource()));
        apiServer.start(new AbstractLifeCycle.AbstractLifeCycleListener() {
            @Override
            public void lifeCycleStarted(LifeCycle event) {
                LOGGER.info("Started trivially healthy API server.");
            }
        });
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:79,代码来源:SchedulerRunner.java

示例13: createServer

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config           An application configuration instance (with properties set)
 * @param applicationClass The {@link io.dropwizard.Application} implementation class
 * @param <T>              The configuration class
 * @return A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration> DropWizardServer<T> createServer(
    T config,
    Class<? extends Application<T>> applicationClass) throws Exception {
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
      System.getProperty("java.io.tmpdir"),
      config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
      = bootstrap.getConfigurationFactoryFactory()
      .create((Class<T>) config.getClass(),
          bootstrap.getValidatorFactory().getValidator(),
          bootstrap.getObjectMapper(),
          "dw");
  final T builtConfig = configurationFactory.build(
      bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
      .configure(bootstrap.getMetricRegistry(),
          bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
      bootstrap.getObjectMapper(),
      bootstrap.getValidatorFactory().getValidator(),
      bootstrap.getMetricRegistry(),
      bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
    @Override
    public void lifeCycleStopped(LifeCycle event) {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
 
开发者ID:brandtg,项目名称:dropwizard-helix,代码行数:64,代码来源:DropWizardApplicationRunner.java

示例14: createServer

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config
 *  An application configuration instance (with properties set)
 * @param applicationClass
 *  The {@link io.dropwizard.Application} implementation class
 * @param <T>
 *  The configuration class
 * @return
 *  A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration>
DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception
{
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
          System.getProperty("java.io.tmpdir"),
          config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
          = bootstrap.getConfigurationFactoryFactory()
                     .create((Class<T>) config.getClass(),
                             bootstrap.getValidatorFactory().getValidator(),
                             bootstrap.getObjectMapper(),
                             "dw");
  final T builtConfig = configurationFactory.build(
          bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
             .configure(bootstrap.getMetricRegistry(),
                        bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                                                  bootstrap.getObjectMapper(),
                                                  bootstrap.getValidatorFactory().getValidator(),
                                                  bootstrap.getMetricRegistry(),
                                                  bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener()
  {
    @Override
    public void lifeCycleStopped(LifeCycle event)
    {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:70,代码来源:DropWizardApplicationRunner.java

示例15: setUp

import org.eclipse.jetty.util.component.AbstractLifeCycle; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    Properties s3ProxyProperties = new Properties();
    InputStream is = Resources.asByteSource(Resources.getResource(
            "s3proxy.conf")).openStream();
    try {
        s3ProxyProperties.load(is);
    } finally {
        is.close();
    }

    String provider = s3ProxyProperties.getProperty(
            Constants.PROPERTY_PROVIDER);
    String identity = s3ProxyProperties.getProperty(
            Constants.PROPERTY_IDENTITY);
    String credential = s3ProxyProperties.getProperty(
            Constants.PROPERTY_CREDENTIAL);
    String endpoint = s3ProxyProperties.getProperty(
            Constants.PROPERTY_ENDPOINT);
    String s3Identity = s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_IDENTITY);
    String s3Credential = s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_CREDENTIAL);
    awsCreds = new BasicAWSCredentials(s3Identity, s3Credential);
    s3Endpoint = new URI(s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_ENDPOINT));
    String keyStorePath = s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_KEYSTORE_PATH);
    String keyStorePassword = s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_KEYSTORE_PASSWORD);
    String virtualHost = s3ProxyProperties.getProperty(
            S3ProxyConstants.PROPERTY_VIRTUAL_HOST);

    ContextBuilder builder = ContextBuilder
            .newBuilder(provider)
            .credentials(identity, credential)
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(s3ProxyProperties);
    if (!Strings.isNullOrEmpty(endpoint)) {
        builder.endpoint(endpoint);
    }
    context = builder.build(BlobStoreContext.class);
    BlobStore blobStore = context.getBlobStore();
    containerName = createRandomContainerName();
    key = "stuff";
    blobStore.createContainerInLocation(null, containerName);

    S3Proxy.Builder s3ProxyBuilder = S3Proxy.builder()
            .blobStore(blobStore)
            .endpoint(s3Endpoint);
    if (s3Identity != null || s3Credential != null) {
        s3ProxyBuilder.awsAuthentication(s3Identity, s3Credential);
    }
    if (keyStorePath != null || keyStorePassword != null) {
        s3ProxyBuilder.keyStore(
                Resources.getResource(keyStorePath).toString(),
                keyStorePassword);
    }
    if (virtualHost != null) {
        s3ProxyBuilder.virtualHost(virtualHost);
    }
    s3Proxy = s3ProxyBuilder.build();
    s3Proxy.start();
    while (!s3Proxy.getState().equals(AbstractLifeCycle.STARTED)) {
        Thread.sleep(1);
    }

    // reset endpoint to handle zero port
    s3Endpoint = new URI(s3Endpoint.getScheme(), s3Endpoint.getUserInfo(),
            s3Endpoint.getHost(), s3Proxy.getPort(), s3Endpoint.getPath(),
            s3Endpoint.getQuery(), s3Endpoint.getFragment());
}
 
开发者ID:alexmojaki,项目名称:s3-stream-upload,代码行数:73,代码来源:StreamTransferManagerTest.java


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