All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.distributeme.test.jsonrpc.jsonrpc.generated.ServerEchoServiceImpl Maven / Gradle / Ivy

package org.distributeme.test.jsonrpc.jsonrpc.generated;

import org.distributeme.test.jsonrpc.EchoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import org.distributeme.core.Verbosity;
import org.distributeme.core.Defaults;
import org.distributeme.core.ServerSideCallContext;
import org.distributeme.core.interceptor.ServerSideRequestInterceptor;
import org.distributeme.core.interceptor.InterceptorResponse;
import org.distributeme.core.interceptor.InterceptionContext;
import org.distributeme.core.interceptor.InterceptorRegistry;
import org.distributeme.core.interceptor.InterceptionPhase;
import org.distributeme.core.concurrencycontrol.ConcurrencyControlStrategy;
import net.anotheria.anoprise.metafactory.Extension;
import net.anotheria.anoprise.metafactory.MetaFactory;
import net.anotheria.anoprise.metafactory.MetaFactoryException;
import net.anotheria.moskito.core.dynamic.MoskitoInvokationProxy;
import net.anotheria.moskito.core.logging.DefaultStatsLogger;
import net.anotheria.moskito.core.logging.IntervalStatsLogger;
import net.anotheria.moskito.core.logging.SL4JLogOutput;
import net.anotheria.moskito.core.stats.DefaultIntervals;
import net.anotheria.moskito.core.predefined.ServiceStatsCallHandler;
import net.anotheria.moskito.core.predefined.ServiceStatsFactory;
import net.anotheria.moskito.core.registry.IProducerRegistryAPI;
import net.anotheria.moskito.core.registry.ProducerRegistryAPIFactory;
import net.anotheria.moskito.core.producers.IStatsProducer;

// Generated by org.distributeme.generator.jsonrpc.ServerImplGenerator
public class ServerEchoServiceImpl implements ClientEchoService {

	private static Logger log = LoggerFactory.getLogger(ServerEchoServiceImpl.class);

	private org.distributeme.test.jsonrpc.EchoService implementation;

	private long lastAccess;
	private long created;

	// CONCURRENCY CONTROL
	// Class wide concurrency control strategy 
	private ConcurrencyControlStrategy clazzWideCCStrategy = Defaults.getDefaultConcurrencyControlStrategy();

	private ConcurrencyControlStrategy echoCCStrategy_longaValue = clazzWideCCStrategy;
	private ConcurrencyControlStrategy echoObjectParam1CCStrategy_javalangObjectaValue = clazzWideCCStrategy;
	private ConcurrencyControlStrategy echoObjectParamCCStrategy_orgdistributemetestjsonrpcAaValue = clazzWideCCStrategy;
	private ConcurrencyControlStrategy echoManyParamsCCStrategy_intind_javalangStringstrNum_javalangLongincremt = clazzWideCCStrategy;
	// CONCURRENCY CONTROL end

	public ServerEchoServiceImpl() throws MetaFactoryException {
		this(MetaFactory.get(org.distributeme.test.jsonrpc.EchoService.class, Extension.LOCAL));
	}

	public ServerEchoServiceImpl(org.distributeme.test.jsonrpc.EchoService anImplementation){
		created = System.currentTimeMillis();
		MoskitoInvokationProxy proxy = new MoskitoInvokationProxy(
			anImplementation,
			new ServiceStatsCallHandler(),
			new ServiceStatsFactory(),
			"EchoService", 
			"service",
			"default",
			org.distributeme.test.jsonrpc.EchoService.class, net.anotheria.anoprise.metafactory.Service.class
		);
		implementation = (org.distributeme.test.jsonrpc.EchoService) proxy.createProxy();
		// add moskito logger
		new DefaultStatsLogger(proxy.getProducer(), new SL4JLogOutput(LoggerFactory.getLogger("MoskitoDefault")));
		new IntervalStatsLogger(proxy.getProducer(), DefaultIntervals.FIVE_MINUTES, new SL4JLogOutput(LoggerFactory.getLogger("Moskito5m")));
		new IntervalStatsLogger(proxy.getProducer(), DefaultIntervals.FIFTEEN_MINUTES, new SL4JLogOutput(LoggerFactory.getLogger("Moskito15m")));
		new IntervalStatsLogger(proxy.getProducer(), DefaultIntervals.ONE_HOUR, new SL4JLogOutput(LoggerFactory.getLogger("Moskito1h")));
		new IntervalStatsLogger(proxy.getProducer(), DefaultIntervals.ONE_DAY, new SL4JLogOutput(LoggerFactory.getLogger("Moskito1d")));
		//end moskito logger
		// //ADD LOGGING FOR ALL BUILTIN PRODUCERS
		IProducerRegistryAPI api = new ProducerRegistryAPIFactory().createProducerRegistryAPI();
		List stats = api.getAllProducersBySubsystem("builtin");
		for (IStatsProducer producer : stats){
			new DefaultStatsLogger(producer, new SL4JLogOutput(LoggerFactory.getLogger("MoskitoBIDefault")));
			new IntervalStatsLogger(producer, DefaultIntervals.FIVE_MINUTES, new SL4JLogOutput(LoggerFactory.getLogger("MoskitoBI5m")));
			new IntervalStatsLogger(producer, DefaultIntervals.FIFTEEN_MINUTES, new SL4JLogOutput(LoggerFactory.getLogger("MoskitoBI15m")));
			new IntervalStatsLogger(producer, DefaultIntervals.ONE_HOUR, new SL4JLogOutput(LoggerFactory.getLogger("MoskitoBI1h")));
			new IntervalStatsLogger(producer, DefaultIntervals.ONE_DAY, new SL4JLogOutput(LoggerFactory.getLogger("MoskitoBI1d")));
		}
	}

	public List echo(long aValue, Map __transportableCallContext) throws org.distributeme.test.jsonrpc.EchoServiceException{
		lastAccess = System.currentTimeMillis();
		ServerSideCallContext diMeCallContext = new ServerSideCallContext("echo", __transportableCallContext);
		diMeCallContext.setServiceId(EchoServiceConstants.getServiceId());
		ArrayList diMeParameters = new ArrayList();
		diMeParameters.add(aValue);
		diMeCallContext.setParameters(diMeParameters);
		InterceptionContext diMeInterceptionContext = new InterceptionContext();
		// Initialize interceptors
		List diMeInterceptors = InterceptorRegistry.getInstance().getServerSideRequestInterceptors();

		ArrayList __return = new ArrayList();

		diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVANT_CALL);
		for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
			InterceptorResponse interceptorResponse = interceptor.beforeServantCall(diMeCallContext, diMeInterceptionContext);
			switch(interceptorResponse.getCommand()){
			case ABORT:
				if (interceptorResponse.getException() instanceof RuntimeException)
					throw (RuntimeException) interceptorResponse.getException();
				if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
					throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
				throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
			case RETURN:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case OVERWRITE_RETURN_AND_CONTINUE:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case CONTINUE:
				break;
			} //...switch
		} //...for
		// Concurrency control, server side - 
		echoCCStrategy_longaValue.notifyServerSideCallStarted(diMeCallContext);

		try{
			Object __result = implementation.echo(aValue);
			__return.add(__result);
			diMeInterceptionContext.setReturnValue(__result);
			__return.add(diMeCallContext.getTransportableCallContext());
			diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVANT_CALL);
			for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.afterServantCall(diMeCallContext, diMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case ABORT:
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeException) interceptorResponse.getException();
					if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
						throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case RETURN:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case OVERWRITE_RETURN_AND_CONTINUE:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case CONTINUE:
					break;
				} //...switch
			} //...for
			return __return;
		}catch(org.distributeme.test.jsonrpc.EchoServiceException e){
			if (Verbosity.logServerSideExceptions())
				log.error("echo()", e);
			throw(e);
		}finally{
			echoCCStrategy_longaValue.notifyServerSideCallFinished(diMeCallContext);
		}
	}

	public List echoObjectParam1(java.lang.Object aValue, Map __transportableCallContext) throws org.distributeme.test.jsonrpc.EchoServiceException{
		lastAccess = System.currentTimeMillis();
		ServerSideCallContext diMeCallContext = new ServerSideCallContext("echoObjectParam1", __transportableCallContext);
		diMeCallContext.setServiceId(EchoServiceConstants.getServiceId());
		ArrayList diMeParameters = new ArrayList();
		diMeParameters.add(aValue);
		diMeCallContext.setParameters(diMeParameters);
		InterceptionContext diMeInterceptionContext = new InterceptionContext();
		// Initialize interceptors
		List diMeInterceptors = InterceptorRegistry.getInstance().getServerSideRequestInterceptors();

		ArrayList __return = new ArrayList();

		diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVANT_CALL);
		for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
			InterceptorResponse interceptorResponse = interceptor.beforeServantCall(diMeCallContext, diMeInterceptionContext);
			switch(interceptorResponse.getCommand()){
			case ABORT:
				if (interceptorResponse.getException() instanceof RuntimeException)
					throw (RuntimeException) interceptorResponse.getException();
				if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
					throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
				throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
			case RETURN:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case OVERWRITE_RETURN_AND_CONTINUE:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case CONTINUE:
				break;
			} //...switch
		} //...for
		// Concurrency control, server side - 
		echoObjectParam1CCStrategy_javalangObjectaValue.notifyServerSideCallStarted(diMeCallContext);

		try{
			Object __result = implementation.echoObjectParam1(aValue);
			__return.add(__result);
			diMeInterceptionContext.setReturnValue(__result);
			__return.add(diMeCallContext.getTransportableCallContext());
			diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVANT_CALL);
			for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.afterServantCall(diMeCallContext, diMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case ABORT:
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeException) interceptorResponse.getException();
					if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
						throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case RETURN:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case OVERWRITE_RETURN_AND_CONTINUE:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case CONTINUE:
					break;
				} //...switch
			} //...for
			return __return;
		}catch(org.distributeme.test.jsonrpc.EchoServiceException e){
			if (Verbosity.logServerSideExceptions())
				log.error("echoObjectParam1()", e);
			throw(e);
		}finally{
			echoObjectParam1CCStrategy_javalangObjectaValue.notifyServerSideCallFinished(diMeCallContext);
		}
	}

	public List echoObjectParam(org.distributeme.test.jsonrpc.A aValue, Map __transportableCallContext) throws org.distributeme.test.jsonrpc.EchoServiceException{
		lastAccess = System.currentTimeMillis();
		ServerSideCallContext diMeCallContext = new ServerSideCallContext("echoObjectParam", __transportableCallContext);
		diMeCallContext.setServiceId(EchoServiceConstants.getServiceId());
		ArrayList diMeParameters = new ArrayList();
		diMeParameters.add(aValue);
		diMeCallContext.setParameters(diMeParameters);
		InterceptionContext diMeInterceptionContext = new InterceptionContext();
		// Initialize interceptors
		List diMeInterceptors = InterceptorRegistry.getInstance().getServerSideRequestInterceptors();

		ArrayList __return = new ArrayList();

		diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVANT_CALL);
		for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
			InterceptorResponse interceptorResponse = interceptor.beforeServantCall(diMeCallContext, diMeInterceptionContext);
			switch(interceptorResponse.getCommand()){
			case ABORT:
				if (interceptorResponse.getException() instanceof RuntimeException)
					throw (RuntimeException) interceptorResponse.getException();
				if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
					throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
				throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
			case RETURN:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case OVERWRITE_RETURN_AND_CONTINUE:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case CONTINUE:
				break;
			} //...switch
		} //...for
		// Concurrency control, server side - 
		echoObjectParamCCStrategy_orgdistributemetestjsonrpcAaValue.notifyServerSideCallStarted(diMeCallContext);

		try{
			Object __result = implementation.echoObjectParam(aValue);
			__return.add(__result);
			diMeInterceptionContext.setReturnValue(__result);
			__return.add(diMeCallContext.getTransportableCallContext());
			diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVANT_CALL);
			for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.afterServantCall(diMeCallContext, diMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case ABORT:
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeException) interceptorResponse.getException();
					if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
						throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case RETURN:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case OVERWRITE_RETURN_AND_CONTINUE:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case CONTINUE:
					break;
				} //...switch
			} //...for
			return __return;
		}catch(org.distributeme.test.jsonrpc.EchoServiceException e){
			if (Verbosity.logServerSideExceptions())
				log.error("echoObjectParam()", e);
			throw(e);
		}finally{
			echoObjectParamCCStrategy_orgdistributemetestjsonrpcAaValue.notifyServerSideCallFinished(diMeCallContext);
		}
	}

	public List echoManyParams(int ind, java.lang.String strNum, java.lang.Long incremt, Map __transportableCallContext) throws org.distributeme.test.jsonrpc.EchoServiceException, java.io.IOException{
		lastAccess = System.currentTimeMillis();
		ServerSideCallContext diMeCallContext = new ServerSideCallContext("echoManyParams", __transportableCallContext);
		diMeCallContext.setServiceId(EchoServiceConstants.getServiceId());
		ArrayList diMeParameters = new ArrayList();
		diMeParameters.add(ind);
		diMeParameters.add(strNum);
		diMeParameters.add(incremt);
		diMeCallContext.setParameters(diMeParameters);
		InterceptionContext diMeInterceptionContext = new InterceptionContext();
		// Initialize interceptors
		List diMeInterceptors = InterceptorRegistry.getInstance().getServerSideRequestInterceptors();

		ArrayList __return = new ArrayList();

		diMeInterceptionContext.setCurrentPhase(InterceptionPhase.BEFORE_SERVANT_CALL);
		for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
			InterceptorResponse interceptorResponse = interceptor.beforeServantCall(diMeCallContext, diMeInterceptionContext);
			switch(interceptorResponse.getCommand()){
			case ABORT:
				if (interceptorResponse.getException() instanceof RuntimeException)
					throw (RuntimeException) interceptorResponse.getException();
				if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
					throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
				if (interceptorResponse.getException() instanceof java.io.IOException)
					throw (java.io.IOException) interceptorResponse.getException();
				throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
			case RETURN:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case OVERWRITE_RETURN_AND_CONTINUE:
				__return.set(0, interceptorResponse.getReturnValue());
				diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
				break;
			case CONTINUE:
				break;
			} //...switch
		} //...for
		// Concurrency control, server side - 
		echoManyParamsCCStrategy_intind_javalangStringstrNum_javalangLongincremt.notifyServerSideCallStarted(diMeCallContext);

		try{
			Object __result = implementation.echoManyParams(ind, strNum, incremt);
			__return.add(__result);
			diMeInterceptionContext.setReturnValue(__result);
			__return.add(diMeCallContext.getTransportableCallContext());
			diMeInterceptionContext.setCurrentPhase(InterceptionPhase.AFTER_SERVANT_CALL);
			for (ServerSideRequestInterceptor interceptor : diMeInterceptors){
				InterceptorResponse interceptorResponse = interceptor.afterServantCall(diMeCallContext, diMeInterceptionContext);
				switch(interceptorResponse.getCommand()){
				case ABORT:
					if (interceptorResponse.getException() instanceof RuntimeException)
						throw (RuntimeException) interceptorResponse.getException();
					if (interceptorResponse.getException() instanceof org.distributeme.test.jsonrpc.EchoServiceException)
						throw (org.distributeme.test.jsonrpc.EchoServiceException) interceptorResponse.getException();
					if (interceptorResponse.getException() instanceof java.io.IOException)
						throw (java.io.IOException) interceptorResponse.getException();
					throw new RuntimeException("Interceptor exception",interceptorResponse.getException());
				case RETURN:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case OVERWRITE_RETURN_AND_CONTINUE:
					__return.set(0, interceptorResponse.getReturnValue());
					diMeInterceptionContext.setReturnValue(interceptorResponse.getReturnValue());
					break;
				case CONTINUE:
					break;
				} //...switch
			} //...for
			return __return;
		}catch(org.distributeme.test.jsonrpc.EchoServiceException e){
			if (Verbosity.logServerSideExceptions())
				log.error("echoManyParams()", e);
			throw(e);
		}catch(java.io.IOException e){
			if (Verbosity.logServerSideExceptions())
				log.error("echoManyParams()", e);
			throw(e);
		}finally{
			echoManyParamsCCStrategy_intind_javalangStringstrNum_javalangLongincremt.notifyServerSideCallFinished(diMeCallContext);
		}
	}

	public EchoService getImplementation() { return implementation; }
	// Service adapter methods
	public long getCreationTimestamp(){ return created; }
	public long getLastAccessTimestamp(){ return lastAccess; }

}