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.mod.generated.RemoteModedServiceStub Maven / Gradle / Ivy
package org.distributeme.test.mod.generated;
//CHECKSTYLE:OFF
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;
public class RemoteModedServiceStub implements org.distributeme.test.mod.ModedService{
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 = createRouterInstance2();
// Method wide routers if applicable
private final org.distributeme.core.routing.Router modEchoRouter = createRouterInstance3();
private final org.distributeme.core.routing.Router printStringRouter = createRouterInstance4();
// Method wide routers END
// ROUTER DECL V2 end
// Failing
// Class wide failing strategy
private FailingStrategy clazzWideFailingStrategy = Defaults.getDefaultFailingStrategy();
private FailingStrategy modEchoFailingStrategy_longparameter = clazzWideFailingStrategy;
private FailingStrategy unmodEchoFailingStrategy_longparameter = clazzWideFailingStrategy;
private FailingStrategy modEchoFailingStrategy_javalangStringdummyParameter_booleanparameter = clazzWideFailingStrategy;
private FailingStrategy printStringFailingStrategy_javalangStringparam = clazzWideFailingStrategy;
// Failing end
// CONCURRENCY CONTROL
// Class wide concurrency control strategy
private ConcurrencyControlStrategy clazzWideCCStrategy = Defaults.getDefaultConcurrencyControlStrategy();
private ConcurrencyControlStrategy modEchoCCStrategy_longparameter = clazzWideCCStrategy;
private ConcurrencyControlStrategy unmodEchoCCStrategy_longparameter = clazzWideCCStrategy;
private ConcurrencyControlStrategy modEchoCCStrategy_javalangStringdummyParameter_booleanparameter = clazzWideCCStrategy;
private ConcurrencyControlStrategy printStringCCStrategy_javalangStringparam = clazzWideCCStrategy;
// CONCURRENCY CONTROL end
public RemoteModedServiceStub(){
discoveryMode = DiscoveryMode.AUTO;
}
private ServiceDescriptor manuallySetDescriptor;
private RemoteModedService manuallySetTarget;
public RemoteModedServiceStub(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 long modEcho(long parameter) throws org.distributeme.test.mod.ModedServiceException{
return modEcho(parameter, (ClientSideCallContext)null);
} //...public long modEcho(long parameter) throws org.distributeme.test.mod.ModedServiceException
private long modEcho(long parameter, org.distributeme.core.ClientSideCallContext diMeCallContext) throws org.distributeme.test.mod.ModedServiceException{
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("modEcho");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ModedServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
modEchoCCStrategy_longparameter.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(parameter);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(clazzWideRouter.getServiceIdForCall(diMeCallContext));
try{
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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Long)interceptorResponse.getReturnValue()).longValue();
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// Reparse parameters in case an interceptor modified them
parameter = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).modEcho(parameter, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return ((Long)__fromServerSide.get(0)).longValue();
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
modEchoCCStrategy_longparameter.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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Long)interceptorResponse.getReturnValue()).longValue();
case OVERWRITE_RETURN_AND_CONTINUE:
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
if (diMeReturnOverriden)
return ((Long)__fromServerSide.get(0)).longValue();
} //...finally
// Failing
if (exceptionInMethod!=null){
FailDecision failDecision = modEchoFailingStrategy_longparameter.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return modEcho(parameter, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return modEcho(parameter, 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.
throw mapException(exceptionInMethod);
}
public long unmodEcho(long parameter) throws org.distributeme.test.mod.ModedServiceException{
return unmodEcho(parameter, (ClientSideCallContext)null);
} //...public long unmodEcho(long parameter) throws org.distributeme.test.mod.ModedServiceException
private long unmodEcho(long parameter, org.distributeme.core.ClientSideCallContext diMeCallContext) throws org.distributeme.test.mod.ModedServiceException{
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("unmodEcho");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ModedServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
unmodEchoCCStrategy_longparameter.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(parameter);
diMeCallContext.setParameters(diMeParameters);
// explicitely skipping routing for method unmodEcho(long)
try{
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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Long)interceptorResponse.getReturnValue()).longValue();
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// Reparse parameters in case an interceptor modified them
parameter = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).unmodEcho(parameter, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return ((Long)__fromServerSide.get(0)).longValue();
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
unmodEchoCCStrategy_longparameter.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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Long)interceptorResponse.getReturnValue()).longValue();
case OVERWRITE_RETURN_AND_CONTINUE:
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
if (diMeReturnOverriden)
return ((Long)__fromServerSide.get(0)).longValue();
} //...finally
// Failing
if (exceptionInMethod!=null){
FailDecision failDecision = unmodEchoFailingStrategy_longparameter.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return unmodEcho(parameter, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return unmodEcho(parameter, 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.
throw mapException(exceptionInMethod);
}
public boolean modEcho(java.lang.String dummyParameter, boolean parameter) throws org.distributeme.test.mod.ModedServiceException{
return modEcho(dummyParameter, parameter, (ClientSideCallContext)null);
} //...public boolean modEcho(java.lang.String dummyParameter, boolean parameter) throws org.distributeme.test.mod.ModedServiceException
private boolean modEcho(java.lang.String dummyParameter, boolean parameter, org.distributeme.core.ClientSideCallContext diMeCallContext) throws org.distributeme.test.mod.ModedServiceException{
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("modEcho");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ModedServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
modEchoCCStrategy_javalangStringdummyParameter_booleanparameter.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(dummyParameter);
diMeParameters.add(parameter);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(modEchoRouter.getServiceIdForCall(diMeCallContext));
try{
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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Boolean)interceptorResponse.getReturnValue()).booleanValue();
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// Reparse parameters in case an interceptor modified them
dummyParameter = (java.lang.String) diMeParameters.get(0);
parameter = ((Boolean)diMeParameters.get(1)).booleanValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).modEcho(dummyParameter, parameter, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return ((Boolean)__fromServerSide.get(0)).booleanValue();
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
modEchoCCStrategy_javalangStringdummyParameter_booleanparameter.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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return ((Boolean)interceptorResponse.getReturnValue()).booleanValue();
case OVERWRITE_RETURN_AND_CONTINUE:
__fromServerSide.set(0, interceptorResponse.getReturnValue());
diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
diMeReturnOverriden = true;
break;
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
if (diMeReturnOverriden)
return ((Boolean)__fromServerSide.get(0)).booleanValue();
} //...finally
// Failing
if (exceptionInMethod!=null){
FailDecision failDecision = modEchoFailingStrategy_javalangStringdummyParameter_booleanparameter.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return modEcho(dummyParameter, parameter, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return modEcho(dummyParameter, parameter, 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.
throw mapException(exceptionInMethod);
}
public void printString(java.lang.String param) throws org.distributeme.test.mod.ModedServiceException{
printString(param, (ClientSideCallContext)null);
} //...public void printString(java.lang.String param) throws org.distributeme.test.mod.ModedServiceException
private void printString(java.lang.String param, org.distributeme.core.ClientSideCallContext diMeCallContext) throws org.distributeme.test.mod.ModedServiceException{
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("printString");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(ModedServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
printStringCCStrategy_javalangStringparam.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(param);
diMeCallContext.setParameters(diMeParameters);
diMeCallContext.setServiceId(printStringRouter.getServiceIdForCall(diMeCallContext));
try{
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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return;
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
// Reparse parameters in case an interceptor modified them
param = (java.lang.String) diMeParameters.get(0);
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).printString(param, __transportableCallContext);
__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
return;
}catch(RemoteException e){
// handle exceptions properly
e.printStackTrace();
notifyDelegateFailed(diMeCallContext.getServiceId());
exceptionInMethod = e;
}catch(NoConnectionToServerException e){
exceptionInMethod = e;
}finally{
// Concurrency control, client side - end
printStringCCStrategy_javalangStringparam.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();
if (interceptorResponse.getException() instanceof org.distributeme.test.mod.ModedServiceException)
throw (org.distributeme.test.mod.ModedServiceException) interceptorResponse.getException();
throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
case RETURN:
return;
case CONTINUE:
break;
default:
throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
} //...switch
} //...for
} //...finally
// Failing
if (exceptionInMethod!=null){
FailDecision failDecision = printStringFailingStrategy_javalangStringparam.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
printString(param, diMeCallContext.increaseCallCount());
return;
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
printString(param, diMeCallContext.increaseCallCount());
return;
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.
throw mapException(exceptionInMethod);
}
private void notifyDelegateFailed(){
notifyDelegateFailed(ModedServiceConstants.getServiceId());
}
private void notifyDelegateFailed(String serviceId){
if (discoveryMode==DiscoveryMode.MANUAL){
manuallySetTarget = null;
return;
}
if (serviceId!=null)
delegates.remove(serviceId);
} //...notifyDelegateFailed
private RemoteModedService getDelegate() throws NoConnectionToServerException{
if (discoveryMode==DiscoveryMode.MANUAL){
if (manuallySetTarget!=null)
return manuallySetTarget;
manuallySetTarget = lookup(manuallySetDescriptor);
return manuallySetTarget;
} //...if (mode==MANUAL)
return getDelegate(ModedServiceConstants.getServiceId());
}
private RemoteModedService getDelegate(String serviceId) throws NoConnectionToServerException{
// if no serviceid is provided, fallback to default resolve with manual mode
if (serviceId==null)
return getDelegate();
RemoteModedService delegate = delegates.get(serviceId);
if (delegate==null){
try{
delegate = lookup(serviceId);
delegates.putIfAbsent(serviceId, delegate);
}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 RemoteModedService 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 "+ModedServiceConstants.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 "+ModedServiceConstants.getServiceId());
}
try{
return (RemoteModedService) 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 RemoteModedService 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{
return (RemoteModedService) registry.lookup(serviceDescriptor.getServiceId());
}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 createRouterInstance2(){
org.distributeme.core.routing.Router router = new org.distributeme.core.routing.ParameterBasedModRouter();
router.customize("2,0");
return router;
}
private org.distributeme.core.routing.Router createRouterInstance3(){
org.distributeme.core.routing.Router router = new org.distributeme.core.routing.ParameterBasedModRouter();
router.customize("2,1");
return router;
}
private org.distributeme.core.routing.Router createRouterInstance4(){
org.distributeme.core.routing.Router router = new org.distributeme.core.routing.SysOutRouter();
router.customize("");
return router;
}
}