org.springframework.data.gemfire.function.annotation.GemfireFunction Java Examples

The following examples show how to use org.springframework.data.gemfire.function.annotation.GemfireFunction. 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: 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 #2
Source File: ProductGroupCounter.java    From geode-demo-application with Apache License 2.0 6 votes vote down vote up
/**
 * Return a count of each Brand
 * @return
 */
@GemfireFunction
public Map<String, AtomicInteger> countByBrand() {
	Map<String,AtomicInteger> results = new HashMap<String,AtomicInteger>();
	Collection<Product> products = productRepository.findAll();
	for (Object objProduct : products) {
		Product product = resolveReference(objProduct);
		if (results.containsKey(product.getBrand())) {
			results.get(product.getBrand()).addAndGet(product.getStockOnHand());
		}
		else {
			results.put(product.getBrand(), new AtomicInteger(product.getStockOnHand()));
		}
	}
	return results;
}
 
Example #3
Source File: ProductGroupCounter.java    From geode-demo-application with Apache License 2.0 6 votes vote down vote up
/**
 * Return a count of all the types
 * @return
 */
@GemfireFunction
public Map<String, AtomicInteger> countByType() {
	Map<String,AtomicInteger> results = new HashMap<String,AtomicInteger>();
	Collection<Product> products = productRepository.findAll();
	for (Object obj : products) {
		Product product = resolveReference(obj);
		if (results.containsKey(product.getType())) {
			results.get(product.getType()).addAndGet(product.getStockOnHand());
		}
		else {
			results.put(product.getType(), new AtomicInteger(product.getStockOnHand()));
		}
	}
	return results;
}
 
Example #4
Source File: CustomerFunctions.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@GemfireFunction(id = "listConsumersForEmailAddressesFnc", HA = true, optimizeForWrite = true, batchSize = 3,
		hasResult = true)
public List<Customer> listAllCustomersForEmailAddress(@RegionData Map<Long, Customer> customerData,
		String... emailAddresses) {
	List<String> emailAddressesAsList = Arrays.asList(emailAddresses);
	List<Customer> collect = customerData.values().parallelStream()
			.filter((customer) -> emailAddressesAsList.contains(customer.getEmailAddress().getValue()))
			.collect(Collectors.toList());
	return collect;
}
 
Example #5
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "add", hasResult = true)
public double add(double operandOne, double operandTwo) {
	return operandOne + operandTwo;
}
 
Example #6
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "divide", hasResult = true)
public double divide(double numerator, double divisor) {
	return numerator / divisor;
}
 
Example #7
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "multiply", hasResult = true)
public double multiply(double  operandOne, double operandTwo) {
	return operandOne * operandTwo;
}
 
Example #8
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "squareRoot", hasResult = true)
public double squareRoot(double number) {
	return Math.sqrt(number);
}
 
Example #9
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "squared", hasResult = true)
public double squared(double number) {
	return number * number;
}
 
Example #10
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "subtract", hasResult = true)
public double subtract(double operandOne, double operandTwo) {
	return operandOne - operandTwo;
}
 
Example #11
Source File: OrderCounter.java    From geode-demo-application with Apache License 2.0 4 votes vote down vote up
@GemfireFunction
public int countTransactions(Object customerObj) {
	Customer customer = resolveReferenceCust(customerObj);
	//System.out.println("Counting orders for: " + customer.toString());
	Collection<Transaction> completedTransactions = transactionRepository.findCompletedOrders(customer.getId());
	//System.out.println("Completed Transactions: " + completedTransactions.size());
	Map<Integer, AtomicInteger> dayOfTheYearCount = new HashMap<Integer,AtomicInteger>();
	int count = 0;
	//go through the orders and increment the count
	for (Object txnObj : completedTransactions) {
		Transaction txn = resolveReferenceTxn(txnObj);
		//did it occur this year
		now.setTime(new Date());
		txn_date.setTime(txn.getTransactionDate());
		if (now.get(Calendar.YEAR) == txn_date.get(Calendar.YEAR)) {
			//System.out.println("Transaction Id: " + txn.getId() + " Transaction Date: " + txn.getTransactionDate());
			//System.out.println("Less than a year increment: " + count);
			count++;
			//if its there birthday they get an extra count per order
			if (isBirthday(txn.getTransactionDate(),customer.getBirthday())) {
				//System.out.println("Birthday add one: " + count);
				count++;
			}
			int currentDayOfYear = getDayOfYear(txn.getTransactionDate());
			//build a map of transactions by day of the year
			if (dayOfTheYearCount.containsKey(currentDayOfYear)) {
				dayOfTheYearCount.get(currentDayOfYear).incrementAndGet();
			}
			else {
				dayOfTheYearCount.put(currentDayOfYear, new AtomicInteger());
			}
		}
		
	}
	//go through the map, for days with 5 or more transactions add an extra count
	for (Integer day : dayOfTheYearCount.keySet()) {
		if (dayOfTheYearCount.get(day).intValue() >= 3) {
			//System.out.println("Three on a day - add one: " + count);
			count++;
		}
	}
	return count;
}
 
Example #12
Source File: ProductFunctions.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "sumPricesForAllProductsFnc", HA = true, hasResult = true)
public BigDecimal sumPricesForAllProductsFnc(@RegionData Map<Long, Product> productData) {
	return productData.values().stream().map(Product::getPrice).reduce(BigDecimal::add).get();
}
 
Example #13
Source File: OrderFunctions.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
@GemfireFunction(id = "sumPricesForAllProductsForOrderFnc", HA = true, optimizeForWrite = false, hasResult = true)
public BigDecimal sumPricesForAllProductsForOrderFnc(Long orderId, @RegionData Map<Long, Order> orderData) {
	return orderData.get(orderId).calcTotal();
}
 
Example #14
Source File: FunctionImpl.java    From tutorials with MIT License 4 votes vote down vote up
@GemfireFunction
public void greeting(String message){
    System.out.println("Message "+message);
}
 
Example #15
Source File: FunctionImpl.java    From tutorials with MIT License 4 votes vote down vote up
@GemfireFunction
public String sayHello(String message){
    return "Hello "+message;
}
 
Example #16
Source File: AutoConfiguredFunctionExecutionsIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@GemfireFunction(id = "factorial", hasResult = true)
public long factorial(long number) {

	Assert.isTrue(number > -1, "Number be greater than -1");

	long result = number == 2 ? 2 : 1;

	while (number > 1) {
		result *= number--;
	}

	return result;
}