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

org.springframework.data.gemfire.function.execution.AbstractFunctionTemplate Maven / Gradle / Ivy

There is a newer version: 2.3.9.RELEASE
Show newest version
/*
 * Copyright 2002-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

package org.springframework.data.gemfire.function.execution;

import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.ResultCollector;

import org.springframework.beans.factory.InitializingBean;

/**
 * The base class for {@link Function} templates used to invoke Apache Geode/Pivotal GemFire {@link Function Functions}.
 *
 * @author David Turanski
 * @author John Blum
 * @see org.apache.geode.cache.execute.Function
 * @see org.apache.geode.cache.execute.ResultCollector
 * @see org.springframework.beans.factory.InitializingBean
 * @see org.springframework.data.gemfire.function.execution.GemfireFunctionOperations
 */
abstract class AbstractFunctionTemplate implements GemfireFunctionOperations, InitializingBean {

	protected long timeout;

	protected volatile ResultCollector resultCollector;

	@Override
	public void afterPropertiesSet() throws Exception { }

	@Override
	public  Iterable execute(Function function, Object... args) {
		 return execute(getFunctionExecution().setArgs(args).setFunction(function));
	}

	@Override
	public  T executeAndExtract(Function function, Object... args) {
		return executeAndExtract(getFunctionExecution().setArgs(args).setFunction(function));
	}

	@Override
	public  Iterable execute(String functionId, Object... args) {
		return execute(getFunctionExecution().setArgs(args).setFunctionId(functionId));
	}

	@Override
	public  T executeAndExtract(String functionId, Object... args) {
		return executeAndExtract(getFunctionExecution().setArgs(args).setFunctionId(functionId));
	}

	@Override
	public void executeWithNoResult(String functionId, Object... args) {
		execute(getFunctionExecution().setArgs(args).setFunctionId(functionId), false);
	}

	@Override
	public  T execute(GemfireFunctionCallback callback) {
		return callback.doInGemfire(getFunctionExecution().getExecution());
	}

	protected  Iterable execute(AbstractFunctionExecution execution) {
		 return execution.setTimeout(timeout).setResultCollector(resultCollector).execute();
	}

	protected  Iterable execute(AbstractFunctionExecution execution, boolean returnResult) {
		 return execution.setTimeout(timeout).setResultCollector(resultCollector).execute(returnResult);
	}

	protected  T executeAndExtract(AbstractFunctionExecution execution) {
		 return execution.setTimeout(timeout).setResultCollector(resultCollector).executeAndExtract();
	}

	public void setResultCollector(ResultCollector resultCollector) {
		this.resultCollector = resultCollector;
	}

	public ResultCollector getResultCollector() {
		return this.resultCollector;
	}

	public void setTimeout(long timeout) {
		this.timeout = timeout;
	}

	protected abstract AbstractFunctionExecution getFunctionExecution();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy