Example usage for java.util.concurrent TimeUnit HOURS

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

Introduction

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

Prototype

TimeUnit HOURS

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

Click Source Link

Document

Time unit representing sixty minutes.

Usage

From source file:com.cazcade.billabong.store.impl.CloudFilesBasedBinaryStore.java

private void initInternal(SimpleDateFormat dateFormat, final XStream xStream, final File serializedStoreFile)
        throws IOException, ParseException {
    int limit = 1000;
    String marker = null;/*from ww  w  . j a va2 s  .  c  o m*/
    for (List<FilesObject> files = client.listObjectsStartingWith(containerName, null, null, limit,
            marker); files.size() > 0; files = client.listObjectsStartingWith(containerName, null, null, limit,
                    marker)) {
        for (FilesObject file : files) {
            map.put(file.getName(), new CloudFilesBinaryStoreEntry(client, containerName, file.getName(),
                    dateFormat.parse(file.getLastModified().substring(0, 25))));
            marker = file.getName();
        }
    }
    loadAndSaveExecutor.scheduleWithFixedDelay(new Runnable() {
        @Override
        public void run() {
            try {
                final FileOutputStream outputStream = new FileOutputStream(serializedStoreFile);
                xStream.toXML(map, outputStream);
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace(System.err);
            }
        }
    }, 1, 1, TimeUnit.HOURS);
}

From source file:info.raack.appliancelabeler.machinelearning.DefaultApplianceDetectionManager.java

private void startDailyRetrainingThread() {
    try {//from  w w  w  . j  a  v a 2 s. c  o  m
        if (autoModelRetraining) {
            logger.info("Starting daily retraining thread...");

            scheduler = Executors.newScheduledThreadPool(1);
            scheduler.scheduleWithFixedDelay(this, 0, retrainingInterval, TimeUnit.HOURS);
        }
    } catch (Exception e) {
        logger.error("Could not schedule daily retraining thread", e);
    }
}

From source file:gr.cti.android.experimentation.service.ModelService.java

public String durationString(long millis) {
    long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

    return String.valueOf(days) + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds";
}

From source file:com.virtusa.isq.vtaf.report.reporter.ReportBuilder.java

/**
 * Sets the execution summary.//  w  w  w. j  ava2s. com
 */
public final void setExecutionSummary() {

    for (TestSuite ts : testExecution.getTestSuites()) {
        for (TestCase tc : ts.getTestCases()) {
            int tcId = tc.getTestCaseId();
            if (!reportedTestCases.contains(tcId)) {
                reportedTestCases.add(tcId);
                if ("Failed".equals(tc.getResult())) {
                    testExecution.setTotalfailedcount(1);
                    testExecution.setTotalerrorcount(1);
                } else if ("Success".equals(tc.getResult())) {
                    testExecution.setTotalsuccesscount(1);
                }
            }
        }

    }

    long millisTotal = stopWatch.getTime();
    String hmsEx = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millisTotal),
            TimeUnit.MILLISECONDS.toMinutes(millisTotal)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisTotal)),
            TimeUnit.MILLISECONDS.toSeconds(millisTotal)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisTotal)));
    System.out.println(hmsEx);

    testExecution.setTotaltime(hmsEx + " HH:MM:SS");
    System.out.println("Report created successfully to the folder " + getReportFolderLocation());

    long timeTsEnd = System.currentTimeMillis();
    long tsTime = timeTsEnd - timeStart;
    String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(tsTime),
            TimeUnit.MILLISECONDS.toMinutes(tsTime)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(tsTime)),
            TimeUnit.MILLISECONDS.toSeconds(tsTime)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(tsTime)));
    System.out.println("Time for TestSuite : " + hms);
    testSuite.setTotaltime(hms);

}

From source file:com.cse3310.phms.ui.activities.AddAppointmentActivity.java

@Override
public void onDialogTimeSet(int reference, int hourOfDay, int minute) {
    long mills = TimeUnit.HOURS.toMillis(hourOfDay) + TimeUnit.MINUTES.toMillis(minute);
    appointmentTime = mSelectedDate.getTime() + mills;
    mTimeButtonTextView.setText(MyDateFormatter.formatTime(appointmentTime));
}

From source file:org.dllearner.algorithms.qtl.experiments.SPARQLLearningProblemsGenerator.java

public void generateBenchmark(int nrOfSPARQLQueries, final int minDepth, final int maxDepth,
        int minNrOfExamples) {
    Collection<OWLClass> classes = getClasses();
    ArrayList<OWLClass> classesList = new ArrayList<>(classes);
    Collections.shuffle(classesList, new Random(123));
    classes = classesList;/*from   w ww. j a  v  a 2  s .c  o  m*/
    //      classes = Sets.newHashSet(new OWLClassImpl(IRI.create("http://semantics.crl.ibm.com/univ-bench-dl.owl#TennisFan")));

    //      ExecutorService tp = Executors.newFixedThreadPool(threadCount);
    List<Path> allPaths = new ArrayList<>();

    //      ThreadPoolExecutor tp = new CustomFutureReturningExecutor(
    //            threadCount, threadCount,
    //                5000L, TimeUnit.MILLISECONDS,
    //                new ArrayBlockingQueue<Runnable>(classes.size(), true));

    ExecutorService tp = Executors.newFixedThreadPool(threadCount);

    CompletionService<List<Path>> ecs = new ExecutorCompletionService<List<Path>>(tp);

    JDKRandomGenerator rndGen = new JDKRandomGenerator();
    rndGen.setSeed(123);

    int nrOfQueriesPerDepth = nrOfSPARQLQueries / (maxDepth - minDepth + 1);

    // for each depth <= maxDepth
    for (int depth = minDepth; depth <= maxDepth; depth++) {
        System.out.println("Generating " + nrOfQueriesPerDepth + " queries for depth " + depth);

        Iterator<OWLClass> iterator = classes.iterator();

        // generate paths of depths <= maxDepth
        List<Path> pathsForDepth = new ArrayList<>();

        while (pathsForDepth.size() < nrOfQueriesPerDepth && iterator.hasNext()) {

            Collection<Future<List<Path>>> futures = new ArrayList<>();

            try {
                int cnt = 0;
                while (iterator.hasNext() && (pathsForDepth.size() + ++cnt < nrOfQueriesPerDepth)) {
                    // pick next class
                    OWLClass cls = iterator.next();

                    //            int depth = rndGen.nextInt(maxDepth) + 1;

                    Future<List<Path>> future = ecs
                            .submit(new PathDetectionTask(dataDir, ks, schema, cls, depth, minNrOfExamples));
                    futures.add(future);
                }

                int n = futures.size();
                try {
                    for (int i = 0; i < n; ++i) {
                        Future<List<Path>> f = ecs.take();
                        if (!f.isCancelled()) {
                            List<Path> paths = f.get();

                            if (paths != null) {
                                for (int j = 0; j < Math.min(paths.size(), maxPathsPerClassAndDepth); j++) {
                                    pathsForDepth.add(paths.get(j));
                                }
                            }
                            //                        System.out.println("#Paths: " + paths.size());
                            //                        paths.forEach(p -> System.out.println(p));

                            if (pathsForDepth.size() >= nrOfQueriesPerDepth) {
                                break;
                            }
                        }
                    }
                } catch (InterruptedException | ExecutionException e) {
                    e.printStackTrace();
                }
            } finally {
                for (Future<List<Path>> f : futures) {
                    f.cancel(true);
                }
            }
        }

        allPaths.addAll(pathsForDepth);
    }

    //      for (Future<Path> future : futures) {
    //            try {
    //               Path path = future.get();
    //               if(path != null) {
    //                  paths.add(path);
    //               }
    //               if(paths.size() == nrOfSPARQLQueries) {
    //                  System.err.println("Benchmark generation finished. Stopping all running threads.");
    //                  tp.shutdownNow();
    //               }
    //         } catch (InterruptedException | ExecutionException e) {
    //            e.printStackTrace();
    //         }
    //            if(paths.size() == nrOfSPARQLQueries) {
    //               System.err.println("Benchmark generation finished. Stopping all running threads.");
    //               tp.shutdownNow();
    //            }
    //      }

    tp.shutdownNow();
    try {
        tp.awaitTermination(1, TimeUnit.HOURS);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //      try {
    //         tp.awaitTermination(1, TimeUnit.DAYS);
    //      } catch (InterruptedException e) {
    //         e.printStackTrace();
    //      }

    // write queries to disk
    String queries = "";
    for (Path path : allPaths) {
        System.out.println(path);
        queries += path.asSPARQLQuery(Var.alloc("s")) + "\n";
    }
    File file = new File(benchmarkDirectory,
            "queries_" + nrOfSPARQLQueries + "_" + minDepth + "-" + maxDepth + "_" + minNrOfExamples + ".txt");
    try {
        Files.write(queries, file, Charsets.UTF_8);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:tools.descartes.wcf.management.timeSeries.TimeSeries.java

private TimeUnit getBiggerTimeUnit(TimeUnit timeUnit) {
    TimeUnit higherUnit = null;/*from   w ww  .  j  a va2  s  . com*/
    switch (timeUnit) {
    case NANOSECONDS:
        higherUnit = TimeUnit.MICROSECONDS;
        break;
    case MICROSECONDS:
        higherUnit = TimeUnit.MILLISECONDS;
        break;
    case MILLISECONDS:
        higherUnit = TimeUnit.SECONDS;
        break;
    case SECONDS:
        higherUnit = TimeUnit.MINUTES;
        break;
    case MINUTES:
        higherUnit = TimeUnit.HOURS;
        break;
    case HOURS:
        higherUnit = TimeUnit.DAYS;
        break;
    default:
        break;
    }
    return higherUnit;
}

From source file:com.philliphsu.clock2.alarms.Alarm.java

/**
 * Returns whether this Alarm is upcoming in the next {@code hours} hours.
 * To return true, this Alarm must not have its {@link #ignoreUpcomingRingTime}
 * member field set to true.//from w  w w .  j  ava2  s  .  c  om
 * @see #ignoreUpcomingRingTime(boolean)
 */
public boolean ringsWithinHours(int hours) {
    return !ignoreUpcomingRingTime && ringsIn() <= TimeUnit.HOURS.toMillis(hours);
}

From source file:org.dcache.util.histograms.TimeseriesHistogramTest.java

@Test
public void updateOnTimeseriesHistogramShouldRotateBufferToMaximum() throws Exception {
    givenTimeseriesHistogram();/*w  w w.jav  a 2s.c  om*/
    givenQueueCountValuesFor(48);
    givenBinUnitOf((double) TimeUnit.HOURS.toMillis(1));
    givenBinCountOf(48);
    givenBinLabelOf(TimeUnit.HOURS.name());
    givenDataLabelOf("COUNT");
    givenHistogramTypeOf("Queued Movers");
    givenHighestBinOf(getHoursInThePastFromNow(53));
    whenConfigureIsCalled();
    assertThatUpdateRotatesBuffer(53);
}

From source file:org.dcache.util.histograms.HistogramModelTest.java

@Test
public void buildShouldSucceedForTimeframeHistogramWithoutData() throws NoSuchMethodException,
        InstantiationException, IllegalAccessException, InvocationTargetException {
    givenTimeframeHistogram();//from   w  w w  .j  a v a 2 s  . c o m
    givenBinUnitOf((double) TimeUnit.HOURS.toMillis(1));
    givenBinCountOf(48);
    givenBinLabelOf(TimeUnit.HOURS.name());
    givenDataLabelOf("COUNT");
    givenHistogramTypeOf("Queued Movers");
    givenHighestBinOf(getHoursInThePastFromNow(0));
    whenConfigureIsCalled();
    assertThatBuildSucceeded();
}