Java Code Examples for java.util.concurrent.TimeUnit.HOURS

The following are Jave code examples for showing how to use HOURS of the java.util.concurrent.TimeUnit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cas-5.1.0   File: DateTimeUtils.java   View Source Code Vote up 6 votes
/**
 * To time unit time unit.
 *
 * @param tu the tu
 * @return the time unit
 */
public static TimeUnit toTimeUnit(final ChronoUnit tu) {
    if (tu == null) {
        return null;
    }
    switch (tu) {
        case DAYS:
            return TimeUnit.DAYS;
        case HOURS:
            return TimeUnit.HOURS;
        case MINUTES:
            return TimeUnit.MINUTES;
        case SECONDS:
            return TimeUnit.SECONDS;
        case MICROS:
            return TimeUnit.MICROSECONDS;
        case MILLIS:
            return TimeUnit.MILLISECONDS;
        case NANOS:
            return TimeUnit.NANOSECONDS;
        default:
            throw new UnsupportedOperationException("Temporal unit is not supported");
    }
}
 
Example 2
Project: hadoop   File: ApplicationMasterLauncher.java   View Source Code Vote up 6 votes
@Override
protected void serviceInit(Configuration conf) throws Exception {
  int threadCount = conf.getInt(
      YarnConfiguration.RM_AMLAUNCHER_THREAD_COUNT,
      YarnConfiguration.DEFAULT_RM_AMLAUNCHER_THREAD_COUNT);
  ThreadFactory tf = new ThreadFactoryBuilder()
      .setNameFormat("ApplicationMasterLauncher #%d")
      .build();
  launcherPool = new ThreadPoolExecutor(threadCount, threadCount, 1,
      TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>());
  launcherPool.setThreadFactory(tf);

  Configuration newConf = new YarnConfiguration(conf);
  newConf.setInt(CommonConfigurationKeysPublic.
          IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY,
      conf.getInt(YarnConfiguration.RM_NODEMANAGER_CONNECT_RETIRES,
          YarnConfiguration.DEFAULT_RM_NODEMANAGER_CONNECT_RETIRES));
  setConfig(newConf);
  super.serviceInit(newConf);
}
 
Example 3
Project: ditb   File: ProtobufUtil.java   View Source Code Vote up 6 votes
/**
 * Convert a protocol buffer TimeUnit to a client TimeUnit
 * @param proto
 * @return the converted client TimeUnit
 */
public static TimeUnit toTimeUnit(final HBaseProtos.TimeUnit proto) {
  switch (proto) {
  case NANOSECONDS:
    return TimeUnit.NANOSECONDS;
  case MICROSECONDS:
    return TimeUnit.MICROSECONDS;
  case MILLISECONDS:
    return TimeUnit.MILLISECONDS;
  case SECONDS:
    return TimeUnit.SECONDS;
  case MINUTES:
    return TimeUnit.MINUTES;
  case HOURS:
    return TimeUnit.HOURS;
  case DAYS:
    return TimeUnit.DAYS;
  default:
    throw new RuntimeException("Invalid TimeUnit " + proto);
  }
}
 
Example 4
Project: shop-manager   File: RedisDao.java   View Source Code Vote up 5 votes
public void add(String key, Object value, long data, int timeType){//data为在redis存储有效时间
	Object type = null;
	switch (timeType) {
	case 0:
		type = TimeUnit.MINUTES;
		break;
	case 1:
		type = TimeUnit.HOURS;
		break;
	case 2:
		type = TimeUnit.DAYS;
	}
	redisTemplate.opsForValue().set(key, value, data, (TimeUnit)type);
}
 
Example 5
Project: BEAST   File: TimeoutValueHandler.java   View Source Code Vote up 5 votes
/**
 * Getter for the timeout
 * @return TimeOut
 */
public TimeOut getTimeout() {
    TimeOut timeOut = new TimeOut();
    Integer timeoutInt;
    if (timeoutSpinner.getValue() == "∞") {
        timeoutInt = 0;
    } else {
        timeoutInt = Integer.parseInt(timeoutSpinner.getValue().toString());
    }
    switch (timeoutUnit.getSelectedIndex()) {
        case 0:
            timeOut = new TimeOut(TimeUnit.SECONDS, timeoutInt.longValue());
            break;
        case 1:
            timeOut = new TimeOut(TimeUnit.MINUTES, timeoutInt.longValue());
            break;
        case 2:
            timeOut = new TimeOut(TimeUnit.HOURS, timeoutInt.longValue());
            break;
        case 3:
            timeOut = new TimeOut(TimeUnit.DAYS, timeoutInt.longValue());
            break;
        default:
            break;
    }
    return timeOut;
}
 
Example 6
Project: BEAST   File: ProjectSaverLoaderTest.java   View Source Code Vote up 5 votes
@BeforeClass
public static void setUpClass() {
    projectSaverLoader = new ProjectSaverLoader();
    ElectionTemplateHandler electionTemplateHandler = new ElectionTemplateHandler();
    ElectionTypeContainer inputType = electionTemplateHandler.getById(ElectionTypeContainer.ElectionInputTypeIds.WEIGHTED_APPROVAL);
    ElectionTypeContainer outputType = electionTemplateHandler.getStandardResult();

    ElectionDescription electionDescription = new ElectionDescription("testDescription", inputType, outputType, 2);
    ArrayList<String> code = new ArrayList<String>();
    code.add("sdfgokdffg");
    code.add("sdkofgdfg");
    electionDescription.setCode(code);

    FormalPropertiesDescription pre = new FormalPropertiesDescription("CODECODEOCDEOASD ASDAOSDASOD ;;; ;ASODAOSD");
    FormalPropertiesDescription post = new FormalPropertiesDescription("CODECODEOCDEOASD ASDAOSDASOD ;;; ;ASODAOSD");
    SymbolicVariableList list = new SymbolicVariableList();
    list.addSymbolicVariable("voter1", new InternalTypeContainer(InternalTypeRep.VOTER));
    list.addSymbolicVariable("voter2", new InternalTypeContainer(InternalTypeRep.VOTER));
    list.addSymbolicVariable("candidate", new InternalTypeContainer(InternalTypeRep.CANDIDATE));
    list.addSymbolicVariable("seat", new InternalTypeContainer(InternalTypeRep.SEAT));
    PreAndPostConditionsDescription description1 = new PreAndPostConditionsDescription("description1",
            pre, post, list);
    PreAndPostConditionsDescription description2 = new PreAndPostConditionsDescription("description2",
            pre, post, list);

    PLModel plModel = new PLModel();
    plModel.initialize();
    PropertyItem propertyItem = new PropertyItem(description1, true, true);
    PropertyItem propertyItem2 = new PropertyItem(description2, false, false);
    plModel.addDescription(propertyItem);
    plModel.addDescription(propertyItem2);
    ElectionCheckParameter electionCheckParameter = new ElectionCheckParameter(Arrays.asList(new Integer[]{1, 2}),
            Arrays.asList(new Integer[]{1, 2}), Arrays.asList(new Integer[]{1, 2}), new TimeOut(TimeUnit.HOURS,
            (long) 3.2),4, "-- unwind 6");
    project = new Project(electionCheckParameter, plModel, electionDescription, "TestProject");
}
 
Example 7
Project: neoscada   File: Helper.java   View Source Code Vote up 5 votes
public static long niceTimeRounded ( final long value )
{
    final TimeUnit tu;

    if ( value >= TimeUnit.DAYS.toMillis ( 1 ) )
    {
        tu = TimeUnit.DAYS;
    }
    else if ( value >= TimeUnit.HOURS.toMillis ( 1 ) )
    {
        tu = TimeUnit.HOURS;
    }
    else if ( value >= TimeUnit.MINUTES.toMillis ( 1 ) )
    {
        tu = TimeUnit.MINUTES;
    }
    else if ( value >= TimeUnit.SECONDS.toMillis ( 1 ) )
    {
        tu = TimeUnit.SECONDS;
    }
    else
    {
        tu = TimeUnit.MILLISECONDS;
    }

    double v = (double)value / (double)tu.toMillis ( 1 );
    v = niceNum ( v, true );
    return (long) ( v * tu.toMillis ( 1 ) );
}
 
Example 8
Project: googles-monorepo-demo   File: CacheBuilderSpec.java   View Source Code Vote up 5 votes
@Override
public void parse(CacheBuilderSpec spec, String key, String value) {
  checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
  try {
    char lastChar = value.charAt(value.length() - 1);
    TimeUnit timeUnit;
    switch (lastChar) {
      case 'd':
        timeUnit = TimeUnit.DAYS;
        break;
      case 'h':
        timeUnit = TimeUnit.HOURS;
        break;
      case 'm':
        timeUnit = TimeUnit.MINUTES;
        break;
      case 's':
        timeUnit = TimeUnit.SECONDS;
        break;
      default:
        throw new IllegalArgumentException(
            format(
                "key %s invalid format.  was %s, must end with one of [dDhHmMsS]", key, value));
    }

    long duration = Long.parseLong(value.substring(0, value.length() - 1));
    parseDuration(spec, duration, timeUnit);
  } catch (NumberFormatException e) {
    throw new IllegalArgumentException(
        format("key %s value set to %s, must be integer", key, value));
  }
}
 
Example 9
Project: guava-mock   File: CacheBuilderSpec.java   View Source Code Vote up 5 votes
@Override
public void parse(CacheBuilderSpec spec, String key, String value) {
  checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
  try {
    char lastChar = value.charAt(value.length() - 1);
    TimeUnit timeUnit;
    switch (lastChar) {
      case 'd':
        timeUnit = TimeUnit.DAYS;
        break;
      case 'h':
        timeUnit = TimeUnit.HOURS;
        break;
      case 'm':
        timeUnit = TimeUnit.MINUTES;
        break;
      case 's':
        timeUnit = TimeUnit.SECONDS;
        break;
      default:
        throw new IllegalArgumentException(
            format(
                "key %s invalid format.  was %s, must end with one of [dDhHmMsS]", key, value));
    }

    long duration = Long.parseLong(value.substring(0, value.length() - 1));
    parseDuration(spec, duration, timeUnit);
  } catch (NumberFormatException e) {
    throw new IllegalArgumentException(
        format("key %s value set to %s, must be integer", key, value));
  }
}
 
Example 10
Project: nges   File: EventStoreStatusHeartbeat.java   View Source Code Vote up 5 votes
private Runnable catchAllAndLogWithThrottle(Runnable r) {
    LogThrottle throttle = new LogThrottle(1, TimeUnit.HOURS);
    return () -> {
        try {
            r.run();
        } catch (RuntimeException e) {
            if (throttle.throttle(e)) {
                log.error("Execution failed: " + e);
            } else {
                log.error("Execution failed", e);
            }
        }
    };
}
 
Example 11
Project: beaker-notebook-archive   File: TimeStringFormatSerializerTest.java   View Source Code Vote up 5 votes
@Test
public void serializeTimeUnit_resultJsonHasTimeUnit() throws IOException {
  //given
  TimeStringFormat timeStringFormat = new TimeStringFormat(TimeUnit.HOURS);
  //when
  JsonNode actualObj = serializeTimeStringFormat(timeStringFormat);
  //then
  Assertions.assertThat(actualObj.has("unit")).isTrue();
  Assertions.assertThat(actualObj.get("unit").asText()).isEqualTo("HOURS");
}
 
Example 12
Project: Android-Gank-Share   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.HOURS)
Observable<Results> getDataResults(Observable<Results> oResults, DynamicKeyGroup pageAndType, EvictDynamicKeyGroup refresh);
 
Example 13
Project: BEAST   File: TimeOutSaverLoaderTest.java   View Source Code Vote up 4 votes
@BeforeClass
public static void setUpClass() {
    timeOut = new TimeOut(TimeUnit.HOURS, (long) 3.2);
}
 
Example 14
Project: BEAST   File: ElectionCheckParameterSaverLoaderTest.java   View Source Code Vote up 4 votes
@BeforeClass
public static void setUpClass() {
    electionCheckParameter = new ElectionCheckParameter(Arrays.asList(new Integer[]{1, 2}),
            Arrays.asList(new Integer[]{1, 2}), Arrays.asList(new Integer[]{1, 2}), new TimeOut(TimeUnit.HOURS,
            (long) 3.2),4, "-- unwind 6");
}
 
Example 15
Project: Elasticsearch   File: TimeValue.java   View Source Code Vote up 4 votes
public static TimeValue timeValueHours(long hours) {
    return new TimeValue(hours, TimeUnit.HOURS);
}
 
Example 16
Project: Android-Gank-Share   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit =  TimeUnit.HOURS)
Observable<RecommendResults> getRecommendResults(Observable<RecommendResults> oRecommend, DynamicKey dateString, EvictProvider refresh);
 
Example 17
Project: tipi-engine   File: TipiThreadPoolExecutor.java   View Source Code Vote up 4 votes
public TipiThreadPoolExecutor() {
	super(0, Integer.MAX_VALUE, 1, TimeUnit.HOURS, new SynchronousQueue<Runnable>());
}
 
Example 18
Project: hadoop   File: NMClientAsyncImpl.java   View Source Code Vote up 4 votes
@Override
protected void serviceStart() throws Exception {
  client.start();

  ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat(
      this.getClass().getName() + " #%d").setDaemon(true).build();

  // Start with a default core-pool size and change it dynamically.
  int initSize = Math.min(INITIAL_THREAD_POOL_SIZE, maxThreadPoolSize);
  threadPool = new ThreadPoolExecutor(initSize, Integer.MAX_VALUE, 1,
      TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>(), tf);

  eventDispatcherThread = new Thread() {
    @Override
    public void run() {
      ContainerEvent event = null;
      Set<String> allNodes = new HashSet<String>();

      while (!stopped.get() && !Thread.currentThread().isInterrupted()) {
        try {
          event = events.take();
        } catch (InterruptedException e) {
          if (!stopped.get()) {
            LOG.error("Returning, thread interrupted", e);
          }
          return;
        }

        allNodes.add(event.getNodeId().toString());

        int threadPoolSize = threadPool.getCorePoolSize();

        // We can increase the pool size only if haven't reached the maximum
        // limit yet.
        if (threadPoolSize != maxThreadPoolSize) {

          // nodes where containers will run at *this* point of time. This is
          // *not* the cluster size and doesn't need to be.
          int nodeNum = allNodes.size();
          int idealThreadPoolSize = Math.min(maxThreadPoolSize, nodeNum);

          if (threadPoolSize < idealThreadPoolSize) {
            // Bump up the pool size to idealThreadPoolSize +
            // INITIAL_POOL_SIZE, the later is just a buffer so we are not
            // always increasing the pool-size
            int newThreadPoolSize = Math.min(maxThreadPoolSize,
                idealThreadPoolSize + INITIAL_THREAD_POOL_SIZE);
            LOG.info("Set NMClientAsync thread pool size to " +
                newThreadPoolSize + " as the number of nodes to talk to is "
                + nodeNum);
            threadPool.setCorePoolSize(newThreadPoolSize);
          }
        }

        // the events from the queue are handled in parallel with a thread
        // pool
        threadPool.execute(getContainerEventProcessor(event));

        // TODO: Group launching of multiple containers to a single
        // NodeManager into a single connection
      }
    }
  };
  eventDispatcherThread.setName("Container  Event Dispatcher");
  eventDispatcherThread.setDaemon(false);
  eventDispatcherThread.start();

  super.serviceStart();
}
 
Example 19
Project: ja-micro   File: PartitionProcessor.java   View Source Code Vote up 4 votes
PartitionProcessor(TopicPartition partitionKey, TypeDictionary typeDictionary, FailedMessageProcessor failedMessageProcessor, Tracer tracer, MetricBuilderFactory metricBuilderFactory) {
    this.partitionKey = partitionKey;
    this.typeDictionary = typeDictionary;
    this.failedMessageProcessor = failedMessageProcessor;

    this.tracer = tracer;
    this.metricsBuilderFactory = metricBuilderFactory;




    undeliveredMessages = new LinkedBlockingQueue<>();

    // Single threaded execution per partition to preserve ordering guarantees.
    // EXTENSION:
    // - if required, allow multiple threads sacrificing ordering.
    // - but then the commmit offset handling requires more thoughts
    executor = new ThreadPoolExecutor(1, 1, 24, TimeUnit.HOURS, undeliveredMessages);
}
 
Example 20
Project: openjdk-jdk10   File: ThrowingTasks.java   View Source Code Vote up 4 votes
CheckingExecutor() {
    super(10, 10,
          1L, TimeUnit.HOURS,
          new LinkedBlockingQueue<Runnable>(),
          tf);
}