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:com.omertron.slackbot.functions.scheduler.AbstractBotTask.java

@Override
public final void stop() {
    LOG.info("{} is stopping.", name);
    if (scheduledTask != null) {
        scheduledTask.cancel(false);/*  w  w  w.j a va  2 s  .c o  m*/
    }
    executorService.shutdown();
    LOG.info("{} stopped.", name);
    try {
        LOG.info("{} awaitTermination, start: isBusy [{}]", name, isBusy);
        // wait one minute to termination if busy
        if (isBusy) {
            executorService.awaitTermination(1, TimeUnit.MINUTES);
        }
    } catch (InterruptedException ex) {
        LOG.error("{} awaitTermination exception", name, ex);
        // Restore interrupted state...
        Thread.currentThread().interrupt();
    } finally {
        LOG.info("{} awaitTermination, finished", name);
    }
}

From source file:com.mnt.base.stream.comm.PacketProcessorManager.java

@Override
public void run() {
    while (runningFlag) {
        StreamPacket streamPacket = null;
        try {/*from ww  w.j a  va2 s.c om*/
            streamPacket = streamPacketQueueMap.get((int) Math.abs(pollAi.incrementAndGet() % maxQueueMapSize))
                    .poll(1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            log.error("Error while process the stream packet in processor queue", e);
        }

        if (streamPacket != null) {

            NetTraffic.log("ready to process: ", streamPacket);

            try {
                dispatchPacket(streamPacket);
            } catch (Exception e) {
                log.error("error while dispatch packet: " + streamPacket.toString(), e);
            }
        }

        NetTraffic.log("processed: ", streamPacket);
    }
}

From source file:at.becast.youploader.youtube.GuiUploadEvent.java

@Override
public void onRead(long length, long position, long size) {
    long now = System.currentTimeMillis();
    if (this.step < now - 2000) {
        frame.getProgressBar().setString(String.format("%6.2f%%", (float) position / size * 100));
        frame.getProgressBar().setValue((int) ((float) position / size * 100));
        frame.getProgressBar().revalidate();
        frame.revalidate();//from   w  w w .  ja  v  a2  s  .c  o  m
        frame.repaint();
        if (lastdb < now - 10000) {
            SQLite.updateUploadProgress(frame.upload_id, position);
            this.lastdb = now;
        }
        this.step = now;
        this.dataDelta = position - this.lastdata;
        this.timeDelta = this.step - this.lasttime;
        this.lasttime = this.step;
        this.lastdata = position;
        long speed = this.dataDelta / (this.timeDelta + 1) * 1000 + 1;
        long duration = ((size - position) / speed) * 1000;
        String time = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(duration),
                TimeUnit.MILLISECONDS.toMinutes(duration)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)),
                TimeUnit.MILLISECONDS.toSeconds(duration)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
        frame.getLblKbs().setText(FileUtils.byteCountToDisplaySize(speed) + "/s");
        frame.getLblETA().setText(time);
        if (Main.debug) {
            LOG.debug("Took {} ms to refresh, Uploaded {} bytes, Speed {} ", System.currentTimeMillis() - now,
                    this.dataDelta, FileUtils.byteCountToDisplaySize(speed));
        }
    }
}

From source file:com.opensoc.alerts.TelemetryAlertsBolt.java

@Override
void doPrepare(Map conf, TopologyContext topologyContext, OutputCollector collector) throws IOException {

    cache = CacheBuilder.newBuilder().maximumSize(_MAX_CACHE_SIZE_OBJECTS_NUM)
            .expireAfterWrite(_MAX_TIME_RETAIN_MINUTES, TimeUnit.MINUTES).build();

    LOG.info("[OpenSOC] Preparing TelemetryAlert Bolt...");

    try {//from ww  w  .j av  a 2  s.c o  m
        _reporter = new MetricReporter();
        _reporter.initialize(metricProperties, TelemetryAlertsBolt.class);
        LOG.info("[OpenSOC] Initialized metrics");
    } catch (Exception e) {
        LOG.info("[OpenSOC] Could not initialize metrics");
    }
}

From source file:co.cask.hydrator.plugin.RunTest.java

@Test
public void testRunWithJarInput() throws Exception {
    String inputTable = "run-jar-input";
    URL testRunnerUrl = this.getClass().getResource("/SampleRunner.jar");
    FileUtils.copyFile(new File(testRunnerUrl.getFile()), new File(sourceFolder, "/SampleRunner.jar"));

    ETLStage source = new ETLStage("source", MockSource.getPlugin(inputTable, INPUT));

    Map<String, String> runProperties = new ImmutableMap.Builder<String, String>()
            .put("commandToExecute", "java -jar " + sourceFolder.toPath() + "/SampleRunner.jar")
            .put("fieldsToProcess", "input").put("fixedInputs", "CASK").put("outputField", "output")
            .put("outputFieldType", "string").build();

    ETLStage transform = new ETLStage("transform",
            new ETLPlugin("Run", Transform.PLUGIN_TYPE, runProperties, null));

    String sinkTable = "run-jar-output";

    ETLStage sink = new ETLStage("sink", MockSink.getPlugin(sinkTable));
    ETLBatchConfig etlConfig = ETLBatchConfig.builder("* * * * *").addStage(source).addStage(transform)
            .addStage(sink).addConnection(source.getName(), transform.getName())
            .addConnection(transform.getName(), sink.getName()).build();

    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(ETLBATCH_ARTIFACT, etlConfig);
    ApplicationId appId = NamespaceId.DEFAULT.app("RunJarTest");
    ApplicationManager appManager = deployApplication(appId.toId(), appRequest);

    DataSetManager<Table> inputManager = getDataset(inputTable);
    List<StructuredRecord> input = ImmutableList.of(
            StructuredRecord.builder(INPUT).set("id", 1).set("input", "Brett").build(),
            StructuredRecord.builder(INPUT).set("id", 2).set("input", "Chang").build(),
            StructuredRecord.builder(INPUT).set("id", 3).set("input", "Roy").build(),
            StructuredRecord.builder(INPUT).set("id", 4).set("input", "John").build(),
            StructuredRecord.builder(INPUT).set("id", 5).set("input", "Michael").build());

    MockSource.writeInput(inputManager, input);
    MapReduceManager mrManager = appManager.getMapReduceManager(ETLMapReduce.NAME);
    mrManager.start();//  ww  w. jav a2 s.  co  m
    mrManager.waitForFinish(5, TimeUnit.MINUTES);

    DataSetManager<Table> outputManager = getDataset(sinkTable);
    List<StructuredRecord> outputRecords = MockSink.readOutput(outputManager);

    Assert.assertEquals("OutputRecords", 5, outputRecords.size());
    for (StructuredRecord record : outputRecords) {
        int value = (record.get("id"));
        if (value == 1) {
            Assert.assertEquals("Brett", record.get("input"));
            Assert.assertEquals("Hello Brett...Welcome to the CASK!!!", record.get("output"));
        } else if (value == 2) {
            Assert.assertEquals("Chang", record.get("input"));
            Assert.assertEquals("Hello Chang...Welcome to the CASK!!!", record.get("output"));
        } else if (value == 3) {
            Assert.assertEquals("Roy", record.get("input"));
            Assert.assertEquals("Hello Roy...Welcome to the CASK!!!", record.get("output"));
        } else if (value == 4) {
            Assert.assertEquals("John", record.get("input"));
            Assert.assertEquals("Hello John...Welcome to the CASK!!!", record.get("output"));
        } else {
            Assert.assertEquals("Michael", record.get("input"));
            Assert.assertEquals("Hello Michael...Welcome to the CASK!!!", record.get("output"));
        }
    }
}

From source file:org.jberet.support.io.MongoItemReaderTest.java

private void testReadWrite0(final String uri, final String skip, final String limit, final int size,
        final Class<?> beanType, final String projection, final String collection, final String collectionOut,
        final String expect, final String forbid) throws Exception {
    final Properties params = CsvItemReaderWriterTest.createParams(CsvProperties.BEAN_TYPE_KEY,
            beanType.getName());/* www. ja va 2 s  .  c om*/
    params.setProperty("collection", collection);
    params.setProperty("collection.out", collectionOut);
    if (uri != null) {
        params.setProperty("uri", uri);
    }
    if (projection != null) {
        params.setProperty("projection", projection);
    }
    if (skip != null) {
        params.setProperty("skip", skip);
    }
    if (limit != null) {
        params.setProperty("limit", limit);
    }

    final long jobExecutionId = jobOperator.start(jobName, params);
    final JobExecutionImpl jobExecution = (JobExecutionImpl) jobOperator.getJobExecution(jobExecutionId);
    jobExecution.awaitTermination(CsvItemReaderWriterTest.waitTimeoutMinutes, TimeUnit.MINUTES);
    Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());

    validate(size, expect, forbid);
}

From source file:nl.esciencecenter.octopus.webservice.job.OctopusManagerTest.java

@Test
public void testStop() throws Exception {
    Octopus octopus = mock(Octopus.class);
    ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
    OctopusManager manager = new OctopusManager(null, octopus, null, null, null, executor);

    manager.stop();/*from  ww  w .  j  av a  2s. c om*/

    verify(octopus).end();
    verify(executor).shutdown();
    verify(executor).awaitTermination(1, TimeUnit.MINUTES);
}

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private void awaitExecutionCompletion(ExecutorService executorService) {
    try {/* ww  w .  j av  a2  s.  c  om*/
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.mortbay.jetty.load.generator.listeners.CollectorServer.java

@Override
public void onResourceNode(Resource.Info info) {
    String path = info.getResource().getPath();

    Recorder recorder = recorderPerPath.get(path);
    if (recorder == null) {
        recorder = new Recorder(TimeUnit.MICROSECONDS.toNanos(1), //
                TimeUnit.MINUTES.toNanos(1), //
                3);/* ww w  .j av  a  2 s .  c  o m*/
        recorderPerPath.put(path, recorder);
    }

    long time = info.getResponseTime() - info.getRequestTime();
    try {
        recorder.recordValue(time);
    } catch (ArrayIndexOutOfBoundsException e) {
        LOGGER.warn("skip error recording time {}, {}", time, e.getMessage());
    }

}

From source file:no.uis.fsws.proxy.StudinfoProxyImpl.java

@Override
@SneakyThrows/* w w  w.j  a v  a 2 s  .c om*/
public List<Emne> getEmnerForOrgenhet(final XMLGregorianCalendar arstall, final Terminkode terminkode,
        final Sprakkode sprak, final int institusjonsnr, final Integer fakultetsnr, final Integer instituttnr,
        final Integer gruppenr) {
    final StudInfoImport svc = getServiceForPrincipal();
    Future<List<Emne>> future = executor.submit(new Callable<List<Emne>>() {

        @Override
        public List<Emne> call() throws Exception {
            final FsStudieinfo sinfo = svc.fetchSubjects(institusjonsnr,
                    fakultetsnr == null ? -1 : fakultetsnr.intValue(), arstall.getYear(), terminkode.toString(),
                    sprak.toString());
            return sinfo.getEmne();
        }
    });

    return future.get(timeoutMinutes, TimeUnit.MINUTES);
}