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:org.pentaho.di.trans.Trans.java

/**
 * Waits until all RunThreads have finished.
 *///w w w .jav a 2  s.c o  m
public void waitUntilFinished() {
    try {
        boolean wait = true;
        while (wait) {
            wait = transFinishedBlockingQueue.poll(1, TimeUnit.DAYS) == null;
        }
    } catch (InterruptedException e) {
        throw new RuntimeException("Waiting for transformation to be finished interrupted!", e);
    }
}

From source file:net.bashtech.geobot.Channel.java

public static String getDurationBreakdown(long millis) {
    if (millis < 0) {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }//from  www  . ja  v a2s  . co  m

    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);

    StringBuilder sb = new StringBuilder(64);
    if (days > 0) {
        sb.append(days);
        sb.append(" days, ");
    }

    if (hours < 10)
        sb.append(0);
    sb.append(hours);

    sb.append(" hours, ");
    if (minutes < 10)
        sb.append(0);
    sb.append(minutes);
    sb.append(" minutes, and ");
    if (seconds < 10)
        sb.append(0);
    sb.append(seconds);
    sb.append(" seconds.");

    return (sb.toString());
}

From source file:tv.phantombot.PhantomBot.java

public void doRefreshGameWispToken() {

    long curTime = System.currentTimeMillis() / 1000L;

    if (!dataStore.exists("settings", "gameWispRefreshTime")) {
        dataStore.set("settings", "gameWispRefreshTime", String.valueOf(curTime));
    }//  w ww.ja  v a2s. c o  m

    ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
    service.scheduleAtFixedRate(() -> {
        Thread.currentThread().setName("tv.phantombot.PhantomBot::doRefreshGameWispToken");

        long curTime1 = System.currentTimeMillis() / 1000L;
        String lastRunStr = dataStore.GetString("settings", "", "gameWispRefreshTime");
        long lastRun = Long.parseLong(lastRunStr);
        if ((curTime1 - lastRun) > (10 * 24 * 60 * 60)) {
            // 10 days, token expires every 35.
            dataStore.set("settings", "gameWispRefreshTime", String.valueOf(curTime1));
            updateGameWispTokens(GameWispAPIv1.instance().refreshToken());
        }
    }, 0, 1, TimeUnit.DAYS);
}

From source file:me.gloriouseggroll.quorrabot.Quorrabot.java

public void doRefreshGameWispToken() {

    long curTime = System.currentTimeMillis() / 1000l;

    if (!dataStoreObj.exists("settings", "gameWispRefreshTime")) {
        dataStoreObj.set("settings", "gameWispRefreshTime", String.valueOf(curTime));
    }//from  w w  w  .  j a v  a2  s . co  m

    ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
    service.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            long curTime = System.currentTimeMillis() / 1000l;
            String lastRunStr = dataStoreObj.GetString("settings", "", "gameWispRefreshTime");

            long lastRun = Long.parseLong(lastRunStr);
            if ((curTime - lastRun) > (10 * 24 * 60 * 60)) { // 10 days, token expires every 35.
                dataStoreObj.set("settings", "gameWispRefreshTime", String.valueOf(curTime));
                updateGameWispTokens(GameWispAPI.instance().refreshToken());
            }
        }
    }, 0, 1, TimeUnit.DAYS);
}

From source file:org.kitodo.production.services.data.ProcessService.java

/**
 * Calculate and return duration/age of given process as a String.
 *
 * @param process ProcessDTO object for which duration/age is calculated
 * @return process age of given process//  w w  w  . ja  v  a  2  s . c om
 */
public static String getProcessDuration(ProcessDTO process) {
    String creationDateTimeString = process.getCreationDate();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter);
    Duration duration = Duration.between(createLocalDate, LocalDateTime.now());
    return String.format("%sd; %sh", duration.toDays(),
            duration.toHours() - TimeUnit.DAYS.toHours(duration.toDays()));
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

public void doRefreshGameWispToken() {

    long curTime = System.currentTimeMillis() / 1000L;

    if (!dataStore.exists("settings", "gameWispRefreshTime")) {
        dataStore.set("settings", "gameWispRefreshTime", String.valueOf(curTime));
    }//from   w  w  w. j a  v a  2 s .c  o m

    ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
    service.scheduleAtFixedRate(() -> {
        long curTime1 = System.currentTimeMillis() / 1000L;
        String lastRunStr = dataStore.GetString("settings", "", "gameWispRefreshTime");
        long lastRun = Long.parseLong(lastRunStr);
        if ((curTime1 - lastRun) > (10 * 24 * 60 * 60)) {
            // 10 days, token expires every 35.
            dataStore.set("settings", "gameWispRefreshTime", String.valueOf(curTime1));
            updateGameWispTokens(GameWispAPIv1.instance().refreshToken());
        }
    }, 0, 1, TimeUnit.DAYS);
}

From source file:org.wso2.carbon.appmgt.impl.utils.AppManagerUtil.java

public static Cache getAPIContextCache() {
    CacheManager contextCacheManager = Caching.getCacheManager(AppMConstants.API_CONTEXT_CACHE_MANAGER)
            .getCache(AppMConstants.API_CONTEXT_CACHE).getCacheManager();
    if (!isContextCacheInitialized) {
        isContextCacheInitialized = true;
        return contextCacheManager.<String, Boolean>createCacheBuilder(AppMConstants.API_CONTEXT_CACHE_MANAGER)
                .setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
                        new CacheConfiguration.Duration(TimeUnit.DAYS,
                                AppMConstants.API_CONTEXT_CACHE_EXPIRY_TIME_IN_DAYS))
                .setStoreByValue(false).build();
    } else {//  ww w . j a  v  a 2s  .c om
        return Caching.getCacheManager(AppMConstants.API_CONTEXT_CACHE_MANAGER)
                .getCache(AppMConstants.API_CONTEXT_CACHE);
    }
}

From source file:org.wso2.carbon.apimgt.impl.utils.APIUtil.java

public static Cache getAPIContextCache() {
    CacheManager contextCacheManager = Caching.getCacheManager(APIConstants.API_CONTEXT_CACHE_MANAGER)
            .getCache(APIConstants.API_CONTEXT_CACHE).getCacheManager();
    if (!isContextCacheInitialized) {
        isContextCacheInitialized = true;
        return contextCacheManager.<String, Boolean>createCacheBuilder(APIConstants.API_CONTEXT_CACHE_MANAGER)
                .setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
                        new CacheConfiguration.Duration(TimeUnit.DAYS,
                                APIConstants.API_CONTEXT_CACHE_EXPIRY_TIME_IN_DAYS))
                .setStoreByValue(false).build();
    } else {/* w  w  w .j  a  va2 s .c  o m*/
        return Caching.getCacheManager(APIConstants.API_CONTEXT_CACHE_MANAGER)
                .getCache(APIConstants.API_CONTEXT_CACHE);
    }
}

From source file:com.vmware.identity.idm.server.provider.vmwdirectory.VMwareDirectoryProvider.java

private long getPwdLifeTime() {
    long pwdLifeTime;
    PasswordPolicy pwdPolicy = null;//from  ww w.j a v  a 2  s. co m
    try {
        pwdPolicy = getPasswordPolicy();
    } catch (Exception e) {
        logger.info(
                String.format("Failed to retrieve password policy for system provider - %s", this.getDomain()));
    }

    pwdLifeTime = (pwdPolicy == null) ? PersonDetail.UNSPECIFIED_PASSWORD_LIFE_TIME_VALUE
            : (pwdPolicy.getPasswordLifetimeDays() * TimeUnit.DAYS.toSeconds(1L));
    return pwdLifeTime;
}

From source file:org.apache.hadoop.hive.conf.HiveConf.java

public static TimeUnit unitFor(String unit, TimeUnit defaultUnit) {
    unit = unit.trim().toLowerCase();//from  w w  w.ja  va2  s . c  o  m
    if (unit.isEmpty() || unit.equals("l")) {
        if (defaultUnit == null) {
            throw new IllegalArgumentException("Time unit is not specified");
        }
        return defaultUnit;
    } else if (unit.equals("d") || unit.startsWith("day")) {
        return TimeUnit.DAYS;
    } else if (unit.equals("h") || unit.startsWith("hour")) {
        return TimeUnit.HOURS;
    } else if (unit.equals("m") || unit.startsWith("min")) {
        return TimeUnit.MINUTES;
    } else if (unit.equals("s") || unit.startsWith("sec")) {
        return TimeUnit.SECONDS;
    } else if (unit.equals("ms") || unit.startsWith("msec")) {
        return TimeUnit.MILLISECONDS;
    } else if (unit.equals("us") || unit.startsWith("usec")) {
        return TimeUnit.MICROSECONDS;
    } else if (unit.equals("ns") || unit.startsWith("nsec")) {
        return TimeUnit.NANOSECONDS;
    }
    throw new IllegalArgumentException("Invalid time unit " + unit);
}