On Thu, Mar 27, 2014 at 2:30 PM, Julian Reschke <[email protected]> wrote:
> I created the first one, and use it occasionally for debugging. (it's
> similar to the Logging*Wrapper. Please do not remove.
Okie but there already one preset in Util. Are they different? If not
we should keep only one
> Example?
Something like
public class SynchronizedDocumentStoreWrapper2 {
public static DocumentStore create(DocumentStore documentStore){
return (DocumentStore) Proxy.newProxyInstance(
SynchronizedDocumentStoreWrapper2.class.getClassLoader(),
new Class[] {DocumentStore.class},
new DocumentStoreProxy(documentStore));
}
private static class DocumentStoreProxy implements InvocationHandler {
private final DocumentStore delegate;
private final Object lock = new Object();
private DocumentStoreProxy(DocumentStore delegate) {
this.delegate = delegate;
}
@Override
public Object invoke(Object proxy, Method method, Object[]
args) throws Throwable {
synchronized (lock){
return method.invoke(delegate, args);
}
}
}
}
Chetan Mehrotra