Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.distributeme.agents.transporter.generated;
  //CHECKSTYLE:OFF
  
  import java.util.List;
  import java.util.HashMap;
  import org.slf4j.Logger;
 
 
 
 
 
 	// 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 
 
 	// Failing end
 
 	// CONCURRENCY CONTROL
 	// Class wide concurrency control strategy 
 
 	// CONCURRENCY CONTROL end
 
 	}
 
 
 		try{
 			throw new IllegalStateException("Can not resolve manually set reference"e);
 		}
 	}
 
 	} //...public void receiveAndAwakeAgent(org.distributeme.agents.AgentPackage agent) throws org.distributeme.agents.transporter.TransporterServiceException
 
 		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("receiveAndAwakeAgent");
 		if (==. && diMeCallContext.getServiceId()==null)
 			diMeCallContext.setServiceId(TransporterServiceConstants.getServiceId());
 
 		HashMap __transportableCallContext = diMeCallContext.getTransportableCallContext();
 		// Initialize interceptors
 		List<ClientSideRequestInterceptordiMeInterceptors = InterceptorRegistry.getInstance().getClientSideRequestInterceptors();
 		InterceptionContext diMeInterceptionContext = new InterceptionContext();
 		// Concurrency control, client side - start
		ArrayList<ObjectdiMeParameters = new ArrayList<Object>();
		diMeParameters.add(agent);
		diMeCallContext.setParameters(diMeParameters);
		try{
			for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.beforeServiceCall(diMeCallContextdiMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case :
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeExceptioninterceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case :
					return;
				case :
					break;
					abortAndFail = true;
					break;
				// 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
			// Reparse parameters in case an interceptor modified them
			agent = (org.distributeme.agents.AgentPackagediMeParameters.get(0);
			if (!abortAndFail){
				__fromServerSide = getDelegate(diMeCallContext.getServiceId()).receiveAndAwakeAgent(agent,  __transportableCallContext);
				__transportableCallContext.putAll(((HashMap)__fromServerSide.get(1)));
				return;
			}
		}catch(RemoteException e){
			// handle exceptions properly
			exceptionInMethod = e;
			exceptionInMethod = e;
		}finally{
			// Concurrency control, client side - end
			if (__fromServerSide!=null){
				diMeInterceptionContext.setReturnValue(__fromServerSide.get(0));
			}
			diMeInterceptionContext.setException(exceptionInMethod);
			boolean diMeReturnOverriden = false;
			for (ClientSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.afterServiceCall(diMeCallContextdiMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case :
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeExceptioninterceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case :
					return;
				case :
					break;
					abortAndFail = true;
					break;
				// Force failing logic to work.
					break;
				default:
					throw new IllegalStateException("Unsupported or unexpected command from interceptor " + interceptorResponse.getCommand()+ " in phase:"+diMeInterceptionContext.getCurrentPhase());
//...switch
//...for
//...finally
		// Failing
		if (exceptionInMethod!=null || diMeForceFailing || abortAndFail){
			if (failDecision.getTargetService()!=null)
				diMeCallContext.setServiceId(failDecision.getTargetService());
			switch(failDecision.getReaction()){
				case :
					receiveAndAwakeAgent(agentdiMeCallContext.increaseCallCount());
					return;
				case :
					// Only retry if its the first call
					if (!diMeCallContext.isFirstCall())
						break;
					receiveAndAwakeAgent(agentdiMeCallContext.increaseCallCount());
					return;
				case :
				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(TransporterServiceConstants.getServiceId());
	}
	private void notifyDelegateFailed(String serviceId){
			return;
		}
		if (serviceId!=null)
			.remove(serviceId);
//...notifyDelegateFailed
//...if (mode==MANUAL)
		return getDelegate(TransporterServiceConstants.getServiceId());
	}
		// if no serviceId is provided, fallback to default resolve with manual mode
		if (serviceId==null)
			return getDelegate();
		RemoteTransporterService delegate = .get(serviceId);
		if (delegate==null){
			try{
				delegate = lookup(serviceId);
				.putIfAbsent(serviceIddelegate);
			}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
		// //first we need to lookup target host.
		ServiceDescriptor toLookup = new ServiceDescriptor(.serviceId);
		ServiceDescriptor targetService = RegistryUtil.resolve(toLookup);
		if (targetService==null)
			throw new RuntimeException("Can't resolve host for an instance of "+TransporterServiceConstants.getServiceId());
		Registry registry = null;
		try{
			registry = LocateRegistry.getRegistry(targetService.getHost(), targetService.getPort());
		}catch(Exception e){
			..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 "+TransporterServiceConstants.getServiceId());
		}
		try{
			return (RemoteTransporterServiceregistry.lookup(serviceId);
		}catch(RemoteException e){
			throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceIde);
			throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceIde);
		}
	}
		Registry registry = null;
		try{
			registry = LocateRegistry.getRegistry(serviceDescriptor.getHost(), serviceDescriptor.getPort());
		}catch(Exception e){
			..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 (RemoteTransporterServiceregistry.lookup(serviceDescriptor.getServiceId());
		}catch(RemoteException e){
			throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceDescriptore);
			throw new NoConnectionToServerException("Can't lookup service in the target rmi registry for an instance of "+serviceDescriptore);
		}
	}
		if (in instanceof DistributemeRuntimeException)
		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);
	}
New to GrepCode? Check out our FAQ X