org.apache.geode.cache.execute.FunctionContext Java Examples

The following examples show how to use org.apache.geode.cache.execute.FunctionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrimeNumber.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(FunctionContext context) {
  RegionFunctionContext regionContext = (RegionFunctionContext) context;
  Region<Integer, String> region = regionContext.getDataSet();

  List<Integer> primes = new ArrayList<>();
  Set<Integer> keys = region.keySet();
  for (Integer key : keys) {
    if (isPrime(key)) {
      primes.add(key);
    }
  }
  Collections.sort(primes);

  context.getResultSender().lastResult(primes);
}
 
Example #2
Source File: PetClinicApplicationSmokeTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@GemfireFunction(id = "AdministerPetVaccinations", optimizeForWrite = true)
public void administerPetVaccinations(FunctionContext functionContext) {

	Optional.ofNullable(functionContext)
		.filter(RegionFunctionContext.class::isInstance)
		.map(RegionFunctionContext.class::cast)
		.map(RegionFunctionContext::getDataSet)
		.map(Region::values)
		.ifPresent(pets -> pets.forEach(pet -> {

			Pet resolvePet = (Pet) pet;

			resolvePet.vaccinate();

			((RegionFunctionContext) functionContext).getDataSet().put(resolvePet.getName(), resolvePet);
		}));
}
 
Example #3
Source File: PrimeNumber.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(FunctionContext context) {
  RegionFunctionContext regionContext = (RegionFunctionContext) context;
  Region<Integer, String> region = regionContext.getDataSet();

  List<Integer> primes = new ArrayList<>();
  Set<Integer> keys = region.keySet();
  for (Integer key : keys) {
    if (isPrime(key)) {
      primes.add(key);
    }
  }
  Collections.sort(primes);

  context.getResultSender().lastResult(primes);
}
 
Example #4
Source File: UpperCaseNames.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void execute(FunctionContext<Boolean> context) {
    RegionFunctionContext regionContext = (RegionFunctionContext) context;
    Region<CustomerKey, Customer> region = regionContext.getDataSet();

    for (Map.Entry<CustomerKey, Customer> entry : region.entrySet()) {
        Customer customer = entry.getValue();
        customer.setFirstName(customer.getFirstName()
            .toUpperCase());
    }

    context.getResultSender()
        .lastResult(true);
}