Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CachingSamples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ The following project provides samples for the following:
- Query sample to demonstrate querying a cache
- Eventing: Read-Through sample
- Eventing: Write-Behind sample
- Streaming: Post-Event sample
- Parallel Method Invocation: Executing ForEach and Reduce operations sample
- Single Method Invocation: Performing server-side analysis on a single object
- InvocationGrid: sample demonstrating IG event registration


6 changes: 2 additions & 4 deletions CachingSamples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ version '1.0-SNAPSHOT'

repositories {
mavenCentral()
maven {
url "https://repo.scaleoutsoftware.com/repository/external"
}
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation fileTree(dir: '..\\build\\libs\\', include: '*.jar')
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.21.6'
implementation group: 'com.scaleoutsoftware.client', name: 'api', version: '1.0.1'
implementation group: 'com.scaleoutsoftware', name: 'client', version: '2.0.0'
implementation group: 'com.scaleoutsoftware', name: 'invocationgrid', version: '2.0.0'
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 by ScaleOut Software, Inc.
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
Expand Down Expand Up @@ -30,7 +30,7 @@

public class CrudSample {
public static void main(String[] args) throws Exception {
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost:721");
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost:721;");
Cache<Integer, String> cache = new CacheBuilder<Integer, String>(connection, "example", Integer.class)
.build();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 by ScaleOut Software, Inc.
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
Expand Down Expand Up @@ -123,7 +123,7 @@ public SimpleObject deserialize(byte[] bytes) throws DeserializationException {
}

public static void main(String[] args) throws Exception {
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost:721");
GridConnection connection = GridConnection.connect("bootstrapGateways=server1:721,server2:721;");
Cache<String, SimpleObject> cache = new CacheBuilder<String, SimpleObject>(connection, "example", String.class)
// supply the custom serializer to the builder
.customSerialization(new SimpleObjectEncryptingSerializer(), new SimpleObjectDecryptingDeserializer())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 by ScaleOut Software, Inc.
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
Expand Down Expand Up @@ -33,7 +33,7 @@

public class LockingSample {
public static void main(String[] args) throws Exception {
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost:721");
GridConnection connection = GridConnection.connect("bootstrapGateways=server1:721,server2:721;");
Cache<Integer, String> cache = new CacheBuilder<Integer, String>(connection, "example", Integer.class)
.build();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 by ScaleOut Software, Inc.
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 by ScaleOut Software, Inc.
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
Expand Down Expand Up @@ -57,7 +57,7 @@ public Person deserialize(byte[] bytes) throws DeserializationException {
}

public static void main(String[] args) throws Exception {
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost:721;");
GridConnection connection = GridConnection.connect("bootstrapGateways=192.168.86.125:2721;");
Cache<String, Person> cache = new CacheBuilder<String, Person>(connection, "example", String.class)
// supply the custom serializer to the builder
.customSerialization(new ProtobufSerializer(), new ProtobufDeserializer())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
* This material contains sample programming source code ("Sample Code").
* ScaleOut Software, Inc. (SSI) grants you a nonexclusive license to compile,
* link, run, display, reproduce, and prepare derivative works of
* this Sample Code. The Sample Code has not been thoroughly
* tested under all conditions. SSI, therefore, does not guarantee
* or imply its reliability, serviceability, or function. SSI
* provides no support services for the Sample Code.
*
* All Sample Code contained herein is provided to you "AS IS" without
* any warranties of any kind. THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGMENT ARE EXPRESSLY
* DISCLAIMED. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU. IN NO
* EVENT WILL SSI BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE CODE
* INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION
* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*/
package com.scaleout.client.samples.compute;

import com.scaleout.client.caching.CacheEntryForEachHandler;
import com.scaleout.client.caching.OperationContext;
import com.scaleout.client.caching.RequestStatus;

import java.time.Duration;

public class FindInactiveUsersForEachHandler implements CacheEntryForEachHandler<String, Long, Void> {
@Override
public void evaluate(String key, OperationContext<String, Long, Void> operationContext) {
try {
// Use the cache in the PMI context to retrieve the object being evaluated:
var readResponse = operationContext.getCache().read(key);
if (readResponse.getStatus() == RequestStatus.ObjectNotFound)
{
System.out.println(key + " removed by another client during PMI operation.");
return;
}
else if (readResponse.getStatus() != RequestStatus.ObjectRetrieved)
{
System.out.println("Unexpected error (" + readResponse.getStatus() + ") while reading key: " + key);
return;
}

// Perform analysis:
long lastLoginEpochMs = readResponse.getValue();
long inactiveTimeMs = System.currentTimeMillis() - lastLoginEpochMs;
if (inactiveTimeMs > Duration.ofDays(7).toMillis())
{
System.out.println(key + " inactive for " + Duration.ofMillis(inactiveTimeMs).toDays() + " days.");
}
} catch (Exception e) {
System.out.println("Unexpected error while processing PMI events: ");
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
* This material contains sample programming source code ("Sample Code").
* ScaleOut Software, Inc. (SSI) grants you a nonexclusive license to compile,
* link, run, display, reproduce, and prepare derivative works of
* this Sample Code. The Sample Code has not been thoroughly
* tested under all conditions. SSI, therefore, does not guarantee
* or imply its reliability, serviceability, or function. SSI
* provides no support services for the Sample Code.
*
* All Sample Code contained herein is provided to you "AS IS" without
* any warranties of any kind. THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGMENT ARE EXPRESSLY
* DISCLAIMED. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU. IN NO
* EVENT WILL SSI BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE CODE
* INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION
* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*/
package com.scaleout.client.samples.compute;

import com.scaleout.client.GridConnectException;
import com.scaleout.client.GridConnection;
import com.scaleout.client.caching.Cache;
import com.scaleout.client.caching.CacheBuilder;
import com.scaleout.client.caching.CacheException;
import com.scaleout.client.caching.InvokeResponse;

import java.nio.charset.StandardCharsets;
import java.time.Duration;

public class PMIClientSample {
public static void main(String[] args) throws GridConnectException, CacheException {
// Connect to the cache that stores login times.
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost");
Cache<String, Long> cache = new CacheBuilder<String, Long>(connection, "PMISample", String.class)
.build();

// Add some test data to the cache:
for (int i = 0; i < 50; i++)
{
long lastLogin = System.currentTimeMillis() - Duration.ofDays(i % 10).toMillis();
cache.addOrUpdate("User_"+i, lastLogin);
}
// ... continued below

InvokeResponse response = cache.invoke("Find inactive users", Duration.ofSeconds(0));
switch (response.getRequestStatus()) {
case InvokeComplete:
System.out.println("Invoke complete.");
System.out.println(response.getSuccessCount() + " were successfully evaluated.");
break;
case UnhandledExceptionInCallback:
System.out.println("Unhandled exception thrown from PMI Handler.");
System.out.println(new String(response.getErrorData(), StandardCharsets.UTF_8));
break;
default:
System.out.println("Unexpected response: " + response.getRequestStatus());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
* This material contains sample programming source code ("Sample Code").
* ScaleOut Software, Inc. (SSI) grants you a nonexclusive license to compile,
* link, run, display, reproduce, and prepare derivative works of
* this Sample Code. The Sample Code has not been thoroughly
* tested under all conditions. SSI, therefore, does not guarantee
* or imply its reliability, serviceability, or function. SSI
* provides no support services for the Sample Code.
*
* All Sample Code contained herein is provided to you "AS IS" without
* any warranties of any kind. THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGMENT ARE EXPRESSLY
* DISCLAIMED. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU. IN NO
* EVENT WILL SSI BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE CODE
* INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION
* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*/
package com.scaleout.client.samples.compute;

import com.scaleout.client.GridConnectException;
import com.scaleout.client.GridConnection;
import com.scaleout.client.ServiceEvents;
import com.scaleout.client.ServiceEventsException;
import com.scaleout.client.caching.Cache;
import com.scaleout.client.caching.CacheBuilder;

import java.io.IOException;

public class PMIHandlerSample {
public static void main(String[] args) throws GridConnectException, ServiceEventsException, IOException {
GridConnection connection = GridConnection.connect("bootstrapGateways=localhost");
Cache<String, Long> cache = new CacheBuilder<String, Long>(connection, "PMISample", String.class)
.build();

ServiceEvents.setForEachEventHandler(cache, "Find inactive users", new FindInactiveUsersForEachHandler());
System.out.println("Waiting for events...");
System.out.println("Press any key to exit.");
System.in.read();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* (C) Copyright 2025 by ScaleOut Software, Inc.
*
* LICENSE AND DISCLAIMER
* ----------------------
* This material contains sample programming source code ("Sample Code").
* ScaleOut Software, Inc. (SSI) grants you a nonexclusive license to compile,
* link, run, display, reproduce, and prepare derivative works of
* this Sample Code. The Sample Code has not been thoroughly
* tested under all conditions. SSI, therefore, does not guarantee
* or imply its reliability, serviceability, or function. SSI
* provides no support services for the Sample Code.
*
* All Sample Code contained herein is provided to you "AS IS" without
* any warranties of any kind. THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGMENT ARE EXPRESSLY
* DISCLAIMED. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
* WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU. IN NO
* EVENT WILL SSI BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
* SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE OF THE SAMPLE CODE
* INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS, BUSINESS
* INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR INFORMATION
* HANDLING SYSTEM OR OTHERWISE, EVEN IF WE ARE EXPRESSLY ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*/
package com.scaleout.client.samples.compute;

import java.util.HashMap;

public class PriceHistory {
private final String _stockTicker;
private final HashMap<Long,Double> _priceHistory;

public PriceHistory(String stockTicker, HashMap<Long,Double> currentPriceHistory) {
_stockTicker = stockTicker;
_priceHistory = currentPriceHistory;
}


public String getStockTicker() {
return _stockTicker;
}

public HashMap<Long, Double> getPriceHistory() {
return _priceHistory;
}

public void addToPriceHistory(long timestampMs, double price) {
_priceHistory.put(timestampMs, price);
}
}
Loading