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

The following examples show how to use java.util.concurrent.TimeUnit#MINUTES . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: pnc   File: TimeUtils.java    License: 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 2
Source Project: cloudbreak   File: SdxStartWaitHandler.java    License: 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 3
Source Project: rya   File: PeriodicQueryUtil.java    License: 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 4
@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 5
Source Project: tajo   File: TajoConf.java    License: 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 6
@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 7
/**
 * 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 8
Source Project: tutorials   File: MetricsIntegrationTest.java    License: 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 9
@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 10
Source Project: riposte   File: ReporterFactory.java    License: 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 11
@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 12
@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 13
Source Project: tomee   File: TimeUnitAdapter.java    License: 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 14
Source Project: enmasse   File: AddressUtils.java    License: 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 15
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 16
Source Project: neoscada   File: ServiceImpl.java    License: 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
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 18
Source Project: Elasticsearch   File: TimeValue.java    License: Apache License 2.0 4 votes vote down vote up
public static TimeValue timeValueMinutes(long minutes) {
    return new TimeValue(minutes, TimeUnit.MINUTES);
}
 
Example 19
Source Project: botbuilder-java   File: RestClient.java    License: 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;
}
 
Example 20
Source Project: v9porn   File: CacheProviders.java    License: 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);