List of usage examples for com.google.common.reflect AbstractInvocationHandler AbstractInvocationHandler
AbstractInvocationHandler
From source file:me.yanaga.winter.data.jpa.proxy.ProxyFactory.java
public static <T> T newProxy(Object target, Class<T> targetInterface) { return Reflection.newProxy(targetInterface, new AbstractInvocationHandler() { @Override//w w w.j a v a2 s . c om protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { return method.invoke(target, args); } }); }
From source file:org.opendaylight.controller.config.yang.config.legacy_entity_ownership_service_provider.LegacyEntityOwnershipServiceProviderModule.java
@Override public AutoCloseable createInstance() { final WaitingServiceTracker<EntityOwnershipService> tracker = WaitingServiceTracker .create(EntityOwnershipService.class, bundleContext); final EntityOwnershipService service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); return Reflection.newProxy(AutoCloseableEntityOwnershipService.class, new AbstractInvocationHandler() { @Override/*from www . java 2s .c o m*/ protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
From source file:org.opendaylight.controller.config.yang.pcep.impl.PCEPDispatcherImplModule.java
@Override public AutoCloseable createInstance() { final WaitingServiceTracker<PCEPDispatcher> tracker = WaitingServiceTracker.create(PCEPDispatcher.class, bundleContext);/* w ww. j a v a2 s. co m*/ final PCEPDispatcher service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); return Reflection.newProxy(AutoCloseablePCEPDispatcher.class, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
From source file:org.opendaylight.controller.config.yang.bgp.rib.impl.StrictBgpPeerRegistryModule.java
@Override public java.lang.AutoCloseable createInstance() { final WaitingServiceTracker<BGPPeerRegistry> tracker = WaitingServiceTracker.create(BGPPeerRegistry.class, this.bundleContext); final BGPPeerRegistry service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); return Reflection.newProxy(BGPPeerRegistry.class, new AbstractInvocationHandler() { @Override/*from w w w. j a v a2 s .c o m*/ protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
@Override public AutoCloseable createInstance() { final WaitingServiceTracker<ClusterSingletonServiceProvider> tracker = WaitingServiceTracker .create(ClusterSingletonServiceProvider.class, bundleContext); final ClusterSingletonServiceProvider service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); // Create a proxy to override close to close the ServiceTracker. The actual DOMClusterSingletonServiceProvider // instance will be closed via blueprint. return Reflection.newProxy(AutoCloseableDOMClusterSingletonServiceProvider.class, new AbstractInvocationHandler() { @Override/*from www .java 2s . c o m*/ protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
From source file:org.opendaylight.controller.config.yang.bmp.impl.BmpDispatcherImplModule.java
@Override public AutoCloseable createInstance() { // The BmpDispatcher instance is created and advertised as an OSGi service via blueprint // so obtain it here (waiting if necessary). final WaitingServiceTracker<BmpDispatcher> tracker = WaitingServiceTracker.create(BmpDispatcher.class, bundleContext);//from w ww. j a v a 2 s .c om final BmpDispatcher service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); // Create a proxy to override close to close the ServiceTracker. The actual BmpDispatcher // instance will be closed via blueprint. return Reflection.newProxy(BmpDispatcher.class, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
From source file:org.opendaylight.controller.config.yang.bgp.rib.impl.BGPDispatcherImplModule.java
@Override public AutoCloseable createInstance() { // The BGPDispatcher instance is created and advertised as an OSGi service via blueprint // so obtain it here (waiting if necessary). final WaitingServiceTracker<BGPDispatcher> tracker = WaitingServiceTracker.create(BGPDispatcher.class, bundleContext);/*from ww w.ja va2 s.co m*/ final BGPDispatcher service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); // Create a proxy to override close to close the ServiceTracker. The actual BGPDispatcher // instance will be closed via blueprint. return Reflection.newProxy(AutoCloseableBGPDispatcher.class, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }
From source file:org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModule.java
@Override public AutoCloseable createInstance() { // The service is provided via blueprint so wait for and return it here for backwards compatibility. String typeFilter = String.format("(type=%s)", getIdentifier().getInstanceName()); final WaitingServiceTracker<EventLoopGroup> tracker = WaitingServiceTracker.create(EventLoopGroup.class, bundleContext, typeFilter);//from w ww . j av a2 s. c o m final EventLoopGroup group = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); return Reflection.newProxy(AutoCloseableEventLoopGroupInterface.class, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(group, args); } } }); }
From source file:org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerModule.java
@Override public AutoCloseable createInstance() { // The service is provided via blueprint so wait for and return it here for backwards compatibility. final WaitingServiceTracker<Timer> tracker = WaitingServiceTracker.create(Timer.class, bundleContext, "(type=global-timer)"); final Timer timer = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); return Reflection.newProxy(AutoCloseableTimerInterface.class, new AbstractInvocationHandler() { @Override//from w w w . ja v a 2s . co m protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(timer, args); } } }); }
From source file:org.opendaylight.controller.config.yang.bgp.rib.spi.RIBExtensionsImplModule.java
@Override public AutoCloseable createInstance() { // The RIBExtensionProviderContext instance is created and advertised as an OSGi service via blueprint // so obtain it here (waiting if necessary). final WaitingServiceTracker<RIBExtensionProviderContext> tracker = WaitingServiceTracker .create(RIBExtensionProviderContext.class, bundleContext); final RIBExtensionProviderContext service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES); // Create a proxy to override close to close the ServiceTracker. The actual RIBExtensionProviderContext // instance will be closed via blueprint. return Reflection.newProxy(AutoCloseableRIBExtensionProviderContext.class, new AbstractInvocationHandler() { @Override/*w ww . j a v a 2 s. c o m*/ protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("close")) { tracker.close(); return null; } else { return method.invoke(service, args); } } }); }