@SuppressWarnings("unchecked")
public<T> T getProxy(ObjectName name, Class<T> type) {
Reference r = proxies.get(name);
T proxy = (r != null) ? (T) r.get() : null;
if (proxy == null) {
MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
factory.setServer(server);
try {
factory.setObjectName(name.toString());
} catch (MalformedObjectNameException e) {
throw new IllegalStateException(e);
}
factory.setProxyInterface(type);
factory.setUseStrictCasing(false);
factory.afterPropertiesSet();
proxy = (T) factory.getObject();
proxies.put(name, new SoftReference<Object>(proxy));
}
return proxy;
}