Skip to content

Commit

Permalink
Updates Infinispan to Protostream 5.0.0.Final
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Mar 11, 2024
1 parent 453014a commit 5a0f7b5
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 208 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<hamcrest.version>2.2</hamcrest.version><!-- The version needs to be compatible with both REST Assured and Awaitility -->
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<infinispan.version>15.0.0.CR1</infinispan.version>
<infinispan.protostream.version>5.0.0.CR2</infinispan.protostream.version>
<infinispan.protostream.version>5.0.0.Final</infinispan.protostream.version>
<caffeine.version>3.1.5</caffeine.version>
<netty.version>4.1.107.Final</netty.version>
<brotli4j.version>1.14.0</brotli4j.version>
Expand Down
85 changes: 37 additions & 48 deletions docs/src/main/asciidoc/infinispan-client-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -373,57 +373,45 @@ Here is an example of how the preceding classes should be changed:
.Author.java
[source,java]
----
@ProtoFactory
public Author(String name, String surname) {
this.name = Objects.requireNonNull(name);
this.surname = Objects.requireNonNull(surname);
}
@ProtoField(number = 1)
public String getName() {
return name;
}
@Proto //<1>
public record Author(String name, String surname) { //<2>
}
----
<1> Since Protostream 5.0, a single annotation is needed to generate a default mapping

Check warning on line 380 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 380, "column": 11}}}, "severity": "WARNING"}
<2> Since Protostream 5.0, records are supported

Check warning on line 381 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 381, "column": 11}}}, "severity": "WARNING"}

@ProtoField(number = 2)
public String getSurname() {
return surname;
}
.Type.java
[source,java]
----
@Proto
public enum Type { //<1>
@ProtoEnumValue(number = 1)
FANTASY,
@ProtoEnumValue(number = 2)
PROGRAMMING
}
----
<1> Enums are supported

Check warning on line 394 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Enums'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Enums'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 394, "column": 5}}}, "severity": "WARNING"}

.Book.java
[source,java]
----
@ProtoFactory
public Book(String title, String description, int publicationYear, Set<Author> authors) {
this.title = Objects.requireNonNull(title);
this.description = Objects.requireNonNull(description);
this.publicationYear = publicationYear;
this.authors = Objects.requireNonNull(authors);
}
@ProtoField(number = 1)
public String getTitle() {
return title;
}
@ProtoField(number = 2)
public String getDescription() {
return description;
}
@ProtoField(number = 3, defaultValue = "-1")
public int getPublicationYear() {
return publicationYear;
}
@ProtoField(number = 4)
public Set<Author> getAuthors() {
return authors;
}
@Proto
@Indexed // <1>
public record Book(@Text String title, //<2>
@Keyword(projectable = true, sortable = true, normalizer = "lowercase", indexNullAs = "unnamed", norms = false) //<3>
String description,
int publicationYear,
Set<Author> authors, // <4>
Type bookType,
BigDecimal price // <5>) {
}
----

If your classes have only mutable fields, then the `ProtoFactory` annotation
is not required, assuming your class has a no arg constructor.
<1> Indicates that the entity will be indexed. Necessary to perform distributed full-text query operations.
<2> Indicates the `title` should be indexed as text

Check warning on line 411 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 411, "column": 45}}}, "severity": "INFO"}
<3> Indicates the `description` field field should be indexed as a Keyword.

Check warning on line 412 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 412, "column": 63}}}, "severity": "INFO"}
<4> Collections are supported
<5> Protostream provides default Protobuf mappers for commonly used types as `BigDecimal`, included in the `org.infinispan.protostream.types` package.

Check warning on line 414 in docs/src/main/asciidoc/infinispan-client-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client-reference.adoc", "range": {"start": {"line": 414, "column": 5}}}, "severity": "WARNING"}

Then all that is required is a very simple `GeneratedSchema` interface with an annotation
on it to specify configuration settings
Expand All @@ -432,23 +420,24 @@ on it to specify configuration settings
[source,java]
----
import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import org.infinispan.protostream.annotations.ProtoSchema;
import org.infinispan.protostream.types.java.math.BigDecimalAdapter;
@AutoProtoSchemaBuilder(includeClasses = { Book.class, Author.class, BigDecimalAdapter.class }, schemaPackageName = "book_sample")
@ProtoSchema(includeClasses = { Book.class, Author.class, BigDecimalAdapter.class }, schemaPackageName = "book_sample")
interface BookStoreSchema extends GeneratedSchema {
}
----

[TIP]
====
Protostream provides default Protobuf mappers for commonly used types as `BigDecimal`, included in the `org.infinispan.protostream.types` package.
You can use the `basePackages` property to scan a full package containing your classes.
You can override the default marshalling by using the `@Protofield` annotation.
====

So in this case we will automatically generate the marshaller and schemas for the included classes and
place them in the schema package automatically. The package does not have to be provided, but if you use Infinispan search capabilities, you must know the generated package.

NOTE: In Quarkus the `schemaFileName` and `schemaFilePath` attributes should NOT be set on the `AutoProtoSchemaBuilder` annotation. Setting either attributes causes native runtime errors.
NOTE: In Quarkus the `schemaFileName` and `schemaFilePath` attributes should NOT be set on the `ProtoSchema` annotation. Setting either attributes causes native runtime errors.

=== Custom serialization

Expand Down
25 changes: 8 additions & 17 deletions docs/src/main/asciidoc/infinispan-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,12 @@ Create the `src/main/java/org/acme/infinispan/client/Greeting.java` file, with t
----
package org.acme.infinispan.client;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
import org.infinispan.protostream.annotations.Proto;
public class Greeting { // <1>
@ProtoField(number = 1) // <2>
public String name;
@ProtoField(number = 2) // <3>
public String message;
}
@Proto //<1>
public record Greeting(String name, String message) {} //<2>
----
<1> If your classes have only mutable fields, then the `ProtoFactory` annotation is not required
is not required, assuming your class has a no arg constructor
<2> `@ProtoField` annotation to add the name field as string in the generated Protobuf schema
<3> `@ProtoField` annotation to add the message field as string in the generated Protobuf schema
<1> You only need an annotation to tag the record to be marshalled by Protostream

Check warning on line 83 in docs/src/main/asciidoc/infinispan-client.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protostream'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client.adoc", "range": {"start": {"line": 83, "column": 71}}}, "severity": "WARNING"}

Check warning on line 83 in docs/src/main/asciidoc/infinispan-client.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Be concise: rewrite the sentence to not use' rather than 'Note that'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Be concise: rewrite the sentence to not use' rather than 'Note that'.", "location": {"path": "docs/src/main/asciidoc/infinispan-client.adoc", "range": {"start": {"line": 83, "column": 73}}}, "severity": "INFO"}

Note that we are not going to use Java serialization. https://github.com/infinispan/protostream[Protostream] is
a serialization library based on Protobuf data format part of Infinispan. Using an annotation based API, we

Check warning on line 86 in docs/src/main/asciidoc/infinispan-client.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protobuf'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protobuf'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client.adoc", "range": {"start": {"line": 86, "column": 23}}}, "severity": "WARNING"}
Expand All @@ -104,13 +95,13 @@ Create the `src/main/java/org/acme/infinispan/client/GreetingSchema.java` file,
package org.acme.infinispan.client;
import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import org.infinispan.protostream.annotations.ProtoSchema;
@AutoProtoSchemaBuilder(includeClasses = Greeting.class) // <1>
@ProtoSchema(includeClasses = Greeting.class) // <1>
public interface GreetingSchema extends GeneratedSchema { // <2>
}
----
<1> Includes the `Greeting` pojo with the `@AutoProtoSchemaBuilder` annotation
<1> Includes the `Greeting` pojo with the `@ProtoSchema` annotation
<2> Extends `GeneratedSchema` Protostream API interface

Check warning on line 105 in docs/src/main/asciidoc/infinispan-client.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protobuf'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'Protobuf'?", "location": {"path": "docs/src/main/asciidoc/infinispan-client.adoc", "range": {"start": {"line": 105, "column": 51}}}, "severity": "WARNING"}

The Protobuf Schema that will be generated and used both on client and Infinispan Server side, will have
Expand All @@ -121,7 +112,7 @@ the following content:
// File name: GreetingSchema.proto
// Generated from : org.acme.infinispan.client.GreetingSchema
syntax = "proto2";
syntax = "proto3";
message Greeting {
Expand Down
30 changes: 15 additions & 15 deletions extensions/infinispan-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security-common</artifactId>
</dependency>
<!-- Will allow projects to run annotation processor -->
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-types</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-sasl-plain</artifactId>
Expand Down Expand Up @@ -111,21 +126,6 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-query-dsl</artifactId>
</dependency>
<!-- Will allow projects to run annotation processor -->
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-types</artifactId>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
package io.quarkus.it.infinispan.client;

import java.util.Objects;
import org.infinispan.protostream.annotations.Proto;

import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;

/**
* @author William Burns
*/
public class Author {
private final String name;
private final String surname;

@ProtoFactory
public Author(String name, String surname) {
this.name = Objects.requireNonNull(name);
this.surname = Objects.requireNonNull(surname);
}

@ProtoField(number = 1)
public String getName() {
return name;
}

@ProtoField(number = 2)
public String getSurname() {
return surname;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Author author = (Author) o;
return name.equals(author.name) &&
surname.equals(author.surname);
}

@Override
public int hashCode() {
return Objects.hash(name, surname);
}
@Proto
public record Author(String name, String surname) {
}
Original file line number Diff line number Diff line change
@@ -1,86 +1,16 @@
package io.quarkus.it.infinispan.client;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.Set;

import org.infinispan.api.annotations.indexing.Indexed;
import org.infinispan.api.annotations.indexing.Keyword;
import org.infinispan.api.annotations.indexing.Text;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
import org.infinispan.protostream.annotations.Proto;

/**
* @author William Burns
*/
@Proto
@Indexed
public class Book {
private final String title;
private final String description;
private final int publicationYear;
private final Set<Author> authors;
private final Type bookType;
private final BigDecimal price;

@ProtoFactory
public Book(String title, String description, int publicationYear, Set<Author> authors, Type bookType, BigDecimal price) {
this.title = Objects.requireNonNull(title);
this.description = Objects.requireNonNull(description);
this.publicationYear = publicationYear;
this.authors = Objects.requireNonNull(authors);
this.bookType = bookType;
this.price = price;
}

@ProtoField(number = 1)
@Text
public String getTitle() {
return title;
}

@ProtoField(number = 2)
@Keyword(projectable = true, sortable = true, normalizer = "lowercase", indexNullAs = "unnamed", norms = false)
public String getDescription() {
return description;
}

@ProtoField(number = 3, defaultValue = "-1")
public int getPublicationYear() {
return publicationYear;
}

@ProtoField(number = 4)
public Set<Author> getAuthors() {
return authors;
}

@ProtoField(number = 5)
public Type getBookType() {
return bookType;
}

@ProtoField(number = 6)
public BigDecimal getPrice() {
return price;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Book book = (Book) o;
return publicationYear == book.publicationYear &&
title.equals(book.title) &&
description.equals(book.description) &&
authors.equals(book.authors) &&
bookType.equals(book.bookType) &&
price.equals(book.price);
}

@Override
public int hashCode() {
return Objects.hash(title, description, publicationYear, authors, bookType, price);
}
public record Book(@Text String title,
@Keyword(projectable = true, sortable = true, normalizer = "lowercase", indexNullAs = "unnamed", norms = false) String description,
int publicationYear, Set<Author> authors, Type bookType, BigDecimal price) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.quarkus.it.infinispan.client;

import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import org.infinispan.protostream.annotations.ProtoSchema;
import org.infinispan.protostream.types.java.math.BigDecimalAdapter;

@AutoProtoSchemaBuilder(includeClasses = { Book.class, Type.class, Author.class,
@ProtoSchema(includeClasses = { Book.class, Type.class, Author.class,
BigDecimalAdapter.class }, schemaPackageName = "book_sample")
interface BookStoreSchema extends GeneratedSchema {
}
Loading

0 comments on commit 5a0f7b5

Please sign in to comment.