![JAR search and dependency download from the Maven repository](/logo.png)
org.oxerr.rescu.ext.singleton.RestProxyFactorySingletonImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rescu-ext-singleton Show documentation
Show all versions of rescu-ext-singleton Show documentation
Add singleton support for ResCU.
The newest version!
package org.oxerr.rescu.ext.singleton;
import java.util.HashMap;
import java.util.Map;
import org.oxerr.rescu.ext.proxy.auth.ProxyAuthenticationSupportedRestProxyFactoryImpl;
import si.mazi.rescu.ClientConfig;
import si.mazi.rescu.IRestProxyFactory;
import si.mazi.rescu.Interceptor;
public class RestProxyFactorySingletonImpl implements IRestProxyFactory {
private final IRestProxyFactory restProxyFactory;
private final Map, Object> cache = new HashMap<>();
public RestProxyFactorySingletonImpl(IRestProxyFactory restProxyFactory) {
this.restProxyFactory = new ProxyAuthenticationSupportedRestProxyFactoryImpl(restProxyFactory);
}
@SuppressWarnings("unchecked")
@Override
public I createProxy(Class restInterface, String baseUrl, ClientConfig config, Interceptor... interceptors) {
I i = (I) this.cache.get(restInterface);
if (i == null) {
i = this.restProxyFactory.createProxy(restInterface, baseUrl, config, interceptors);
synchronized (this.cache) {
I previous = (I) this.cache.putIfAbsent(restInterface, i);
if (previous != null) {
i = previous;
}
}
}
return i;
}
@SuppressWarnings("unchecked")
@Override
public I createProxy(Class restInterface, String baseUrl) {
I i = (I) this.cache.get(restInterface);
if (i == null) {
i = this.restProxyFactory.createProxy(restInterface, baseUrl);
synchronized (this.cache) {
I previous = (I) this.cache.putIfAbsent(restInterface, i);
if (previous != null) {
i = previous;
}
}
}
return i;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy