### Run the Coherence server with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Starts the stand-alone Coherence instance (circuit-breaker-cache-demo-server) using Spring Boot's Maven plugin. Run this before starting the client application. ```bash cd samples/circuit-breaker-cache-demo/circuit-breaker-cache-demo-server mvn spring-boot:run ``` -------------------------------- ### Plant JSON response example Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example JSON response for a Plant object with taxonomic properties. ```json {"id": 1, "genus": "Sabal", "species": "minor", "commonName": "Dwarf palmetto"} ``` -------------------------------- ### Run the Spring Boot demo application Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Starts the packaged Spring Boot demo JAR. The application runs an embedded HSQL database and exposes a REST API for managing events and people. ```bash $ java -jar samples/coherence-spring-demo/coherence-spring-demo-boot/target/coherence-spring-demo-boot-3.2.0.jar ``` -------------------------------- ### List all plants with cache hint Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to GET all plants with the use-cache parameter to demonstrate query caching. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:9090/plants?use-cache=true" ``` -------------------------------- ### Run the client application with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Starts the client application (circuit-breaker-cache-demo-app) that connects to the Coherence server via Coherence*Extend. Run after the server is running. ```bash cd samples/circuit-breaker-cache-demo/circuit-breaker-cache-demo-app mvn spring-boot:run ``` -------------------------------- ### List people Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle GET request to list all people. ```bash curl --request GET 'http://localhost:8080/api/people' ``` -------------------------------- ### List all plants via REST API Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to GET all plants from the application. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:9090/plants" ``` -------------------------------- ### Entity and Repository for Projections Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example of an entity class Book and a repository interface using a projection BookProjection. ```java @Entity public class Book implements Cloneable, Serializable { @Id protected final UUID uuid; protected String title; protected Author author; protected int pages; protected Calendar published; } @CoherenceMap("book") interface BookRepository extends CrudRepository { List findByTitle(String title); // ... } ``` -------------------------------- ### Start Spring Cloud Config Server Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to build and run the Spring Cloud Config Server demo application. The first command builds the server, the second changes to the target directory, and the third runs the server with a git URI for the configuration repository. ```bash $ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-server $ cd coherence-spring-samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-server/target $ java -jar coherence-spring-cloud-config-demo-server-3.2.0.jar \n --spring.cloud.config.server.git.uri=file:///path/to/git/repo ``` -------------------------------- ### Start Coherence Spring Application Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to build and run the Coherence Spring application demo. The first command builds the app, the second changes to the target directory, and the third runs the application. ```bash $ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-app $ cd coherence-spring-samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-app/target $ java -jar coherence-spring-cloud-config-demo-app-3.2.0.jar ``` -------------------------------- ### Hibernate Cache Statistics output Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example console output showing Hibernate second-level cache statistics when retrieving a single plant repeatedly. ```text 2021-06-28 16:12:42.545 INFO 29022 --- [nio-9090-exec-7] i.StatisticalLoggingSessionEventListener : Session Metrics { 27579 nanoseconds spent acquiring 1 JDBC connections; 0 nanoseconds spent releasing 0 JDBC connections; 0 nanoseconds spent preparing 0 JDBC statements; 0 nanoseconds spent executing 0 JDBC statements; 0 nanoseconds spent executing 0 JDBC batches; 0 nanoseconds spent performing 0 L2C puts; 1587296 nanoseconds spent performing 1 L2C hits; 0 nanoseconds spent performing 0 L2C misses; 0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections); 0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections) } ``` -------------------------------- ### GET request to retrieve a person (404 expected) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Sends a GET request to the /api/people/100 endpoint. Expect a 404 response because no person with id 100 exists yet. ```bash curl -i -X GET http://localhost:8080/api/people/100 ``` -------------------------------- ### Get a single book via REST API Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Sends a GET request to retrieve a single book by ID. The book is retrieved from the Coherence cache immediately. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:8090/api/books/1" ``` -------------------------------- ### Open projection using method parameters with args array Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows how to use method parameters in a SpEL expression via the args array. The example uses args[0] to reference the first method parameter. ```java interface NameOnly { @Value("args[0] + ' ' + #{target.author.firstName}") String getHonorificName(String honorific); } ``` -------------------------------- ### Using a repository with dynamic projections Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows how to invoke the dynamic projection repository method with different projection classes to get different result types. ```java Collection aggregates = books.findByTitle("Shadow", BookSummary.class); Collection aggregates = books.findByTitle("Remember", BookTitleAndPages.class); ``` -------------------------------- ### List all books via REST API Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Sends a GET request to retrieve all books. On first call, the data is fetched from the database and added to the Coherence cache. Subsequent calls will hit the cache. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:8090/api/books" ``` -------------------------------- ### Get a single book that triggers a BusinessException Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Sends a GET request for book ID 42, which causes a BusinessException to be thrown. The response is an Internal Server Error (HTTP 500), and a Resilience4j fallback method handles the exception. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:8090/api/books/42" ``` -------------------------------- ### GET request after creation with response Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Re-runs the GET request to retrieve the person created earlier. Shows the HTTP 200 response with JSON body containing the person details. ```bash curl -i -X GET http://localhost:8080/api/people/100 HTTP/1.1 200 Content-Type: application/json Transfer-Encoding: chunked Date: Thu, 19 Aug 2021 16:13:47 GMT {"id":100,"age":21,"firstname":"Joe","lastname":"Smith"}% ``` -------------------------------- ### Get a single plant via REST API Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to GET a single plant by ID. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:9090/plants/1" ``` -------------------------------- ### Example Authentication Request JSON Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle JSON payload for authenticating with the sample application. The username is 'coherence' and the password is 'rocks'. A successful authentication returns a 2xx HTTP status with an empty body and a session cookie. ```json { "username": "coherence", "password": "rocks" } ``` -------------------------------- ### Map locations cache to db-scheme with locationRepository bean Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example mapping for a different cache store, using the default bean name 'locationRepository' for a LocationRepository class. Shows how to add another cache mapping with a different repository bean. ```xml locations db-scheme repository-bean locationRepository ``` -------------------------------- ### @CoherenceTopicListener receive(Element) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example of an annotated subscriber method that receives an Element parameter, providing access to the message value and metadata. ```APIDOC ## [TOPIC] receive(Element product) ### Description This method is invoked when a message is received from the topic. It receives an Element containing the message value and metadata. ### Method TOPIC ### Endpoint Not applicable (in-process method) ### Parameters #### Method Parameters - **product** (Element) - Required - The Element received from the topic, containing the message value and metadata. ### Request Example ```java @CoherenceTopicListener @Topic("my-products") public void receive(Element product) { // ... process message ... } ``` ### Response #### Success Response (200) - No explicit return value (void) #### Response Example Not applicable ``` -------------------------------- ### Receive only Started and Stopped events Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use @Started and @Stopped annotations on the method parameter to receive only the specified event types. ```java @CoherenceEventListener public void onEvent(@Started @Stopped CoherenceLifecycleEvent event) { // TODO: process the event } ``` -------------------------------- ### Coherence Spring Boot YAML Configuration Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Example YAML configuration for Coherence with Spring Boot, including logging, sessions, and native properties. ```yaml coherence: logging: destination: slf4j logger-name: MyCoherence sessions: - name: default config: "coherence-cache-config.xml" priority: 1 - name: test config: "test-coherence-config.xml" priority: 2 properties: coherence.log.limit: 400 coherence.log.level: 1 ``` -------------------------------- ### Retrieving Cache Statistics Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle GET request to retrieve cache statistics for the 'events' cache. The response should show TotalPuts of 1. ```bash $ curl --request GET 'http://localhost:8080/api/statistics/events' ``` -------------------------------- ### Using @CoherenceMap with session parameter Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle A more concise way to specify both the cache name and session name using the session parameter of @CoherenceMap. This example injects a NamedMap from the 'products' cache in the 'Catalog' session. ```java @CoherenceMap(name="products", session="Catalog") private NamedMap map; ``` -------------------------------- ### Retrieve Event Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle GET request to retrieve the event with id 1. The value is returned directly from the cache without executing SQL queries. ```bash curl --request GET 'http://localhost:8080/api/events/1' ``` -------------------------------- ### Receive specific EntryEvent types with @Inserted and @Removed Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Apply one or more event type annotations to the method parameter to restrict received events. This example receives only Inserted and Removed events. ```java @CoherenceEventListener public void onEvent(@Inserted @Removed EntryEvent event) { // TODO: process the event } ``` -------------------------------- ### Build the cache store sample with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Builds the cache store demo module using the Maven wrapper. Run from the cache store sample root directory. ```bash ./mvnw clean package -pl samples/cachestore-demo ``` -------------------------------- ### Receive specific SessionLifecycleEvent types with @Started and @Stopped Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Annotate the event parameter with @Started and @Stopped to receive only those event types. The method will not receive Starting or Stopping events. ```java @CoherenceEventListener public void onEvent(@Started @Stopped SessionLifecycleEvent event) { // TODO: process the event } ``` -------------------------------- ### Set up Config Data Git Repository Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to create and initialize a Git repository for the configuration data. ```bash $ cd /path/to/git/repo $ mkdir coherence-spring-config-repository $ cd coherence-spring-config-repository $ git init ``` -------------------------------- ### Build the Coherence Server instance with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Command to build the Hibernate cache demo application using Maven wrapper. ```bash $ ./mvnw clean package -pl samples/hibernate-cache-demo ``` -------------------------------- ### Build the Spring Boot demo with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Builds the coherence-spring-demo-boot module using the Maven wrapper. The -pl flag targets the specific module. ```bash $ ./mvnw clean package -pl samples/coherence-spring-demo/coherence-spring-demo-boot ``` -------------------------------- ### config-client.properties Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Properties file for the demo client, setting Coherence logging severity and destination. ```properties coherence.logging.severity-level=6 __**(1)** coherence.logging.destination=slf4j __**(2)** ``` -------------------------------- ### Run the Spring Boot application Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Command to run the built Hibernate cache demo JAR file. ```bash $ java -jar samples/hibernate-cache-demo/target/hibernate-cache-demo-3.2.0.jar ``` -------------------------------- ### Demo Client Maven Dependencies Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven dependencies for the demo client, including coherence-spring-boot-starter, coherence, and spring-cloud-starter-config. ```xml com.oracle.coherence.spring coherence-spring-boot-starter __**(1)** {coherence-spring.version} com.oracle.coherence.ce coherence __**(2)** {coherence.version} org.springframework.cloud spring-cloud-starter-config __**(3)** ``` -------------------------------- ### Build Coherence Server Instance (Embedded) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven command to build the Spring Session demo application for the embedded Coherence use case. Run from the repository root. ```bash $ ./mvnw clean package -pl samples/spring-session-demo/spring-session-demo-app ``` -------------------------------- ### Inject a View with a More Complex @WhereFilter Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle The @WhereFilter can include more complex CohQL expressions, such as combining conditions with 'and'. This example filters on both lastName and age. ```java @CoherenceMap("people") @View @WhereFilter("lastName = 'Simpson' and age > 10") __**(1)** private NamedMap simpsons; ``` -------------------------------- ### Clone the Spring Cloud Config demo project Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to clone the Coherence Spring repository and change into the coherence-spring directory to access the Spring Cloud Config demo. ```bash $ git clone https://github.com/coherence-community/coherence-spring.git $ cd coherence-spring ``` -------------------------------- ### Enable Coherence Repositories with @EnableCoherenceRepositories Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Configuration class that enables Coherence and Coherence repositories. Must be used to activate repository support. ```java import com.oracle.coherence.spring.configuration.annotation.EnableCoherence; import com.oracle.coherence.spring.configuration.data.config.EnableCoherenceRepositories; // ... @Configuration @EnableCoherence @EnableCoherenceRepositories public static class Config { } ``` -------------------------------- ### Run the Spring Boot jar Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Runs the built Spring Boot jar using the standard java -jar command. ```bash java -jar samples/cachestore-demo/target/coherence-spring-cachestore-demo-3.2.0.jar ``` -------------------------------- ### POM configuration: Add Coherence Spring Boot Starter and Coherence dependencies Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Add the coherence-spring-boot-starter dependency to activate AutoConfiguration, and the desired version of Coherence (CE or Commercial). The version shown is 3.2.0 for the starter and 21.12.4 for Coherence CE. ```xml com.oracle.coherence.spring coherence-spring-boot-starter __**(1)** 3.2.0 com.oracle.coherence.ce coherence __**(2)** 21.12.4 ``` -------------------------------- ### Build Coherence Server Instance (Remote) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven command to build the Coherence server instance for the remote Coherence use case. ```bash $ ./mvnw clean package -pl samples/spring-session-demo/spring-session-demo-server ``` -------------------------------- ### Receive TransferEvent from a specific cache service Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Apply the @ServiceName annotation to the method parameter to restrict events to those from a specific cache service. The example receives events only for caches owned by the service named 'StorageService'. ```java @CoherenceEventListener public void onEvent(@ServiceName("StorageService") TransferEvent event) { // TODO: process the event } ``` -------------------------------- ### Enable Async Support with @EnableAsync Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Configuration class that enables async support along with Coherence repositories. Required for @Async methods to work. ```java import com.oracle.coherence.spring.configuration.annotation.EnableCoherence; import com.oracle.coherence.spring.configuration.data.config.EnableCoherenceRepositories; import org.springframework.scheduling.annotation.EnableAsync; // ... @Configuration @EnableAsync @EnableCoherence @EnableCoherenceRepositories public static class Config { } ``` -------------------------------- ### Using ProductClient bean Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Retrieve the ProductClient bean from the ApplicationContext and send a message. ```java ProductClient client = applicationContext.getBean(ProductClient.class); client.sendProduct("Blue Trainers"); ``` -------------------------------- ### POST request to create a person Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Creates a Person with id 100, firstName Joe, lastName Smith, and age 21. Expect a 200 response and the person is stored in the database. ```bash curl -i -X POST http://localhost:8080/api/people \ -d 'firstName=Joe' -d 'lastName=Smith' \ -d 'age=21' -d 'id=100' ``` -------------------------------- ### Define a custom filter binding annotation with @FilterBinding Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Create a custom annotation annotated with @FilterBinding, @Documented, and @Retention(RUNTIME). The annotation is used to specify a Coherence Filter at injection points. The example defines the LargePalmTrees annotation. ```java import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import com.oracle.coherence.spring.annotation.FilterBinding; @FilterBinding __**(1)** @Documented @Retention(RetentionPolicy.RUNTIME) public @interface LargePalmTrees { __**(2)** } ``` -------------------------------- ### Receive TransactionEvent from specific cache service with @ServiceName Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Restrict events received by a method to only those related to caches owned by a specific service by annotating the method parameter with @ServiceName. This example only receives events for the caches owned by the service named 'StorageService'. ```java @CoherenceEventListener public void onEvent(@ServiceName("StorageService") TransactionEvent event) { // TODO: process the event } ``` -------------------------------- ### Log into the application using CURL Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to authenticate to the application at localhost:8090/login. It sends a JSON POST request with the username and password, and saves the session cookie to cookie.txt. ```bash $ curl -i -c cookie.txt \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X POST --data '{"username": "coherence", "password": "rocks"}' \ "http://localhost:8090/login" ``` -------------------------------- ### Using @CoherenceMap with session parameter in a constructor Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle The @CoherenceMap annotation with session parameter can also be used on method parameter injection points, such as constructor parameters. This example shows a controller constructor injecting a NamedMap from the 'products' cache in the 'Catalog' session. ```java @Controller public class CatalogController { public CatalogController(@CoherenceMap(name="products", session="Catalog") NamedMap products) { // TODO: initialize the bean... } } ``` -------------------------------- ### POM configuration: Add Spring Cache Abstraction dependency Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Add the spring-boot-starter-cache dependency to use Spring's caching abstraction with Coherence. ```xml org.springframework.boot spring-boot-starter-cache ``` -------------------------------- ### Receive Committed TransactionEvent with @Committed annotation Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Restrict the TransactionEvent types received by a method by applying one or more annotations (e.g., @Committing, @Committed) to the method parameter. This example receives only Committed events, which are raised after mutations have been committed to the underlying backing maps. ```java @CoherenceEventListener public void onEvent(@Committed TransactionEvent event) { // TODO: process the event } ``` -------------------------------- ### Create the first event Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle POST request to create an event with title 'First Event' and date '2020-11-30'. The event is persisted and added to the 'events' cache via @CachePut. ```bash curl --request POST 'http://localhost:8080/api/events?title=First%20Event&date=2020-11-30' ``` -------------------------------- ### Access the HelloController Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to access the /hello endpoint using the session cookie from cookie.txt. It returns the string 'Hello Coherence'. ```bash $ curl -i -b cookie.txt \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X GET "http://localhost:8090/hello" ``` -------------------------------- ### Inject a Publisher that publishes on the 'orders' topic (constructor parameter) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Injects a Publisher into a constructor parameter, using @Name("orders") to specify the topic name. ```java @Controller public class OrderController { @Inject public OrderController(@Name("orders") Publisher topic) { // ToDo: } } ``` -------------------------------- ### Add a plant via REST API Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Curl command to POST a new plant to the application on port 9090. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X POST --data '{"genus": "Sabal", "species": "minor", "commonName": "Dwarf palmetto"}' \ "http://localhost:9090/plants" ``` -------------------------------- ### Log output showing cache hit for all books Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Expected log output when retrieving the list of books again after the first call, indicating the cache entry for key 'SimpleKey []' was found in cache 'allBooks'. ```log Cache entry for key 'SimpleKey []' found in cache 'allBooks' ``` -------------------------------- ### Clone the Coherence Spring repository Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Clones the coherence-spring repository from GitHub and changes into the project directory. Required before building the demo. ```bash $ git clone https://github.com/coherence-community/coherence-spring.git $ cd coherence-spring ``` -------------------------------- ### Run Spring Boot Application (Embedded) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to launch two instances of the Spring Boot application for the embedded Coherence use case. The first instance uses the pre-configured port 8090, the second uses port 8091 via the --server.port argument. ```bash $ java -jar samples/spring-session-demo/spring-session-demo-app/target/spring-session-demo-app-3.2.0.jar $ java -jar samples/spring-session-demo/spring-session-demo-app/target/spring-session-demo-app-3.2.0.jar --server.port=8091 ``` -------------------------------- ### Projection interface using nullable wrappers Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows a projection interface using java.util.Optional as a nullable wrapper for null-safety. Supported wrappers include Optional, Guava Optional, scala.Option, and vavr Option. ```java interface TitleOnly { Optional getTitle(); } ``` -------------------------------- ### Open projection using a default method Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Defines an open projection interface with a default method that implements custom logic using the projection's getter methods. ```java interface BookTitleAndAuthor { default String getTitleAndAuthor() { return getAuthor().getFirstName().concat(' - ').concat(getTitle()); } } ``` -------------------------------- ### Async Repository with @Async and CoherenceAsyncRepository Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Repository interface extending CoherenceAsyncRepository with an async finder method annotated with @Async. Requires @EnableAsync on configuration. ```java import com.oracle.coherence.spring.data.config.CoherenceMap; import com.oracle.coherence.spring.data.model.Author; import com.oracle.coherence.spring.data.model.Book; import com.oracle.coherence.spring.data.repository.CoherenceAsyncRepository; import com.tangosol.util.UUID; import org.springframework.scheduling.annotation.Async; // ... @CoherenceMap("book") public interface CoherenceBookAsyncRepository extends CoherenceAsyncRepository { @Async CompletableFuture> findByAuthor(Author author); } ``` -------------------------------- ### Assign People to Events Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle POST requests to assign people with ids 2 and 3 to event with id 1. ```bash curl --request POST 'http://localhost:8080/api/people/2/add-to-event/1' curl --request POST 'http://localhost:8080/api/people/3/add-to-event/1' ``` -------------------------------- ### Inject a Publisher while specifying the owning session Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Injects a Publisher from the 'Customers' session, with topic name 'orders' specified via @Name. ```java @Inject @Name("orders") @SessionName("Customers") private Publisher orders; ``` -------------------------------- ### PersonController.java - REST controller for cache store sample Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Spring Boot controller with endpoints to create and retrieve Person entities. Uses @CoherenceMap to inject a NamedMap for the 'people' cache, which is configured to use a CacheStore. The createPerson method puts a Person into the cache, and the getPerson method retrieves it, throwing a 404 if not found. ```java @RestController @RequestMapping(path = "/api/people") @Transactional() public class PersonController { /** * The {@link NamedMap} to store {@link Person} entities. */ @CoherenceMap private NamedMap people; /** * Create a {@link Person} in the cache. * @param id the unique identifier for the person * @param firstName the person's first name * @param lastName the person's last name * @param age the person's age * @return the identifier used to create the person */ @PostMapping public Long createPerson(@RequestParam("id") long id, @RequestParam("firstName") String firstName, @RequestParam("lastName") String lastName, @RequestParam("age") int age) { Person person = new Person(); person.setFirstname(firstName); person.setLastname(lastName); person.setAge(age); person.setId(id); people.put(id, person); return id; } /** * Returns the {@link Person} with the specified identifier. * * @param personId the unique identifier for the person * @return the {@link Person} with the specified identifier */ @GetMapping("/{personId}") public Person getPerson(@PathVariable("personId") Long personId) { Person person = people.get(personId); if (person == null) { throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Person " + personId + " does not exist"); } return person; } } ``` -------------------------------- ### Evict a book from the Coherence cache Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Sends a DELETE request to evict book with ID 1 from the Coherence cache. After this, retrieving the book again will fetch it from the persistence store. ```bash curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -X DELETE "http://localhost:8090/api/books/1" ``` -------------------------------- ### Generate a Docker image Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven command to generate a Docker image for the Spring Session demo application using spring-boot:build-image. The image name is set to coherence/spring_session_demo. ```bash $ mvn spring-boot:build-image -pl samples/spring-session-demo/spring-session-demo-app -Dspring-boot.build-image.imageName=coherence/spring_session_demo ``` -------------------------------- ### Run Spring Boot Application (Remote) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Commands to run the Coherence server and the application instance for the remote Coherence use case. The application is run with the 'coherence-client' Spring Boot profile activated. ```bash $ java -jar samples/spring-session-demo/spring-session-demo-app/target/spring-session-demo-server-3.2.0.jar $ java -jar samples/spring-session-demo/spring-session-demo-app/target/spring-session-demo-app-3.2.0.jar ``` -------------------------------- ### Add Coherence Spring Boot Starter Dependency (Gradle) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Gradle dependencies for the Coherence Spring Boot starter and Coherence CE. Requires Oracle Coherence CE version 20.12 or higher. ```groovy dependencies { compile("com.oracle.coherence.spring:coherence-spring-boot-starter:3.2.0") compile("com.oracle.coherence.ce:coherence:21.12.4") } ``` -------------------------------- ### Using Query Hints for caching query results Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Java method with @QueryHints and @Query annotations to make a query cacheable. ```java @QueryHints(@QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true")) @Query("select p from Plant p") List getAllPlantsCacheable(); ``` -------------------------------- ### Add Coherence Spring Boot Starter Dependency (Maven) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven dependencies for the Coherence Spring Boot starter and Coherence CE. Requires Oracle Coherence CE version 20.12 or higher. ```xml com.oracle.coherence.spring coherence-spring-boot-starter 3.2.0 com.oracle.coherence.ce coherence 21.12.4 ``` -------------------------------- ### Return result of the created event Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle JSON response showing the created event with id 1, title 'First Event', and date '2020-11-30T00:00:00.000+00:00'. ```json { "id" : 1, "title" : "First Event", "date" : "2020-11-30T00:00:00.000+00:00" } ``` -------------------------------- ### Repository Using Interface-based Projection Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Repository interface with a query method returning a projection interface. ```java interface BookRepository extends CrudRepository { List findByTitle(String title); } ``` -------------------------------- ### Define a CacheManager with additional cache configuration in XML Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use this XML configuration to define a CoherenceCacheManager with a CoherenceCacheConfiguration that sets a time-to-live of 1234 milliseconds. The cacheConfiguration is passed as the second constructor argument. ```xml ``` -------------------------------- ### Use @SessionName to specify session Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Injects a NamedTopic from the 'Customers' session, with topic name 'orders' specified via @Name. ```java @Inject @SessionName("Customers") @Name("orders") private NamedTopic topic; ``` -------------------------------- ### Listen to events for ALL caches in the "Customer" session Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use @SessionName("Customer") without @MapName or @CacheName to receive events for all caches owned by the session named 'Customer'. ```java @CoherenceEventListener public void onEventInAllCachesInCustomerSession(@SessionName("Customer") __**(1)** MapEvent event) { // TODO: process the event } ``` -------------------------------- ### Repository using a dynamic projection parameter Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Defines a repository method that accepts a Class parameter to select the projection type at invocation time. ```java @CoherenceMap("book") interface BookRepository extends CrudRepository { Collection findByTitle(String title, Class type); } ``` -------------------------------- ### Log output showing cache hit for a single book Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Expected log output when retrieving a single book, indicating the cache entry for key '1' was found in cache 'books'. ```log Cache entry for key '1' found in cache 'books' ``` -------------------------------- ### Configuration class with @CoherencePublisherScan Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Annotate a configuration class with @CoherencePublisherScan to specify the base package for scanning @CoherencePublisher interfaces. ```java @Configuration @CoherencePublisherScan("com.example.app.services") public class Config { } ``` -------------------------------- ### Define distributed scheme with repository bean as CacheStore Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Defines a distributed-scheme named db-scheme with a read-write-backing-map-scheme that uses a {repository-bean} as the cachestore. The repository-bean parameter is a macro that will be replaced per cache mapping. ```xml db-scheme StorageService {repository-bean} true ``` -------------------------------- ### Equivalent Coherence Properties Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Two sets of equivalent properties for configuring Coherence logging. The first set uses the 'coherence.logging' prefix, while the second uses the 'coherence.log' prefix. ```properties coherence.logging.severity-level=5 coherence.logging.destination=log4j coherence.log.level=5 coherence.log=log4j ``` -------------------------------- ### Configure default session with SessionConfigurationBean Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Defines a SessionConfigurationBean to set the session type to SERVER and use a custom Coherence configuration file. This is for cluster member or Coherence*Extend client sessions. ```java @Bean SessionConfigurationBean sessionConfigurationBeanDefault() { final SessionConfigurationBean sessionConfigurationBean = new SessionConfigurationBean(); sessionConfigurationBean.setType(SessionType.SERVER); sessionConfigurationBean.setConfig("test-coherence-config.xml"); return sessionConfigurationBean; } ``` -------------------------------- ### Mono value and return type Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Method signature for a publisher that accepts a Mono and returns a Mono. ```java Mono sendBook(Mono book); ``` -------------------------------- ### Define Finder Query on CoherenceRepository Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Repository interface extending CoherenceRepository with a finder method findByAuthor. Finder queries execute in a blocking manner. ```java import com.oracle.coherence.spring.data.repository.CoherenceRespository; import com.oracle.coherence.spring.data.model.Author; import com.oracle.coherence.spring.data.model.Book; import com.tangosol.util.UUID; // ... public interface BookRepository extends CoherenceRepository { List findByAuthor(Author author); // other finders } ``` -------------------------------- ### Inject a Publisher that publishes on the 'orders' topic Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Injects a Publisher with @Name("orders") to specify the topic name, overriding the field name. ```java @Inject @Name("orders") private Publisher orders; ``` -------------------------------- ### Define a CacheManager with additional cache configuration in Java Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use this Java configuration to define a CoherenceCacheManager with a custom CoherenceCacheConfiguration that sets a time-to-live of 1234 milliseconds. The cacheConfiguration is passed as the second constructor argument. ```java @Configuration @EnableCaching public class CacheConfiguration { @Bean public CacheManager cacheManager(Coherence coherence) { CoherenceCacheConfiguration cacheConfiguration = new CoherenceCacheConfiguration(Duration.ofMillis(1234)); return new CoherenceCacheManager(coherenceInstance, cacheConfiguration); } } ``` -------------------------------- ### Add Oracle Coherence CE dependency (Gradle) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Gradle dependency for the open source Coherence CE version. Specify this to use Coherence CE. ```groovy implementation("com.oracle.coherence.ce:coherence:21.12.4") ``` -------------------------------- ### Spring Boot configuration to enable health endpoints Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle YAML configuration to expose all management endpoints and show health details. This is for demonstration purposes only and should not be used in production without security. ```yaml management.endpoints.web.exposure.include: "*" management.endpoint.health.show-details: always ``` -------------------------------- ### Forwarding messages with @SendTo (imperative) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows how to use @SendTo on a @CoherenceTopicListener method that returns a value. The return value is forwarded to the specified topic, and the key of the original ConsumerRecord is used as the key when forwarding. ```java import com.oracle.coherence.spring.*; import org.springframework.messaging.handler.annotation.SendTo; @CoherenceTopicListener public class ProductListener { @Topic("awesome-products") __**(1)** @SendTo("product-quantities") __**(2)** public int receive(Product product) { System.out.println("Got Product - " + product.getName() + " by " + product.getBrand()); return product.getQuantity(); __**(3)** } } ``` -------------------------------- ### Subscribe to EntryProcessorEvent with @CoherenceEventListener Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Create a Spring bean with a listener method annotated with @CoherenceEventListener. The method takes a single parameter of type EntryProcessorEvent and receives events for all caches. ```java @CoherenceEventListener public void onEvent(EntryProcessorEvent event) { // TODO: process the event } ``` -------------------------------- ### Listen to events for the "orders" map in the "Customer" session only Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use @MapName("orders") with @SessionName("Customer") to receive events for the map named 'orders' only from the session named 'Customer'. ```java @CoherenceEventListener public void onOrdersEventInCustomerSession(@MapName("orders") @SessionName("Customer") __**(1)** MapEvent event) { // TODO: process the event } ``` -------------------------------- ### Add Coherence Spring Data Support with Maven Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Maven dependencies to add Coherence Spring Boot starter, Coherence Spring Data, and Coherence CE to a Spring Boot project. Auto-configuration activates automatically. ```xml com.oracle.coherence.spring coherence-spring-boot-starter 3.2.0 com.oracle.coherence.spring coherence-spring-data 3.2.0 com.oracle.coherence.ce coherence 21.12.4 ``` -------------------------------- ### Add Coherence Spring Data Support with Gradle Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Gradle dependencies to add Coherence Spring Boot starter, Coherence Spring Data, and Coherence CE to a Spring Boot project. Auto-configuration activates automatically. ```groovy dependencies { compile("com.oracle.coherence.spring:coherence-spring-boot-starter:3.2.0") compile("com.oracle.coherence.spring:coherence-spring-data:3.2.0") compile("com.oracle.coherence.ce:coherence:21.12.4") } ``` -------------------------------- ### Annotate injection point with @PalmTrees and @CoherenceCache Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows how to inject a NamedMap view using @View, @PalmTrees(1), and @CoherenceCache("plants"). The annotation value of 1 indicates palm trees of at least 1 meter in height. ```java @View __**(1)** @PalmTrees(1) __**(2)** @CoherenceCache("plants") __**(3)** private NamedMap palmTrees; ``` -------------------------------- ### Configure gRPC session with GrpcSessionConfigurationBean Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Defines a GrpcSessionConfigurationBean to connect as a gRPC client. The channelName property refers to a grpcChannel bean. ```java @Bean GrpcSessionConfigurationBean grpcSessionConfigurationBean() { final GrpcSessionConfigurationBean sessionConfigurationBean = new GrpcSessionConfigurationBean(); sessionConfigurationBean.setName("sessionName"); sessionConfigurationBean.setChannelName("grpcChanelBeanName"); return sessionConfigurationBean; } ``` -------------------------------- ### Listen to events for the "orders" map in ALL sessions Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use @MapName("orders") without @SessionName to receive events for the map named 'orders' from all sessions. ```java @CoherenceEventListener public void onOrdersEventAllSessions(@MapName("orders") __**(1)** MapEvent event) { // TODO: process the event } ``` -------------------------------- ### Recursive Projection Interface Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Projection interface with a nested projection interface for the author. ```java interface BookSummary { String getTitle(); int getPages(); AuthorSummary getAuthor(); interface AuthorSummary { String getFirstName(); } } ``` -------------------------------- ### Forwarding messages with @SendTo (reactive) Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Shows the reactive equivalent of forwarding messages with @SendTo. The method returns a Mono and maps the product quantity to the return value. ```java import com.oracle.coherence.spring.*; import org.springframework.messaging.handler.annotation.SendTo; import reactor.core.publisher.Mono; @CoherenceTopicListener public class ProductListener { @Topic("awesome-products") __**(1)** @SendTo("product-quantities") __**(2)** public Mono receiveProduct(Mono productSingle) { return productSingle.map(product -> { System.out.println("Got Product - " + product.getName() + " by " + product.getBrand()); return product.getQuantity(); __**(3)** }); } } ``` -------------------------------- ### Log output when fallback method is called due to Coherence connection failure Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Expected log output when the Coherence server is shut down and a book is retrieved. The fallback method is called because the CacheManager cannot connect to the Coherence instance, and the book is returned from the persistence store. ```log getBook fallback method (For Throwable) was called: Unable to locate ProxyService 'ExtendTcpCacheService' ... ``` -------------------------------- ### Listen to events for the "foo" map on all services Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Use @MapName("foo") without @ServiceName to receive events for the map named 'foo' from all cache services. ```java @CoherenceEventListener public void onEventFromAllServices(@MapName("foo") __**(1)** MapEvent event) { // TODO: process the event } ``` -------------------------------- ### Interface-based Projection Interface Source: https://spring.coherence.community/3.2.0/refdocs/reference/htmlsingle Projection interface exposing getTitle and getPages to retrieve a subset of attributes. ```java interface BookTitleAndPages { String getTitle(); int getPages(); } ```