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.asynch.generated.RemoteTestServiceStub Maven / Gradle / Ivy
package org.distributeme.test.asynch.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 RemoteTestServiceStub implements org.distributeme.test.asynch.TestService{
private volatile ConcurrentMap delegates = new ConcurrentHashMap();
private DiscoveryMode discoveryMode = DiscoveryMode.AUTO;
// ROUTER DECL V2
// No class-wide-router set, skipping.
// Method wide routers if applicable
// Method wide routers END
// ROUTER DECL V2 end
// Failing
// Class wide failing strategy
private FailingStrategy clazzWideFailingStrategy = Defaults.getDefaultFailingStrategy();
private FailingStrategy pingFailingStrategy_longparam = clazzWideFailingStrategy;
private FailingStrategy sleepAndReturnRandomFailingStrategy_longsleepTime = clazzWideFailingStrategy;
private FailingStrategy sleepFailingStrategy_longsleepTime = clazzWideFailingStrategy;
private FailingStrategy sleepAndThrowTypedExceptionFailingStrategy_longsleepTime = clazzWideFailingStrategy;
private FailingStrategy sleepAndThrowRuntimeExceptionFailingStrategy_longsleepTime = clazzWideFailingStrategy;
// Failing end
// CONCURRENCY CONTROL
// Class wide concurrency control strategy
private ConcurrencyControlStrategy clazzWideCCStrategy = Defaults.getDefaultConcurrencyControlStrategy();
private ConcurrencyControlStrategy pingCCStrategy_longparam = clazzWideCCStrategy;
private ConcurrencyControlStrategy sleepAndReturnRandomCCStrategy_longsleepTime = clazzWideCCStrategy;
private ConcurrencyControlStrategy sleepCCStrategy_longsleepTime = clazzWideCCStrategy;
private ConcurrencyControlStrategy sleepAndThrowTypedExceptionCCStrategy_longsleepTime = clazzWideCCStrategy;
private ConcurrencyControlStrategy sleepAndThrowRuntimeExceptionCCStrategy_longsleepTime = clazzWideCCStrategy;
// CONCURRENCY CONTROL end
public RemoteTestServiceStub(){
discoveryMode = DiscoveryMode.AUTO;
}
private ServiceDescriptor manuallySetDescriptor;
private RemoteTestService manuallySetTarget;
public RemoteTestServiceStub(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 ping(long param){
return ping(param, (ClientSideCallContext)null);
} //...public long ping(long param)
private long ping(long param, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("ping");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(TestServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
pingCCStrategy_longparam.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(param);
diMeCallContext.setParameters(diMeParameters);
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();
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
param = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).ping(param, __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
pingCCStrategy_longparam.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 ((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 = pingFailingStrategy_longparam.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return ping(param, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return ping(param, 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 sleepAndReturnRandom(long sleepTime){
return sleepAndReturnRandom(sleepTime, (ClientSideCallContext)null);
} //...public long sleepAndReturnRandom(long sleepTime)
private long sleepAndReturnRandom(long sleepTime, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("sleepAndReturnRandom");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(TestServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
sleepAndReturnRandomCCStrategy_longsleepTime.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(sleepTime);
diMeCallContext.setParameters(diMeParameters);
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();
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
sleepTime = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).sleepAndReturnRandom(sleepTime, __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
sleepAndReturnRandomCCStrategy_longsleepTime.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 ((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 = sleepAndReturnRandomFailingStrategy_longsleepTime.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
return sleepAndReturnRandom(sleepTime, diMeCallContext.increaseCallCount());
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
return sleepAndReturnRandom(sleepTime, 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 sleep(long sleepTime){
sleep(sleepTime, (ClientSideCallContext)null);
} //...public void sleep(long sleepTime)
private void sleep(long sleepTime, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("sleep");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(TestServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
sleepCCStrategy_longsleepTime.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(sleepTime);
diMeCallContext.setParameters(diMeParameters);
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();
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
sleepTime = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).sleep(sleepTime, __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
sleepCCStrategy_longsleepTime.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;
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 = sleepFailingStrategy_longsleepTime.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
sleep(sleepTime, diMeCallContext.increaseCallCount());
return;
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
sleep(sleepTime, 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);
}
public void sleepAndThrowTypedException(long sleepTime) throws org.distributeme.test.asynch.TestServiceException{
sleepAndThrowTypedException(sleepTime, (ClientSideCallContext)null);
} //...public void sleepAndThrowTypedException(long sleepTime) throws org.distributeme.test.asynch.TestServiceException
private void sleepAndThrowTypedException(long sleepTime, org.distributeme.core.ClientSideCallContext diMeCallContext) throws org.distributeme.test.asynch.TestServiceException{
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("sleepAndThrowTypedException");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(TestServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
sleepAndThrowTypedExceptionCCStrategy_longsleepTime.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(sleepTime);
diMeCallContext.setParameters(diMeParameters);
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.asynch.TestServiceException)
throw (org.distributeme.test.asynch.TestServiceException) 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
sleepTime = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).sleepAndThrowTypedException(sleepTime, __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
sleepAndThrowTypedExceptionCCStrategy_longsleepTime.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.asynch.TestServiceException)
throw (org.distributeme.test.asynch.TestServiceException) 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 = sleepAndThrowTypedExceptionFailingStrategy_longsleepTime.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
sleepAndThrowTypedException(sleepTime, diMeCallContext.increaseCallCount());
return;
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
sleepAndThrowTypedException(sleepTime, 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);
}
public void sleepAndThrowRuntimeException(long sleepTime){
sleepAndThrowRuntimeException(sleepTime, (ClientSideCallContext)null);
} //...public void sleepAndThrowRuntimeException(long sleepTime)
private void sleepAndThrowRuntimeException(long sleepTime, org.distributeme.core.ClientSideCallContext diMeCallContext){
List __fromServerSide = null;;
Exception exceptionInMethod = null;
if (diMeCallContext == null)
diMeCallContext = new ClientSideCallContext("sleepAndThrowRuntimeException");
if (discoveryMode==DiscoveryMode.AUTO && diMeCallContext.getServiceId()==null)
diMeCallContext.setServiceId(TestServiceConstants.getServiceId());
HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
// Initialize interceptors
List diMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
InterceptionContext diMeInterceptionContext = new InterceptionContext();
// Concurrency control, client side - start
sleepAndThrowRuntimeExceptionCCStrategy_longsleepTime.notifyClientSideCallStarted(diMeCallContext);
ArrayList diMeParameters = new ArrayList();
diMeParameters.add(sleepTime);
diMeCallContext.setParameters(diMeParameters);
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();
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
sleepTime = ((Long)diMeParameters.get(0)).longValue();
__fromServerSide = getDelegate(diMeCallContext.getServiceId()).sleepAndThrowRuntimeException(sleepTime, __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
sleepAndThrowRuntimeExceptionCCStrategy_longsleepTime.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;
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 = sleepAndThrowRuntimeExceptionFailingStrategy_longsleepTime.callFailed(diMeCallContext);
if (failDecision.getTargetService()!=null)
diMeCallContext.setServiceId(failDecision.getTargetService());
switch(failDecision.getReaction()){
case RETRY:
sleepAndThrowRuntimeException(sleepTime, diMeCallContext.increaseCallCount());
return;
case RETRYONCE:
// Only retry if its the first call
if (!diMeCallContext.isFirstCall())
break;
sleepAndThrowRuntimeException(sleepTime, 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(TestServiceConstants.getServiceId());
}
private void notifyDelegateFailed(String serviceId){
if (discoveryMode==DiscoveryMode.MANUAL){
manuallySetTarget = null;
return;
}
if (serviceId!=null)
delegates.remove(serviceId);
} //...notifyDelegateFailed
private RemoteTestService getDelegate() throws NoConnectionToServerException{
if (discoveryMode==DiscoveryMode.MANUAL){
if (manuallySetTarget!=null)
return manuallySetTarget;
manuallySetTarget = lookup(manuallySetDescriptor);
return manuallySetTarget;
} //...if (mode==MANUAL)
return getDelegate(TestServiceConstants.getServiceId());
}
private RemoteTestService getDelegate(String serviceId) throws NoConnectionToServerException{
// if no serviceid is provided, fallback to default resolve with manual mode
if (serviceId==null)
return getDelegate();
RemoteTestService 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 RemoteTestService 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 "+TestServiceConstants.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 "+TestServiceConstants.getServiceId());
}
try{
return (RemoteTestService) 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 RemoteTestService 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 (RemoteTestService) 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);
}
}