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:eu.europa.ec.fisheries.uvms.rules.service.bean.MDRCache.java

@PostConstruct
public void init() {
    cache = CacheBuilder.newBuilder().refreshAfterWrite(1, TimeUnit.HOURS).maximumSize(100).initialCapacity(80)
            .recordStats().build(new CacheLoader<MDRAcronymType, List<ObjectRepresentation>>() {
                @Override/*from  ww  w  . j  a va 2  s  .c  om*/
                public List<ObjectRepresentation> load(MDRAcronymType acronymType) throws Exception {
                    return mdrCodeListByAcronymType(acronymType);
                }
            });

    //loadAllMdrCache();
}

From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.AbstractConfigCache.java

/**
 * Initializes the Config Settings cache.
 *
 *//*from ww w .  j  a  va  2s. c  om*/
protected void initializeCache() {
    if (cache == null) {
        cache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(1, TimeUnit.HOURS)
                .build(new CacheLoader<String, Map<String, String>>() {
                    @Override
                    public Map<String, String> load(String moduleName) throws Exception {
                        return getAllModuleConfigurations(moduleName);
                    }
                });
    }
}

From source file:ms1quant.MS1TargetQuantThread.java

@Override
public void run() {
    try {/*ww w  .j  a v  a2  s. c o m*/

        Logger.getRootLogger().info("Processing file " + mzxmlfile.getAbsolutePath() + "....");

        long time = System.currentTimeMillis();
        LCMSPeakMS1 LCMS1 = new LCMSPeakMS1(mzxmlfile.getAbsolutePath(), NoCPUs);
        LCMS1.SetParameter(param);

        LCMS1.Resume = false;
        if (!param.TargetIDOnly) {
            LCMS1.CreatePeakFolder();
        }
        LCMS1.ExportPeakClusterTable = false;

        if (id.PSMList.isEmpty()) {
            Logger.getRootLogger()
                    .warn("There is no PSM mapped to the file:" + mzxmlfile.getName() + ", skipping the file.");
            return;
        }
        LCMS1.IDsummary = id;
        LCMS1.IDsummary.mzXMLFileName = mzxmlfile.getAbsolutePath();

        if (param.TargetIDOnly) {
            LCMS1.SaveSerializationFile = false;
        }

        if (param.TargetIDOnly || !LCMS1.ReadPeakCluster()) {
            LCMS1.PeakClusterDetection();
        }

        LCMS1.AssignQuant(false);
        LCMS1.IDsummary.ExportPepID(outputfolder);

        time = System.currentTimeMillis() - time;
        //logger.info(LCMS1.ParentmzXMLName + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))));
        Logger.getRootLogger()
                .info(LCMS1.ParentmzXMLName + " processed time:"
                        + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time),
                                TimeUnit.MILLISECONDS.toMinutes(time)
                                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
                                TimeUnit.MILLISECONDS.toSeconds(time)
                                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))));
        LCMS1.BaseClearAllPeaks();
        LCMS1.SetSpectrumParser(null);
        LCMS1.IDsummary = null;
        LCMS1 = null;
        id.ReleaseIDs();
        id = null;
        System.gc();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

From source file:com.pinterest.pinlater.backends.common.BackendQueueMonitorBase.java

public BackendQueueMonitorBase(ImmutableMap<String, T> shardMap, PropertiesConfiguration configuration) {
    this(shardMap, configuration.getInt("BACKEND_MONITOR_UPDATE_MAX_SIZE"),
            configuration.getInt("BACKEND_NUM_AUTO_RETRIES"), configuration.getInt("MONITOR_LOG_INTERVAL", 1),
            TimeUnit.SECONDS.toMillis(configuration.getInt("BACKEND_MONITOR_JOB_CLAIMED_TIMEOUT_SECONDS")),
            TimeUnit.HOURS.toMillis(configuration.getInt("BACKEND_MONITOR_JOB_SUCCEEDED_GC_TTL_HOURS")),
            TimeUnit.HOURS.toMillis(configuration.getInt("BACKEND_MONITOR_JOB_FAILED_GC_TTL_HOURS")),
            configuration.getInt("NUM_PRIORITY_LEVELS"));
}

From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java

@Test
public void testNonNumericalPeriod() throws Exception {
    assertPeriodQuery("hugo", 1, TimeUnit.DAYS);
    assertPeriodQuery("hugod", 1, TimeUnit.DAYS);
    assertPeriodQuery("hugoD", 1, TimeUnit.DAYS);
    assertPeriodQuery("hugom", 1, TimeUnit.MINUTES);
    assertPeriodQuery("hugoM", 1, TimeUnit.MINUTES);
    assertPeriodQuery("hugoh", 1, TimeUnit.HOURS);
    assertPeriodQuery("hugoH", 1, TimeUnit.HOURS);
}

From source file:org.apache.metron.profiler.client.window.WindowProcessorTest.java

@Test
public void testDenseWindow() {
    for (String text : new String[] { "from 2 hours ago to 30 minutes ago",
            "starting from 2 hours until 30 minutes", "starting from 2 hours ago until 30 minutes ago",
            "starting from 30 minutes ago until 2 hours ago", "from 30 minutes ago to 2 hours ago " }) {
        Window w = WindowProcessor.process(text);
        /*//from w w  w . j  a va 2s .  c  o  m
        A dense window starting 2 hour ago and continuing until 30 minutes ago
         */
        Date now = new Date();
        List<Range<Long>> intervals = w.toIntervals(now.getTime());
        Assert.assertEquals(1, intervals.size());
        assertEquals(now.getTime() - TimeUnit.HOURS.toMillis(2), intervals.get(0).getMinimum());
        assertEquals(now.getTime() - TimeUnit.MINUTES.toMillis(30), intervals.get(0).getMaximum());
    }
}

From source file:org.apache.carbondata.sdk.file.ConcurrentAvroSdkWriterTest.java

@Test
public void testWriteFiles() throws IOException {
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    String mySchema = "{" + "  \"name\": \"address\", " + "   \"type\": \"record\", " + "    \"fields\": [  "
            + "  { \"name\": \"name\", \"type\": \"string\"}, " + "  { \"name\": \"age\", \"type\": \"int\"}, "
            + "  { " + "    \"name\": \"address\", " + "      \"type\": { " + "    \"type\" : \"record\", "
            + "        \"name\" : \"my_address\", " + "        \"fields\" : [ "
            + "    {\"name\": \"street\", \"type\": \"string\"}, "
            + "    {\"name\": \"city\", \"type\": \"string\"} " + "  ]} " + "  } " + "] " + "}";

    String json = "{\"name\":\"bob\", \"age\":10, \"address\" : {\"street\":\"abc\", \"city\":\"bang\"}}";

    // conversion to GenericData.Record
    org.apache.avro.Schema avroSchema = new org.apache.avro.Schema.Parser().parse(mySchema);
    GenericData.Record record = TestUtil.jsonToAvro(json, mySchema);

    ExecutorService executorService = Executors.newFixedThreadPool(numOfThreads);
    try {/*from w w w.  ja va  2  s .co  m*/
        CarbonWriterBuilder builder = CarbonWriter.builder().outputPath(path).withThreadSafe(numOfThreads);
        CarbonWriter writer = builder.withAvroInput(avroSchema).writtenBy("ConcurrentAvroSdkWriterTest")
                .build();
        // write in multi-thread
        for (int i = 0; i < numOfThreads; i++) {
            executorService.submit(new WriteLogic(writer, record));
        }
        executorService.shutdown();
        executorService.awaitTermination(2, TimeUnit.HOURS);
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    // read the files and verify the count
    CarbonReader reader;
    try {
        reader = CarbonReader.builder(path, "_temp2122").projection(new String[] { "name", "age" }).build();
        int i = 0;
        while (reader.hasNext()) {
            Object[] row = (Object[]) reader.readNextRow();
            i++;
        }
        Assert.assertEquals(i, numOfThreads * recordsPerItr);
        reader.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    FileUtils.deleteDirectory(new File(path));
}

From source file:ch.cyberduck.core.s3.S3UrlProvider.java

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.isFile()) {
        if (!session.getHost().isDefaultWebURL()) {
            list.addAll(new WebUrlProvider(session.getHost()).toUrl(file));
        }//from   w w w .j  a va2 s.c  om
        // Publicly accessible URL of given object
        list.add(this.toUrl(file, session.getHost().getProtocol().getScheme()));
        list.add(this.toUrl(file, Scheme.http));
        if (!session.getHost().getCredentials().isAnonymousLogin()) {
            // X-Amz-Expires must be less than a week (in seconds); that is, the given X-Amz-Expires must be less
            // than 604800 seconds
            // In one hour
            list.add(this.sign(file, (int) TimeUnit.HOURS.toSeconds(1)));
            // Default signed URL expiring in 24 hours.
            list.add(this.sign(file, (int) TimeUnit.SECONDS
                    .toSeconds(PreferencesFactory.get().getInteger("s3.url.expire.seconds"))));
            // 1 Week
            list.add(this.sign(file, (int) TimeUnit.DAYS.toSeconds(7)));
            switch (session.getSignatureVersion()) {
            case AWS2:
                // 1 Month
                list.add(this.sign(file, (int) TimeUnit.DAYS.toSeconds(30)));
                // 1 Year
                list.add(this.sign(file, (int) TimeUnit.DAYS.toSeconds(365)));
                break;
            case AWS4HMACSHA256:
                break;
            }
        }
        // Torrent
        list.add(new DescriptiveUrl(
                URI.create(new S3TorrentUrlProvider(session.getHost())
                        .create(containerService.getContainer(file).getName(), containerService.getKey(file))),
                DescriptiveUrl.Type.torrent, MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                        LocaleFactory.localizedString("Torrent"))));
    }
    list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file));
    if (!file.isRoot()) {
        list.add(
                new DescriptiveUrl(
                        URI.create(String.format("s3://%s%s", containerService.getContainer(file).getName(),
                                containerService.isContainer(file) ? "/"
                                        : String.format("/%s",
                                                URIEncoder.encode(containerService.getKey(file))))),
                        DescriptiveUrl.Type.provider,
                        MessageFormat.format(LocaleFactory.localizedString("{0} URL"), "S3")));
    }
    return list;
}

From source file:com.ryantenney.metrics.spring.reporter.AbstractScheduledReporterFactoryBean.java

/**
 * Parses and converts to nanoseconds a string representing
 * a duration, ie: 500ms, 30s, 5m, 1h, etc
 * @param duration a string representing a duration
 * @return the duration in nanoseconds/*  www  . j  a  va2  s.  com*/
 */
protected long convertDurationString(String duration) {
    final Matcher m = DURATION_STRING_PATTERN.matcher(duration);
    if (!m.matches()) {
        throw new IllegalArgumentException("Invalid duration string format");
    }

    final long sourceDuration = Long.parseLong(m.group(1));
    final String sourceUnitString = m.group(2);
    final TimeUnit sourceUnit;
    if ("ns".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.NANOSECONDS;
    } else if ("us".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MICROSECONDS;
    } else if ("ms".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MILLISECONDS;
    } else if ("s".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.SECONDS;
    } else if ("m".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.MINUTES;
    } else if ("h".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.HOURS;
    } else if ("d".equalsIgnoreCase(sourceUnitString)) {
        sourceUnit = TimeUnit.DAYS;
    } else {
        sourceUnit = TimeUnit.MILLISECONDS;
    }

    return sourceUnit.toNanos(sourceDuration);
}