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

The following examples show how to use java.util.concurrent.TimeUnit#HOURS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestYamlJsonSerde.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testSequenceSplit() {
    SequenceSplit[] splits = new SequenceSplit[] {new SequenceSplitTimeSeparation("col", 1, TimeUnit.HOURS),
                    new SplitMaxLengthSequence(100, false)};

    for (SequenceSplit f : splits) {
        String yaml = y.serialize(f);
        String json = j.serialize(f);

        //            System.out.println(yaml);
        //            System.out.println(json);
        //            System.out.println();

        SequenceSplit t2 = y.deserializeSequenceSplit(yaml);
        SequenceSplit t3 = j.deserializeSequenceSplit(json);
        assertEquals(f, t2);
        assertEquals(f, t3);
    }
}
 
Example 2
Source File: CSVThirdEyeResponseTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void beforeMethod(){
  ThirdEyeRequest request = ThirdEyeRequest.
      newBuilder()
      .setStartTimeInclusive(0)
      .setEndTimeExclusive(100)
      .addGroupBy("country")
      .addMetricFunction(new MetricFunction(MetricAggFunction.AVG, "views", 0L, "source", null, null))
      .build("");
  response = new CSVThirdEyeResponse(
      request,
      new TimeSpec("timestamp", new TimeGranularity(1, TimeUnit.HOURS), TimeSpec.SINCE_EPOCH_FORMAT),
      new DataFrame().addSeries("timestamp", 100).addSeries("country", "us")
      .addSeries("AVG_views", 1000)
  );
}
 
Example 3
Source File: SessionHandler.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
private TimeUnit convertTimeUnit(int unit) {
    switch (unit) {
        case 0:
            return TimeUnit.NANOSECONDS;
        case 1:
            return TimeUnit.MICROSECONDS;
        case 2:
            return TimeUnit.MILLISECONDS;
        case 3:
            return TimeUnit.SECONDS;
        case 4:
            return TimeUnit.MINUTES;
        case 5:
            return TimeUnit.HOURS;
        case 6:
            return TimeUnit.DAYS;
        default:
            return TimeUnit.MILLISECONDS;
    }
}
 
Example 4
Source File: CSVThirdEyeDataSourceTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteSelectTimeSeries() throws Exception {
  ThirdEyeRequest request = ThirdEyeRequest.newBuilder()
      .addMetricFunction(new MetricFunction(MetricAggFunction.SUM, "views", 1L, "source", null, null))
      .setDataSource("source")
      .setGroupByTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS))
      .setStartTimeInclusive(2000000)
      .setEndTimeExclusive(10800000)
      .build("ref");
  ThirdEyeResponse expectedResponse = new CSVThirdEyeResponse(
      request,
      new TimeSpec("timestamp", new TimeGranularity(1, TimeUnit.HOURS), TimeSpec.SINCE_EPOCH_FORMAT),
      new DataFrame()
          .addSeries("timestamp", 3600000, 7200000)
          .addSeries("SUM_views", 3002, 3004)
  );

  ThirdEyeResponse response = dataSource.execute(request);
  Assert.assertEquals(response, expectedResponse);
}
 
Example 5
Source File: TimeUtils.java    From brein-time-utilities with Apache License 2.0 6 votes vote down vote up
public static TimeUnit convert(final ChronoUnit chronoUnit) {
    if (chronoUnit == null) {
        return null;
    }

    switch (chronoUnit) {
        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:
            return null;
    }
}
 
Example 6
Source File: CSVThirdEyeDataSourceTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteGroupByColumns() throws Exception {

  ThirdEyeRequest request = ThirdEyeRequest.newBuilder()
      .addMetricFunction(new MetricFunction(MetricAggFunction.SUM, "views", 1L, "source", null, null))
      .setDataSource("source")
      .addGroupBy(Arrays.asList("country", "browser"))
      .build("ref");

  ThirdEyeResponse expectedResponse = new CSVThirdEyeResponse(
      request,
      new TimeSpec("timestamp", new TimeGranularity(1, TimeUnit.HOURS), TimeSpec.SINCE_EPOCH_FORMAT),
      new DataFrame()
          .addSeries("country", "cn", "us", "cn")
          .addSeries("browser", "chrome", "chrome", "safari")
          .addSeries("SUM_views", 6003, 4094, 2003)
  );

  ThirdEyeResponse response = dataSource.execute(request);
  Assert.assertEquals(response, expectedResponse);
}
 
Example 7
Source File: CSVThirdEyeDataSourceTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecuteTimeSeries() throws Exception {
  ThirdEyeRequest request = ThirdEyeRequest.newBuilder()
      .addMetricFunction(new MetricFunction(MetricAggFunction.SUM, "views", 1L, "source", null, null))
      .setDataSource("source")
      .setGroupByTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS))
      .build("ref");
  ThirdEyeResponse expectedResponse = new CSVThirdEyeResponse(
      request,
      new TimeSpec("timestamp", new TimeGranularity(1, TimeUnit.HOURS), TimeSpec.SINCE_EPOCH_FORMAT),
      new DataFrame()
          .addSeries("timestamp", 0, 3600000, 7200000, 10800000)
          .addSeries("SUM_views", 3088, 3002, 3004, 3006)
  );

  ThirdEyeResponse response = dataSource.execute(request);
  Assert.assertEquals(response, expectedResponse);
}
 
Example 8
Source File: Temporals.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
public static TimeUnit timeUnit(ChronoUnit unit) {
    switch (unit) {
        case NANOS:
            return TimeUnit.NANOSECONDS;
        case MICROS:
            return TimeUnit.MICROSECONDS;
        case MILLIS:
            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 IllegalArgumentException("Cannot convert chronounit");
    }
}
 
Example 9
Source File: TajoConf.java    From tajo with Apache License 2.0 6 votes vote down vote up
public static TimeUnit unitFor(String unit) {
  unit = unit.trim().toLowerCase();
  if (unit.isEmpty() || unit.equals("l")) {
    return TimeUnit.MILLISECONDS;
  } 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);
}
 
Example 10
Source File: ApplicationMasterLauncher.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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 11
Source File: CypherUtilService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/curies")
@ApiOperation(value = "Get the curie map", response = String.class, responseContainer = "Map")
@Timed
@CacheControl(maxAge = 2, maxAgeUnit = TimeUnit.HOURS)
@Produces({MediaType.APPLICATION_JSON})
public Object getCuries(
    @ApiParam(value = DocumentationStrings.JSONP_DOC, required = false) @QueryParam("callback") String callback) {
  return JaxRsUtil.wrapJsonp(request.get(),
      new GenericEntity<Map<String, String>>(cypherUtil.getCurieMap()) {}, callback);
}
 
Example 12
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
  }
  throw new RuntimeException("Invalid TimeUnit " + proto);
}
 
Example 13
Source File: ProfilePeriodTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoHourPeriods() {
  long duration = 2;
  TimeUnit units = TimeUnit.HOURS;

  ProfilePeriod period = ProfilePeriod.fromTimestamp(AUG2016, duration, units);
  assertEquals(204462, period.getPeriod());
  assertEquals(1472126400000L, period.getStartTimeMillis());  //  Thu, 25 Aug 2016 12:00:00 GMT
  assertEquals(units.toMillis(duration), period.getDurationMillis());
}
 
Example 14
Source File: CommonEventEncoderTest.java    From aeron with Apache License 2.0 5 votes vote down vote up
@Test
void testStateTransitionStringLength()
{
    final TimeUnit from = TimeUnit.NANOSECONDS;
    final TimeUnit to = TimeUnit.HOURS;
    assertEquals(from.name().length() + STATE_SEPARATOR.length() + to.name().length() + SIZE_OF_INT,
        stateTransitionStringLength(from, to));
}
 
Example 15
Source File: TestExclusiveConditions.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
@AssertWarning("AndEqualsAlwaysFalse")
public void testEnum(TimeUnit tu) {
    if(tu.equals(TimeUnit.DAYS) && tu == TimeUnit.HOURS) {
        System.out.println("Never!");
    }
}
 
Example 16
Source File: HistoryFileManager.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected ThreadPoolExecutor createMoveToDoneThreadPool(int numMoveThreads) {
  ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat(
      "MoveIntermediateToDone Thread #%d").build();
  return new ThreadPoolExecutor(numMoveThreads, numMoveThreads,
      1, TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>(), tf);
}
 
Example 17
Source File: SettingsCommand.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public SettingsCommand(Command type, Options options, Count count, Duration duration, Uncertainty uncertainty)
{
    this.type = type;
    this.consistencyLevel = ConsistencyLevel.valueOf(options.consistencyLevel.value().toUpperCase());
    this.noWarmup = options.noWarmup.setByUser();
    this.truncate = TruncateWhen.valueOf(options.truncate.value().toUpperCase());

    if (count != null)
    {
        this.count = OptionDistribution.parseLong(count.count.value());
        this.duration = 0;
        this.durationUnits = null;
        this.targetUncertainty = -1;
        this.minimumUncertaintyMeasurements = -1;
        this.maximumUncertaintyMeasurements = -1;
    }
    else if (duration != null)
    {
        this.count = -1;
        this.duration = Long.parseLong(duration.duration.value().substring(0, duration.duration.value().length() - 1));
        switch (duration.duration.value().toLowerCase().charAt(duration.duration.value().length() - 1))
        {
            case 's':
                this.durationUnits = TimeUnit.SECONDS;
                break;
            case 'm':
                this.durationUnits = TimeUnit.MINUTES;
                break;
            case 'h':
                this.durationUnits = TimeUnit.HOURS;
                break;
            default:
                throw new IllegalStateException();
        }
        this.targetUncertainty = -1;
        this.minimumUncertaintyMeasurements = -1;
        this.maximumUncertaintyMeasurements = -1;
    }
    else
    {
        this.count = -1;
        this.duration = 0;
        this.durationUnits = null;
        this.targetUncertainty = Double.parseDouble(uncertainty.uncertainty.value());
        this.minimumUncertaintyMeasurements = Integer.parseInt(uncertainty.minMeasurements.value());
        this.maximumUncertaintyMeasurements = Integer.parseInt(uncertainty.maxMeasurements.value());
    }
}
 
Example 18
Source File: TezContainerLauncherImpl.java    From tez with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws TezException {
  // pass a copy of config to ContainerManagementProtocolProxy until YARN-3497 is fixed
  cmProxy =
      new ContainerManagementProtocolProxy(conf);

  ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat(
      "ContainerLauncher #%d").setDaemon(true).build();

  // Start with a default core-pool size of 10 and change it dynamically.
  launcherPool = new ThreadPoolExecutor(INITIAL_POOL_SIZE,
      Integer.MAX_VALUE, 1, TimeUnit.HOURS,
      new LinkedBlockingQueue<Runnable>(),
      tf, new CustomizedRejectedExecutionHandler());
  eventHandlingThread = new Thread() {
    @Override
    public void run() {
      ContainerOp event = null;
      while (!Thread.currentThread().isInterrupted()) {
        try {
          event = eventQueue.take();
        } catch (InterruptedException e) {
          if(!serviceStopped.get()) {
            LOG.error("Returning, interrupted : " + e);
          }
          return;
        }
        int poolSize = launcherPool.getCorePoolSize();

        // See if we need up the pool size only if haven't reached the
        // maximum limit yet.
        if (poolSize != limitOnPoolSize) {

          // nodes where containers will run at *this* point of time. This is
          // *not* the cluster size and doesn't need to be.
          int numNodes =
              getContext().getNumNodes(TezConstants.getTezYarnServicePluginName());
          int idealPoolSize = Math.min(limitOnPoolSize, numNodes);

          if (poolSize < idealPoolSize) {
            // Bump up the pool size to idealPoolSize+INITIAL_POOL_SIZE, the
            // later is just a buffer so we are not always increasing the
            // pool-size
            int newPoolSize = Math.min(limitOnPoolSize, idealPoolSize
                + INITIAL_POOL_SIZE);
            LOG.info("Setting ContainerLauncher pool size to " + newPoolSize
                + " as number-of-nodes to talk to is " + numNodes);
            launcherPool.setCorePoolSize(newPoolSize);
          }
        }

        // the events from the queue are handled in parallel
        // using a thread pool
        launcherPool.execute(createEventProcessor(event));

        // TODO: Group launching of multiple containers to a single
        // NodeManager into a single connection
      }
    }
  };
  eventHandlingThread.setName("ContainerLauncher Event Handler");
  eventHandlingThread.start();
  boolean cleanupDagDataOnComplete = ShuffleUtils.isTezShuffleHandler(conf)
      && conf.getBoolean(TezConfiguration.TEZ_AM_DAG_CLEANUP_ON_COMPLETION,
      TezConfiguration.TEZ_AM_DAG_CLEANUP_ON_COMPLETION_DEFAULT);
  if (cleanupDagDataOnComplete) {
    String deletionTrackerClassName = conf.get(TezConfiguration.TEZ_AM_DELETION_TRACKER_CLASS,
        TezConfiguration.TEZ_AM_DELETION_TRACKER_CLASS_DEFAULT);
    deletionTracker = ReflectionUtils.createClazzInstance(
        deletionTrackerClassName, new Class[]{Configuration.class}, new Object[]{conf});
  }
}
 
Example 19
Source File: TimeValue.java    From bboss-elasticsearch with Apache License 2.0 4 votes vote down vote up
public static TimeValue timeValueHours(long hours) {
	return new TimeValue(hours, TimeUnit.HOURS);
}
 
Example 20
Source File: Configuration.java    From hadoop with Apache License 2.0 votes vote down vote up
TimeUnit unit() { return TimeUnit.HOURS; }