org.springframework.data.gemfire.function.execution.AbstractFunctionTemplate Maven / Gradle / Ivy
/*
* Copyright 2002-2013 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
*
* http://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.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.ResultCollector;
/**
* The base class for GemFire FunctionTemplates used to invoke GemFire Functions.
*
* @author David Turanski
* @author John Blum
* @see com.gemstone.gemfire.cache.execute.Function
* @see com.gemstone.gemfire.cache.execute.ResultCollector
*/
abstract class AbstractFunctionTemplate implements GemfireFunctionOperations {
protected Log log = LogFactory.getLog(this.getClass());
protected long timeout;
protected volatile ResultCollector resultCollector;
@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();
}