Search in sources :

Example 11 with Var

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();
}
Also used : Path(java.nio.file.Path) Var(com.google.errorprone.annotations.Var)

Example 12 with Var

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);
}
Also used : Timer(org.opendaylight.infrautils.metrics.Timer) Var(com.google.errorprone.annotations.Var) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 13 with Var

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;
    }
}
Also used : Var(com.google.errorprone.annotations.Var) SystemReadyListener(org.opendaylight.infrautils.ready.SystemReadyListener) SystemStateFailureException(org.opendaylight.odlparent.bundlestest.lib.SystemStateFailureException)

Example 14 with Var

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());
}
Also used : Var(com.google.errorprone.annotations.Var) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with Var

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;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Var(com.google.errorprone.annotations.Var) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

Var (com.google.errorprone.annotations.Var)37 Test (org.junit.Test)9 Path (java.nio.file.Path)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ObjectName (javax.management.ObjectName)6 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)4 Nullable (javax.annotation.Nullable)4 MBeanException (javax.management.MBeanException)4 MBeanServer (javax.management.MBeanServer)4 ReflectionException (javax.management.ReflectionException)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 IOException (java.io.IOException)3 AccessibleObject (java.lang.reflect.AccessibleObject)3 ClassPath (com.google.common.reflect.ClassPath)2 EqualsTester (com.google.common.testing.EqualsTester)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2