Example usage for java.util.concurrent TimeUnit DAYS

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

Introduction

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

Prototype

TimeUnit DAYS

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

Click Source Link

Document

Time unit representing twenty four hours.

Usage

From source file:io.chucknorris.app.facebook.messenger.cache.CategoriesCache.java

public CategoriesCache(final ChuckNorrisClient chuckNorrisClient) {
    this(chuckNorrisClient, TimeUnit.DAYS.toMillis(1));
}

From source file:opensnap.config.ContainerConfig.java

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {

    if (container instanceof TomcatEmbeddedServletContainerFactory) {
        TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
        factory.setSessionTimeout(1, TimeUnit.DAYS);
        factory.addContextCustomizers((context) -> {
            context.addMimeMapping("dart", "application/dart");
        });/* ww w .ja  va  2  s  .c o  m*/
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
            connector.setProperty("compression", "on");
            connector.setProperty("compressionMinSize", "2048");
            connector.setProperty("compressableMimeType",
                    "text/html,text/css,application/javascript,application/dart");
        });
    }
}

From source file:com.enitalk.configs.BotConfig.java

@Bean
@Primary//from w w w . jav  a2s.c o  m
public LoadingCache<String, String> tokenCache() {
    LoadingCache<String, String> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS)
            .build(new CacheLoader<String, String>() {

                @Override
                public String load(String key) throws Exception {
                    String id = jackson.createObjectNode().put("login", env.getProperty("bot.login"))
                            .put("password", env.getProperty("bot.pass")).toString();
                    byte[] auth = Request.Post(env.getProperty("bot.auth"))
                            .bodyString(id, ContentType.APPLICATION_JSON).execute().returnContent().asBytes();
                    JsonNode tree = jackson.readTree(auth);
                    logger.info("Bot token came {}", tree);
                    String authToken = tree.path("token").asText();
                    return authToken;
                }

            });
    return cache;
}

From source file:net.easymfne.factionsdb.Util.java

/**
 * Convert a time in milliseconds to a user-friendly String format.
 * /*from  ww w  .  j a  v  a  2 s .  c  om*/
 * @param time
 *            Number of milliseconds
 * @return User-friendly String
 */
public static String generateTimeString(long time) {
    List<String> timeStrings = new ArrayList<String>();
    long d = TimeUnit.MILLISECONDS.toDays(time);
    time -= TimeUnit.DAYS.toMillis(d);
    long h = TimeUnit.MILLISECONDS.toHours(time);
    time -= TimeUnit.HOURS.toMillis(h);
    long m = TimeUnit.MILLISECONDS.toMinutes(time);
    time -= TimeUnit.MINUTES.toMillis(m);
    long s = TimeUnit.MILLISECONDS.toSeconds(time);

    if (d > 0) {
        timeStrings.add(d + (d == 1 ? " day" : " days"));
    }
    if (h > 0) {
        timeStrings.add(h + (h == 1 ? " hour" : " hours"));
    }
    if (m > 0) {
        timeStrings.add(m + (m == 1 ? " minute" : " minutes"));
    }
    if (s > 0 || timeStrings.size() < 1) {
        timeStrings.add(s + (s == 1 ? " second" : " seconds"));
    }

    return StringUtils.join(timeStrings, ", ");
}

From source file:org.jdal.text.PeriodFormatter.java

/**
 * {@inheritDoc}//from w  ww .  j a va2s.c o m
 */
public String print(Number number, Locale locale) {
    long period = number.longValue();
    long days = TimeUnit.MILLISECONDS.toDays(period);
    long left = period - TimeUnit.DAYS.toMillis(days);
    long hours = TimeUnit.MILLISECONDS.toHours(left);
    left -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(left);
    left -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(left);

    StringBuilder sb = new StringBuilder();

    if (days != 0)
        append(sb, days, DAYS);

    if (hours != 0)
        append(sb, hours, HOURS);

    if (minutes != 0)
        append(sb, minutes, MINUTES);

    if (seconds != 0)
        append(sb, seconds, SECONDS);

    return sb.toString();
}

From source file:edu.msu.cme.rdp.kmer.KmerFilter.java

public static void main(String[] args) throws Exception {
    final KmerTrie kmerTrie;
    final SeqReader queryReader;
    final SequenceType querySeqType;
    final File queryFile;
    final KmerStartsWriter out;
    final boolean translQuery;
    final int wordSize;
    final int translTable;
    final boolean alignedSeqs;
    final List<String> refLabels = new ArrayList();
    final int maxThreads;

    try {//from www  .  j  a  v a 2s .  c o  m
        CommandLine cmdLine = new PosixParser().parse(options, args);
        args = cmdLine.getArgs();

        if (args.length < 3) {
            throw new Exception("Unexpected number of arguments");
        }

        if (cmdLine.hasOption("out")) {
            out = new KmerStartsWriter(cmdLine.getOptionValue("out"));
        } else {
            out = new KmerStartsWriter(System.out);
        }

        if (cmdLine.hasOption("aligned")) {
            alignedSeqs = true;
        } else {
            alignedSeqs = false;
        }

        if (cmdLine.hasOption("transl-table")) {
            translTable = Integer.valueOf(cmdLine.getOptionValue("transl-table"));
        } else {
            translTable = 11;
        }

        if (cmdLine.hasOption("threads")) {
            maxThreads = Integer.valueOf(cmdLine.getOptionValue("threads"));
        } else {
            maxThreads = Runtime.getRuntime().availableProcessors();
        }

        queryFile = new File(args[1]);
        wordSize = Integer.valueOf(args[0]);
        SequenceType refSeqType = null;

        querySeqType = SeqUtils.guessSequenceType(queryFile);
        queryReader = new SequenceReader(queryFile);

        if (querySeqType == SequenceType.Protein) {
            throw new Exception("Expected nucl query sequences");
        }

        refSeqType = SeqUtils
                .guessSequenceType(new File(args[2].contains("=") ? args[2].split("=")[1] : args[2]));

        translQuery = refSeqType == SequenceType.Protein;

        if (translQuery && wordSize % 3 != 0) {
            throw new Exception("Word size must be a multiple of 3 for nucl ref seqs");
        }

        int trieWordSize;
        if (translQuery) {
            trieWordSize = wordSize / 3;
        } else {
            trieWordSize = wordSize;
        }
        kmerTrie = new KmerTrie(trieWordSize, translQuery);

        for (int index = 2; index < args.length; index++) {
            String refName;
            String refFileName = args[index];
            if (refFileName.contains("=")) {
                String[] lexemes = refFileName.split("=");
                refName = lexemes[0];
                refFileName = lexemes[1];
            } else {
                String tmpName = new File(refFileName).getName();
                if (tmpName.contains(".")) {
                    refName = tmpName.substring(0, tmpName.lastIndexOf("."));
                } else {
                    refName = tmpName;
                }
            }

            File refFile = new File(refFileName);

            if (refSeqType != SeqUtils.guessSequenceType(refFile)) {
                throw new Exception(
                        "Reference file " + refFile + " contains " + SeqUtils.guessFileFormat(refFile)
                                + " sequences but expected " + refSeqType + " sequences");
            }

            SequenceReader seqReader = new SequenceReader(refFile);
            Sequence seq;

            while ((seq = seqReader.readNextSequence()) != null) {
                if (seq.getSeqName().startsWith("#")) {
                    continue;
                }
                if (alignedSeqs) {
                    kmerTrie.addModelSequence(seq, refLabels.size());
                } else {
                    kmerTrie.addSequence(seq, refLabels.size());
                }
            }
            seqReader.close();

            refLabels.add(refName);
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("KmerSearch <word_size> <query_file> [name=]<ref_file> ...", options);
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(1);
        throw new RuntimeException("Stupid jvm"); //While this will never get thrown it is required to make sure javac doesn't get confused about uninitialized variables
    }

    long startTime = System.currentTimeMillis();
    long seqCount = 0;
    final int maxTasks = 25000;

    /*
     * if (args.length == 4) { maxThreads = Integer.valueOf(args[3]); } else {
     */

    //}

    System.err.println("Starting kmer mapping at " + new Date());
    System.err.println("*  Number of threads:       " + maxThreads);
    System.err.println("*  References:              " + refLabels);
    System.err.println("*  Reads file:              " + queryFile);
    System.err.println("*  Kmer length:             " + kmerTrie.getWordSize());

    final AtomicInteger processed = new AtomicInteger();
    final AtomicInteger outstandingTasks = new AtomicInteger();

    ExecutorService service = Executors.newFixedThreadPool(maxThreads);

    Sequence querySeq;

    while ((querySeq = queryReader.readNextSequence()) != null) {
        seqCount++;

        String seqString = querySeq.getSeqString();

        if (seqString.length() < 3) {
            System.err.println("Sequence " + querySeq.getSeqName() + "'s length is less than 3");
            continue;
        }

        final Sequence threadSeq = querySeq;

        Runnable r = new Runnable() {

            public void run() {
                try {
                    processSeq(threadSeq, refLabels, kmerTrie, out, wordSize, translQuery, translTable, false);
                    processSeq(threadSeq, refLabels, kmerTrie, out, wordSize, translQuery, translTable, true);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                processed.incrementAndGet();
                outstandingTasks.decrementAndGet();
            }
        };

        outstandingTasks.incrementAndGet();
        service.submit(r);

        while (outstandingTasks.get() >= maxTasks)
            ;

        if ((processed.get() + 1) % 1000000 == 0) {
            System.err.println("Processed " + processed + " sequences in "
                    + (System.currentTimeMillis() - startTime) + " ms");
        }
    }

    service.shutdown();
    service.awaitTermination(1, TimeUnit.DAYS);

    System.err.println("Finished Processed " + processed + " sequences in "
            + (System.currentTimeMillis() - startTime) + " ms");

    out.close();
}

From source file:com.tyndalehouse.step.tools.modules.ConvertXmlToOSISModule.java

private void convert() throws Exception {
    final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(1024);
    final ExecutorService executorService = new ThreadPoolExecutor(3, 3, 1, TimeUnit.DAYS, queue);

    final File[] files = SOURCE_DIRECTORY.listFiles();
    for (final File f : files) {
        if (f.isDirectory()) {
            final File[] unzippedFiles = f.listFiles();
            for (final File unzipped : unzippedFiles) {
                if (unzipped.getName().endsWith(".xml")) {
                    executorService.submit(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                convertToXml(f.getName(), unzipped);
                                LOGGER.debug("Finished [{}], [{}] remaining", f.getName(), queue.size());
                            } catch (Exception e) {
                                LOGGER.error("Failed to convert [{}]", f.getName(), e);
                            }//  ww w  . ja v  a2s .c  o  m
                        }
                    });
                    break;
                }
            }
            //                break;
        }
    }
    executorService.shutdown();
}

From source file:org.wso2.carbon.identity.account.suspension.notification.task.NotificationReceiversRetrievalManager.java

public static List<NotificationReceiver> getReceivers(long delay, String tenantDomain, long delayForSuspension)
        throws AccountSuspensionNotificationException {

    Set<String> userStoreDomains = NotificationReceiversRetrievalUtil
            .getSuspensionNotificationEnabledUserStores(tenantDomain);

    List<NotificationReceiver> receivers = new ArrayList<>();

    for (String userStoreDomain : userStoreDomains) {
        NotificationReceiversRetrieval notificationReceiversRetrieval = NotificationReceiversRetrievalUtil
                .getNotificationReceiversRetrievalForDomain(userStoreDomain, tenantDomain);
        if (notificationReceiversRetrieval != null) {
            long lookupMin = 0;
            try {
                lookupMin = getCurrentExecutionTime(
                        NotificationTaskDataHolder.getInstance().getNotificationTriggerTime()).getTimeInMillis()
                        - TimeUnit.DAYS.toMillis(delay + 1);
            } catch (ParseException e) {
                throw new AccountSuspensionNotificationException(
                        "Error occurred while reading notification " + "trigger time", e);
            }//from  w  w  w .j a v a  2s.c om
            long lookupMax = lookupMin + TimeUnit.DAYS.toMillis(1);
            List<NotificationReceiver> newReceivers = notificationReceiversRetrieval
                    .getNotificationReceivers(lookupMin, lookupMax, delayForSuspension, tenantDomain);
            receivers.addAll(newReceivers);
        }
    }

    return receivers;
}

From source file:org.blocks4j.reconf.client.validation.ConnectionSettingsValidator.java

private static void checkTimeUnit(ConnectionSettings arg, Collection<String> errors) {
    if (arg.getTimeUnit() == null) {
        errors.add(msg.get("timeUnit.null"));
        return;//from  www .j a va2  s. c  o m
    }
    if (!EnumSet.of(TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS)
            .contains(arg.getTimeUnit())) {
        errors.add(msg.get("timeUnit.null"));
    }
}

From source file:se.uu.it.cs.recsys.semantic.config.ComputingDomainReasonerSpringConfig.java

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();

    GuavaCache fpTreeCache = new GuavaCache("ComputingDomainCache",
            CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS).maximumSize(100).build());

    cacheManager.setCaches(Stream.of(fpTreeCache).collect(Collectors.toList()));

    return cacheManager;
}