Example usage for com.google.common.reflect Reflection newProxy

List of usage examples for com.google.common.reflect Reflection newProxy

Introduction

In this page you can find the example usage for com.google.common.reflect Reflection newProxy.

Prototype

public static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) 

Source Link

Document

Returns a proxy instance that implements interfaceType by dispatching method invocations to handler .

Usage

From source file:edu.jhu.hlt.concrete.metadata.AnnotationMetadatable.java

static AnnotationMetadatable proxy(Object o) {
    return Reflection.newProxy(AnnotationMetadatable.class, (object, method, args) -> method.invoke(o, args));
}

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  av  a  2  s. co m*/
        protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
            return method.invoke(target, args);
        }
    });
}

From source file:org.nickelproject.util.RetryProxy.java

public static <T> T newInstance(final Class<T> pClass, final T obj) {
    return Reflection.newProxy(pClass, new RetryProxy<T>(obj, LoggerFactory.getLogger(pClass)));
}

From source file:com.newlandframework.rpc.netty.MessageSendExecutor.java

public static <T> T execute(Class<T> rpcInterface) {
    return (T) Reflection.newProxy(rpcInterface, new MessageSendProxy<T>());
}

From source file:org.grycap.gpf4med.reflect.ProxyFactory.java

/**
 * Creates a proxy to the {@link Gpf4MedResource} resource that internally maps method 
 * calls to a set of replicas in the available servers. Exceptionally, some of the methods
 * can be attended by a local instance of the resource (e.g. methods that list the status
 * of the service)./*from   w  ww  .j a v a 2s  . co m*/
 * @param executorService the pool of threads that will be used to execute the methods.
 * @return a proxy to the {@link Gpf4MedResource} resource.
 */
public static Gpf4MedResource newGpf4MedResourceProxy(final ListeningExecutorService executorService) {
    return Reflection.newProxy(Gpf4MedResource.class, new Gpf4MedHandler(executorService));
}

From source file:de.uniulm.omi.cloudiator.sword.drivers.openstack4j.internal.Openstack4jClientProvider.java

@Override
public OSClient get() {
    return Reflection.newProxy(keyStoneVersion.osClientClass(),
            injector.getInstance(LazyAuthenticationOSClient.class));
}

From source file:zipkin.autoconfigure.storage.cassandra.brave.TracedSession.java

public static Session create(Session target, Brave brave, SpanCollector collector) {
    return Reflection.newProxy(Session.class, new TracedSession(target, brave, collector));
}

From source file:org.grycap.gpf4med.reflect.ProxyFactory.java

/**
 * Creates a proxy to a resource that internally maps the method calls to a set of
 * replicas in the available servers./*from   w w w . j a  v a2 s  .c om*/
 * @param type the interface where the resource is defined, including REST annotations.
 * @param executorService the pool of threads that will be used to execute the methods.
 * @return a proxy to the resource.
 */
public static <T> T newResourceProxy(final Class<T> type, final ListeningExecutorService executorService) {
    checkArgument(type != null, "Uninitialized type");
    checkArgument(type.isAnnotationPresent(Path.class),
            "No @Path annotation found, type must be a REST resource");
    return Reflection.newProxy(type, new AsyncHandler<T>(executorService, type));
}

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  ww  w.j  a v a  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:com.infinities.skyport.async.impl.service.AsyncStorageServicesImpl.java

public AsyncStorageServicesImpl(String configurationId, ServiceProvider inner,
        StorageConfiguration configuration, DistributedThreadPool threadPools) throws ConcurrentException {
    this.inner = inner.getSkyportStorageServices();
    if (this.inner.hasOfflineStorageSupport()) {
        this.asyncOfflineStoreSupport = Reflection.newProxy(AsyncOfflineStoreSupport.class,
                new AsyncHandler(configurationId, TaskType.OfflineStoreSupport, inner, threadPools,
                        configuration.getOfflineStoreConfiguration()));
    }/* w  w w . j a  v  a  2s  .  c om*/
    if (this.inner.hasOnlineStorageSupport()) {
        this.asyncBlobStoreSupport = Reflection.newProxy(AsyncBlobStoreSupport.class,
                new AsyncHandler(configurationId, TaskType.BlobStoreSupport, inner, threadPools,
                        configuration.getOnlineStorageConfiguration()));
    }
}