X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fapi%2Fosgi%2FWaitingServiceTracker.java;h=5cb99d34d4a8afde5c958b4630866d1941e5a2df;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hp=d6abc64dda0571e0014c6f0fa9541844cdd71a9a;hpb=3314dddc5692bed5eb837b0739ac3bb5ed1962ab;p=controller.git diff --git a/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/osgi/WaitingServiceTracker.java b/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/osgi/WaitingServiceTracker.java index d6abc64dda..5cb99d34d4 100644 --- a/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/osgi/WaitingServiceTracker.java +++ b/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/osgi/WaitingServiceTracker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -28,7 +28,7 @@ public final class WaitingServiceTracker implements AutoCloseable { private final ServiceTracker tracker; private final Class serviceInterface; - private WaitingServiceTracker(Class serviceInterface, ServiceTracker tracker) { + private WaitingServiceTracker(final Class serviceInterface, final ServiceTracker tracker) { this.tracker = tracker; this.serviceInterface = serviceInterface; } @@ -36,34 +36,39 @@ public final class WaitingServiceTracker implements AutoCloseable { /** * Waits for an OSGi services. * - * @param timeoutInMillis the timeout in millis + * @param timeoutInMillis + * the timeout in millis * @return the service instance - * @throws ServiceNotFoundException if it times out or is interrupted + * @throws ServiceNotFoundException + * if it times out or is interrupted */ @SuppressWarnings("unchecked") - public T waitForService(long timeoutInMillis) throws ServiceNotFoundException { + public T waitForService(final long timeoutInMillis) throws ServiceNotFoundException { try { T service = (T) tracker.waitForService(timeoutInMillis); - if(service == null) { - throw new ServiceNotFoundException(String.format("OSGi Service %s was not found after %d ms", - serviceInterface, timeoutInMillis)); + if (service == null) { + throw new ServiceNotFoundException( + String.format("OSGi Service %s was not found after %d ms", serviceInterface, timeoutInMillis)); } return service; - } catch(InterruptedException e) { - throw new ServiceNotFoundException(String.format("Wait for OSGi service %s was interrrupted", - serviceInterface)); + } catch (final InterruptedException e) { + throw new ServiceNotFoundException( + String.format("Wait for OSGi service %s was interrrupted", serviceInterface), e); } } /** * Creates an instance. * - * @param serviceInterface the service interface - * @param context the BundleContext + * @param serviceInterface + * the service interface + * @param context + * the BundleContext * @return new WaitingServiceTracker instance */ - public static WaitingServiceTracker create(@Nonnull Class serviceInterface, @Nonnull BundleContext context) { + public static WaitingServiceTracker create(@Nonnull final Class serviceInterface, + @Nonnull final BundleContext context) { ServiceTracker tracker = new ServiceTracker<>(context, serviceInterface, null); tracker.open(); return new WaitingServiceTracker<>(serviceInterface, tracker); @@ -72,31 +77,28 @@ public final class WaitingServiceTracker implements AutoCloseable { /** * Creates an instance. * - * @param serviceInterface the service interface - * @param context the BundleContext - * @param filter the OSGi service filter + * @param serviceInterface + * the service interface + * @param context + * the BundleContext + * @param filter + * the OSGi service filter * @return new WaitingServiceTracker instance */ - public static WaitingServiceTracker create(@Nonnull Class serviceInterface, @Nonnull BundleContext context, - @Nonnull String filter) { + public static WaitingServiceTracker create(@Nonnull final Class serviceInterface, + @Nonnull final BundleContext context, @Nonnull final String filter) { String newFilter = String.format("(&(%s=%s)%s)", Constants.OBJECTCLASS, serviceInterface.getName(), filter); try { ServiceTracker tracker = new ServiceTracker<>(context, context.createFilter(newFilter), null); tracker.open(); return new WaitingServiceTracker<>(serviceInterface, tracker); - } catch(InvalidSyntaxException e) { + } catch (final InvalidSyntaxException e) { throw new IllegalArgumentException(String.format("Invalid OSGi filter %s", newFilter), e); } } @Override public void close() { - try { - tracker.close(); - } catch(RuntimeException e) { - // The ServiceTracker could throw IllegalStateException if the BundleContext is already closed. - // This is benign so ignore it. - LOG.debug("Error closing ServiceTracker", e); - } + tracker.close(); } }