X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Futil%2FOsgiRegistrationUtil.java;h=607cf49db9c02cf770a747a839cce715a52ade5a;hp=4f792e72b10ccb826acb99c3d4117b071bdeef84;hb=cbcc2b61265e903959f11d44c292771e76b3926e;hpb=5448d6812e386bd56aec7209c4852c586a6163b3 diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java index 4f792e72b1..607cf49db9 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java @@ -20,7 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class OsgiRegistrationUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(OsgiRegistrationUtil.class); + private static final Logger LOG = LoggerFactory.getLogger(OsgiRegistrationUtil.class); private OsgiRegistrationUtil() { } @@ -39,32 +39,17 @@ public class OsgiRegistrationUtil { public static AutoCloseable wrap(final ServiceRegistration reg) { checkNotNull(reg); - return new AutoCloseable() { - @Override - public void close() throws Exception { - reg.unregister(); - } - }; + return reg::unregister; } public static AutoCloseable wrap(final BundleTracker bundleTracker) { checkNotNull(bundleTracker); - return new AutoCloseable() { - @Override - public void close() throws Exception { - bundleTracker.close(); - } - }; + return bundleTracker::close; } public static AutoCloseable wrap(final ServiceTracker serviceTracker) { checkNotNull(serviceTracker); - return new AutoCloseable() { - @Override - public void close() throws Exception { - serviceTracker.close(); - } - }; + return serviceTracker::close; } /** @@ -73,26 +58,23 @@ public class OsgiRegistrationUtil { public static AutoCloseable aggregate(final List list) { checkNotNull(list); - return new AutoCloseable() { - @Override - public void close() throws Exception { - Exception firstException = null; - for (ListIterator it = list.listIterator(list.size()); it.hasPrevious();) { - AutoCloseable ac = it.previous(); - try { - ac.close(); - } catch (Exception e) { - LOGGER.warn("Exception while closing {}", ac, e); - if (firstException == null) { - firstException = e; - } else { - firstException.addSuppressed(e); - } + return () -> { + Exception firstException = null; + for (ListIterator it = list.listIterator(list.size()); it.hasPrevious();) { + AutoCloseable ac = it.previous(); + try { + ac.close(); + } catch (final Exception e) { + LOG.warn("Exception while closing {}", ac, e); + if (firstException == null) { + firstException = e; + } else { + firstException.addSuppressed(e); } } - if (firstException != null) { - throw firstException; - } + } + if (firstException != null) { + throw firstException; } }; }