Example usage for java.util.concurrent TimeUnit MINUTES

List of usage examples for java.util.concurrent TimeUnit MINUTES

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MINUTES.

Prototype

TimeUnit MINUTES

To view the source code for java.util.concurrent TimeUnit MINUTES.

Click Source Link

Document

Time unit representing sixty seconds.

Usage

From source file:onl.area51.httpd.HttpServerBuilder.java

static HttpServerBuilder builder() {
    return new HttpServerBuilder() {
        private final ServerBootstrap sb = ServerBootstrap.bootstrap();
        private long gracePeriod = 5;
        private TimeUnit gracePeriodUnit = TimeUnit.MINUTES;
        private HttpRequestHandlerBuilder globalHandler;

        @Override/*from  ww w .  j a  va2  s.  c  o  m*/
        public HttpServerBuilder shutdown(long gracePeriod, TimeUnit gracePeriodUnit) {
            if (gracePeriod < 1 || gracePeriodUnit == null) {
                throw new IllegalArgumentException("Invalid GracePeriod");
            }
            this.gracePeriod = gracePeriod;
            this.gracePeriodUnit = gracePeriodUnit;
            return this;
        }

        @Override
        public HttpServerBuilder setListenerPort(int listenerPort) {
            sb.setListenerPort(listenerPort);
            return this;
        }

        @Override
        public HttpServerBuilder setLocalAddress(InetAddress localAddress) {
            sb.setLocalAddress(localAddress);
            return this;
        }

        @Override
        public HttpServerBuilder setSocketConfig(SocketConfig socketConfig) {
            sb.setSocketConfig(socketConfig);
            return this;
        }

        @Override
        public HttpServerBuilder setConnectionConfig(ConnectionConfig connectionConfig) {
            sb.setConnectionConfig(connectionConfig);
            return this;
        }

        @Override
        public HttpServerBuilder setHttpProcessor(HttpProcessor httpProcessor) {
            sb.setHttpProcessor(httpProcessor);
            return this;
        }

        @Override
        public HttpServerBuilder addInterceptorFirst(HttpResponseInterceptor itcp) {
            sb.addInterceptorFirst(itcp);
            return this;
        }

        @Override
        public HttpServerBuilder addInterceptorLast(HttpResponseInterceptor itcp) {
            sb.addInterceptorLast(itcp);
            return this;
        }

        @Override
        public HttpServerBuilder addInterceptorFirst(HttpRequestInterceptor itcp) {
            sb.addInterceptorFirst(itcp);
            return this;
        }

        @Override
        public HttpServerBuilder addInterceptorLast(HttpRequestInterceptor itcp) {
            sb.addInterceptorLast(itcp);
            return this;
        }

        @Override
        public HttpServerBuilder setServerInfo(String serverInfo) {
            sb.setServerInfo(serverInfo);
            return this;
        }

        @Override
        public HttpServerBuilder setConnectionReuseStrategy(ConnectionReuseStrategy connStrategy) {
            sb.setConnectionReuseStrategy(connStrategy);
            return this;
        }

        @Override
        public HttpServerBuilder setResponseFactory(HttpResponseFactory responseFactory) {
            sb.setResponseFactory(responseFactory);
            return this;
        }

        @Override
        public HttpServerBuilder setHandlerMapper(HttpRequestHandlerMapper handlerMapper) {
            sb.setHandlerMapper(handlerMapper);
            return this;
        }

        @Override
        public HttpServerBuilder registerHandler(String pattern, HttpRequestHandler handler) {
            sb.registerHandler(pattern, handler);
            return this;
        }

        @Override
        public HttpServerBuilder setExpectationVerifier(HttpExpectationVerifier expectationVerifier) {
            sb.setExpectationVerifier(expectationVerifier);
            return this;
        }

        @Override
        public HttpServerBuilder setConnectionFactory(
                HttpConnectionFactory<? extends DefaultBHttpServerConnection> connectionFactory) {
            sb.setConnectionFactory(connectionFactory);
            return this;
        }

        @Override
        public HttpServerBuilder setSslSetupHandler(SSLServerSetupHandler sslSetupHandler) {
            sb.setSslSetupHandler(sslSetupHandler);
            return this;
        }

        @Override
        public HttpServerBuilder setServerSocketFactory(ServerSocketFactory serverSocketFactory) {
            sb.setServerSocketFactory(serverSocketFactory);
            return this;
        }

        @Override
        public HttpServerBuilder setSslContext(SSLContext sslContext) {
            sb.setSslContext(sslContext);
            return this;
        }

        @Override
        public HttpServerBuilder setExceptionLogger(ExceptionLogger exceptionLogger, boolean filter) {
            sb.setExceptionLogger(filter ? ex -> {
                if (!(ex instanceof SocketTimeoutException) && !(ex instanceof ConnectionClosedException)
                        && !(ex instanceof SocketException)) {
                    exceptionLogger.log(ex);
                }
            } : exceptionLogger);
            return this;
        }

        @Override
        public HttpRequestHandlerBuilder getGlobalHandlerBuilder() {
            if (globalHandler == null) {
                globalHandler = HttpRequestHandlerBuilder.create();
            }
            return globalHandler;
        }

        @Override
        public HttpServer build() {
            if (globalHandler != null) {
                sb.registerHandler("/*", globalHandler.build());
            }

            org.apache.http.impl.bootstrap.HttpServer server = sb.create();
            return new HttpServer() {
                @Override
                public void start() throws IOException {
                    server.start();
                }

                @Override
                public void stop() {
                    server.shutdown(gracePeriod, gracePeriodUnit);
                }
            };
        }

    };
}

From source file:io.fabric8.elasticsearch.RequestRunner.java

protected final OkHttpClient getHttpClient() throws Exception {
    File ksFile = new File(keyStore);
    KeyStore trusted = KeyStore.getInstance("JKS");
    FileInputStream in = new FileInputStream(ksFile);
    trusted.load(in, password.toCharArray());
    in.close();/*from w w w  .j  av a 2  s .  c o  m*/
    SSLContext sslContext = SSLContext.getInstance("TLS");
    TrustManagerFactory trustManagerFactory = InsecureTrustManagerFactory.INSTANCE;
    X509TrustManager trustManager = (X509TrustManager) trustManagerFactory.getTrustManagers()[0];
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    OkHttpClient client = new okhttp3.OkHttpClient.Builder()
            .sslSocketFactory(sslContext.getSocketFactory(), trustManager).readTimeout(1, TimeUnit.MINUTES)
            .writeTimeout(1, TimeUnit.MINUTES).build();
    return client;
}

From source file:org.axonframework.migration.eventstore.JpaEventStoreMigrator.java

public boolean run() throws Exception {
    final AtomicInteger updateCount = new AtomicInteger();
    final AtomicInteger skipCount = new AtomicInteger();
    final AtomicLong lastId = new AtomicLong(
            Long.parseLong(configuration.getProperty("lastProcessedId", "-1")));
    try {// w  w w . ja  v  a  2  s  . c o m
        TransactionTemplate template = new TransactionTemplate(txManager);
        template.setReadOnly(true);
        System.out.println("Starting conversion. Fetching batches of " + QUERY_BATCH_SIZE + " items.");
        while (template.execute(new TransactionCallback<Boolean>() {
            @Override
            public Boolean doInTransaction(TransactionStatus status) {
                final Session hibernate = entityManager.unwrap(Session.class);
                Iterator<Object[]> results = hibernate.createQuery(
                        "SELECT e.aggregateIdentifier, e.sequenceNumber, e.type, e.id FROM DomainEventEntry e "
                                + "WHERE e.id > :lastIdentifier ORDER BY e.id ASC")
                        .setFetchSize(1000).setMaxResults(QUERY_BATCH_SIZE).setReadOnly(true)
                        .setParameter("lastIdentifier", lastId.get()).iterate();
                if (!results.hasNext()) {
                    System.out.println("Empty batch. Assuming we're done.");
                    return false;
                } else if (Thread.interrupted()) {
                    System.out.println("Received an interrupt. Stopping...");
                    return false;
                }
                while (results.hasNext()) {
                    List<ConversionItem> conversionBatch = new ArrayList<ConversionItem>();
                    while (conversionBatch.size() < CONVERSION_BATCH_SIZE && results.hasNext()) {
                        Object[] item = results.next();
                        String aggregateIdentifier = (String) item[0];
                        long sequenceNumber = (Long) item[1];
                        String type = (String) item[2];
                        Long entryId = (Long) item[3];
                        lastId.set(entryId);
                        conversionBatch
                                .add(new ConversionItem(sequenceNumber, aggregateIdentifier, type, entryId));
                    }
                    if (!conversionBatch.isEmpty()) {
                        executor.submit(new TransformationTask(conversionBatch, skipCount));
                    }
                }
                return true;
            }
        })) {
            System.out.println("Reading next batch, starting at ID " + lastId.get() + ".");
            System.out.println(
                    "Estimated backlog size is currently: " + (workQueue.size() * CONVERSION_BATCH_SIZE));
        }
    } finally {
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.MINUTES);
        if (lastId.get() >= 0) {
            System.out.println(
                    "Processed events from old event store up to (and including) id = " + lastId.get());
        }
    }
    System.out.println("In total " + updateCount.get() + " items have been converted.");
    return skipCount.get() == 0;
}

From source file:com.spotify.helios.ZooKeeperClusterTestManager.java

@Override
public void start() {
    try {/* w w  w.j a  v  a2 s.  co  m*/
        start0();
    } catch (BindException e) {
        throw Throwables.propagate(e);
    }
    try {
        awaitUp(5, TimeUnit.MINUTES);
    } catch (TimeoutException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.apache.zeppelin.sap.universe.UniverseClient.java

public UniverseClient(String user, String password, String apiUrl, String authType, int queryTimeout) {
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(queryTimeout)
            .setSocketTimeout(queryTimeout).build();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(100);/*w  w w.  j  a  v  a 2  s.  c o m*/
    cm.setDefaultMaxPerRoute(100);
    cm.closeIdleConnections(10, TimeUnit.MINUTES);
    httpClient = HttpClientBuilder.create().setConnectionManager(cm).setDefaultRequestConfig(requestConfig)
            .build();

    this.user = user;
    this.password = password;
    this.authType = authType;
    if (StringUtils.isNotBlank(apiUrl)) {
        this.apiUrl = apiUrl.replaceAll("/$", "");
    }
}

From source file:br.unb.cic.bionimbuz.services.storage.StorageService.java

/**
 * Mtodo que inicia a storage/*from   ww w.ja v  a2  s .  c o m*/
 *
 * @param config
 * @param listeners
 */
@Override
public void start(List<Listeners> listeners) {
    this.listeners = listeners;
    if (listeners != null) {
        listeners.add(this);
    }
    // Criando pastas zookeeper para o mdulo de armazenamento
    if (!this.cms.getZNodeExist(Path.PENDING_SAVE.getFullPath(), null)) {
        this.cms.createZNode(CreateMode.PERSISTENT, Path.PENDING_SAVE.getFullPath(), null);
    }
    if (!this.cms.getZNodeExist(Path.FILES.getFullPath(BioNimbusConfig.get().getId()), null)) {
        this.cms.createZNode(CreateMode.PERSISTENT, Path.FILES.getFullPath(BioNimbusConfig.get().getId()), "");
    }

    // watcher para verificar se um pending_save foi lanado
    this.cms.getChildren(Path.PENDING_SAVE.getFullPath(), new UpdatePeerData(this.cms, this, null));
    this.cms.getChildren(Path.PEERS.getFullPath(), new UpdatePeerData(this.cms, this, null));

    // NECESSARIO atualizar a lista de arquivo local , a lista do zookeeper com os arquivos locais.
    // checkFiles();
    this.checkPeers();
    try {
        if (this.getPeers().size() != 1) {
            this.checkReplicationFiles();
        }
    } catch (final Exception ex) {
        LOGGER.error("[Exception] - " + ex.getMessage());
    }
    this.executorService.scheduleAtFixedRate(this, 0, 1, TimeUnit.MINUTES);
}

From source file:com.kixeye.chassis.support.test.metrics.cloudwatch.MetricsCloudWatchConfigurationTest.java

@Test
public void testUpdatePublishIntervalUnit() {
    TimeUnit originalIntervalUnit = metricsCloudWatchConfiguration.getReporter().getPublishIntervalUnit();
    Assert.assertEquals(originalIntervalUnit, TimeUnit.MINUTES);

    ConfigurationManager.getConfigInstance().setProperty(
            removePlaceholder(MetricsCloudWatchReporter.METRICS_AWS_PUBLISH_INTERVAL_UNIT_PROPERTY_NAME),
            TimeUnit.SECONDS + "");

    Assert.assertEquals(TimeUnit.SECONDS,
            metricsCloudWatchConfiguration.getReporter().getPublishIntervalUnit());

    ConfigurationManager.getConfigInstance().setProperty(
            removePlaceholder(MetricsCloudWatchReporter.METRICS_AWS_PUBLISH_INTERVAL_UNIT_PROPERTY_NAME),
            TimeUnit.MINUTES + "");
}

From source file:com.linkedin.pinot.integration.tests.MetadataAndDictionaryAggregationPlanClusterIntegrationTest.java

private void createAndUploadSegments(List<File> avroFiles, String tableName, boolean createStarTreeIndex,
        List<String> rawIndexColumns, Schema pinotSchema) throws Exception {
    TestUtils.ensureDirectoriesExistAndEmpty(_segmentDir, _tarDir);

    ExecutorService executor = Executors.newCachedThreadPool();
    ClusterIntegrationTestUtils.buildSegmentsFromAvro(avroFiles, 0, _segmentDir, _tarDir, tableName,
            createStarTreeIndex, rawIndexColumns, pinotSchema, executor);
    executor.shutdown();//  ww  w . j a va  2  s.c  o  m
    executor.awaitTermination(10, TimeUnit.MINUTES);

    uploadSegments(_tarDir);
}

From source file:net.openhft.chronicle.logger.log4j1.Log4j1VanillaChroniclePerfTest.java

@Test
public void testMultiThreadLogging() throws IOException, InterruptedException {
    warmup(LoggerFactory.getLogger("perf-binary-vanilla-chronicle"));
    warmup(LoggerFactory.getLogger("perf-plain-vanilla"));

    final int RUNS = 100000; // ~ 10s
    final int THREADS = Runtime.getRuntime().availableProcessors();

    for (int size : new int[] { 64, 128, 256 }) {
        {/* w w w  . j  a  va 2  s  .  com*/
            final long start = System.nanoTime();

            ExecutorService es = Executors.newFixedThreadPool(THREADS);
            for (int t = 0; t < THREADS; t++) {
                es.submit(new RunnableLogger(RUNS, size, "perf-binary-vanilla-chronicle"));
            }

            es.shutdown();
            es.awaitTermination(2, TimeUnit.MINUTES);

            final long time = System.nanoTime() - start;

            System.out.printf(
                    "ChronicleLog.MT (runs=%d, min size=%03d, elapsed=%.3f ms) took an average of %.3f us per entry\n",
                    RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS));
        }

        {
            final long start = System.nanoTime();

            ExecutorService es = Executors.newFixedThreadPool(THREADS);
            for (int t = 0; t < THREADS; t++) {
                es.submit(new RunnableLogger(RUNS, size, "perf-plain-vanilla"));
            }

            es.shutdown();
            es.awaitTermination(5, TimeUnit.MINUTES);

            final long time = System.nanoTime() - start;

            System.out.printf(
                    "Plain.MT (runs=%d, min size=%03d, elapsed=%.3f ms)): took an average of %.3f us per entry\n",
                    RUNS, size, time / 1e6, time / 1e3 / (RUNS * THREADS));
        }
    }

    IOTools.deleteDir(basePath("perf-binary-vanilla-chronicle"));
}