use of java.util.concurrent.TimeUnit in project geode by apache.
the class WaitUntilParallelGatewaySenderFlushedCoordinatorJUnitTest method testWaitUntilParallelGatewaySenderFlushedUnsuccessfulInitiator.
@Test
public void testWaitUntilParallelGatewaySenderFlushedUnsuccessfulInitiator() throws Throwable {
long timeout = 5000;
TimeUnit unit = TimeUnit.MILLISECONDS;
WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this.sender, timeout, unit, true);
WaitUntilParallelGatewaySenderFlushedCoordinator coordinatorSpy = spy(coordinator);
doReturn(getLocalBucketRegions()).when(coordinatorSpy).getLocalBucketRegions(any());
doReturn(getCallableResult(false)).when(coordinatorSpy).createWaitUntilBucketRegionQueueFlushedCallable(any(), anyLong(), any());
boolean result = coordinatorSpy.waitUntilFlushed();
assertFalse(result);
}
use of java.util.concurrent.TimeUnit in project geode by apache.
the class SerializableTimeoutTest method canBeSerialized.
@Test
public void canBeSerialized() throws Exception {
long timeout = 2;
TimeUnit timeUnit = TimeUnit.SECONDS;
boolean lookingForStuckThread = true;
SerializableTimeout instance = SerializableTimeout.builder().withTimeout(timeout, timeUnit).withLookingForStuckThread(lookingForStuckThread).build();
assertThat(readField(Timeout.class, instance, FIELD_TIMEOUT)).isEqualTo(timeout);
assertThat(readField(Timeout.class, instance, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
assertThat(readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD)).isEqualTo(lookingForStuckThread);
SerializableTimeout cloned = (SerializableTimeout) SerializationUtils.clone(instance);
assertThat(readField(Timeout.class, cloned, FIELD_TIMEOUT)).isEqualTo(timeout);
assertThat(readField(Timeout.class, cloned, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
assertThat(readField(Timeout.class, cloned, FIELD_LOOK_FOR_STUCK_THREAD)).isEqualTo(lookingForStuckThread);
}
use of java.util.concurrent.TimeUnit in project logging-log4j2 by apache.
the class IdlePurgePolicy method createPurgePolicy.
/**
* Create the PurgePolicy
*
* @param timeToLive the number of increments of timeUnit before the Appender should be purged.
* @param checkInterval when all appenders purged, the number of increments of timeUnit to check if any appenders appeared
* @param timeUnit the unit of time the timeToLive and the checkInterval is expressed in.
* @return The Routes container.
*/
@PluginFactory
public static PurgePolicy createPurgePolicy(@PluginAttribute("timeToLive") final String timeToLive, @PluginAttribute("checkInterval") final String checkInterval, @PluginAttribute("timeUnit") final String timeUnit, @PluginConfiguration final Configuration configuration) {
if (timeToLive == null) {
LOGGER.error("A timeToLive value is required");
return null;
}
TimeUnit units;
if (timeUnit == null) {
units = TimeUnit.MINUTES;
} else {
try {
units = TimeUnit.valueOf(timeUnit.toUpperCase());
} catch (final Exception ex) {
LOGGER.error("Invalid timeUnit value {}. timeUnit set to MINUTES", timeUnit, ex);
units = TimeUnit.MINUTES;
}
}
long ttl = units.toMillis(Long.parseLong(timeToLive));
if (ttl < 0) {
LOGGER.error("timeToLive must be positive. timeToLive set to 0");
ttl = 0;
}
long ci;
if (checkInterval == null) {
ci = ttl;
} else {
ci = units.toMillis(Long.parseLong(checkInterval));
if (ci < 0) {
LOGGER.error("checkInterval must be positive. checkInterval set equal to timeToLive = {}", ttl);
ci = ttl;
}
}
return new IdlePurgePolicy(ttl, ci, configuration.getScheduler());
}
use of java.util.concurrent.TimeUnit in project logging-log4j2 by apache.
the class Log4jServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(final ServletContextEvent event) {
if (this.servletContext == null || this.initializer == null) {
LOGGER.warn("Context destroyed before it was initialized.");
return;
}
LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly.");
// the application is finished
this.initializer.clearLoggerContext();
// shutting down now
if (initializer instanceof LifeCycle2) {
final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT : Long.parseLong(stopTimeoutStr);
final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
} else {
this.initializer.stop();
}
}
use of java.util.concurrent.TimeUnit in project lucene-solr by apache.
the class ZkStateReader method waitForState.
/**
* Block until a CollectionStatePredicate returns true, or the wait times out
*
* Note that the predicate may be called again even after it has returned true, so
* implementors should avoid changing state within the predicate call itself.
*
* @param collection the collection to watch
* @param wait how long to wait
* @param unit the units of the wait parameter
* @param predicate the predicate to call on state changes
* @throws InterruptedException on interrupt
* @throws TimeoutException on timeout
*/
public void waitForState(final String collection, long wait, TimeUnit unit, CollectionStatePredicate predicate) throws InterruptedException, TimeoutException {
final CountDownLatch latch = new CountDownLatch(1);
CollectionStateWatcher watcher = (n, c) -> {
boolean matches = predicate.matches(n, c);
if (matches)
latch.countDown();
return matches;
};
registerCollectionStateWatcher(collection, watcher);
try {
// wait for the watcher predicate to return true, or time out
if (!latch.await(wait, unit))
throw new TimeoutException();
} finally {
removeCollectionStateWatcher(collection, watcher);
}
}
Aggregations