All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaomi.infra.galaxy.talos.client.TalosClient Maven / Gradle / Ivy

There is a newer version: 2.6.1.4
Show newest version
/**
 * Copyright 2015, Xiaomi.
 * All rights reserved.
 * Author: [email protected]
 */

package com.xiaomi.infra.galaxy.talos.client;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class TalosClient {

  private static class TalosClientHandler implements InvocationHandler {
    private final Object instance;

    public TalosClientHandler(Class interfaceClass, Object instance) {
      this.instance = instance;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
      try {
        return method.invoke(instance, args);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      }
    }
  }

  @SuppressWarnings("unchecked")
  public static  T getClient(Class interfaceClass, Object instance) {
    return (T) Proxy.newProxyInstance(TalosClient.class.getClassLoader(),
        new Class[]{ interfaceClass },
        new TalosClientHandler(interfaceClass, instance));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy