org.apache.druid.java.util.common.lifecycle.Lifecycle.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.apache.druid.java.util.common.lifecycle.Lifecycle.<init>()方法的一些代码示例,展示了Lifecycle.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lifecycle.<init>()方法的具体详情如下:
包路径:org.apache.druid.java.util.common.lifecycle.Lifecycle
类名称:Lifecycle
方法名:<init>

Lifecycle.<init>介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-druid

public static Lifecycle asMmxLifecycle(Lifecycle lifecycle)
 {
  final Lifecycle metamxLifecycle = new Lifecycle("http-client");
  try {
   lifecycle.addMaybeStartHandler(new Lifecycle.Handler()
   {
    @Override
    public void start() throws Exception
    {
     metamxLifecycle.start();
    }

    @Override
    public void stop()
    {
     metamxLifecycle.stop();
    }
   });
  }
  catch (Exception e) {
   throw Throwables.propagate(e);
  }

  return metamxLifecycle;
 }
}

代码示例来源:origin: apache/incubator-druid

private Emitter parametrizedEmmiter(String uriPattern) throws Exception
{
 final Properties props = new Properties();
 props.setProperty("org.apache.druid.java.util.emitter.type", "parametrized");
 props.setProperty("org.apache.druid.java.util.emitter.recipientBaseUrlPattern", uriPattern);
 lifecycle = new Lifecycle();
 Emitter emitter = Emitters.create(props, httpClient, lifecycle);
 assertEquals(ParametrizedUriEmitter.class, emitter.getClass());
 lifecycle.start();
 return emitter;
}

代码示例来源:origin: apache/incubator-druid

private HttpPostEmitter sizeBasedEmitterGeneralizedCreation(int size)
{
 Properties props = new Properties();
 props.setProperty("org.apache.druid.java.util.emitter.type", "http");
 props.setProperty("org.apache.druid.java.util.emitter.recipientBaseUrl", TARGET_URL);
 props.setProperty("org.apache.druid.java.util.emitter.flushMillis", String.valueOf(Long.MAX_VALUE));
 props.setProperty("org.apache.druid.java.util.emitter.flushCount", String.valueOf(size));
 Lifecycle lifecycle = new Lifecycle();
 Emitter emitter = Emitters.create(props, httpClient, jsonMapper, lifecycle);
 Assert.assertTrue(StringUtils.format(
   "HttpPostEmitter emitter should be created, but found %s",
   emitter.getClass().getName()
 ), emitter instanceof HttpPostEmitter);
 emitter.start();
 return (HttpPostEmitter) emitter;
}

代码示例来源:origin: apache/incubator-druid

ClientHolder(int maxClientConnections)
{
 final Lifecycle druidLifecycle = new Lifecycle();
 try {
  this.client = HttpClientInit.createClient(
    new HttpClientConfig(maxClientConnections, SSLContext.getDefault(), Duration.ZERO),
    LifecycleUtils.asMmxLifecycle(druidLifecycle)
  );
 }
 catch (Exception e) {
  throw Throwables.propagate(e);
 }
}

代码示例来源:origin: apache/incubator-druid

@Before
public void setUp()
{
 exec = PrioritizedExecutorService.create(
   new Lifecycle(),
   new DruidProcessingConfig()
   {
    @Override
    public String getFormatString()
    {
     return "test";
    }
    @Override
    public int getNumThreads()
    {
     return 1;
    }
    @Override
    public boolean isFifo()
    {
     return useFifo;
    }
   }
 );
 latch = new CountDownLatch(1);
 finishLatch = new CountDownLatch(3);
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testCustomEmitter()
 {
  final Properties props = new Properties();
  props.put("org.apache.druid.java.util.emitter.stringProperty", "http://example.com/");
  props.put("org.apache.druid.java.util.emitter.intProperty", "1");
  props.put("org.apache.druid.java.util.emitter.type", "test");

  final ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.registerSubtypes(TestEmitterConfig.class);
  final Lifecycle lifecycle = new Lifecycle();
  final Emitter emitter = Emitters.create(props, null, objectMapper, lifecycle);

  Assert.assertTrue("created emitter should be of class StubEmitter", emitter instanceof StubEmitter);
  StubEmitter stubEmitter = (StubEmitter) emitter;
  Assert.assertEquals("http://example.com/", stubEmitter.getStringProperty());
  Assert.assertEquals(1, stubEmitter.getIntProperty());
 }
}

代码示例来源:origin: apache/incubator-druid

final Lifecycle leaderLifecycle = new Lifecycle("task-master");
if (leaderLifecycleRef.getAndSet(leaderLifecycle) != null) {
 log.makeAlert("TaskMaster set a new Lifecycle without the old one being cleared!  Race condition")

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpSilentServerWithRequestTimeout() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().withReadTimeout(new Duration(86400L * 365)).build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> future = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", silentServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8),
      new Duration(100L)
    );
  Throwable e = null;
  try {
   future.get();
  }
  catch (ExecutionException e1) {
   e = e1.getCause();
  }
  Assert.assertTrue("ReadTimeoutException thrown by 'get'", e instanceof ReadTimeoutException);
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpConnectionClosingServer() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> response = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", closingServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8)
    );
  Throwable e = null;
  try {
   response.get();
  }
  catch (ExecutionException e1) {
   e = e1.getCause();
   e1.printStackTrace();
  }
  Assert.assertTrue("ChannelException thrown by 'get'", isChannelClosedException(e));
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpsSilentServer() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder()
                          .withSslContext(SSLContext.getDefault())
                          .withSslHandshakeTimeout(new Duration(100))
                          .build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> response = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", silentServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8)
    );
  Throwable e = null;
  try {
   response.get();
  }
  catch (ExecutionException e1) {
   e = e1.getCause();
  }
  Assert.assertTrue("ChannelException thrown by 'get'", e instanceof ChannelException);
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpsConnectionClosingServer() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> response = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", closingServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8)
    );
  Throwable e = null;
  try {
   response.get();
  }
  catch (ExecutionException e1) {
   e = e1.getCause();
   e1.printStackTrace();
  }
  Assert.assertTrue("ChannelException thrown by 'get'", isChannelClosedException(e));
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpSilentServerWithGlobalTimeout() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().withReadTimeout(new Duration(100)).build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> future = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", silentServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8)
    );
  Throwable e = null;
  try {
   future.get();
  }
  catch (ExecutionException e1) {
   e = e1.getCause();
  }
  Assert.assertTrue("ReadTimeoutException thrown by 'get'", e instanceof ReadTimeoutException);
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testHttpsEchoServer() throws Throwable
 {
  final Lifecycle lifecycle = new Lifecycle();
  try {
   final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build();
   final HttpClient client = HttpClientInit.createClient(config, lifecycle);

   final ListenableFuture<StatusResponseHolder> response = client
     .go(
       new Request(HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", echoServerSocket.getLocalPort()))),
       new StatusResponseHandler(StandardCharsets.UTF_8)
     );

   expectedException.expect(ExecutionException.class);
   expectedException.expectMessage("org.jboss.netty.channel.ChannelException: Faulty channel in resource pool");

   response.get();
  }
  finally {
   lifecycle.stop();
  }
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testHttpEchoServer() throws Throwable
{
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().build();
  final HttpClient client = HttpClientInit.createClient(config, lifecycle);
  final ListenableFuture<StatusResponseHolder> response = client
    .go(
      new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", echoServerSocket.getLocalPort()))),
      new StatusResponseHandler(StandardCharsets.UTF_8)
    );
  expectedException.expect(ExecutionException.class);
  expectedException.expectMessage("java.lang.IllegalArgumentException: invalid version format: GET");
  response.get();
 }
 finally {
  lifecycle.stop();
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testStartStopOnce() throws Exception
 final Lifecycle lifecycle = new Lifecycle();
 final AtomicLong failedCount = new AtomicLong(0L);
 Lifecycle.Handler exceptionalHandler = new Lifecycle.Handler()

代码示例来源:origin: apache/incubator-druid

@Test
public void testAddToLifecycleInStartMethod() throws Exception
 final Lifecycle lifecycle = new Lifecycle();

代码示例来源:origin: apache/incubator-druid

public void testHttpBin() throws Throwable
 final Lifecycle lifecycle = new Lifecycle();
 try {
  final HttpClientConfig config = HttpClientConfig.builder().withSslContext(SSLContext.getDefault()).build();

代码示例来源:origin: apache/incubator-druid

@Test
public void testSanity() throws Exception
{
 Lifecycle lifecycle = new Lifecycle();
 List<Integer> startOrder = new ArrayList<>();
 List<Integer> stopOrder = new ArrayList<>();
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(0, startOrder, stopOrder));
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(1, startOrder, stopOrder), Lifecycle.Stage.NORMAL);
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(2, startOrder, stopOrder), Lifecycle.Stage.NORMAL);
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(3, startOrder, stopOrder), Lifecycle.Stage.LAST);
 lifecycle.addStartCloseInstance(new ObjectToBeLifecycled(4, startOrder, stopOrder));
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(5, startOrder, stopOrder));
 lifecycle.addStartCloseInstance(new ObjectToBeLifecycled(6, startOrder, stopOrder), Lifecycle.Stage.LAST);
 lifecycle.addManagedInstance(new ObjectToBeLifecycled(7, startOrder, stopOrder));
 lifecycle.addStartCloseInstance(new ObjectToBeLifecycled(8, startOrder, stopOrder), Lifecycle.Stage.INIT);
 final List<Integer> expectedOrder = Arrays.asList(8, 0, 1, 2, 4, 5, 7, 3, 6);
 lifecycle.start();
 Assert.assertEquals(9, startOrder.size());
 Assert.assertEquals(0, stopOrder.size());
 Assert.assertEquals(expectedOrder, startOrder);
 lifecycle.stop();
 Assert.assertEquals(9, startOrder.size());
 Assert.assertEquals(9, stopOrder.size());
 Assert.assertEquals(Lists.reverse(expectedOrder), stopOrder);
}

代码示例来源:origin: apache/incubator-druid

private HttpClient makeCertlessClient()
{
 SSLContext certlessClientSSLContext = new TLSUtils.ClientSSLContextBuilder()
   .setProtocol(sslClientConfig.getProtocol())
   .setTrustStoreType(sslClientConfig.getTrustStoreType())
   .setTrustStorePath(sslClientConfig.getTrustStorePath())
   .setTrustStoreAlgorithm(sslClientConfig.getTrustStoreAlgorithm())
   .setTrustStorePasswordProvider(sslClientConfig.getTrustStorePasswordProvider())
   .setCertificateChecker(certificateChecker)
   .build();
 final HttpClientConfig.Builder builder = getHttpClientConfigBuilder(certlessClientSSLContext);
 final Lifecycle lifecycle = new Lifecycle();
 HttpClient client = HttpClientInit.createClient(
   builder.build(),
   LifecycleUtils.asMmxLifecycle(lifecycle)
 );
 HttpClient adminClient = new CredentialedHttpClient(
   new BasicCredentials("admin", "priest"),
   client
 );
 return adminClient;
}

代码示例来源:origin: apache/incubator-druid

final Lifecycle lifecycle = new Lifecycle();

相关文章