use of com.google.errorprone.annotations.Var in project java-common-lib by sosy-lab.
the class NativeLibraries method findPathForLibrary.
/**
* Search for a native library in some directories as listed in the documentation of {@link
* NativeLibraries}.
*
* @param libraryName A library name as for {@link System#loadLibrary(String)}.
* @return Found path or {@code Optional.absent()}
*/
// will become private
@Deprecated
public static Optional<Path> findPathForLibrary(String libraryName) {
String osLibName = System.mapLibraryName(libraryName);
@Var Path p = getNativeLibraryPath().resolve(osLibName).toAbsolutePath();
if (Files.exists(p)) {
return Optional.of(p);
}
p = getPathToJar().resolve(osLibName).toAbsolutePath();
if (Files.exists(p)) {
return Optional.of(p);
}
return Optional.empty();
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class MetricProviderTest method testTimeCallableWithLabels.
@Test
public void testTimeCallableWithLabels() {
Labeled<Labeled<Timer>> timerWithTwoLabels = metrics.newTimer(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_timer_with_labels").build(), "l1", "l2");
Timer timerA = timerWithTwoLabels.label("l1value").label("l2value");
assertThat(timerA.time(() -> {
@Var int sum = 0;
for (int i = 1; i < 101; i++) {
sum += i;
}
return sum;
})).isEqualTo(5050);
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class SystemReadyImpl method run.
@Override
// below
@SuppressWarnings("checkstyle:IllegalCatch")
public void run() {
try {
// 5 minutes really ought to be enough for the whole circus to completely boot up?!
testBundleDiag.checkBundleDiagInfos(5, TimeUnit.MINUTES, (timeInfo, bundleDiagInfos) -> LOG.info("checkBundleDiagInfos: Elapsed time {}s, remaining time {}s, {}", timeInfo.getElapsedTimeInMS() / 1000, timeInfo.getRemainingTimeInMS() / 1000, // INFRAUTILS-17: getSummaryText() instead getFullDiagnosticText() because ppl found log confusing
bundleDiagInfos.getSummaryText()));
currentSystemState.set(ACTIVE);
LOG.info("System ready; AKA: Aye captain, all warp coils are now operating at peak efficiency! [M.]");
if (!listeners.isEmpty()) {
LOG.info("Now notifying all its registered SystemReadyListeners...");
}
@Var SystemReadyListener listener;
while ((listener = listeners.poll()) != null) {
listener.onSystemBootReady();
}
} catch (SystemStateFailureException e) {
LOG.error("Failed, some bundles did not start (SystemReadyListeners are not called)", e);
currentSystemState.set(FAILURE);
// We do not re-throw this
} catch (RuntimeException throwable) {
// It's exceptionally OK to catch RuntimeException here,
// because we do want to set the currentFullSystemStatus
LOG.error("Failed unexpectedly (SystemReadyListeners are not called)", throwable);
currentSystemState.set(FAILURE);
// and now we do re-throw it!
throw throwable;
}
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class KeyedLocksTest method testTryLock.
@Test(timeout = 20000)
public void testTryLock() throws InterruptedException {
@Var boolean locked = keyedLocks.tryLock(KEY1);
assertTrue("Expected tryLock to return true", locked);
assertEquals("KeyedLock size", 1, keyedLocks.size());
keyedLocks.unlock(KEY1);
assertEquals("KeyedLock size", 0, keyedLocks.size());
locked = keyedLocks.tryLock(KEY1, 200, TimeUnit.MILLISECONDS);
assertTrue("Expected tryLock to return true", locked);
assertEquals("KeyedLock size", 1, keyedLocks.size());
AtomicReference<Throwable> uncaughtException = new AtomicReference<>();
CountDownLatch thread1AtTryLock = new CountDownLatch(1);
Thread thread1 = new Thread(() -> {
thread1AtTryLock.countDown();
boolean threadLockedA = keyedLocks.tryLock(KEY1);
assertFalse("Expected tryLock to return false", threadLockedA);
assertEquals("KeyedLock size", 1, keyedLocks.size());
boolean threadLockedB = keyedLocks.tryLock(KEY1, 200, TimeUnit.MILLISECONDS);
assertFalse("Expected tryLock to return false", threadLockedB);
assertEquals("KeyedLock size", 1, keyedLocks.size());
});
thread1.setUncaughtExceptionHandler((th, ex) -> uncaughtException.set(ex));
thread1.start();
assertTrue("Thread 2 did not reach tryLock", thread1AtTryLock.await(3, TimeUnit.SECONDS));
thread1.join(3000);
assertEquals("Thread isAlive", false, thread1.isAlive());
if (uncaughtException.get() != null) {
throw new AssertionError("Thread threw exception", uncaughtException.get());
}
keyedLocks.unlock(KEY1);
assertEquals("KeyedLock size", 0, keyedLocks.size());
}
use of com.google.errorprone.annotations.Var in project infrautils by opendaylight.
the class AbstractMXBean method unregisterMBean.
/**
* Unregisters this bean with the platform MBean server.
*
* @return true is successfully unregistered, false otherwise.
*/
protected boolean unregisterMBean() {
@Var boolean unregister = false;
try {
ObjectName mbeanobjectname = this.getMBeanObjectName();
unregisterMBean(mbeanobjectname);
unregister = true;
} catch (InstanceNotFoundException | MBeanRegistrationException | MalformedObjectNameException e) {
LOG.debug("Failed when unregistering MBean {}", e);
}
return unregister;
}
Aggregations