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

The following examples show how to use java.util.concurrent.TimeUnit#MINUTES . 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: 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 2
Source File: SdxUpgradeWaitHandler.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
protected void doAccept(HandlerEvent event) {
    SdxUpgradeWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling cluster upgrade process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(SLEEP_TIME_IN_SEC, TimeUnit.SECONDS, DURATION_IN_MINUTES, TimeUnit.MINUTES);
        upgradeService.waitCloudbreakFlow(sdxId, pollingConfig, "Upgrade");
        response = new SdxUpgradeSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Upgrade polling exited before timeout. Cause: ", userBreakException);
        response = new SdxUpgradeFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Upgrade poller stopped for cluster: {}", sdxId);
        response = new SdxUpgradeFailedEvent(sdxId, userId,
                new PollerStoppedException("Datalake repair timed out after " + DURATION_IN_MINUTES + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Upgrade polling failed for cluster: {}", sdxId);
        response = new SdxUpgradeFailedEvent(sdxId, userId, exception);
    }
    sendEvent(response, event);
}
 
Example 3
Source File: TimeUtils.java    From pnc with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a {@code ChronoUnit} to a {@code TimeUnit}.
 * <p>
 * This handles the seven units declared in {@code TimeUnit}.
 *
 * @param unit the unit to convert, not null
 * @return the converted unit, not null
 * @throws IllegalArgumentException if the unit cannot be converted
 */
public static TimeUnit timeUnit(ChronoUnit unit) {
    Objects.requireNonNull(unit, "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("ChronoUnit cannot be converted to TimeUnit: " + unit);
    }
}
 
Example 4
Source File: PeriodicQueryUtil.java    From rya with Apache License 2.0 6 votes vote down vote up
private static TimeUnit getTimeUnit(ValueConstant val) {
    Preconditions.checkArgument(val.getValue() instanceof IRI);
    IRI uri = (IRI) val.getValue();
    Preconditions.checkArgument(uri.getNamespace().equals(temporalNameSpace));

    switch (uri.getLocalName()) {
    case "days":
        return TimeUnit.DAYS;
    case "hours":
        return TimeUnit.HOURS;
    case "minutes":
        return TimeUnit.MINUTES;
    default:
        throw new IllegalArgumentException("Invalid time unit for Periodic Function.");
    }
}
 
Example 5
Source File: SdxStartWaitHandler.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
protected void doAccept(HandlerEvent event) {
    SdxStartWaitRequest waitRequest = event.getData();
    Long sdxId = waitRequest.getResourceId();
    String userId = waitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack deletion process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(SLEEP_TIME_IN_SEC, TimeUnit.SECONDS, DURATION_IN_MINUTES, TimeUnit.MINUTES);
        sdxStartService.waitCloudbreakCluster(sdxId, pollingConfig);
        response = new SdxStartSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Start polling exited before timeout. Cause: ", userBreakException);
        response = new SdxStartFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Start poller stopped for stack: {}", sdxId);
        response = new SdxStartFailedEvent(sdxId, userId,
                new PollerStoppedException("Datalake start timed out after " + DURATION_IN_MINUTES + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Start polling failed for stack: {}", sdxId);
        response = new SdxStartFailedEvent(sdxId, userId, exception);
    }
    sendEvent(response, event);
}
 
Example 6
Source File: TimeUnitAdapter.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public String marshal(final TimeUnit t) throws Exception {
    if (t == TimeUnit.DAYS) return "Days";
    if (t == TimeUnit.HOURS) return "Hours";
    if (t == TimeUnit.MINUTES) return "Minutes";
    if (t == TimeUnit.SECONDS) return "Seconds";
    if (t == TimeUnit.MILLISECONDS) return "Milliseconds";
    if (t == TimeUnit.MICROSECONDS) return "Microseconds";
    if (t == TimeUnit.NANOSECONDS) return "Nanoseconds";
    throw new IllegalArgumentException("Unknown time unit: " + t);
}
 
Example 7
Source File: TestTimeDuration.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testHigherLower() {
  final TimeUnit[] units = {TimeUnit.NANOSECONDS, TimeUnit.MICROSECONDS, TimeUnit.MILLISECONDS,
      TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS};
  for(int i = 1; i < units.length; i++) {
    assertHigherLower(units[i-1], units[i]);
  }

  Assert.assertSame(TimeUnit.NANOSECONDS, TimeDuration.lowerUnit(TimeUnit.NANOSECONDS));
  Assert.assertSame(TimeUnit.DAYS, TimeDuration.higherUnit(TimeUnit.DAYS));
}
 
Example 8
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ScheduledReporter} instance. The reporter does not report metrics until
 * {@link #start(long, TimeUnit)}.
 *
 * @param registry        the {@link MetricRegistry} containing the metrics this reporter will report
 * @param metricNamespace (optional) CloudWatch metric namespace that all metrics reported by this reporter will
 *                        fall under
 * @param metricFilter    (optional) see {@link MetricFilter}
 * @param cloudWatch      client
 */
public CloudWatchReporter(MetricRegistry registry,
                          String metricNamespace,
                          MetricFilter metricFilter,
                          AmazonCloudWatchAsync cloudWatch) {

    super(registry, "CloudWatchReporter:" + metricNamespace, metricFilter, TimeUnit.MINUTES, TimeUnit.MINUTES);

    this.metricNamespace = metricNamespace;
    this.cloudWatch = cloudWatch;
}
 
Example 9
Source File: MetricsIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUseDerivativeGauge_thenCorrectGaugeFromBase() {
    Gauge<List<Long>> activeUsersGauge = new ActiveUsersGauge(15, TimeUnit.MINUTES);
    Gauge<Integer> activeUserCountGauge = new ActiveUserCountGauge(activeUsersGauge);

    assertThat(activeUserCountGauge.getValue(), equalTo(1));
}
 
Example 10
Source File: RunningStatisticsPerTimeTest.java    From myrrix-recommender with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoll() throws Exception {
  RunningStatisticsPerTime perTime = new RunningStatisticsPerTime(TimeUnit.MINUTES);
  perTime.increment(1.2);

  assertEquals(1.2, perTime.getMin());
  assertEquals(1.2, perTime.getMax());
  assertEquals(1.2, perTime.getMean());
  assertEquals(1L, perTime.getCount());

  Thread.sleep(2000L);
  perTime.increment(2.0);

  assertEquals(1.2, perTime.getMin());
  assertEquals(2.0, perTime.getMax());
  assertEquals(1.6, perTime.getMean());
  assertEquals(2L, perTime.getCount());

  Thread.sleep(59000L);
  perTime.refresh();

  assertEquals(2.0, perTime.getMin());
  assertEquals(2.0, perTime.getMax());
  assertEquals(2.0, perTime.getMean());
  assertEquals(1L, perTime.getCount());

  Thread.sleep(2000L);
  perTime.refresh();

  assertTrue(Double.isNaN(perTime.getMin()));
  assertTrue(Double.isNaN(perTime.getMax()));
  assertTrue(Double.isNaN(perTime.getMean()));
  assertEquals(0L, perTime.getCount());
}
 
Example 11
Source File: ReporterFactory.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * The units associated with the interval
 */
default TimeUnit getTimeUnit() {
    if (isScheduled()) {
        return TimeUnit.MINUTES;
    }
    else {
        return null;
    }
}
 
Example 12
Source File: CacheBuilderSpec.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 13
Source File: RunningStatisticsPerTimeTest.java    From myrrix-recommender with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneBucket() {
  RunningStatisticsPerTime perTime = new RunningStatisticsPerTime(TimeUnit.MINUTES);
  perTime.increment(1.2);
  assertEquals(1.2, perTime.getMin());
  assertEquals(1.2, perTime.getMax());
  assertEquals(1.2, perTime.getMean());
  assertEquals(1L, perTime.getCount());
}
 
Example 14
Source File: TimeValue.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static TimeValue timeValueMinutes(long minutes) {
    return new TimeValue(minutes, TimeUnit.MINUTES);
}
 
Example 15
Source File: ExecutorServiceObject.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 4 votes vote down vote up
public ExecutorServiceObject(final String namingPattern, final int threadSize) {
    workQueue = new LinkedBlockingQueue<>();
    threadPoolExecutor = new ThreadPoolExecutor(threadSize, threadSize, 5L, TimeUnit.MINUTES, workQueue, 
            new BasicThreadFactory.Builder().namingPattern(Joiner.on("-").join(namingPattern, "%s")).build());
    threadPoolExecutor.allowCoreThreadTimeOut(true);
}
 
Example 16
Source File: ServiceImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public ServiceImpl ( final ConfigurationAdministrator service, final BundleContext context, final Executor executor ) throws Exception
{
    super ( context, executor );
    this.service = service;
    this.executor = new ExportedExecutorService ( "org.eclipse.scada.ca.server.osgi.ServiceImpl", 1, 1, 1, TimeUnit.MINUTES ); //$NON-NLS-1$
}
 
Example 17
Source File: ActorExecuterService.java    From actor4j-core with Apache License 2.0 4 votes vote down vote up
public void start(Runnable onStartup, Runnable onTermination) {
	if (system.cells.size()==0)
		return;
	
	int poolSize = Runtime.getRuntime().availableProcessors();
	
	globalTimerExecuterService = new ActorTimerExecuterService(system, 1, "actor4j-global-timer-thread");
	timerExecuterService = new ActorTimerExecuterService(system, poolSize);
	
	resourceExecuterService = new ThreadPoolExecutor(poolSize, maxResourceThreads, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory("actor4j-resource-thread"));
	if (system.clientMode)
		clientExecuterService = Executors.newSingleThreadExecutor();
	
	if (system.persistenceMode) {
		persistenceService = new ActorPersistenceService(system.wrapper, system.parallelismMin, system.parallelismFactor, system.persistenceConnector);
		persistenceService.start();
	}
	
	this.onTermination = onTermination;
	
	actorThreadPool = new ActorThreadPool(system);
	
	podReplicationControllerExecuterService = new ScheduledThreadPoolExecutor(1, new DefaultThreadFactory("actor4j-replication-controller-thread"));
	try {
		Constructor<? extends PodReplicationControllerRunnable> constructor;
		constructor = system.podReplicationControllerRunnableClass.getConstructor(ActorSystemImpl.class);
		podReplicationControllerRunnable = constructor.newInstance(system);
	} catch (Exception e) {
		e.printStackTrace();
	}
	if (podReplicationControllerRunnable!=null)
		podReplicationControllerExecuterService.scheduleAtFixedRate(podReplicationControllerRunnable, system.horizontalPodAutoscalerSyncTime, system.horizontalPodAutoscalerSyncTime, TimeUnit.MILLISECONDS);
	
	/*
	 * necessary before executing onStartup; 
	 * creating of childrens in Actor::preStart: childrens needs to register at the dispatcher
	 * (see also ActorSystemImpl::internal_addCell)
	 */
	started.set(true);
	
	if (onStartup!=null)
		onStartup.run();
}
 
Example 18
Source File: AddressUtils.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public static void waitForDestinationsReady(Address... destinations) throws Exception {
    TimeoutBudget budget = new TimeoutBudget(10, TimeUnit.MINUTES);
    AddressUtils.waitForDestinationsReady(budget, destinations);
}
 
Example 19
Source File: CacheProviders.java    From v9porn with MIT License 2 votes vote down vote up
/**
 * 获取我的收藏
 *
 * @param stringObservable   ob
 * @param filterPageCategory 页码
 * @param evictFilter        缓存控制
 * @return oab对象
 */
@ProviderKey("favorite")
@LifeCache(duration = CACHE_TIME, timeUnit = TimeUnit.MINUTES)
Observable<Reply<String>> getFavorite(Observable<String> stringObservable, DynamicKeyGroup filterPageCategory, EvictDynamicKey evictFilter);
 
Example 20
Source File: RestClient.java    From botbuilder-java with MIT License 2 votes vote down vote up
/**
 * Set the maximum idle connections for the HTTP client. Default is 5.
 *
 * @param maxIdleConnections the maximum idle connections
 * @return the builder itself for chaining
 * @deprecated use {@link #withConnectionPool(ConnectionPool)} instead
 */
@Deprecated
public Builder withMaxIdleConnections(int maxIdleConnections) {
    this.connectionPool = new ConnectionPool(maxIdleConnections, 5, TimeUnit.MINUTES);
    return this;
}