
com.xiaomi.infra.galaxy.emq.client.EMQClient Maven / Gradle / Ivy
package com.xiaomi.infra.galaxy.emq.client;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Copyright 2015, Xiaomi.
* All rights reserved.
* Author: [email protected]
*/
public class EMQClient {
private static class EMQClientHandler implements InvocationHandler {
private final Object instance;
public EMQClientHandler(Class interfaceClass, Object instance) {
this.instance = instance;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
EMQRequestCheckUtils.checkRequest(args);
try {
return method.invoke(instance, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
}
/**
* Create client wrapper which validate parameters of client.
*/
@SuppressWarnings("unchecked")
public static T getClient(Class interfaceClass, Object instance) {
return (T) Proxy.newProxyInstance(EMQClient.class.getClassLoader(),
new Class[]{interfaceClass},
new EMQClientHandler(interfaceClass, instance));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy