com.gemstone.gemfire.cache.execute.FunctionAdapter Maven / Gradle / Ivy
Show all versions of gemfire-core Show documentation
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* 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. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.cache.execute;
/**
* Application developers can extend this class instead of implementing the
* {@link Function} interface.
*
*
* This implementation provides the following defaults
*
*
* - {@link Function#hasResult()} returns true
* - {@link Function#optimizeForWrite()} returns false
* - {@link Function#isHA()} returns true
*
*
*
* @author Yogesh Mahajan
* @since 6.0
* @see Function
*
*/
public abstract class FunctionAdapter implements Function {
/**
* The method which contains the logic to be executed. This method should be
* thread safe and may be invoked more than once on a given member for a
* single {@link Execution}. The context provided to this function is the one
* which was built using {@linkplain Execution}. The contexts can be data
* dependent or data-independent so user should check to see if the context
* provided in parameter is instance of {@link RegionFunctionContext}.
*
* @param context
* as created by {@link Execution}
* @since 6.0
*/
public abstract void execute(FunctionContext context);
/**
* Return a unique function identifier, used to register the function with
* {@link FunctionService}
*
* @return string identifying this function
* @since 6.0
*/
public abstract String getId();
/**
* Specifies whether the function sends results while executing. The method
* returns false if no result is expected.
*
* If {@link Function#hasResult()} returns false,
* {@link ResultCollector#getResult()} throws {@link FunctionException}.
*
*
* If {@link Function#hasResult()} returns true,
* {@link ResultCollector#getResult()} blocks and waits for the result of
* function execution
*
*
* @return whether this function returns a Result back to the caller.
* @since 6.0
*/
public boolean hasResult() {
return true;
}
/**
*
* Return true to indicate to GemFire the method requires optimization for
* writing the targeted
* {@link FunctionService#onRegion(com.gemstone.gemfire.cache.Region)} and any
* associated {@linkplain Execution#withFilter(java.util.Set) routing objects}
* .
*
*
*
* Returning false will optimize for read behavior on the targeted
* {@link FunctionService#onRegion(com.gemstone.gemfire.cache.Region)} and any
* associated {@linkplain Execution#withFilter(java.util.Set) routing objects}
* .
*
*
*
* This method is only consulted when invoked as a
* {@linkplain FunctionService#onRegion(com.gemstone.gemfire.cache.Region)
* data dependent function}
*
*
* @return false if the function is read only, otherwise returns true
* @since 6.0
* @see FunctionService
*/
public boolean optimizeForWrite() {
return false;
}
/**
* Specifies whether the function is eligible for re-execution (in case of
* failure).
*
* @return whether the function is eligible for re-execution.
* @see RegionFunctionContext#isPossibleDuplicate()
*
* @since 6.5
*/
public boolean isHA() {
return true;
}
}