Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.distributeme.test.list.generated.RemoteListServiceStub Maven / Gradle / Ivy
package org.distributeme.test.list.generated;
//BEGIN GENERATED CODE
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import java.rmi.RemoteException;
import java.rmi.NotBoundException;
import org.distributeme.core.RegistryUtil;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import org.distributeme.core.ServiceDescriptor;
import org.distributeme.core.ServiceDescriptor.Protocol;
import org.distributeme.core.DiscoveryMode;
import org.distributeme.core.failing.FailingStrategy;
import org.distributeme.core.concurrencycontrol.ConcurrencyControlStrategy;
import org.distributeme.core.failing.FailDecision;
import org.distributeme.core.ClientSideCallContext;
import org.distributeme.core.exception.DistributemeRuntimeException;
import org.distributeme.core.exception.NoConnectionToServerException;
import org.distributeme.core.exception.ServiceUnavailableException;
import org.distributeme.core.Defaults;
import org.distributeme.core.interceptor.ClientSideRequestInterceptor;
import org.distributeme.core.interceptor.InterceptorRegistry;
import org.distributeme.core.interceptor.InterceptorResponse;
import org.distributeme.core.interceptor.InterceptionContext;
import org.distributeme.core.interceptor.InterceptionPhase;
import org.distributeme.core.interceptor.FailedByInterceptorException;
@SuppressWarnings("PMD")
public class RemoteListServiceStub implements org.distributeme.test.list.ListService{
private volatile ConcurrentMap delegates = new ConcurrentHashMap();
private DiscoveryMode discoveryMode = DiscoveryMode.AUTO;
// ROUTER DECL V2
// Class wide router
private final org.distributeme.core.routing.Router clazzWideRouter = createRouterInstance11();
// Method wide routers if applicable
// Method wide routers END
// ROUTER DECL V2 end
// Failing
// Class wide failing strategy
private FailingStrategy clazzWideFailingStrategy = (FailingStrategy) clazzWideRouter;
private FailingStrategy getListObjectFailingStrategy_orgdistributemetestlistListObjectIdid = clazzWideFailingStrategy;
private FailingStrategy getListObjectsFailingStrategy = clazzWideFailingStrategy;
private FailingStrategy getSomeListObjectsFailingStrategy_javautilCollectionids = clazzWideFailingStrategy;
private FailingStrategy getListObjectsShardedFailingStrategy = clazzWideFailingStrategy;
private FailingStrategy getSomeListObjectsShardedFailingStrategy_javautilCollectionids = clazzWideFailingStrategy;
// Failing end
// CONCURRENCY CONTROL
// Class wide concurrency control strategy
private ConcurrencyControlStrategy clazzWideCCStrategy = Defaults.getDefaultConcurrencyControlStrategy();
private ConcurrencyControlStrategy getListObjectCCStrategy_orgdistributemetestlistListObjectIdid = clazzWideCCStrategy;
private ConcurrencyControlStrategy getListObjectsCCStrategy = clazzWideCCStrategy;
private ConcurrencyControlStrategy getSomeListObjectsCCStrategy_javautilCollectionids = clazzWideCCStrategy;
private ConcurrencyControlStrategy getListObjectsShardedCCStrategy = clazzWideCCStrategy;
private ConcurrencyControlStrategy getSomeListObjectsShardedCCStrategy_javautilCollectionids = clazzWideCCStrategy;
// CONCURRENCY CONTROL end
public RemoteListServiceStub(){
discoveryMode = DiscoveryMode.AUTO;
}
private ServiceDescriptor manuallySetDescriptor;
private RemoteListService manuallySetTarget;
public RemoteListServiceStub(ServiceDescriptor target){
discoveryMode = DiscoveryMode.MANUAL;
manuallySetDescriptor = target;
try{
manuallySetTarget = lookup(manuallySetDescriptor);
}catch(NoConnectionToServerException e){
throw new IllegalStateException("Can not resolve manually set reference", e);
}
}
public org.distributeme.test.list.ListObject getListObject(org.distributeme.test.list.ListObjectId id){
return getListObject(id, (ClientSideCallContext)null);
} //...public org.distributeme.test.list.ListObject getListObject(org.distributeme.test.list.ListObjectId id)
private org.distributeme.test.list.ListObject getListObject(org.distributeme.test.list.ListObjectId id, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;
Exception exceptionInMethod = null;
// This flag is used by the interceptor logic to mark a request es failed, even it is not.
boolean diMeForceFailing = false;
boolean abortAndFail = false;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("getListObject");
if (discoveryMode == DiscoveryMode.MANUAL) {
diMeCallContext.setServiceId(manuallySetDescriptor.getServiceId());
}
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ListServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
getListObjectCCStrategy_orgdistributemetestlistListObjectIdid.notifyClientSideCallStarted(diMeCallContext);
try{
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(id);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVICE_CALL);
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (org.distributeme.test.list.ListObject) interceptorResponse.getReturnValue();
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
exceptionInMethod = new FailedByInterceptorException();
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
diMeForceFailing = true;
exceptionInMethod = new FailedByInterceptorException();
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// parse parameters again in case an interceptor modified them
id = (org.distributeme.test.list.ListObjectId) diMeParameters.get(0);
if (!abortAndFail){
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).getListObject(id, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return (org.distributeme.test.list.ListObject) __fromServerSide.get(0);
}
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
getListObjectCCStrategy_orgdistributemetestlistListObjectIdid.notifyClientSideCallFinished(diMeCallContext);
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVICE_CALL);
if (__fromServerSide!=null){
diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
}
diMeInterceptionContext.setException(exceptionInMethod);
boolean diMeReturnOverriden = false;
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (org.distributeme.test.list.ListObject) interceptorResponse.getReturnValue();
case OVERWRITE_RETURN_AND_CONTINUE:
if (__fromServerSide == null)
throw new AssertionError("Incorrect use of interceptor, there is no return value in this method or it is null");
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
getListObjectFailingStrategy_orgdistributemetestlistListObjectIdid.callFailed(diMeCallContext);
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// The next check for null of __fromServerSide is unneeded but for security reasons.
if (diMeReturnOverriden && __fromServerSide!=null)
return (org.distributeme.test.list.ListObject) __fromServerSide.get(0);
} //...finally
// Failing
if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
FailDecision failDecision = getListObjectFailingStrategy_orgdistributemetestlistListObjectIdid.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return getListObject(id, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return getListObject(id, diMeCallContext.increaseCallCount());
case FAIL:
default:
// Fail or default is to do nothing at all and let the request fail
} //...switch(failDecision)
}
// fail through, if we are here, we must have had an exception before.
if (exceptionInMethod == null)
throw new AssertionError("Exception must have been thrown before, but it wasn't, framework error!");
throw mapException(exceptionInMethod);
}
public java.util.Collection getListObjects(){
return getListObjects((ClientSideCallContext)null);
} //...public java.util.Collection getListObjects()
private java.util.Collection getListObjects(org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;
Exception exceptionInMethod = null;
// This flag is used by the interceptor logic to mark a request es failed, even it is not.
boolean diMeForceFailing = false;
boolean abortAndFail = false;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("getListObjects");
if (discoveryMode == DiscoveryMode.MANUAL) {
diMeCallContext.setServiceId(manuallySetDescriptor.getServiceId());
}
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ListServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
getListObjectsCCStrategy.notifyClientSideCallStarted(diMeCallContext);
try{
ArrayList diMeParameters = new ArrayList();
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVICE_CALL);
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
exceptionInMethod = new FailedByInterceptorException();
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
diMeForceFailing = true;
exceptionInMethod = new FailedByInterceptorException();
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// parse parameters again in case an interceptor modified them
if (!abortAndFail){
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).getListObjects( __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return (java.util.Collection) __fromServerSide.get(0);
}
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
getListObjectsCCStrategy.notifyClientSideCallFinished(diMeCallContext);
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVICE_CALL);
if (__fromServerSide!=null){
diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
}
diMeInterceptionContext.setException(exceptionInMethod);
boolean diMeReturnOverriden = false;
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case OVERWRITE_RETURN_AND_CONTINUE:
if (__fromServerSide == null)
throw new AssertionError("Incorrect use of interceptor, there is no return value in this method or it is null");
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
getListObjectsFailingStrategy.callFailed(diMeCallContext);
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// The next check for null of __fromServerSide is unneeded but for security reasons.
if (diMeReturnOverriden && __fromServerSide!=null)
return (java.util.Collection) __fromServerSide.get(0);
} //...finally
// Failing
if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
FailDecision failDecision = getListObjectsFailingStrategy.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return getListObjects(diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return getListObjects(diMeCallContext.increaseCallCount());
case FAIL:
default:
// Fail or default is to do nothing at all and let the request fail
} //...switch(failDecision)
}
// fail through, if we are here, we must have had an exception before.
if (exceptionInMethod == null)
throw new AssertionError("Exception must have been thrown before, but it wasn't, framework error!");
throw mapException(exceptionInMethod);
}
public java.util.Collection getSomeListObjects(java.util.Collection ids){
return getSomeListObjects(ids, (ClientSideCallContext)null);
} //...public java.util.Collection getSomeListObjects(java.util.Collection ids)
private java.util.Collection getSomeListObjects(java.util.Collection ids, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;
Exception exceptionInMethod = null;
// This flag is used by the interceptor logic to mark a request es failed, even it is not.
boolean diMeForceFailing = false;
boolean abortAndFail = false;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("getSomeListObjects");
if (discoveryMode == DiscoveryMode.MANUAL) {
diMeCallContext.setServiceId(manuallySetDescriptor.getServiceId());
}
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ListServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
getSomeListObjectsCCStrategy_javautilCollectionids.notifyClientSideCallStarted(diMeCallContext);
try{
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(ids);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVICE_CALL);
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
exceptionInMethod = new FailedByInterceptorException();
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
diMeForceFailing = true;
exceptionInMethod = new FailedByInterceptorException();
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// parse parameters again in case an interceptor modified them
ids = (java.util.Collection) diMeParameters.get(0);
if (!abortAndFail){
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).getSomeListObjects(ids, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return (java.util.Collection) __fromServerSide.get(0);
}
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
getSomeListObjectsCCStrategy_javautilCollectionids.notifyClientSideCallFinished(diMeCallContext);
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVICE_CALL);
if (__fromServerSide!=null){
diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
}
diMeInterceptionContext.setException(exceptionInMethod);
boolean diMeReturnOverriden = false;
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case OVERWRITE_RETURN_AND_CONTINUE:
if (__fromServerSide == null)
throw new AssertionError("Incorrect use of interceptor, there is no return value in this method or it is null");
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
getSomeListObjectsFailingStrategy_javautilCollectionids.callFailed(diMeCallContext);
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// The next check for null of __fromServerSide is unneeded but for security reasons.
if (diMeReturnOverriden && __fromServerSide!=null)
return (java.util.Collection) __fromServerSide.get(0);
} //...finally
// Failing
if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
FailDecision failDecision = getSomeListObjectsFailingStrategy_javautilCollectionids.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return getSomeListObjects(ids, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return getSomeListObjects(ids, diMeCallContext.increaseCallCount());
case FAIL:
default:
// Fail or default is to do nothing at all and let the request fail
} //...switch(failDecision)
}
// fail through, if we are here, we must have had an exception before.
if (exceptionInMethod == null)
throw new AssertionError("Exception must have been thrown before, but it wasn't, framework error!");
throw mapException(exceptionInMethod);
}
public java.util.Collection getListObjectsSharded(){
return getListObjectsSharded((ClientSideCallContext)null);
} //...public java.util.Collection getListObjectsSharded()
private java.util.Collection getListObjectsSharded(org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;
Exception exceptionInMethod = null;
// This flag is used by the interceptor logic to mark a request es failed, even it is not.
boolean diMeForceFailing = false;
boolean abortAndFail = false;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("getListObjectsSharded");
if (discoveryMode == DiscoveryMode.MANUAL) {
diMeCallContext.setServiceId(manuallySetDescriptor.getServiceId());
}
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ListServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
getListObjectsShardedCCStrategy.notifyClientSideCallStarted(diMeCallContext);
try{
ArrayList diMeParameters = new ArrayList();
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVICE_CALL);
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
exceptionInMethod = new FailedByInterceptorException();
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
diMeForceFailing = true;
exceptionInMethod = new FailedByInterceptorException();
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// parse parameters again in case an interceptor modified them
if (!abortAndFail){
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).getListObjectsSharded( __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return (java.util.Collection) __fromServerSide.get(0);
}
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
getListObjectsShardedCCStrategy.notifyClientSideCallFinished(diMeCallContext);
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVICE_CALL);
if (__fromServerSide!=null){
diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
}
diMeInterceptionContext.setException(exceptionInMethod);
boolean diMeReturnOverriden = false;
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case OVERWRITE_RETURN_AND_CONTINUE:
if (__fromServerSide == null)
throw new AssertionError("Incorrect use of interceptor, there is no return value in this method or it is null");
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
getListObjectsShardedFailingStrategy.callFailed(diMeCallContext);
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// The next check for null of __fromServerSide is unneeded but for security reasons.
if (diMeReturnOverriden && __fromServerSide!=null)
return (java.util.Collection) __fromServerSide.get(0);
} //...finally
// Failing
if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
FailDecision failDecision = getListObjectsShardedFailingStrategy.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return getListObjectsSharded(diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return getListObjectsSharded(diMeCallContext.increaseCallCount());
case FAIL:
default:
// Fail or default is to do nothing at all and let the request fail
} //...switch(failDecision)
}
// fail through, if we are here, we must have had an exception before.
if (exceptionInMethod == null)
throw new AssertionError("Exception must have been thrown before, but it wasn't, framework error!");
throw mapException(exceptionInMethod);
}
public java.util.Collection getSomeListObjectsSharded(java.util.Collection ids){
return getSomeListObjectsSharded(ids, (ClientSideCallContext)null);
} //...public java.util.Collection getSomeListObjectsSharded(java.util.Collection ids)
private java.util.Collection getSomeListObjectsSharded(java.util.Collection ids, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;
Exception exceptionInMethod = null;
// This flag is used by the interceptor logic to mark a request es failed, even it is not.
boolean diMeForceFailing = false;
boolean abortAndFail = false;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("getSomeListObjectsSharded");
if (discoveryMode == DiscoveryMode.MANUAL) {
diMeCallContext.setServiceId(manuallySetDescriptor.getServiceId());
}
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ListServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
getSomeListObjectsShardedCCStrategy_javautilCollectionids.notifyClientSideCallStarted(diMeCallContext);
try{
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(ids);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVICE_CALL);
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
exceptionInMethod = new FailedByInterceptorException();
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
diMeForceFailing = true;
exceptionInMethod = new FailedByInterceptorException();
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// parse parameters again in case an interceptor modified them
ids = (java.util.Collection) diMeParameters.get(0);
if (!abortAndFail){
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).getSomeListObjectsSharded(ids, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return (java.util.Collection) __fromServerSide.get(0);
}
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
getSomeListObjectsShardedCCStrategy_javautilCollectionids.notifyClientSideCallFinished(diMeCallContext);
diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVICE_CALL);
if (__fromServerSide!=null){
diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
}
diMeInterceptionContext.setException(exceptionInMethod);
boolean diMeReturnOverriden = false;
for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContext, diMeInterceptionContext);
switch(interceptorResponse.getCommand()){
case ABORT:
if (interceptorResponse.getException() instanceof RuntimeException)
throw (RuntimeException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return (java.util.Collection) interceptorResponse.getReturnValue();
case OVERWRITE_RETURN_AND_CONTINUE:
if (__fromServerSide == null)
throw new AssertionError("Incorrect use of interceptor, there is no return value in this method or it is null");
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
case ABORT_AND_FAIL:
abortAndFail = true;
break;
case RETURN_AND_FAIL:
// Force failing logic to work.
getSomeListObjectsShardedFailingStrategy_javautilCollectionids.callFailed(diMeCallContext);
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// The next check for null of __fromServerSide is unneeded but for security reasons.
if (diMeReturnOverriden && __fromServerSide!=null)
return (java.util.Collection) __fromServerSide.get(0);
} //...finally
// Failing
if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
FailDecision failDecision = getSomeListObjectsShardedFailingStrategy_javautilCollectionids.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return getSomeListObjectsSharded(ids, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return getSomeListObjectsSharded(ids, diMeCallContext.increaseCallCount());
case FAIL:
default:
// Fail or default is to do nothing at all and let the request fail
} //...switch(failDecision)
}
// fail through, if we are here, we must have had an exception before.
if (exceptionInMethod == null)
throw new AssertionError("Exception must have been thrown before, but it wasn't, framework error!");
throw mapException(exceptionInMethod);
}
// according to findbugs this method is never used, so we remove it for now reduce warnings.
//private void notifyDelegateFailed(){
//notifyDelegateFailed(ListServiceConstants.getServiceId());
//}
private void notifyDelegateFailed(String serviceId){
if (discoveryMode==DiscoveryMode.MANUAL){
manuallySetTarget = null;
return;
}
if (serviceId!=null)
delegates.remove(serviceId);
} //...notifyDelegateFailed
private RemoteListService getDelegate() throws NoConnectionToServerException{
if (discoveryMode==DiscoveryMode.MANUAL){
if (manuallySetTarget!=null)
return manuallySetTarget;
manuallySetTarget = lookup(manuallySetDescriptor);
return manuallySetTarget;
} //...if (mode==MANUAL)
return getDelegate(ListServiceConstants.getServiceId());
}
private RemoteListService getDelegate(String serviceId) throws NoConnectionToServerException{
// if no serviceId is provided, fallback to default resolve with manual mode
if (serviceId==null || discoveryMode==DiscoveryMode.MANUAL)
return getDelegate();
RemoteListService delegate = delegates.get(serviceId);
if (delegate==null){
try{
delegate = lookup(serviceId);
RemoteListService existingDelegate = delegates.putIfAbsent(serviceId, delegate);
if (existingDelegate!=null)
delegate = existingDelegate;
}catch(Exception e){
// //TODO - generate and throw typed exception.
throw new NoConnectionToServerException("Couldn't lookup delegate because: "+e.getMessage()+" at "+RegistryUtil.describeRegistry(), e);
}//try
} //...first if (del==null)
return delegate;
} //...fun
private RemoteListService lookup(String serviceId) throws NoConnectionToServerException{
// //first we need to lookup target host.
ServiceDescriptor toLookup = new ServiceDescriptor(Protocol.RMI, serviceId);
ServiceDescriptor targetService = RegistryUtil.resolve(toLookup);
if (targetService==null)
throw new RuntimeException("Can't resolve host for an instance of "+ListServiceConstants.getServiceId());
Registry registry = null;
try{
registry = LocateRegistry.getRegistry(targetService.getHost(), targetService.getPort());
}catch(Exception e){
System.err.println("lookup - couldn't obtain rmi registry on "+targetService+", aborting lookup"); e.printStackTrace();
throw new NoConnectionToServerException("Can't resolve rmi registry for an instance of "+ListServiceConstants.getServiceId());
}
try{
return (RemoteListService) registry.lookup(serviceId);
}catch(RemoteException e){
throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceId, e);
}catch(NotBoundException e){
throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceId, e);
}
}
private RemoteListService lookup(ServiceDescriptor serviceDescriptor) throws NoConnectionToServerException{
Registry registry = null;
try{
registry = LocateRegistry.getRegistry(serviceDescriptor.getHost(), serviceDescriptor.getPort());
}catch(Exception e){
System.err.println("lookup - couldn't obtain rmi registry on "+serviceDescriptor+", aborting lookup"); e.printStackTrace();
throw new NoConnectionToServerException("Can't resolve rmi registry for "+serviceDescriptor);
}
try{
RemoteListService ret = (RemoteListService) registry.lookup(serviceDescriptor.getServiceId());
return ret;
}catch(RemoteException e){
throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceDescriptor, e);
}catch(NotBoundException e){
throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceDescriptor, e);
}
}
private DistributemeRuntimeException mapException(Exception in){
if (in instanceof DistributemeRuntimeException)
return (DistributemeRuntimeException) in;
if (in instanceof RemoteException)
return new ServiceUnavailableException ("Service unavailable due to rmi failure: "+in.getMessage(), in);
return new ServiceUnavailableException("Unexpected exception: "+in.getMessage()+" " + in.getClass().getName(), in);
}
private org.distributeme.core.routing.Router createRouterInstance11(){
org.distributeme.core.routing.Router router = new org.distributeme.test.list.ListRouter();
((org.distributeme.core.routing.ConfigurableRouter)router).setConfigurationName(ListServiceConstants.getServiceId(), "list-config");
return router;
}
}