Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Adds Java Controller and Metadata support
Browse files Browse the repository at this point in the history
I've only added metadata support inputs for event sourcing and crdts, I
haven't added it for outputs yet.

Controller support is in full.
  • Loading branch information
jroper committed Jul 2, 2020
1 parent 86d0a21 commit 41103e7
Show file tree
Hide file tree
Showing 38 changed files with 2,655 additions and 101 deletions.
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
version: 2.1
# CircleCi Build Config for CloudState
commands:
install-java-11:
description: install openjdk-11
steps:
- run:
name: Install java 11
command: |
wget https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz -O /tmp/openjdk-11.tar.gz
sudo mkdir -p /usr/lib/jvm
sudo tar xfvz /tmp/openjdk-11.tar.gz --directory /usr/lib/jvm
rm -f /tmp/openjdk-11.tar.gz
sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.6+10/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done'
sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.6+10/bin/*; do update-alternatives --set $(basename $bin) $bin; done'
setup_sbt:
description: "Set up SBT"
parameters:
Expand Down Expand Up @@ -32,6 +47,7 @@ jobs:
description: "native image tck tests"
steps:
- checkout
- install-java-11
- setup_sbt
- run: |
sbt -Dconfig.resource=native-image.conf \
Expand Down
9 changes: 5 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ lazy val `java-support` = (project in file("java-support"))
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.9.3"
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8"),
javacOptions in (Compile, compile) ++= Seq("-source", "1.8", "-target", "1.8"),
javacOptions in (Compile, compile) ++= Seq("-source", "11", "-target", "11"),
akkaGrpcGeneratedSources in Compile := Seq(AkkaGrpc.Server),
akkaGrpcGeneratedLanguages in Compile := Seq(AkkaGrpc.Scala), // FIXME should be Java, but here be dragons

Expand All @@ -639,7 +639,8 @@ lazy val `java-support` = (project in file("java-support"))
sbtprotoc.ProtocPlugin.protobufConfigSettings ++ Seq(
PB.protoSources ++= {
val baseDir = (baseDirectory in ThisBuild).value / "protocols"
Seq(baseDir / "example")
val testSources = sourceDirectory.value / "proto"
Seq(baseDir / "example", testSources)
},
PB.targets := Seq(
PB.gens.java -> crossTarget.value / "akka-grpc" / "test"
Expand Down Expand Up @@ -725,7 +726,7 @@ lazy val `java-shopping-cart` = (project in file("samples/java-shopping-cart"))
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8"),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "11", "-target", "11"),
assemblySettings("java-shopping-cart.jar")
)

Expand All @@ -745,7 +746,7 @@ lazy val `java-pingpong` = (project in file("samples/java-pingpong"))
PB.targets in Compile := Seq(
PB.gens.java -> (sourceManaged in Compile).value
),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8"),
javacOptions in Compile ++= Seq("-encoding", "UTF-8", "-source", "11", "-target", "11"),
assemblySettings("java-pingpong.jar")
)

Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/paradox/user/lang/java/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ Exactly which context parameters are available depend on the type of entity and
|--------------------------------------------------------|-----------------------|-----------------------|
| @javadoc[`Context`](io.cloudstate.javasupport.Context) | | The super type of all Cloudstate contexts. Every invoker makes a subtype of this available for injection, and method or constructor may accept that sub type, or any super type of that subtype that is a subtype of `Context`. |
| `java.lang.String` | @javadoc[`@EntityId`](io.cloudstate.javasupport.EntityId) | The ID of the entity. |

| @javadoc[`Metadata`](io.cloudstate.javasupport.Metadata) | | The metadata associated with the command. |
| @javadoc[`CloudEvent`](io.cloudstate.javasupport.CloudEvent) | | The CloudEvent metadata associated with the command. May be wrapped in `java.util.Optional`. |
171 changes: 171 additions & 0 deletions java-support/src/main/java/io/cloudstate/javasupport/CloudEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package io.cloudstate.javasupport;

import java.net.URI;
import java.time.ZonedDateTime;
import java.util.Optional;

/** CloudEvent representation of Metadata. */
public interface CloudEvent {

/**
* The CloudEvent spec version.
*
* @return The spec version.
*/
String specversion();

/**
* The id of this CloudEvent.
*
* @return The id.
*/
String id();

/**
* Return a new CloudEvent with the given id.
*
* @param id The id to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withId(String id);

/**
* The source of this CloudEvent.
*
* @return The source.
*/
URI source();

/**
* Return a new CloudEvent with the given source.
*
* @param source The source to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withSource(URI source);

/**
* The type of this CloudEvent.
*
* @return The type.
*/
String type();

/**
* Return a new CloudEvent with the given type.
*
* @param type The type to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withType(String type);

/**
* The data content type of this CloudEvent.
*
* @return The data content type, if set.
*/
Optional<String> datacontenttype();

/**
* Return a new CloudEvent with the given data content type.
*
* @param datacontenttype The data content type to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withDatacontenttype(String datacontenttype);

/**
* Clear the data content type of this CloudEvent, if set.
*
* @return A copy of this CloudEvent.
*/
CloudEvent clearDatacontenttype();

/**
* The data schema of this CloudEvent.
*
* @return The data schema, if set.
*/
Optional<URI> dataschema();

/**
* Return a new CloudEvent with the given data schema.
*
* @param dataschema The data schema to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withDataschema(URI dataschema);

/**
* Clear the data schema of this CloudEvent, if set.
*
* @return A copy of this CloudEvent.
*/
CloudEvent clearDataschema();

/**
* The subject of this CloudEvent.
*
* @return The subject, if set.
*/
Optional<String> subject();

/**
* Return a new CloudEvent with the given subject.
*
* @param subject The subject to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withSubject(String subject);

/**
* Clear the subject of this CloudEvent, if set.
*
* @return A copy of this CloudEvent.
*/
CloudEvent clearSubject();

/**
* The time of this CloudEvent.
*
* @return The time, if set.
*/
Optional<ZonedDateTime> time();

/**
* Return a new CloudEvent with the given time.
*
* @param time The time to set.
* @return A copy of this CloudEvent.
*/
CloudEvent withTime(ZonedDateTime time);

/**
* Clear the time of this CloudEvent, if set.
*
* @return A copy of this CloudEvent.
*/
CloudEvent clearTime();

/**
* Return this CloudEvent represented as Metadata.
*
* <p>If this CloudEvent was created by {{@link Metadata#asCloudEvent()}}, then any non CloudEvent
* metadata that was present will still be present.
*
* @return This CloudEvent expressed as Cloudstate metadata.
*/
Metadata asMetadata();

/**
* Create a CloudEvent.
*
* @param id The id of the CloudEvent.
* @param source The source of the CloudEvent.
* @param type The type of the CloudEvent.
* @return The newly created CloudEvent.
*/
static CloudEvent of(String id, URI source, String type) {
return Metadata.EMPTY.asCloudEvent(id, source, type);
}
}
Loading

0 comments on commit 41103e7

Please sign in to comment.