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

The following are Jave code examples for showing how to use MINUTES 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: csap-core   File: LogRollerRunnable.java   View Source Code Vote up 6 votes
public LogRollerRunnable( Application csapApp ) {

		this.csapApp = csapApp;

		long initialDelay = 5;
		long interval = csapApp.lifeCycleSettings().getLogRotationMinutes();

		TimeUnit logRotationTimeUnit = TimeUnit.MINUTES;

		if ( Application.isRunningOnDesktop() ) {
			logger.warn( "Setting DESKTOP to seconds" );
			logRotationTimeUnit = TimeUnit.SECONDS;
		}

		logger.warn(
			"Scheduling logrotates to be triggered every {} {}. Logs only rotated if size exceeds threshold (default is 10mb)",
			interval, logRotationTimeUnit );

		ScheduledFuture<?> jobHandle = scheduledExecutorService
			.scheduleAtFixedRate(
				() -> executeLogRotateForAllServices(),
				initialDelay,
				interval,
				logRotationTimeUnit );

	}
 
Example 2
Project: ontonethub   File: PrefixccProviderComponent.java   View Source Code Vote up 6 votes
/**
 * uses the {@link #providerProperties} and {@link #offlineMode}
 * state to decide if the {@link PrefixccProvider} should be registered as
 * a service or not. If the current state is different the desired state it
 * creates and register / unregister destroys the {@link #provider<p>
 * Consumes: {@link #providerProperties} and {@link #offlineMode}<br>
 * Manages: {@link #provider} and {@link #providerRegistration}
 */
private synchronized void updateProviderState(){
    if(providerProperties != null && offlineMode == null){ //register
        if(providerRegistration == null){
            provider = new PrefixccProvider(updateInterval, TimeUnit.MINUTES);
            providerRegistration = bc.registerService(
                NamespacePrefixProvider.class.getName(), provider, providerProperties);
            log.info("registered prefix.cc NamespacePrefixProvider ...");
        }
    } else { //unregister
        if(providerRegistration != null){
            providerRegistration.unregister();
            log.info("unregistered prefix.cc NamespacePrefixProvider ...");
        }
        if(provider != null){
            provider.close();
            provider = null;
        }
    }
}
 
Example 3
Project: MooProject   File: TimeUtil.java   View Source Code Vote up 6 votes
/**
 * Gets the duration and timeunit from string (like 1d or 5h)
 *
 * @param str The string
 * @return The pair with both values
 */
public static Pair<Integer, TimeUnit> getTime(String str) {
    if(!Validation.TIME.matches(str)) return null;
    String timeUnitStr = str.substring(str.length() - 1, str.length());
    int duration = Integer.parseInt(str.substring(0, str.length() - 1));

    TimeUnit unit = null;
    switch(timeUnitStr) {
        case "d":
            unit = TimeUnit.DAYS;
            break;
        case "h":
            unit = TimeUnit.HOURS;
            break;
        case "m":
            unit = TimeUnit.MINUTES;
            break;
        case "s":
            unit = TimeUnit.SECONDS;
            break;
    }
    return new Pair<>(duration, unit);
}
 
Example 4
Project: datarouter   File: BaseExecutorGuiceModule.java   View Source Code Vote up 5 votes
protected ThreadPoolExecutor createThreadPool(ThreadGroup parentGroup, String name, int minThreadCound,
		int maxThreadCount, int queueSize, RejectedExecutionHandler rejectPolicy){
	ThreadFactory threadFactory = new NamedThreadFactory(parentGroup, name, true);
	BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(queueSize);
	return new ThreadPoolExecutor(minThreadCound, maxThreadCount, 1, TimeUnit.MINUTES, queue, threadFactory,
			rejectPolicy);
}
 
Example 5
Project: oryx2   File: ALSServingModelManager.java   View Source Code Vote up 5 votes
public ALSServingModelManager(Config config) {
  super(config);
  String rescorerProviderClass =
      ConfigUtils.getOptionalString(config, "oryx.als.rescorer-provider-class");
  rescorerProvider = loadRescorerProviders(rescorerProviderClass);
  sampleRate = config.getDouble("oryx.als.sample-rate");
  minModelLoadFraction = config.getDouble("oryx.serving.min-model-load-fraction");
  Preconditions.checkArgument(sampleRate > 0.0 && sampleRate <= 1.0);
  Preconditions.checkArgument(minModelLoadFraction >= 0.0 && minModelLoadFraction <= 1.0);
  logRateLimit = new RateLimitCheck(1, TimeUnit.MINUTES);
}
 
Example 6
Project: indeed-grpc-java   File: ConsulNameResolver.java   View Source Code Vote up 5 votes
ConsulNameResolver(
        final CatalogClient catalogClient,
        final KeyValueClient keyValueClient,
        final String serviceName,
        final Optional<String> tag,
        final Resource<ScheduledExecutorService> timerServiceResource,
        final Resource<ExecutorService> executorResource
) {
    this(
            catalogClient, keyValueClient, serviceName,
            tag, timerServiceResource, executorResource,
            1, TimeUnit.MINUTES
    );
}
 
Example 7
Project: avaire   File: GithubChangesJob.java   View Source Code Vote up 5 votes
public GithubChangesJob(AvaIre avaire) {
    super(avaire, 30, 75, TimeUnit.MINUTES);

    if (!avaire.getCache().getAdapter(CacheType.FILE).has("github.commits")) {
        run();
    }
}
 
Example 8
Project: jetcache   File: DefaultCacheMonitorManager.java   View Source Code Vote up 5 votes
protected static LocalDateTime computeFirstResetTime(LocalDateTime baseTime, int time, TimeUnit unit) {
    if (unit != TimeUnit.SECONDS && unit != TimeUnit.MINUTES && unit != TimeUnit.HOURS && unit != TimeUnit.DAYS) {
        throw new IllegalArgumentException();
    }
    LocalDateTime t = baseTime;
    switch (unit) {
        case DAYS:
            t = t.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
            break;
        case HOURS:
            if (24 % time == 0) {
                t = t.plusHours(time - t.getHour() % time);
            } else {
                t = t.plusHours(1);
            }
            t = t.withMinute(0).withSecond(0).withNano(0);
            break;
        case MINUTES:
            if (60 % time == 0) {
                t = t.plusMinutes(time - t.getMinute() % time);
            } else {
                t = t.plusMinutes(1);
            }
            t = t.withSecond(0).withNano(0);
            break;
        case SECONDS:
            if (60 % time == 0) {
                t = t.plusSeconds(time - t.getSecond() % time);
            } else {
                t = t.plusSeconds(1);
            }
            t = t.withNano(0);
            break;
    }
    return t;
}
 
Example 9
Project: BEAST   File: TimeOutSaverLoader.java   View Source Code Vote up 5 votes
/**
 * Creates a TimeOut object from a given, by createSaveString() generated, saveString
 * @param s the SaveString
 * @return the TimeOut object
 */
public static TimeOut createFromSaveString(String s) {
    String [] split = s.split("\n</duration>\n");
    Long duration = Long.parseLong(split[0].replace("<duration>\n", ""));
    split = split[1].split("\n</timeunit>\n");
    TimeUnit timeUnit = TimeUnit.MINUTES;
    String timeunit = split[0].replace("<timeunit>\n", "");
    switch(timeunit) {
        case "MILLISECONDS":
            timeUnit = TimeUnit.MILLISECONDS;
            break;
        case "MINUTES":
            timeUnit = TimeUnit.MINUTES;
            duration = TimeUnit.MILLISECONDS.toMinutes(duration);
            break;
        case "SECONDS":
            timeUnit = TimeUnit.SECONDS;
            duration = TimeUnit.MILLISECONDS.toSeconds(duration);
            break;
        case "HOURS":
            timeUnit = TimeUnit.HOURS;
            duration = TimeUnit.MILLISECONDS.toHours(duration);
            break;
        case "DAYS":
            timeUnit = TimeUnit.DAYS;
            duration = TimeUnit.MILLISECONDS.toDays(duration);
            break;
        default:
            break;
    }
    return new TimeOut(timeUnit, duration);
}
 
Example 10
Project: neoscada   File: Hive.java   View Source Code Vote up 5 votes
@Override
protected void performStart () throws Exception
{
    this.executor = new ExportedExecutorService ( Hive.class.getName (), 0, 1, 1, TimeUnit.MINUTES );

    super.performStart ();

    this.factory.setReceiver ( this.configurationReceiver );
}
 
Example 11
Project: AAVT   File: MediaMuxerWraper.java   View Source Code Vote up 5 votes
public MediaMuxerWraper(String path, int format) throws IOException {
    mMuxer=new MediaMuxer(path,format);
    datas=new LinkedBlockingQueue<>(30);
    recycler=new Recycler<>();
    ThreadFactory factory= Executors.defaultThreadFactory();
    mExec=new ThreadPoolExecutor(1,1,1,TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>(16),factory);
}
 
Example 12
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 13
Project: neoscada   File: ServiceImpl.java   View Source Code Vote up 4 votes
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 14
Project: Cognizant-Intelligent-Test-Scripter   File: ThreadPool.java   View Source Code Vote up 4 votes
public ThreadPool(int threadCount, long keepAliveTime, boolean isGridMode) {
    super(threadCount, threadCount, keepAliveTime, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
    doSelectiveThreading = threadCount > 1 && !isGridMode;
}
 
Example 15
Project: MVPArmsTest1   File: CommonCache.java   View Source Code Vote up 4 votes
@LifeCache(duration = 2, timeUnit = TimeUnit.MINUTES)
Observable<Reply<List<User>>> getUsers(Observable<List<User>> users, DynamicKey idLastUserQueried, EvictProvider evictProvider);
 
Example 16
Project: fakeload   File: AbstractFakeLoadTest.java   View Source Code Vote up 4 votes
@Test
public void testEqualsMethodSymmetry() {
    FakeLoad parent1, parent2;
    FakeLoad child1 = new SimpleFakeLoad(5, TimeUnit.SECONDS);
    FakeLoad child2 = new SimpleFakeLoad(500, TimeUnit.MILLISECONDS);
    FakeLoad child3 = new SimpleFakeLoad(1, TimeUnit.MINUTES);
    FakeLoad child1Copy = new SimpleFakeLoad(5, TimeUnit.SECONDS);
    FakeLoad child2Copy = new SimpleFakeLoad(500, TimeUnit.MILLISECONDS);

    // parent load identical, children identical
    parent1 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1)
            .addLoad(child2);
    parent2 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1)
            .addLoad(child2);

    assertEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);


    // parent load identical, children logically equal
    parent2 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1Copy)
            .addLoad(child2Copy);

    assertEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);


    // parent load identical, children different
    parent2 = new SimpleFakeLoad().lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1).addLoad(child3);

    assertNotEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);



    // parent load different, children identical
    parent1 = fakeload.lasting(10, TimeUnit.SECONDS).withCpu(20)
            .addLoad(child1)
            .addLoad(child2);

    parent2 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1)
            .addLoad(child2);

    assertNotEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);

    // parent load different, children logically equal
    parent1 = fakeload.lasting(10, TimeUnit.SECONDS).withCpu(20)
            .addLoad(child1)
            .addLoad(child2);

    parent2 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1Copy)
            .addLoad(child2Copy);

    assertNotEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);

    // parent load different, children different
    parent1 = fakeload.lasting(10, TimeUnit.SECONDS).withCpu(20)
            .addLoad(child1)
            .addLoad(child2);

    parent2 = fakeload.lasting(20, TimeUnit.SECONDS).withCpu(30)
            .addLoad(child1)
            .addLoad(child3);

    assertNotEquals(parent1, parent2);
    assertEqualsSymmetry(parent1, parent2);
}
 
Example 17
Project: DiscogsBrowser   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 5, timeUnit = TimeUnit.MINUTES)
Single<RootWantlistResponse> fetchWantlist(Single<RootWantlistResponse> fetchWantlistSingle, DynamicKey username, EvictDynamicKey update);
 
Example 18
Project: storm-dynamic-spout   File: SpoutCoordinator.java   View Source Code Vote up 4 votes
/**
 * Constructor.
 * @param topologyConfig Storm topology config.
 * @param threadContext Contextual information used to name spawned threads.
 * @param virtualSpoutMessageBus ThreadSafe message bus for passing messages between DynamicSpout and VirtualSpouts.
 * @param metricsRecorder MetricRecorder implementation for recording metrics.
 */
public SpoutCoordinator(
    final Map<String, Object> topologyConfig,
    final ThreadContext threadContext,
    final VirtualSpoutMessageBus virtualSpoutMessageBus,
    final MetricsRecorder metricsRecorder
) {
    this.virtualSpoutMessageBus = virtualSpoutMessageBus;
    this.topologyConfig = Tools.immutableCopy(topologyConfig);
    this.metricsRecorder = metricsRecorder;
    this.threadContext = threadContext;

    // Create new ThreadFactory
    final String threadName = "[" + DynamicSpout.class.getSimpleName() + ":" + getClass().getSimpleName() + "] "
        + VirtualSpout.class.getSimpleName() + " Pool %d on " + threadContext.toString() + " ";
    final ThreadFactory threadFactory = new ThreadFactoryBuilder()
        .setNameFormat(threadName)
        .setDaemon(false)
        .build();

    /*
     * Create our executor service with a fixed thread size.
     * Its configured to:
     *   - Time out idle threads after 1 minute
     *   - Keep at most 0 idle threads alive (after timing out).
     *   - Maximum of SPOUT_RUNNER_THREAD_POOL_SIZE threads running concurrently.
     *   - Use essentially an unbounded task queue.
     */
    this.executor = new ThreadPoolExecutor(
        // Number of idle threads to keep around
        getMaxConcurrentVirtualSpouts(),
        // Maximum number of threads to utilize
        getMaxConcurrentVirtualSpouts(),
        // How long to keep idle threads around for before closing them
        1L, TimeUnit.MINUTES,
        // Task input queue
        new LinkedBlockingQueue<>(),
        // Pass in our custom thread factory.
        threadFactory
    );
}
 
Example 19
Project: grpc-proxy   File: ProxyHandlerRegistry.java   View Source Code Vote up 4 votes
ProxyHandlerRegistry(HttpUrl backend) {
  this.backend = backend;
  final ConnectionPool connectionPool = new ConnectionPool(100, 5, TimeUnit.MINUTES);
  this.client = new OkHttpClient.Builder().connectionPool(connectionPool).build();
}
 
Example 20
Project: pcloud-networking-java   File: ConnectionPool.java   View Source Code Vote up 2 votes
/**
 * Create a {@linkplain ConnectionPool} with default parameters.
 * <p>
 * By default the pool will be created with 5 maximum idle connections and it will keep
 * idle connections alive for 5 minutes before disposing of them.
 */
@SuppressWarnings("unused")
public ConnectionPool() {
    this(MAX_IDLE_CONN_COUNT, MAX_KEEP_ALIVE_DURATION, TimeUnit.MINUTES);
}