diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bdfd80b2..2208f3804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,19 +21,27 @@ jobs: env: JDK_VER: 13.0.x DAPR_RUNTIME_VER: 0.3.0 + OSSRH_USER_TOKEN: ${{ secrets.OSSRH_USER_TOKEN }} + OSSRH_PWD_TOKEN: ${{ secrets.OSSRH_PWD_TOKEN }} + GPG_KEY: ${{ secrets.GPG_KEY }} + GPG_PWD: ${{ secrets.GPG_PWD }} steps: - uses: actions/checkout@v1 - - name: Set up ${{ env.JDK_VER }} + - name: Set up OpenJDK ${{ env.JDK_VER }} uses: actions/setup-java@v1 with: java-version: ${{ env.JDK_VER }} - name: Set up Dapr CLI run: wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash - - name: Initialize Dapr runtime as a standalone mode + - name: Initialize Dapr runtime ${{ env.DAPR_RUNTIME_VER }} run: | sudo dapr init --runtime-version ${{ env.DAPR_RUNTIME_VER }} echo "Showing dapr version..." dapr --version + - name: Install Local kafka using docker-compose + run: | + docker-compose -f ./sdk/src/test/java/io/dapr/it/deploy/local-test-kafka.yml up -d + docker ps - name: Clean up files run: mvn clean - name: Build sdk @@ -42,3 +50,32 @@ jobs: run: mvn test - name: Integration-test run: mvn integration-test + - name: Upload test report for sdk + uses: actions/upload-artifact@master + with: + name: report-dapr-java-sdk + path: sdk/target/jacoco-report/ + - name: Upload test report for sdk-actors + uses: actions/upload-artifact@master + with: + name: report-dapr-java-sdk-actors + path: sdk-actors/target/jacoco-report/ + - name: Packaging jars + run: mvn package + - name: Get pom parent version + run: | + PARENT_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) + echo "##[set-env name=PARENT_VERSION;]$PARENT_VERSION" + - name: Is SNAPSHOT release ? + if: contains(github.ref, 'master') && contains(env.PARENT_VERSION, '-SNAPSHOT') + run: echo "##[set-env name=DEPLOY_OSSRH;]true" + - name: Is Release or RC version ? + if: startswith(github.ref, 'refs/tags/v') && !contains(env.PARENT_VERSION, '-SNAPSHOT') + run: echo "##[set-env name=DEPLOY_OSSRH;]true" + - name: Publish to ossrh + if: env.DEPLOY_OSSRH == 'true' + run: | + echo ${{ secrets.GPG_PRIVATE_KEY }} | base64 -d > private-key.gpg + export GPG_TTY=$(tty) + gpg --batch --import private-key.gpg + mvn -V -B -Dgpg.skip=false -s settings.xml deploy diff --git a/.gitignore b/.gitignore index e4b7f0fd4..21ff40244 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # Log file *.log +/syslog.txt # BlueJ files *.ctxt diff --git a/README.md b/README.md index 319491294..f6bf9cf37 100644 --- a/README.md +++ b/README.md @@ -48,27 +48,28 @@ mvn versions:commit ### Debug Java application or Dapr's Java SDK -If you have a Java application or an issue on this SDK that needs to be debugged, follow the steps below: +If you have a Java application or an issue on this SDK that needs to be debugged, run Dapr using a dummy command and start the application from your IDE (IntelliJ, for example). +For Linux and MacOS: -Install [Pen Load Balancer](https://sourceforge.net/projects/penloadbalancer/) or your preferred load balancer utility: ```sh -sudo apt-get install pen -``` -Note: Pen is also available on Windows in the link above. For MacOS, you will need to [build it from source code](https://github.com/UlricE/pen/wiki/Building-Pen-from-Git). - -Then run Dapr with the load balancer process listening on port 3001 and forwarding to port 3000. For Pen Load Balancer, it would be: -```sh -dapr run --app-id testapp --app-port 3001 --port 3500 -- pen -b 99999999 -f localhost:3001 localhost:3000 +dapr run --app-id testapp --app-port 3000 --port 3500 --grpc-port 5001-- cat ``` -The command below will start a load balancer listening on port `3001` that forwards connections to port `3000`, while Dapr's app identifier is `testapp` and listening port is `3500`. If you try to make a HTTP call to any URL on `localhost:3001`, it will fail until you have an application listening on `localhost:3000`. +For Windows: +```sh +dapr run --app-id testapp --app-port 3000 --port 3500 --grpc-port 5001 -- waitfor FOREVER +``` + +When running your Java application from IDE, make sure the following environment variables are set, so the Java SDK knows how to connect to Dapr's sidecar: +``` +DAPR_HTTP_PORT=3500 +DAPR_GRPC_PORT=5001 +``` Now you can go to your IDE (like IntelliJ, for example) and debug your Java application, using port `3500` to call Dapr while also listening to port `3000` to expose Dapr's callback endpoint. Calls to Dapr's APIs on `http://localhost:3500/*` should work now and trigger breakpoints in your code. -**If your application needs to suscribe to topics or register Actors in Dapr, for example, then start debugging your app first and run dapr with load balancer last.** - -Reminder: for Dapr, your application is listening to port `3001` and not `3000` since it can only see the load balancer's port. +**If your application needs to suscribe to topics or register Actors in Dapr, for example, then start debugging your app first and run dapr with dummy command last.** **If using Visual Studio Code, also consider [this solution as well](https://github.com/dapr/docs/tree/master/howto/vscode-debugging-daprd).** diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 000000000..642023427 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,268 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/components/kafka_bindings.yaml b/examples/components/kafka_bindings.yaml new file mode 100644 index 000000000..280e241e1 --- /dev/null +++ b/examples/components/kafka_bindings.yaml @@ -0,0 +1,20 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sample123 +spec: + type: bindings.kafka + metadata: + # Kafka broker connection setting + - name: brokers + value: localhost:9092 + # consumer configuration: topic and consumer group + - name: topics + value: sample + - name: consumerGroup + value: group1 + # publisher configuration: topic + - name: publishTopic + value: sample + - name: authRequired + value: "false" diff --git a/examples/pom.xml b/examples/pom.xml index 0c48a705a..6fc3a8c8a 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -7,17 +7,22 @@ io.dapr dapr-sdk-parent - 0.3.0-alpha + 0.2.0-SNAPSHOT + io.dapr dapr-sdk-examples jar - 0.3.0-alpha + 0.2.0-SNAPSHOT dapr-sdk-examples ${project.build.directory}/generated-sources - ${project.parent.basedir}/proto + ${project.basedir}/proto + 11 + ${java.version} + ${java.version} + true @@ -34,18 +39,27 @@ io.grpc grpc-protobuf + ${grpc.version} io.grpc grpc-stub + ${grpc.version} + + + io.grpc + grpc-api + ${grpc.version} javax.annotation javax.annotation-api + 1.3.2 io.grpc grpc-testing + ${grpc.version} test @@ -58,10 +72,25 @@ protoc-jar-maven-plugin 3.10.1 + + org.springframework.boot + spring-boot-starter-web + 2.2.2.RELEASE + + + org.springframework.boot + spring-boot-autoconfigure + 2.2.2.RELEASE + + + io.dapr + dapr-sdk-actors + ${project.version} + io.dapr dapr-sdk - 0.3.0-alpha + ${project.version} @@ -83,7 +112,7 @@ direct true - ${protobuf.input.directory}/examples + ${protobuf.input.directory} @@ -100,6 +129,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + + diff --git a/proto/examples/helloworld.proto b/examples/proto/helloworld.proto similarity index 100% rename from proto/examples/helloworld.proto rename to examples/proto/helloworld.proto diff --git a/examples/src/main/java/io/dapr/examples/actors/http/DemoActor.java b/examples/src/main/java/io/dapr/examples/actors/http/DemoActor.java new file mode 100644 index 000000000..6cf19f784 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/actors/http/DemoActor.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.actors.http; + +import reactor.core.publisher.Mono; + +/** + * Example of implementation of an Actor. + */ +public interface DemoActor { + + void registerReminder(); + + String say(String something); + + void clock(String message); + + Mono incrementAndGet(int delta); +} diff --git a/examples/src/main/java/io/dapr/examples/actors/http/DemoActorClient.java b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorClient.java new file mode 100644 index 000000000..a3f370c57 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.actors.http; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyBuilder; +import io.dapr.serializer.DefaultObjectSerializer; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +/** + * Client for Actor runtime. + * 1. Build and install jars: + * mvn clean install + * 2. Run the client: + * dapr run --app-id demoactorclient --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.actors.http.DemoActorClient + */ +public class DemoActorClient { + + private static final int NUM_ACTORS = 3; + + private static final int NUM_MESSAGES_PER_ACTOR = 10; + + private static final String METHOD_NAME = "say"; + + private static final ExecutorService POOL = Executors.newFixedThreadPool(NUM_ACTORS); + + public static void main(String[] args) throws Exception { + ActorProxyBuilder builder = new ActorProxyBuilder("DemoActor", new DefaultObjectSerializer()); + + List> futures = new ArrayList<>(NUM_ACTORS); + + for (int i = 0; i < NUM_ACTORS; i++) { + ActorProxy actor = builder.build(ActorId.createRandom()); + futures.add(callActorNTimes(actor)); + } + + futures.forEach(CompletableFuture::join); + POOL.shutdown(); + POOL.awaitTermination(1, TimeUnit.MINUTES); + + System.out.println("Done."); + } + + private static final CompletableFuture callActorNTimes(ActorProxy actor) { + return CompletableFuture.runAsync(() -> { + actor.invokeActorMethod("registerReminder").block(); + for (int i = 0; i < NUM_MESSAGES_PER_ACTOR; i++) { + actor.invokeActorMethod("incrementAndGet", 1).block(); + String result = actor.invokeActorMethod(METHOD_NAME, + String.format("Actor %s said message #%d", actor.getActorId().toString(), i), String.class).block(); + System.out.println(String.format("Actor %s got a reply: %s", actor.getActorId().toString(), result)); + try { + Thread.sleep((long)(1000 * Math.random())); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + return; + } + } + + System.out.println( + "Messages sent: " + actor.invokeActorMethod("incrementAndGet", 0, int.class).block()); + }, POOL); + } +} diff --git a/examples/src/main/java/io/dapr/examples/actors/http/DemoActorImpl.java b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorImpl.java new file mode 100644 index 000000000..870ea9b40 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorImpl.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.actors.http; + +import io.dapr.actors.ActorId; +import io.dapr.actors.runtime.AbstractActor; +import io.dapr.actors.runtime.ActorRuntimeContext; +import io.dapr.actors.runtime.ActorType; +import io.dapr.actors.runtime.Remindable; +import reactor.core.publisher.Mono; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.Calendar; +import java.util.TimeZone; + +/** + * Implementation of the DemoActor for the server side. + */ +@ActorType(name = "DemoActor") +public class DemoActorImpl extends AbstractActor implements DemoActor, Remindable { + + /** + * Format to output date and time. + */ + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + + public DemoActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + + super.registerActorTimer( + null, + "clock", + "ping!", + Duration.ofSeconds(2), + Duration.ofSeconds(1)).block(); + } + + @Override + public void registerReminder() { + super.registerReminder( + "myremind", + (int)(Integer.MAX_VALUE * Math.random()), + Duration.ofSeconds(5), + Duration.ofSeconds(2)).block(); + } + + @Override + public String say(String something) { + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + // Handles the request by printing message. + System.out.println("Server say method for actor " + + super.getId() + ": " + + (something == null ? "" : something + " @ " + utcNowAsString)); + + super.getActorStateManager().set("lastmessage", something).block(); + + // Now respond with current timestamp. + return utcNowAsString; + } + + @Override + public Mono incrementAndGet(int delta) { + return super.getActorStateManager().contains("counter") + .flatMap(exists -> exists ? super.getActorStateManager().get("counter", int.class) : Mono.just(0)) + .map(c -> c + delta) + .flatMap(c -> super.getActorStateManager().set("counter", c).thenReturn(c)); + } + + @Override + public void clock(String message) { + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + // Handles the request by printing message. + System.out.println("Server timer for actor " + + super.getId() + ": " + + (message == null ? "" : message + " @ " + utcNowAsString)); + } + + @Override + public Class getStateType() { + return Integer.class; + } + + @Override + public Mono receiveReminder(String reminderName, Integer state, Duration dueTime, Duration period) { + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + // Handles the request by printing message. + System.out.println(String.format( + "Server reminded actor %s of: %s for %d @ %s", + this.getId(), reminderName, state, utcNowAsString)); + return Mono.empty(); + } +} diff --git a/examples/src/main/java/io/dapr/examples/actors/http/DemoActorService.java b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorService.java new file mode 100644 index 000000000..031be77fc --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/actors/http/DemoActorService.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.actors.http; + +import io.dapr.actors.runtime.ActorRuntime; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.springboot.DaprApplication; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Service for Actor runtime. + * 1. Build and install jars: + * mvn clean install + * 2. Run the server: + * dapr run --app-id demoactorservice --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.actors.http.DemoActorService -Dexec.args="-p 3000" + */ +@SpringBootApplication +public class DemoActorService { + + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port Dapr will listen to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + // Register the Actor class. + ActorRuntime.getInstance().registerActor( + DemoActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + + // Start Dapr's callback endpoint. + DaprApplication.start(port); + + // Start application's endpoint. + SpringApplication.run(DemoActorService.class); + } +} diff --git a/examples/src/main/java/io/dapr/examples/actors/http/HelloController.java b/examples/src/main/java/io/dapr/examples/actors/http/HelloController.java new file mode 100644 index 000000000..37eeec522 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/actors/http/HelloController.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.actors.http; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @RequestMapping("/") + public String index() { + return "Greetings from your Spring Boot Application!"; + } + +} diff --git a/examples/src/main/java/io/dapr/examples/bindings/InputBindingController.java b/examples/src/main/java/io/dapr/examples/bindings/InputBindingController.java new file mode 100644 index 000000000..564fdab06 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/bindings/InputBindingController.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.bindings; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +/** + * SpringBoot Controller to handle input binding. + */ +@RestController +public class InputBindingController { + + @PostMapping(path = "/bindingSample") + public Mono handleInputBinding(@RequestBody(required = false) byte[] body) { + return Mono.fromRunnable(() -> + System.out.println("Received message through binding: " + (body == null ? "" : new String(body)))); + } + +} diff --git a/examples/src/main/java/io/dapr/examples/bindings/InputBindingExample.java b/examples/src/main/java/io/dapr/examples/bindings/InputBindingExample.java new file mode 100644 index 000000000..594aeee8e --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/bindings/InputBindingExample.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.bindings; + +import io.dapr.springboot.DaprApplication; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +/** + * Service for input binding example. + * 1. From your repo root, build and install jars: + * mvn clean install + * 2. cd to [repo-root]/examples + * 3. Run : + * dapr run --app-id inputbinding --app-port 3000 --port 3005 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.InputBindingExample -D exec.args="-p 3000" + */ +public class InputBindingExample { + + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port Dapr will listen to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + // Start Dapr's callback endpoint. + DaprApplication.start(port); + } +} \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/bindings/OutputBindingExample.java b/examples/src/main/java/io/dapr/examples/bindings/OutputBindingExample.java new file mode 100644 index 000000000..aefd1dea3 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/bindings/OutputBindingExample.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.bindings; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.serializer.DefaultObjectSerializer; + +/** + * Service for output binding example. + * 1. From your repo root, build and install jars: + * mvn clean install + * 2. cd to [repo-root]/examples + * 3. Run the program: + * dapr run --app-id outputbinding --port 3006 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.OutputBindingExample + */ +public class OutputBindingExample { + + public static class MyClass { + public MyClass(){} + public String message; + } + + public static void main(String[] args) { + DaprClient client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + + final String BINDING_NAME = "bindingSample"; + + // This is an example of sending data in a user-defined object. The input binding will receive: + // {"message":"hello"} + MyClass myClass = new MyClass(); + myClass.message = "hello"; + + System.out.println("sending a class with message: " + myClass.message); + client.invokeBinding(BINDING_NAME, myClass).block(); + + // This is an example of sending a plain string. The input binding will receive: + // "cat" + final String m = "cat"; + System.out.println("sending a plain string: " + m); + client.invokeBinding(BINDING_NAME, m).block(); + + try { + Thread.sleep((long) (10000 * Math.random())); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + return; + } + + System.out.println("Done."); + } +} \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/bindings/README.md b/examples/src/main/java/io/dapr/examples/bindings/README.md new file mode 100644 index 000000000..a69ea1488 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/bindings/README.md @@ -0,0 +1,142 @@ +# Dapr Bindings Sample + +In this sample, we'll create two java applications: an output binding application and an input binding application, using Dapr Java SDK. +This sample includes two applications: + +* InputBindingExample (Initializes the Dapr Spring boot application client) +* OutputBindingExample (pushes the event message) + +Visit [this](https://github.com/dapr/docs/tree/master/concepts/bindings) link for more information about Dapr and bindings concepts. + +## Binding sample using the Java-SDK + +In this example, the component used is Kafka but others are also available. + +Visit [this](https://github.com/dapr/components-contrib/tree/master/bindings) link for more information about binding implementations. + + +## Pre-requisites + +* [Dapr and Dapr Cli](https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup). +* Java JDK 11 (or greater): [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11) or [OpenJDK](https://jdk.java.net/13/). +* [Apache Maven](https://maven.apache.org/install.html) version 3.x. + +### Checking out the code + +Clone this repository: + +```sh +git clone https://github.com/dapr/java-sdk.git +cd java-sdk +``` + +Then build the Maven project: + +```sh +# make sure you are in the `java-sdk` directory. +mvn install +``` +### Setting Kafka locally + +Before getting into the application code, follow these steps in order to setup a local instance of Kafka. This is needed for the local instances. Steps are: + +1. navigate to the [repo-root]/examples/src/main/java/io/dapr/examples/bindings +2. Run `docker-compose -f ./docker-compose-single-kafka.yml up -d` to run the container locally +3. Run `docker ps` to see the container running locally: + +```bash +342d3522ca14 kafka-docker_kafka "start-kafka.sh" 14 hours ago Up About +a minute 0.0.0.0:9092->9092/tcp kafka-docker_kafka_1 +0cd69dbe5e65 wurstmeister/zookeeper "/bin/sh -c '/usr/sb…" 8 days ago Up About +a minute 22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp kafka-docker_zookeeper_1 +``` +Click [here](https://github.com/wurstmeister/kafka-docker) for more information about the kafka broker server. + +### Running the Input binding sample + +The input binding sample uses the Spring Boot´s DaprApplication class for initializing the `InputBindingController`. In `InputBindingExample.java` file, you will find the `InputBindingExample` class and the `main` method. See the code snippet below: + +```java +public class InputBindingExample { + + public static void main(String[] args) throws Exception { + ///.. + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + // Start Dapr's callback endpoint. + DaprApplication.start(port); + } +///... +} +``` + +`DaprApplication.start()` Method will run an Spring Boot application that registers the `InputBindingController`, which exposes the actual handling of the event message as a POST request. The Dapr's sidecar is the one that performs the actual call to this controller, based on the binding features and the output binding action. + +```java +@RestController +public class InputBindingController { + + @PostMapping(path = "/bindingSample") + public Mono handleInputBinding(@RequestBody(required = false) byte[] body) { + return Mono.fromRunnable(() -> + System.out.println("Received message through binding: " + (body == null ? "" : new String(body)))); + } + +} +``` + + Execute the follow script in order to run the Input Binding example: +```sh +cd to [repo-root]/examples +dapr run --app-id inputbinding --app-port 3000 --port 3005 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.InputBindingExample -D exec.args="-p 3000" +``` + +### Running the Output binding sample + +The output binding application is a simple java class with a main method that uses the Dapr Client to invoke binding. + +In the `OutputBindingExample.java` file, you will find the `OutputBindingExample` class, containing the main method. The main method declares a Dapr Client using the `DaprClientBuilder` class. Notice that this builder gets two serializer implementations in the constructor: One is for Dapr's sent and recieved objects, and second is for objects to be persisted. The client publishes events using `invokeBinding` method. See the code snippet below: +```java +public class OutputBindingExample { +///... + public static void main(String[] args) throws Exception { + DaprClient client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + final String BINDING_NAME = "bindingSample"; + ///... + MyClass myClass = new MyClass(); + myClass.message = "hello"; + + System.out.println("sending an object instance with message: " + myClass.message); + client.invokeBinding(BINDING_NAME, myClass); //Binding a data object + ///.. + final String m = "cat"; + System.out.println("sending a plain string: " + m); + client.invokeBinding(BINDING_NAME, m); //Binding a plain string text + } +///... +} +``` + +This example binds two events: A user-defined data object (using the `myClass` object as parameter) and a simple string using the same `invokeBinding` method. + +Use the follow command to execute the Output Binding example: + +```sh +cd to [repo-root]/examples +dapr run --app-id outputbinding --port 3006 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.OutputBindingExample +``` + +Once running, the OutputBindingExample should print the output as follows: + +![publisheroutput](../../../../../resources/img/outputbinding.png) + +Events have been sent. + +Once running, the InputBindingExample should print the output as follows: + +![publisheroutput](../../../../../resources/img/inputbinding.png) + +Events have been retrieved from the binding. + +For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../springboot/DaprApplication.java) Application implementation. \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/bindings/docker-compose-single-kafka.yml b/examples/src/main/java/io/dapr/examples/bindings/docker-compose-single-kafka.yml new file mode 100644 index 000000000..16f9e4801 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/bindings/docker-compose-single-kafka.yml @@ -0,0 +1,14 @@ +version: '2' +services: + zookeeper: + image: wurstmeister/zookeeper:latest + ports: + - "2181:2181" + kafka: + image: wurstmeister/kafka:latest + ports: + - "9092:9092" + environment: + KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1 + KAFKA_CREATE_TOPICS: "sample:1:1" + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java index 45afaaa52..0115d2daf 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java +++ b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java @@ -23,105 +23,108 @@ import static io.dapr.examples.DaprExamplesProtos.SayResponse; /** * 1. Build and install jars: - * mvn clean install + * mvn clean install * 2. Send messages to the server: - * dapr run --protocol grpc --grpc-port 50001 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient -Dexec.args="-p 50001 'message one' 'message two'" + * dapr run --protocol grpc --grpc-port 50001 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient -Dexec.args="-p 50001 'message one' 'message two'" */ public class HelloWorldClient { + /** + * Client mode: class representing a client-side logic for calling HelloWorld over Dapr. + */ + private static class GrpcHelloWorldDaprClient { + /** - * Client mode: class representing a client-side logic for calling HelloWorld over Dapr. + * Client communication channel: host, port and tls(on/off) */ - private static class GrpcHelloWorldDaprClient { + private final ManagedChannel channel; - /** - * Client communication channel: host, port and tls(on/off) - */ - private final ManagedChannel channel; - - /** - * Calls will be done asynchronously. - */ - private final DaprGrpc.DaprFutureStub client; - - /** - * Creates a Grpc client for the DaprGrpc service. - * @param host host for the remote service endpoint - * @param port port for the remote service endpoint - */ - public GrpcHelloWorldDaprClient(String host, int port) { - this(ManagedChannelBuilder - .forAddress("localhost", port) - .usePlaintext() // SSL/TLS is default, we turn it off just because this is a sample and not prod. - .build()); - } - - /** - * Helper constructor to build client from channel. - * @param channel - */ - private GrpcHelloWorldDaprClient(ManagedChannel channel) { - this.channel = channel; - this.client = DaprGrpc.newFutureStub(channel); - } - - /** - * Client mode: sends messages, one per second. - * @param messages - */ - private void sendMessages(String... messages) throws ExecutionException, InterruptedException, InvalidProtocolBufferException { - List> futureResponses = new ArrayList<>(); - for (String message : messages) - { - SayRequest request = SayRequest - .newBuilder() - .setMessage(message) - .build(); - - // Now, wrap the request with Dapr's envelope. - InvokeServiceEnvelope requestEnvelope = InvokeServiceEnvelope - .newBuilder() - .setId("hellogrpc") // Service's identifier. - .setData(Any.pack(request)) - .setMethod("say") // The service's method to be invoked by Dapr. - .build(); - - futureResponses.add(client.invokeService(requestEnvelope)); - System.out.println("Client: sent => " + message); - Thread.sleep(TimeUnit.SECONDS.toMillis(10)); - } - - for (ListenableFuture future : futureResponses) { - Any data = future.get().getData(); // Blocks waiting for response. - // IMPORTANT: do not use Any.unpack(), use Type.ParseFrom() instead. - SayResponse response = SayResponse.parseFrom(data.getValue()); - System.out.println("Client: got response => " + response.getTimestamp()); - } - } - - /** - * Client mode: gracefully shutdown client within 1 min, otherwise force it. - * @throws InterruptedException Propagated interrupted exception. - */ - private void shutdown() throws InterruptedException { - this.channel.shutdown().awaitTermination(1, TimeUnit.MINUTES); - System.out.println("Client: Bye."); - } + /** + * Calls will be done asynchronously. + */ + private final DaprGrpc.DaprFutureStub client; + /** + * Creates a Grpc client for the DaprGrpc service. + * + * @param host host for the remote service endpoint + * @param port port for the remote service endpoint + */ + public GrpcHelloWorldDaprClient(String host, int port) { + this(ManagedChannelBuilder + .forAddress("localhost", port) + .usePlaintext() // SSL/TLS is default, we turn it off just because this is a sample and not prod. + .build()); } - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addRequiredOption("p", "port", true, "Port to listen or send event to."); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - // If port string is not valid, it will throw an exception. - int port = Integer.parseInt(cmd.getOptionValue("port")); - - GrpcHelloWorldDaprClient helloWorldClient = new GrpcHelloWorldDaprClient("localhost", port); - helloWorldClient.sendMessages(cmd.getArgs()); - helloWorldClient.shutdown(); + /** + * Helper constructor to build client from channel. + * + * @param channel + */ + private GrpcHelloWorldDaprClient(ManagedChannel channel) { + this.channel = channel; + this.client = DaprGrpc.newFutureStub(channel); } + + /** + * Client mode: sends messages, one per second. + * + * @param messages + */ + private void sendMessages(String... messages) throws ExecutionException, InterruptedException, InvalidProtocolBufferException { + List> futureResponses = new ArrayList<>(); + for (String message : messages) { + SayRequest request = SayRequest + .newBuilder() + .setMessage(message) + .build(); + + // Now, wrap the request with Dapr's envelope. + InvokeServiceEnvelope requestEnvelope = InvokeServiceEnvelope + .newBuilder() + .setId("hellogrpc") // Service's identifier. + .setData(Any.pack(request)) + .setMethod("say") // The service's method to be invoked by Dapr. + .build(); + + futureResponses.add(client.invokeService(requestEnvelope)); + System.out.println("Client: sent => " + message); + Thread.sleep(TimeUnit.SECONDS.toMillis(10)); + } + + for (ListenableFuture future : futureResponses) { + Any data = future.get().getData(); // Blocks waiting for response. + // IMPORTANT: do not use Any.unpack(), use Type.ParseFrom() instead. + SayResponse response = SayResponse.parseFrom(data.getValue()); + System.out.println("Client: got response => " + response.getTimestamp()); + } + } + + /** + * Client mode: gracefully shutdown client within 1 min, otherwise force it. + * + * @throws InterruptedException Propagated interrupted exception. + */ + private void shutdown() throws InterruptedException { + this.channel.shutdown().awaitTermination(1, TimeUnit.MINUTES); + System.out.println("Client: Bye."); + } + + } + + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port to listen or send event to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + GrpcHelloWorldDaprClient helloWorldClient = new GrpcHelloWorldDaprClient("localhost", port); + helloWorldClient.sendMessages(cmd.getArgs()); + helloWorldClient.shutdown(); + } } diff --git a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java index 9e61368a7..f674c6430 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java +++ b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java @@ -25,116 +25,116 @@ import static io.dapr.examples.DaprExamplesProtos.SayResponse; * 1. Build and install jars: * mvn clean install * 2. Run in server mode: - * dapr run --app-id hellogrpc --app-port 5000 --protocol grpc -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService -Dexec.args="-p 5000" + * dapr run --app-id hellogrpc --app-port 5000 --protocol grpc -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService -Dexec.args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009" */ public class HelloWorldService { + /** + * Server mode: class that encapsulates all server-side logic for Grpc. + */ + private static class GrpcHelloWorldDaprService extends DaprClientGrpc.DaprClientImplBase { + /** - * Server mode: class that encapsulates all server-side logic for Grpc. + * Format to output date and time. */ - private static class GrpcHelloWorldDaprService extends DaprClientGrpc.DaprClientImplBase { + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - /** - * Format to output date and time. - */ - private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + /** + * Server mode: Grpc server. + */ + private Server server; - /** - * Server mode: Grpc server. - */ - private Server server; + /** + * Server mode: starts listening on given port. + * + * @param port Port to listen on. + * @throws IOException Errors while trying to start service. + */ + private void start(int port) throws IOException { + this.server = ServerBuilder + .forPort(port) + .addService(this) + .build() + .start(); + System.out.printf("Server: started listening on port %d\n", port); - /** - * Server mode: starts listening on given port. - * - * @param port Port to listen on. - * @throws IOException Errors while trying to start service. - */ - private void start(int port) throws IOException { - this.server = ServerBuilder - .forPort(port) - .addService(this) - .build() - .start(); - System.out.printf("Server: started listening on port %d\n", port); + // Now we handle ctrl+c (or any other JVM shutdown) + Runtime.getRuntime().addShutdownHook(new Thread() { - // Now we handle ctrl+c (or any other JVM shutdown) - Runtime.getRuntime().addShutdownHook(new Thread() { - - @Override - public void run() { - System.out.println("Server: shutting down gracefully ..."); - GrpcHelloWorldDaprService.this.server.shutdown(); - System.out.println("Server: Bye."); - } - }); - } - - /** - * Server mode: waits for shutdown trigger. - * - * @throws InterruptedException Propagated interrupted exception. - */ - private void awaitTermination() throws InterruptedException { - if (this.server != null) { - this.server.awaitTermination(); - } - } - - /** - * Server mode: this is the Dapr method to receive Invoke operations via Grpc. - * - * @param request Dapr envelope request, - * @param responseObserver Dapr envelope response. - */ @Override - public void onInvoke(DaprClientProtos.InvokeEnvelope request, StreamObserver responseObserver) { - try { - if ("say".equals(request.getMethod())) { - // IMPORTANT: do not use Any.unpack(), use Type.ParseFrom() instead. - SayRequest sayRequest = SayRequest.parseFrom(request.getData().getValue()); - SayResponse sayResponse = this.say(sayRequest); - responseObserver.onNext(Any.pack(sayResponse)); - } - } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); - responseObserver.onError(e); - } finally { - responseObserver.onCompleted(); - } - } - - /** - * Handling of the 'say' method. - * - * @param request Request to say something. - * @return Response with when it was said. - */ - public SayResponse say(SayRequest request) { - Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); - - // Handles the request by printing message. - System.out.println("Server: " + request.getMessage() + " @ " + utcNowAsString); - - // Now respond with current timestamp. - SayResponse.Builder responseBuilder = SayResponse.newBuilder(); - return responseBuilder.setTimestamp(utcNowAsString).build(); + public void run() { + System.out.println("Server: shutting down gracefully ..."); + GrpcHelloWorldDaprService.this.server.shutdown(); + System.out.println("Server: Bye."); } + }); } - public static void main(String[] args) throws Exception { - Options options = new Options(); - options.addRequiredOption("p", "port", true, "Port to listen or send event to."); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - // If port string is not valid, it will throw an exception. - int port = Integer.parseInt(cmd.getOptionValue("port")); - - final GrpcHelloWorldDaprService service = new GrpcHelloWorldDaprService(); - service.start(port); - service.awaitTermination(); + /** + * Server mode: waits for shutdown trigger. + * + * @throws InterruptedException Propagated interrupted exception. + */ + private void awaitTermination() throws InterruptedException { + if (this.server != null) { + this.server.awaitTermination(); + } } + + /** + * Server mode: this is the Dapr method to receive Invoke operations via Grpc. + * + * @param request Dapr envelope request, + * @param responseObserver Dapr envelope response. + */ + @Override + public void onInvoke(DaprClientProtos.InvokeEnvelope request, StreamObserver responseObserver) { + try { + if ("say".equals(request.getMethod())) { + // IMPORTANT: do not use Any.unpack(), use Type.ParseFrom() instead. + SayRequest sayRequest = SayRequest.parseFrom(request.getData().getValue()); + SayResponse sayResponse = this.say(sayRequest); + responseObserver.onNext(Any.pack(sayResponse)); + } + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + responseObserver.onError(e); + } finally { + responseObserver.onCompleted(); + } + } + + /** + * Handling of the 'say' method. + * + * @param request Request to say something. + * @return Response with when it was said. + */ + public SayResponse say(SayRequest request) { + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + // Handles the request by printing message. + System.out.println("Server: " + request.getMessage() + " @ " + utcNowAsString); + + // Now respond with current timestamp. + SayResponse.Builder responseBuilder = SayResponse.newBuilder(); + return responseBuilder.setTimestamp(utcNowAsString).build(); + } + } + + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port to listen to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + final GrpcHelloWorldDaprService service = new GrpcHelloWorldDaprService(); + service.start(port); + service.awaitTermination(); + } } diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java b/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java new file mode 100644 index 000000000..e16a87aee --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.invoke.http; + +import io.dapr.springboot.DaprApplication; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +/** + * 1. Build and install jars: + * mvn clean install + * 2. Run in server mode: + * dapr run --app-id invokedemo --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.DemoService -D exec.args="-p 3000" + */ +public class DemoService { + + /** + * Starts the service. + * @param args Expects the port: -p PORT + * @throws Exception If cannot start service. + */ + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port to listen to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + DaprApplication.start(port); + } +} diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/DemoServiceController.java b/examples/src/main/java/io/dapr/examples/invoke/http/DemoServiceController.java new file mode 100644 index 000000000..d08667f9a --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/invoke/http/DemoServiceController.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.invoke.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Map; +import java.util.TimeZone; + +/** + * SpringBoot Controller to handle input binding. + */ +@RestController +public class DemoServiceController { + + /** + * Json serializer/deserializer. + */ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * Format to output date and time. + */ + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + + @PostMapping(path = "/say") + public Mono handleMethod(@RequestBody(required = false) byte[] body, + @RequestHeader Map headers) { + return Mono.fromSupplier(() -> { + try { + String message = body == null ? "" : new String(body, StandardCharsets.UTF_8); + + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + String metadataString = headers == null ? "" : OBJECT_MAPPER.writeValueAsString(headers); + + // Handles the request by printing message. + System.out.println( + "Server: " + message + " @ " + utcNowAsString + " and metadata: " + metadataString); + + return utcNowAsString; + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + +} diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/InvokeClient.java b/examples/src/main/java/io/dapr/examples/invoke/http/InvokeClient.java new file mode 100644 index 000000000..ced9ab84b --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/invoke/http/InvokeClient.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.invoke.http; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.client.domain.Verb; + +/** + * 1. Build and install jars: + * mvn clean install + * 2. Send messages to the server: + * dapr run --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.http.InvokeClient -Dexec.args="'message one' 'message two'" + */ +public class InvokeClient { + + /** + * Identifier in Dapr for the service this client will invoke. + */ + private static final String SERVICE_APP_ID = "invokedemo"; + + /** + * Starts the invoke client. + * @param args Messages to be sent as request for the invoke API. + */ + public static void main(String[] args) { + DaprClient client = (new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer())).build(); + for (String message : args) { + client.invokeService(Verb.POST, SERVICE_APP_ID, "say", message, null, String.class).block(); + } + } +} diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/README.md b/examples/src/main/java/io/dapr/examples/invoke/http/README.md new file mode 100644 index 000000000..40e3c1f0c --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/invoke/http/README.md @@ -0,0 +1,130 @@ +# Method invocation Sample + +In this sample, we'll create a two java applications: An exposer service application which exposes a method and a client application which will invoke the method from demo service using Dapr. +This sample includes: + +* DemoService (Exposes the method to be remotely accessed) +* InvokeClient (Invokes the exposed method from DemoService) + +Visit [this](https://github.com/dapr/docs/blob/master/concepts/service-invocation/service-invocation.md) link for more information about Dapr and service invocation. + +## Remote invocation using the Java-SDK + +This sample uses the Client provided in Dapr Java SDK invoking a remote method. Exposing the method + + +## Pre-requisites + +* [Dapr and Dapr Cli](https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup). +* Java JDK 11 (or greater): [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11) or [OpenJDK](https://jdk.java.net/13/). +* [Apache Maven](https://maven.apache.org/install.html) version 3.x. + +### Checking out the code + +Clone this repository: + +```sh +git clone https://github.com/dapr/java-sdk.git +cd java-sdk +``` + +Then build the Maven project: + +```sh +# make sure you are in the `java-sdk` directory. +mvn install +``` + +### Running the Demo service sample + +The Demo service application is meant to expose a method that can be remotely invoked. In this example, the exposer feature has two parts: + +In the `DemoService.java` file, you will find the `DemoService` class, containing the main method. The main method uses the Spring Boot´s DaprApplication class for initializing the `ExposerServiceController`. See the code snippet below: + +```java +public class DemoService { + ///... + public static void main(String[] args) throws Exception { + ///... + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + DaprApplication.start(port); + } +} +``` + +`DaprApplication.start()` Method will run an Spring Boot application that registers the `DemoServiceController`, which exposes the invoking action as a POST request. The Dapr's sidecar is the one that performs the actual call to the controller, based on the binding features and the remote invocation action. + +This Spring Controller exposes the `say` method. The method retrieves metadata from the headers and prints them along with the current date in console. The actual response from method is the formatted current date. See the code snippet below: + +```java +@RestController +public class DemoServiceController { + ///... + @PostMapping(path = "/say") + public Mono handleMethod(@RequestBody(required = false) byte[] body, + @RequestHeader Map headers) { + return Mono.fromSupplier(() -> { + try { + String message = body == null ? "" : new String(body, StandardCharsets.UTF_8); + + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + String metadataString = headers == null ? "" : OBJECT_MAPPER.writeValueAsString(headers); + + // Handles the request by printing message. + System.out.println( + "Server: " + message + " @ " + utcNowAsString + " and metadata: " + metadataString); + + return utcNowAsString; + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } +} +``` + +Use the follow command to execute the exposer example: + +```sh +dapr run --app-id invokedemo --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.DemoService -D exec.args="-p 3000" +``` + +Once running, the ExposerService is now ready to be invoked by Dapr. + + +### Running the InvokeClient sample + +The Invoke client sample uses the Dapr SDK for invoking the remote method. The main method declares a Dapr Client using the DaprClientBuilder class. Notice that this builder gets two serializer implementations in the constructor: One is for Dapr's sent and recieved objects, and second is for objects to be persisted. It needs to know the method name to invoke as well as the application id for the remote application. In `InvokeClient.java` file, you will find the `InvokeClient` class and the `main` method. See the code snippet below: + +```java +public class InvokeClient { + +private static final String SERVICE_APP_ID = "invokedemo"; +///... + public static void main(String[] args) { + DaprClient client = (new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer())).build(); + for (String message : args) { + client.invokeService(Verb.POST, SERVICE_APP_ID, "say", message, null, String.class).block(); + } + } +///... +} +``` + +The class knows the app id for the remote application. It uses the the static `Dapr.getInstance().invokeService` method to invoke the remote method defining the parameters: The verb, application id, method name, and proper data and metadata, as well as the type of the expected retun data. + + Execute the follow script in order to run the InvokeClient example, passing two messages for the remote method: +```sh +dapr run --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.InvokeClient -D exec.args="'message one' 'message two'" +``` +Once running, the output should display the messages sent from invoker in the exposer service output as follows: + +![exposeroutput](../../../../../../resources/img/exposer-service.png) + +Method have been remotely invoked and displaying the remote messages. + +For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation. \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java b/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java new file mode 100644 index 000000000..18eb1d615 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.pubsub.http; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.serializer.DefaultObjectSerializer; + +import java.util.Collections; + +/** + * Message publisher. + * 1. Build and install jars: + * mvn clean install + * 2. Run the program: + * dapr run --app-id publisher --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Publisher + */ +public class Publisher { + + //Number of messages to be sent: 10 + private static final int NUM_MESSAGES = 10; + //The title of the topic to be used for publishing + private static final String TOPIC_NAME = "testingtopic"; + + public static void main(String[] args) throws Exception { + //Creating the DaprClient: Using the default builder client produces an HTTP Dapr Client + DaprClient client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + for (int i = 0; i < NUM_MESSAGES; i++) { + String message = String.format("This is message #%d", i); + //Publishing messages + client.publishEvent(TOPIC_NAME, message).block(); + System.out.println("Published message: " + message); + + try { + Thread.sleep((long)(1000 * Math.random())); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + return; + } + } + + //Publishing a single bite: Example of non-string based content published + client.publishEvent( + TOPIC_NAME, + new byte[] { 1 }, + Collections.singletonMap("content-type", "application/octet-stream")).block(); + System.out.println("Published one byte."); + + System.out.println("Done."); + } +} diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/README.md b/examples/src/main/java/io/dapr/examples/pubsub/http/README.md new file mode 100644 index 000000000..572d5f1d9 --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/README.md @@ -0,0 +1,140 @@ +# Dapr Pub-Sub Sample + +In this sample, we'll create a publisher and a subscriber java applications using Dapr, based on the publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscriber will listen for messages of specific topic. See [Why Pub-Sub](#why-pub-sub) to understand when this pattern might be a good choice for your software architecture. + +Visit [this](https://github.com/dapr/docs/tree/master/concepts/publish-subscribe-messaging) link for more information about Dapr and Pub-Sub. + +## Pub-Sub Sample using the Java-SDK + +This sample uses the HTTP Client provided in Dapr Java SDK for subscribing, and Dapr Spring Boot integration for publishing. This example uses Redis Streams (enabled in Redis versions => 5). +## Pre-requisites + +* [Dapr and Dapr Cli](https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup). +* Java JDK 11 (or greater): [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11) or [OpenJDK](https://jdk.java.net/13/). +* [Apache Maven](https://maven.apache.org/install.html) version 3.x. + +### Checking out the code + +Clone this repository: + +```sh +git clone https://github.com/dapr/java-sdk.git +cd java-sdk +``` + +Then build the Maven project: + +```sh +# make sure you are in the `java-sdk` directory. +mvn install +``` +### Running the subscriber + +The first is the subscriber. It will subscribe to the topic to be used by the publisher and read the messages published. The Subscriber uses the Spring Boot´s DaprApplication class for initializing the `SubscriberController`. In `Subscriber.java` file, you will find the `Subscriber` class and the `main` method. See the code snippet below: + +```java +public class Subscriber { + + public static void main(String[] args) throws Exception { + ///... + // Start Dapr's callback endpoint. + DaprApplication.start(port); + } +} +``` +`DaprApplication.start()` Method will run an Spring Boot application that registers the `SubscriberController`, which exposes the message retrieval as a POST request. The Dapr's sidecar is the one that performs the actual call to the controller, based on the pubsub features. + +This Spring Controller handles the message endpoint, Printing the recieved message which is recieved as the POST body. See the code snippet below: + +```java +@RestController +public class SubscriberController { + ///... + @GetMapping("/dapr/subscribe") + public byte[] daprConfig() throws Exception { + return SERIALIZER.serialize(new String[] { "message" }); + } + + @PostMapping(path = "/message") + public Mono handleMessage(@RequestBody(required = false) byte[] body, + @RequestHeader Map headers) { + return Mono.fromRunnable(() -> { + try { + // Dapr's event is compliant to CloudEvent. + CloudEventEnvelope envelope = SERIALIZER.deserialize(body, CloudEventEnvelope.class); + + String message = envelope.getData() == null ? "" : new String(envelope.getData()); + System.out.println("Subscriber got message: " + message); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } +} +``` +Execute the follow script in order to run the Subscriber example: +```sh +dapr run --app-id subscriber --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Subscriber -D exec.args="-p 3000" +``` + +### Running the publisher + +The other component is the publisher. It is a simple java application with a main method that uses the Dapr HTTP Client to publish 10 messages to an specific topic. + +In the `Publisher.java` file, you will find the `Publisher` class, containing the main method. The main method declares a Dapr Client using the `DaprClientBuilder` class. Notice that this builder gets two serializer implementations in the constructor: One is for Dapr's sent and recieved objects, and second is for objects to be persisted. The client publishes messages using `publishEvent` method. See the code snippet below: +```java +public class Publisher { + private static final int NUM_MESSAGES = 10; + private static final String TOPIC_NAME = "testingtopic"; +///... + public static void main(String[] args) throws Exception { + DaprClient client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + for (int i = 0; i < NUM_MESSAGES; i++) { + String message = String.format("This is message #%d", i); + client.publishEvent(TOPIC_NAME, message).block(); + System.out.println("Published message: " + message); + //.. + } + } +///... +} +``` + +This example also pushes a non-string content event, the follow code in same `Publisher` main method publishes a bite: + +```java +public class Publisher { +///... + public static void main(String[] args) throws Exception { +///... + //Publishing a single bite: Example of non-string based content published + client.publishEvent( + TOPIC_NAME, + new byte[] { 1 }, + Collections.singletonMap("content-type", "application/octet-stream")).block(); + System.out.println("Published one byte."); + System.out.println("Done."); + } +///... +} +``` + +Use the follow command to execute the Publisher example: + +```sh +dapr run --app-id publisher --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Publisher +``` + +Once running, the Publisher should print the output as follows: + +![publisheroutput](../../../../../../resources/img/publisher.png) + +Messages have been published in the topic. + +Once running, the Subscriber should print the output as follows: + +![publisheroutput](../../../../../../resources/img/subscriber.png) + +Messages have been retrieved from the topic. + +For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation. \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/Subscriber.java b/examples/src/main/java/io/dapr/examples/pubsub/http/Subscriber.java new file mode 100644 index 000000000..e772e331f --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/Subscriber.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.pubsub.http; + +import io.dapr.springboot.DaprApplication; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +/** + * Service for subscriber. + * 1. Build and install jars: + * mvn clean install + * 2. Run the server: + * dapr run --app-id subscriber --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.pubsub.http.Subscriber -Dexec.args="-p 3000" + */ +public class Subscriber { + + public static void main(String[] args) throws Exception { + Options options = new Options(); + options.addRequiredOption("p", "port", true, "Port Dapr will listen to."); + + CommandLineParser parser = new DefaultParser(); + CommandLine cmd = parser.parse(options, args); + + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(cmd.getOptionValue("port")); + + // Start Dapr's callback endpoint. + DaprApplication.start(port); + } +} \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/SubscriberController.java b/examples/src/main/java/io/dapr/examples/pubsub/http/SubscriberController.java new file mode 100644 index 000000000..dee0a131a --- /dev/null +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/SubscriberController.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.examples.pubsub.http; + +import io.dapr.client.domain.CloudEvent; +import io.dapr.serializer.DefaultObjectSerializer; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.Map; + +/** + * SpringBoot Controller to handle input binding. + */ +@RestController +public class SubscriberController { + + /** + * Dapr's default serializer/deserializer. + */ + private static final DefaultObjectSerializer SERIALIZER = new DefaultObjectSerializer (); + + @GetMapping("/dapr/subscribe") + public byte[] daprConfig() throws Exception { + return SERIALIZER.serialize(new String[] { "testingtopic" }); + } + + @PostMapping(path = "/testingtopic") + public Mono handleMessage(@RequestBody(required = false) byte[] body, + @RequestHeader Map headers) { + return Mono.fromRunnable(() -> { + try { + // Dapr's event is compliant to CloudEvent. + CloudEvent envelope = CloudEvent.deserialize(body); + + String message = envelope.getData() == null ? "" : new String(envelope.getData()); + System.out.println("Subscriber got message: " + message); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + +} diff --git a/examples/src/main/java/io/dapr/examples/state/grpc/Example.java b/examples/src/main/java/io/dapr/examples/state/grpc/Example.java index 7b9b20d19..9b01b2dfc 100644 --- a/examples/src/main/java/io/dapr/examples/state/grpc/Example.java +++ b/examples/src/main/java/io/dapr/examples/state/grpc/Example.java @@ -16,46 +16,46 @@ import java.util.UUID; * dapr run --grpc-port 50001 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.Example */ public class Example { - public static void main(String[] args) { - ManagedChannel channel = - ManagedChannelBuilder.forAddress("localhost", 50001).usePlaintext().build(); - DaprBlockingStub client = DaprGrpc.newBlockingStub(channel); + public static void main(String[] args) { + ManagedChannel channel = + ManagedChannelBuilder.forAddress("localhost", 50001).usePlaintext().build(); + DaprBlockingStub client = DaprGrpc.newBlockingStub(channel); - String key = "mykey"; - // First, write key-value pair. - { - String value = UUID.randomUUID().toString(); - StateRequest req = StateRequest - .newBuilder() - .setKey(key) - .setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build()) - .build(); - SaveStateEnvelope state = SaveStateEnvelope.newBuilder() - .addRequests(req) - .build(); - client.saveState(state); - System.out.println("Saved!"); - } - - // Now, read it back. - { - GetStateEnvelope req = GetStateEnvelope - .newBuilder() - .setKey(key) - .build(); - GetStateResponseEnvelope response = client.getState(req); - String value = response.getData().getValue().toStringUtf8(); - System.out.println("Got: " + value); - } - - // Then, delete it. - { - DeleteStateEnvelope req = DeleteStateEnvelope - .newBuilder() - .setKey(key) - .build(); - client.deleteState(req); - System.out.println("Deleted!"); - } + String key = "mykey"; + // First, write key-value pair. + { + String value = UUID.randomUUID().toString(); + StateRequest req = StateRequest + .newBuilder() + .setKey(key) + .setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build()) + .build(); + SaveStateEnvelope state = SaveStateEnvelope.newBuilder() + .addRequests(req) + .build(); + client.saveState(state); + System.out.println("Saved!"); } + + // Now, read it back. + { + GetStateEnvelope req = GetStateEnvelope + .newBuilder() + .setKey(key) + .build(); + GetStateResponseEnvelope response = client.getState(req); + String value = response.getData().getValue().toStringUtf8(); + System.out.println("Got: " + value); + } + + // Then, delete it. + { + DeleteStateEnvelope req = DeleteStateEnvelope + .newBuilder() + .setKey(key) + .build(); + client.deleteState(req); + System.out.println("Deleted!"); + } + } } diff --git a/examples/src/main/java/io/dapr/examples/state/http/OrderManager.java b/examples/src/main/java/io/dapr/examples/state/http/OrderManager.java index 05fa5d108..df2650f7e 100644 --- a/examples/src/main/java/io/dapr/examples/state/http/OrderManager.java +++ b/examples/src/main/java/io/dapr/examples/state/http/OrderManager.java @@ -2,6 +2,9 @@ package io.dapr.examples.state.http; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpServer; +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.serializer.DefaultObjectSerializer; import org.json.JSONArray; import org.json.JSONObject; @@ -20,6 +23,8 @@ import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.nio.charset.Charset; import java.time.Duration; +import java.util.Arrays; +import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -27,117 +32,84 @@ import static java.lang.System.out; /** * OrderManager web app. - * + *

* Based on the helloworld Node.js example in https://github.com/dapr/samples/blob/master/1.hello-world/app.js - * + *

* To install jars into your local maven repo: - * mvn clean install - * + * mvn clean install + *

* To run (after step above): - * dapr run --app-id orderapp --app-port 3000 --port 3500 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.state.http.OrderManager - * + * dapr run --app-id orderapp --app-port 3000 --port 3500 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.state.http.OrderManager + *

* If this class changes, run this before running it again: - * mvn compile + * mvn compile */ public class OrderManager { - static HttpClient httpClient; + public static void main(String[] args) throws IOException { + int httpPort = 3001; + HttpServer httpServer = HttpServer.create(new InetSocketAddress(httpPort), 0); - public static void main(String[] args) throws IOException { - int httpPort = 3000; - String daprPort = Optional.ofNullable(System.getenv("DAPR_HTTP_PORT")).orElse("3500"); - String stateUrl = String.format("http://localhost:%s/v1.0/state", daprPort); - HttpServer httpServer = HttpServer.create(new InetSocketAddress(httpPort), 0); + DaprClient daprClient = + (new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer())).build(); - httpClient = HttpClient.newBuilder().version(Version.HTTP_1_1).followRedirects(Redirect.NORMAL) - .connectTimeout(Duration.ofSeconds(2)).build(); - - httpServer.createContext("/order").setHandler(e -> { - out.println("Fetching order!"); - fetch(stateUrl + "/order").thenAccept(response -> { - int resCode = response.statusCode() == 200 ? 200 : 500; - String body = response.statusCode() == 200 ? response.body() : "Could not get state."; - - try { - e.sendResponseHeaders(resCode, body.getBytes().length); - OutputStream os = e.getResponseBody(); - try { - os.write(body.getBytes()); - } finally { - os.close(); - } - } catch (IOException ioerror) { - out.println(ioerror); - } - }); - }); - - httpServer.createContext("/neworder").setHandler(e -> { - try { - out.println("Received new order ..."); - String json = readBody(e); - JSONObject jsonObject = new JSONObject(json); - JSONObject data = jsonObject.getJSONObject("data"); - String orderId = data.getString("orderId"); - out.printf("Got a new order! Order ID: %s\n", orderId); - - JSONObject item = new JSONObject(); - item.put("key", "order"); - item.put("value", data); - JSONArray state = new JSONArray(); - state.put(item); - out.printf("Writing to state: %s\n", state.toString()); - - post(stateUrl, state.toString()).thenAccept(response -> { - int resCode = response.statusCode() == 200 ? 200 : 500; - String body = response.body(); - try { - e.sendResponseHeaders(resCode, body.getBytes().length); - OutputStream os = e.getResponseBody(); - try { - os.write(body.getBytes()); - } finally { - os.close(); - } - } catch (IOException ioerror) { - out.println(ioerror); - } - }); - } catch (IOException ioerror) { - out.println(ioerror); - } - }); - - httpServer.start(); - out.printf("Java App listening on port %s.", httpPort); - } - - private static CompletableFuture> fetch(String url) { - HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build(); - return httpClient.sendAsync(request, BodyHandlers.ofString()); - } - - private static CompletableFuture> post(String url, String body) { - HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)) - .header("Content-Type", "application/json; charset=UTF-8").POST(BodyPublishers.ofString(body)).build(); - - return httpClient.sendAsync(request, BodyHandlers.ofString()); - } - - private static String readBody(HttpExchange t) throws IOException { - // retrieve the request json data - InputStream is = t.getRequestBody(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int len; + httpServer.createContext("/order").setHandler(e -> { + out.println("Fetching order!"); try { - while ((len = is.read(buffer)) > 0) - bos.write(buffer, 0, len); - } catch (IOException e) { - e.printStackTrace(); - } finally { - bos.close(); + byte[] data = daprClient.getState("order", String.class).block().getValue().getBytes(); + e.getResponseHeaders().set("content-type", "application/json"); + e.sendResponseHeaders(200, data.length); + e.getResponseBody().write(data); + e.getResponseBody().close(); + } catch (IOException ioerror) { + out.println(ioerror); + e.sendResponseHeaders(500, ioerror.getMessage().getBytes().length); + e.getResponseBody().write(ioerror.getMessage().getBytes()); + e.getResponseBody().close(); } - return new String(bos.toByteArray(), Charset.forName("UTF-8")); + }); + + httpServer.createContext("/neworder").setHandler(e -> { + try { + out.println("Received new order ..."); + String json = readBody(e); + JSONObject jsonObject = new JSONObject(json); + JSONObject data = jsonObject.getJSONObject("data"); + String orderId = data.getString("orderId"); + out.printf("Got a new order! Order ID: %s\n", orderId); + + daprClient.saveState("order", data.toString()).block(); + + out.printf("Saved state: %s\n", data.toString()); + e.sendResponseHeaders(200, 0); + e.getResponseBody().write(new byte[0]); + e.getResponseBody().close(); + } catch (IOException ioerror) { + out.println(ioerror); + e.sendResponseHeaders(500, ioerror.getMessage().getBytes().length); + e.getResponseBody().write(ioerror.getMessage().getBytes()); + e.getResponseBody().close(); + } + }); + + httpServer.start(); + out.printf("Java App listening on port %s.", httpPort); + } + + private static String readBody(HttpExchange t) throws IOException { + // retrieve the request json data + InputStream is = t.getRequestBody(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len; + try { + while ((len = is.read(buffer)) > 0) + bos.write(buffer, 0, len); + } catch (IOException e) { + e.printStackTrace(); + } finally { + bos.close(); } + return new String(bos.toByteArray(), Charset.forName("UTF-8")); + } } diff --git a/examples/src/main/java/io/dapr/springboot/DaprApplication.java b/examples/src/main/java/io/dapr/springboot/DaprApplication.java new file mode 100644 index 000000000..22d22ea6b --- /dev/null +++ b/examples/src/main/java/io/dapr/springboot/DaprApplication.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Dapr's HTTP callback implementation via SpringBoot. + */ +@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.examples"}) +public class DaprApplication { + + /** + * Starts Dapr's callback in a given port. + * @param port Port to listen to. + */ + public static void start(int port) { + SpringApplication app = new SpringApplication(DaprApplication.class); + app.run(String.format("--server.port=%d", port)); + } + +} diff --git a/examples/src/main/java/io/dapr/springboot/DaprController.java b/examples/src/main/java/io/dapr/springboot/DaprController.java new file mode 100644 index 000000000..1f1ffa018 --- /dev/null +++ b/examples/src/main/java/io/dapr/springboot/DaprController.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.springboot; + +import io.dapr.actors.runtime.ActorRuntime; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +/** + * SpringBoot Controller to handle callback APIs for Dapr. + */ +@RestController +public class DaprController { + + @GetMapping("/") + public String index() { + return "Greetings from Dapr!"; + } + + @GetMapping("/dapr/config") + public byte[] daprConfig() throws Exception { + return ActorRuntime.getInstance().serializeConfig(); + } + + @PostMapping(path = "/actors/{type}/{id}") + public Mono activateActor(@PathVariable("type") String type, + @PathVariable("id") String id) throws Exception { + return ActorRuntime.getInstance().activate(type, id); + } + + @DeleteMapping(path = "/actors/{type}/{id}") + public Mono deactivateActor(@PathVariable("type") String type, + @PathVariable("id") String id) throws Exception { + return ActorRuntime.getInstance().deactivate(type, id); + } + + @PutMapping(path = "/actors/{type}/{id}/method/{method}") + public Mono invokeActorMethod(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("method") String method, + @RequestBody(required = false) byte[] body) { + return ActorRuntime.getInstance().invoke(type, id, method, body); + } + + @PutMapping(path = "/actors/{type}/{id}/method/timer/{timer}") + public Mono invokeActorTimer(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("timer") String timer) { + return ActorRuntime.getInstance().invokeTimer(type, id, timer); + } + + @PutMapping(path = "/actors/{type}/{id}/method/remind/{reminder}") + public Mono invokeActorReminder(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("reminder") String reminder, + @RequestBody(required = false) byte[] body) { + return ActorRuntime.getInstance().invokeReminder(type, id, reminder, body); + } + +} diff --git a/examples/src/main/resources/img/exposer-service.png b/examples/src/main/resources/img/exposer-service.png new file mode 100644 index 000000000..8034d839a Binary files /dev/null and b/examples/src/main/resources/img/exposer-service.png differ diff --git a/examples/src/main/resources/img/inputbinding.png b/examples/src/main/resources/img/inputbinding.png new file mode 100644 index 000000000..662b798bf Binary files /dev/null and b/examples/src/main/resources/img/inputbinding.png differ diff --git a/examples/src/main/resources/img/outputbinding.png b/examples/src/main/resources/img/outputbinding.png new file mode 100644 index 000000000..a9ed04b1f Binary files /dev/null and b/examples/src/main/resources/img/outputbinding.png differ diff --git a/examples/src/main/resources/img/publisher.png b/examples/src/main/resources/img/publisher.png new file mode 100644 index 000000000..cea3d8e60 Binary files /dev/null and b/examples/src/main/resources/img/publisher.png differ diff --git a/examples/src/main/resources/img/subscriber.png b/examples/src/main/resources/img/subscriber.png new file mode 100644 index 000000000..506456d98 Binary files /dev/null and b/examples/src/main/resources/img/subscriber.png differ diff --git a/pom.xml b/pom.xml index fe5af2040..24a4907f8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.dapr dapr-sdk-parent pom - 0.3.0-alpha + 0.2.0-SNAPSHOT dapr-sdk-parent SDK for Dapr. https://dapr.io @@ -22,8 +22,23 @@ 1.8 8 8 + true + true + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + @@ -33,6 +48,11 @@ pom import + + io.grpc + grpc-api + ${grpc.version} + javax.annotation javax.annotation-api @@ -54,6 +74,87 @@ + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --batch + --pinentry-mode + loopback + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.codehaus.mojo + failsafe-maven-plugin + 2.4.3-alpha-1 + + + + integration-test + verify + + + ${skipITs} + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + checkstyle.xml + UTF-8 + true + false + false + + + + validate + validate + + check + + + + + + com.puppycrawl.tools + checkstyle + 8.27 + + + + + + MIT License @@ -71,13 +172,15 @@ - scm:git:git://github.com/dapr/java-sdk.git - scm:git:ssh://github.com:dapr/java-sdk.git - http://github.com/dapr/java-sdk + https://github.com/dapr/java-sdk + scm:git:https://github.com/dapr/java-sdk.git + HEAD + sdk-autogen sdk + sdk-actors examples diff --git a/sdk-actors/pom.xml b/sdk-actors/pom.xml new file mode 100644 index 000000000..7f6868eca --- /dev/null +++ b/sdk-actors/pom.xml @@ -0,0 +1,158 @@ + + 4.0.0 + + + io.dapr + dapr-sdk-parent + 0.2.0-SNAPSHOT + + + dapr-sdk-actors + jar + 0.2.0-SNAPSHOT + dapr-sdk-actors + SDK for Actors on Dapr + + + + + false + + central + libs-release + https://repo.spring.io/libs-release + + + + + true + false + + + + + io.dapr + dapr-sdk + ${project.version} + + + junit + junit + test + + + org.mockito + mockito-core + test + + + com.github.gmazzo + okhttp-mock + 1.3.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.5.2 + test + + + com.github.stefanbirkner + system-rules + 1.19.0 + test + + + commons-cli + commons-cli + 1.4 + test + + + org.springframework.boot + spring-boot-starter-web + 2.2.2.RELEASE + test + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.4 + + + default-prepare-agent + + prepare-agent + + + + report + test + + report + + + target/jacoco-report/ + + + + check + + check + + + + + BUNDLE + + + LINE + COVEREDRATIO + 80% + + + + + + + + + + + + diff --git a/sdk-actors/src/main/java/io/dapr/actors/ActorId.java b/sdk-actors/src/main/java/io/dapr/actors/ActorId.java new file mode 100644 index 000000000..27c1198fb --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/ActorId.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors; + +import java.util.UUID; + +/** + * The ActorId represents the identity of an actor within an actor service. + */ +public class ActorId extends Object implements Comparable { + + /** + * The ID of the actor as a String. + */ + private final String stringId; + + /** + * An error message for an invalid constructor arg. + */ + private final String errorMsg = "actor needs to be initialized with an id!"; + + /** + * Initializes a new instance of the ActorId class with the id passed in. + * + * @param id Value for actor id + */ + public ActorId(String id) { + if (id != null) { + this.stringId = id; + } else { + throw new IllegalArgumentException(errorMsg); + } + } + + /** + * Returns the String representation of this Actor's identifier. + * + * @return The String representation of this ActorId + */ + @Override + public String toString() { + return this.stringId; + } + + /** + * Compares this instance with a specified {link #ActorId} object and + * indicates whether this instance precedes, follows, or appears in the same + * position in the sort order as the specified actorId. + * The comparison is done based on the id if both the instances. + * + * @param other The actorId to compare with this instance. + * @return A 32-bit signed integer that indicates whether this instance + * precedes, follows, or appears in the same position in the sort order as the + * other parameter. + */ + @Override + public int compareTo(ActorId other) { + return (other == null) ? 1 + : compareContent(this, other); + } + + /** + * Calculates the hash code for this ActorId. + * + * @return The hash code of this ActorId. + */ + @Override + public int hashCode() { + return this.stringId.hashCode(); + } + + /** + * Compare if the content of two ids are the same. + * + * @param id1 One identifier. + * @param id2 Another identifier. + * @return -1, 0, or 1 depending on the compare result of the stringId member. + */ + private int compareContent(ActorId id1, ActorId id2) { + return id1.stringId.compareTo(id2.stringId); + } + + /** + * Checks if this instance is equals to the other instance. + * + * @return true if the 2 ActorId's are equal. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return hasEqualContent(this, (ActorId) obj); + } + + /** + * Creates a new ActorId with a random id. + * + * @return A new ActorId with a random id. + */ + public static ActorId createRandom() { + UUID id = UUID.randomUUID(); + return new ActorId(id.toString()); + } + + + /** + * Compares if two actors have the same content. + * + * @param id1 One identifier. + * @param id2 Another identifier. + * @return true if the two ActorId's are equal + */ + private static boolean hasEqualContent(ActorId id1, ActorId id2) { + return id1.stringId.equals(id2.stringId); + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/ActorTrace.java b/sdk-actors/src/main/java/io/dapr/actors/ActorTrace.java new file mode 100644 index 000000000..8a65a9548 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/ActorTrace.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors; + +import java.util.logging.Level; +import java.util.logging.Logger; + +// TODO: Implement distributed tracing. +// TODO: Make this generic to the SDK and not only for Actors. + +/** + * Class to emit trace log messages. + */ +public final class ActorTrace { + + /** + * Gets the default Logger. + */ + private static final Logger LOGGER = Logger.getLogger(ActorTrace.class.getName()); + + /** + * Writes an information trace log. + * + * @param type Type of log. + * @param id Instance identifier. + * @param msgFormat Message or message format (with type and id input as well). + * @param params Params for the message. + */ + public void writeInfo(String type, String id, String msgFormat, Object... params) { + this.write(Level.INFO, type, id, msgFormat, params); + } + + /** + * Writes an warning trace log. + * + * @param type Type of log. + * @param id Instance identifier. + * @param msgFormat Message or message format (with type and id input as well). + * @param params Params for the message. + */ + public void writeWarning(String type, String id, String msgFormat, Object... params) { + this.write(Level.WARNING, type, id, msgFormat, params); + } + + /** + * Writes an error trace log. + * + * @param type Type of log. + * @param id Instance identifier. + * @param msgFormat Message or message format (with type and id input as well). + * @param params Params for the message. + */ + public void writeError(String type, String id, String msgFormat, Object... params) { + this.write(Level.SEVERE, type, id, msgFormat, params); + } + + /** + * Writes a trace log. + * + * @param level Severity level of the log. + * @param type Type of log. + * @param id Instance identifier. + * @param msgFormat Message or message format (with type and id input as well). + * @param params Params for the message. + */ + private void write(Level level, String type, String id, String msgFormat, Object... params) { + String formatString = String.format("%s:%s %s", emptyIfNul(type), emptyIfNul(id), emptyIfNul(msgFormat)); + if ((params == null) || (params.length == 0)) { + LOGGER.log(level, formatString); + } else { + LOGGER.log(level, String.format(formatString, params)); + } + } + + /** + * Utility method that returns empty if String is null. + * + * @param s String to be checked. + * @return String (if not null) or empty (if null). + */ + private static String emptyIfNul(String s) { + if (s == null) { + return ""; + } + + return s; + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxy.java b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxy.java new file mode 100644 index 000000000..6955c3796 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxy.java @@ -0,0 +1,63 @@ +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import reactor.core.publisher.Mono; + +/** + * Proxy to communicate to a given Actor instance in Dapr. + */ +public interface ActorProxy { + + /** + * Returns the ActorId associated with the proxy object. + * + * @return An ActorId object. + */ + ActorId getActorId(); + + /** + * Returns actor implementation type of the actor associated with the proxy object. + * + * @return Actor's type name. + */ + String getActorType(); + + /** + * Invokes an Actor method on Dapr. + * + * @param methodName Method name to invoke. + * @param clazz The type of the return class. + * @param The type to be returned. + * @return Asynchronous result with the Actor's response. + */ + Mono invokeActorMethod(String methodName, Class clazz); + + /** + * Invokes an Actor method on Dapr. + * + * @param methodName Method name to invoke. + * @param data Object with the data. + * @param clazz The type of the return class. + * @param The type to be returned. + * @return Asynchronous result with the Actor's response. + */ + Mono invokeActorMethod(String methodName, Object data, Class clazz); + + /** + * Invokes an Actor method on Dapr. + * + * @param methodName Method name to invoke. + * @return Asynchronous result with the Actor's response. + */ + Mono invokeActorMethod(String methodName); + + /** + * Invokes an Actor method on Dapr. + * + * @param methodName Method name to invoke. + * @param data Object with the data. + * @return Asynchronous result with the Actor's response. + */ + Mono invokeActorMethod(String methodName, Object data); + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyBuilder.java b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyBuilder.java new file mode 100644 index 000000000..37ed0a909 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyBuilder.java @@ -0,0 +1,63 @@ +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import io.dapr.client.DaprHttpBuilder; +import io.dapr.serializer.DaprObjectSerializer; + +/** + * Builder to generate an ActorProxy instance. Builder can be reused for multiple instances. + */ +public class ActorProxyBuilder { + + /** + * Builder for Dapr's raw http client. + */ + private final DaprHttpBuilder daprHttpBuilder = new DaprHttpBuilder(); + + /** + * Actor's type. + */ + private final String actorType; + + /** + * Dapr's object serializer. + */ + private final DaprObjectSerializer objectSerializer; + + /** + * Instantiates a new builder for a given Actor type. + * + * @param actorType Actor's type. + * @param objectSerializer Serializer for objects sent/received. + */ + public ActorProxyBuilder(String actorType, DaprObjectSerializer objectSerializer) { + if ((actorType == null) || actorType.isEmpty()) { + throw new IllegalArgumentException("ActorType is required."); + } + if (objectSerializer == null) { + throw new IllegalArgumentException("Serializer is required."); + } + + this.actorType = actorType; + this.objectSerializer = objectSerializer; + } + + /** + * Instantiates a new ActorProxy. + * + * @param actorId Actor's identifier. + * @return New instance of ActorProxy. + */ + public ActorProxy build(ActorId actorId) { + if (actorId == null) { + throw new IllegalArgumentException("Cannot instantiate an Actor without Id."); + } + + return new ActorProxyImpl( + this.actorType, + actorId, + this.objectSerializer, + new DaprHttpClient(this.daprHttpBuilder.build())); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyImpl.java b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyImpl.java new file mode 100644 index 000000000..de354ab6c --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/client/ActorProxyImpl.java @@ -0,0 +1,136 @@ +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import io.dapr.actors.runtime.ObjectSerializer; +import io.dapr.serializer.DaprObjectSerializer; +import java.io.IOException; +import reactor.core.publisher.Mono; + +/** + * Implements a proxy client for an Actor's instance. + */ +class ActorProxyImpl implements ActorProxy { + + /** + * Serializer used for internal objects. + */ + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + /** + * Actor's identifier for this Actor instance. + */ + private final ActorId actorId; + + /** + * Actor's type for this Actor instance. + */ + private final String actorType; + + /** + * Serializer/deserialzier to exchange message for Actors. + */ + private final DaprObjectSerializer serializer; + + /** + * Client to talk to the Dapr's API. + */ + private final DaprClient daprClient; + + /** + * Creates a new instance of {@link ActorProxyImpl}. + * + * @param actorType actor implementation type of the actor associated with the proxy object. + * @param actorId The actorId associated with the proxy + * @param serializer Serializer and deserializer for method calls. + * @param daprClient Dapr client. + */ + ActorProxyImpl(String actorType, ActorId actorId, DaprObjectSerializer serializer, DaprClient daprClient) { + this.actorType = actorType; + this.actorId = actorId; + this.daprClient = daprClient; + this.serializer = serializer; + } + + /** + * {@inheritDoc} + */ + public ActorId getActorId() { + return actorId; + } + + /** + * {@inheritDoc} + */ + public String getActorType() { + return actorType; + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeActorMethod(String methodName, Object data, Class clazz) { + return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, this.wrap(data)) + .filter(s -> s.length > 0) + .map(s -> unwrap(s, clazz)); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeActorMethod(String methodName, Class clazz) { + return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, null) + .filter(s -> s.length > 0) + .map(s -> unwrap(s, clazz)); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeActorMethod(String methodName) { + return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, null).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeActorMethod(String methodName, Object data) { + return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, this.wrap(data)).then(); + } + + /** + * Extracts the response object from the Actor's method result. + * + * @param response response returned by API. + * @param clazz Expected response class. + * @param Expected response type. + * @return Response object or null. + * @throws RuntimeException In case it cannot generate Object. + */ + private T unwrap(final byte[] response, Class clazz) { + try { + return this.serializer.deserialize(INTERNAL_SERIALIZER.unwrapData(response), clazz); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Builds the request to invoke an API for Actors. + * + * @param request Request object for the original Actor's method. + * @return Payload to be sent to Dapr's API. + * @throws RuntimeException In case it cannot generate payload. + */ + private byte[] wrap(final Object request) { + try { + return INTERNAL_SERIALIZER.wrapData(this.serializer.serialize(request)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/DaprClient.java b/sdk-actors/src/main/java/io/dapr/actors/client/DaprClient.java new file mode 100644 index 000000000..5871f4cdc --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/client/DaprClient.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.client; + +import reactor.core.publisher.Mono; + +/** + * Generic Client Adapter to be used regardless of the GRPC or the HTTP Client implementation required. + */ +interface DaprClient { + + /** + * Invokes an Actor method on Dapr. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param methodName Method name to invoke. + * @param jsonPayload Serialized body. + * @return Asynchronous result with the Actor's response. + */ + Mono invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload); + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/DaprHttpClient.java b/sdk-actors/src/main/java/io/dapr/actors/client/DaprHttpClient.java new file mode 100644 index 000000000..45d109349 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/client/DaprHttpClient.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.client; + +import io.dapr.client.DaprHttp; +import io.dapr.utils.Constants; +import reactor.core.publisher.Mono; + +/** + * DaprClient over HTTP for actor client. + * + * @see DaprHttp + */ +class DaprHttpClient implements DaprClient { + + /** + * The HTTP client to be used. + * + * @see DaprHttp + */ + private final DaprHttp client; + + /** + * Instantiates a new Dapr Http Client to invoke Actors. + * + * @param client Dapr's http client. + */ + DaprHttpClient(DaprHttp client) { + this.client = client; + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload) { + String url = String.format(Constants.ACTOR_METHOD_RELATIVE_URL_FORMAT, actorType, actorId, methodName); + Mono responseMono = + this.client.invokeAPI(DaprHttp.HttpMethods.POST.name(), url, null, jsonPayload, null); + return responseMono.map(r -> r.getBody()); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/AbstractActor.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/AbstractActor.java new file mode 100644 index 000000000..a9662ac86 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/AbstractActor.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.ActorTrace; +import java.io.IOException; +import java.time.Duration; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import reactor.core.publisher.Mono; + +/** + * Represents the base class for actors. + * The base type for actors, that provides the common functionality for actors. + * The state is preserved across actor garbage collections and fail-overs. + */ +public abstract class AbstractActor { + + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + /** + * Type of tracing messages. + */ + private static final String TRACE_TYPE = "Actor"; + + /** + * Context for the Actor runtime. + */ + private final ActorRuntimeContext actorRuntimeContext; + + /** + * Actor identifier. + */ + private final ActorId id; + + /** + * Emits trace messages for Actors. + */ + private final ActorTrace actorTrace; + + /** + * Registered timers for this Actor. + */ + private final Map timers; + + /** + * Manager for the states in Actors. + */ + private final ActorStateManager actorStateManager; + + /** + * Internal control to assert method invocation on start and finish in this SDK. + */ + private boolean started; + + /** + * Instantiates a new Actor. + * + * @param runtimeContext Context for the runtime. + * @param id Actor identifier. + */ + protected AbstractActor(ActorRuntimeContext runtimeContext, ActorId id) { + this.actorRuntimeContext = runtimeContext; + this.id = id; + this.actorStateManager = new ActorStateManager( + runtimeContext.getStateProvider(), + runtimeContext.getActorTypeInformation().getName(), + id); + this.actorTrace = runtimeContext.getActorTrace(); + this.timers = Collections.synchronizedMap(new HashMap<>()); + this.started = false; + } + + /** + * Returns the id of the actor. + * + * @return Actor id. + */ + protected ActorId getId() { + return this.id; + } + + /** + * Returns the state store manager for this Actor. + * + * @return State store manager for this Actor + */ + protected ActorStateManager getActorStateManager() { + return this.actorStateManager; + } + + /** + * Registers a reminder for this Actor. + * + * @param reminderName Name of the reminder. + * @param state State to be send along with reminder triggers. + * @param dueTime Due time for the first trigger. + * @param period Frequency for the triggers. + * @param Type of the state object. + * @return Asynchronous void response. + */ + protected Mono registerReminder( + String reminderName, + T state, + Duration dueTime, + Duration period) { + try { + byte[] data = this.actorRuntimeContext.getObjectSerializer().serialize(state); + ActorReminderParams params = new ActorReminderParams(data, dueTime, period); + byte[] serialized = INTERNAL_SERIALIZER.serialize(params); + return this.actorRuntimeContext.getDaprClient().registerActorReminder( + this.actorRuntimeContext.getActorTypeInformation().getName(), + this.id.toString(), + reminderName, + serialized); + } catch (IOException e) { + return Mono.error(e); + } + } + + /** + * Registers a Timer for the actor. A timer name is autogenerated by the runtime to keep track of it. + * + * @param timerName Name of the timer, unique per Actor (auto-generated if null). + * @param callback Name of the method to be called. + * @param state State to be passed it to the method when timer triggers. + * @param dueTime The amount of time to delay before the async callback is first invoked. + * Specify negative one (-1) milliseconds to prevent the timer from starting. + * Specify zero (0) to start the timer immediately. + * @param period The time interval between invocations of the async callback. + * Specify negative one (-1) milliseconds to disable periodic signaling. + * @param Type for the state to be passed in to timer. + * @return Asynchronous result. + */ + protected Mono registerActorTimer( + String timerName, + String callback, + T state, + Duration dueTime, + Duration period) { + return Mono.fromSupplier(() -> { + if ((callback == null) || callback.isEmpty()) { + throw new IllegalArgumentException("Timer requires a callback function."); + } + + String name = timerName; + if ((timerName == null) || (timerName.isEmpty())) { + name = String.format("%s_Timer_%d", this.id.toString(), this.timers.size() + 1); + } + + ActorTimer actorTimer = new ActorTimer(this, name, callback, state, dueTime, period); + this.timers.put(name, actorTimer); + return actorTimer; + }).flatMap(actorTimer -> { + try { + return this.actorRuntimeContext.getDaprClient().registerActorTimer( + this.actorRuntimeContext.getActorTypeInformation().getName(), + this.id.toString(), + actorTimer.getName(), + INTERNAL_SERIALIZER.serialize(actorTimer)); + } catch (Exception e) { + return Mono.error(e); + } + }); + } + + /** + * Unregisters an Actor timer. + * + * @param timerName Name of Timer to be unregistered. + * @return Asynchronous void response. + */ + protected Mono unregisterTimer(String timerName) { + return Mono.fromSupplier(() -> getActorTimer(timerName)) + .flatMap(actorTimer -> this.actorRuntimeContext.getDaprClient().unregisterActorTimer( + this.actorRuntimeContext.getActorTypeInformation().getName(), + this.id.toString(), + timerName)) + .then(Mono.fromRunnable(() -> this.timers.remove(timerName))); + } + + /** + * Unregisters a Reminder. + * + * @param reminderName Name of Reminder to be unregistered. + * @return Asynchronous void response. + */ + protected Mono unregisterReminder(String reminderName) { + return this.actorRuntimeContext.getDaprClient().unregisterActorReminder( + this.actorRuntimeContext.getActorTypeInformation().getName(), + this.id.toString(), + reminderName); + } + + /** + * Callback function invoked after an Actor has been activated. + * + * @return Asynchronous void response. + */ + protected Mono onActivate() { + return Mono.empty(); + } + + /** + * Callback function invoked after an Actor has been deactivated. + * + * @return Asynchronous void response. + */ + protected Mono onDeactivate() { + return Mono.empty(); + } + + /** + * Callback function invoked before method is invoked. + * + * @param actorMethodContext Method context. + * @return Asynchronous void response. + */ + protected Mono onPreActorMethod(ActorMethodContext actorMethodContext) { + return Mono.empty(); + } + + /** + * Callback function invoked after method is invoked. + * + * @param actorMethodContext Method context. + * @return Asynchronous void response. + */ + protected Mono onPostActorMethod(ActorMethodContext actorMethodContext) { + return Mono.empty(); + } + + /** + * Saves the state of this Actor. + * + * @return Asynchronous void response. + */ + protected Mono saveState() { + return this.actorStateManager.save(); + } + + /** + * Resets the cached state of this Actor. + */ + void rollback() { + if (!this.started) { + throw new IllegalStateException("Cannot reset state before starting call."); + } + + this.resetState(); + this.started = false; + } + + /** + * Resets the cached state of this Actor. + */ + void resetState() { + this.actorStateManager.clear(); + } + + /** + * Gets a given timer by name. + * + * @param timerName Timer name. + * @return Asynchronous void response. + */ + ActorTimer getActorTimer(String timerName) { + return timers.getOrDefault(timerName, null); + } + + /** + * Internal callback when an Actor is activated. + * + * @return Asynchronous void response. + */ + Mono onActivateInternal() { + return Mono.fromRunnable(() -> { + this.actorTrace.writeInfo(TRACE_TYPE, this.id.toString(), "Activating ..."); + this.resetState(); + }).then(this.onActivate()) + .then(this.doWriteInfo(TRACE_TYPE, this.id.toString(), "Activated")) + .then(this.saveState()); + } + + /** + * Internal callback when an Actor is deactivated. + * + * @return Asynchronous void response. + */ + Mono onDeactivateInternal() { + this.actorTrace.writeInfo(TRACE_TYPE, this.id.toString(), "Deactivating ..."); + + return Mono.fromRunnable(() -> this.resetState()) + .then(this.onDeactivate()) + .then(this.doWriteInfo(TRACE_TYPE, this.id.toString(), "Deactivated")); + } + + /** + * Internal callback prior to method be invoked. + * + * @param actorMethodContext Method context. + * @return Asynchronous void response. + */ + Mono onPreActorMethodInternal(ActorMethodContext actorMethodContext) { + return Mono.fromRunnable(() -> { + if (this.started) { + throw new IllegalStateException("Cannot invoke a method before completing previous call."); + } + + this.started = true; + }).then(this.onPreActorMethod(actorMethodContext)); + } + + /** + * Internal callback after method is invoked. + * + * @param actorMethodContext Method context. + * @return Asynchronous void response. + */ + Mono onPostActorMethodInternal(ActorMethodContext actorMethodContext) { + return Mono.fromRunnable(() -> { + if (!this.started) { + throw new IllegalStateException("Cannot complete a method before starting a call."); + } + }).then(this.onPostActorMethod(actorMethodContext)) + .then(this.saveState()) + .then(Mono.fromRunnable(() -> { + this.started = false; + })); + } + + /** + * Internal method to emit a trace message. + * + * @param type Type of trace message. + * @param id Identifier of entity relevant for the trace message. + * @param message Message to be logged. + * @return Asynchronous void response. + */ + private Mono doWriteInfo(String type, String id, String message) { + return Mono.fromRunnable(() -> this.actorTrace.writeInfo(type, id, message)); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorCallType.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorCallType.java new file mode 100644 index 000000000..b0293b58e --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorCallType.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +/** + * Represents the call-type associated with the method invoked by actor runtime. + */ +enum ActorCallType { + + /** + * Specifies that the method invoked is an actor interface method for a given + * client request. + */ + ACTOR_INTERFACE_METHOD, + /** + * Specifies that the method invoked is a timer callback method. + */ + TIMER_METHOD, + /** + * Specifies that the method is when a reminder fires. + */ + REMINDER_METHOD +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorFactory.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorFactory.java new file mode 100644 index 000000000..8b34432e2 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; + +/** + * Creates an actor of a given type. + * + * @param Actor Type to be created. + */ +@FunctionalInterface +public interface ActorFactory { + + /** + * Creates an Actor. + * + * @param actorRuntimeContext Actor type's context in the runtime. + * @param actorId Actor Id. + * @return Actor or null it failed. + */ + T createActor(ActorRuntimeContext actorRuntimeContext, ActorId actorId); +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java new file mode 100644 index 000000000..8acc020a8 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java @@ -0,0 +1,342 @@ +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import reactor.core.publisher.Mono; + +/** + * Manages actors of a specific type. + */ +class ActorManager { + + /** + * Serializer for internal Dapr objects. + */ + private static final ObjectSerializer OBJECT_SERIALIZER = new ObjectSerializer(); + + /** + * Context for the Actor runtime. + */ + private final ActorRuntimeContext runtimeContext; + + /** + * Methods found in Actors. + */ + private final ActorMethodInfoMap actorMethods; + + /** + * Active Actor instances. + */ + private final Map activeActors; + + /** + * Instantiates a new manager for a given actor referenced in the runtimeContext. + * + * @param runtimeContext Runtime context for the Actor. + */ + ActorManager(ActorRuntimeContext runtimeContext) { + this.runtimeContext = runtimeContext; + this.actorMethods = new ActorMethodInfoMap(runtimeContext.getActorTypeInformation().getInterfaces()); + this.activeActors = Collections.synchronizedMap(new HashMap<>()); + } + + /** + * Activates an Actor. + * + * @param actorId Actor identifier. + * @return Asynchronous void response. + */ + Mono activateActor(ActorId actorId) { + return Mono.fromSupplier(() -> this.runtimeContext.getActorFactory().createActor(runtimeContext, actorId)) + .flatMap(actor -> actor.onActivateInternal().then(this.onActivatedActor(actorId, actor))); + } + + /** + * Deactivates an Actor. + * + * @param actorId Actor identifier. + * @return Asynchronous void response. + */ + Mono deactivateActor(ActorId actorId) { + return Mono.fromSupplier(() -> this.activeActors.remove(actorId)).flatMap(actor -> actor.onDeactivateInternal()); + } + + /** + * Invokes reminder for Actor. + * + * @param actorId Identifier for Actor being invoked. + * @param reminderName Name of reminder being invoked. + * @param params Parameters for the reminder. + * @return Asynchronous void response. + */ + Mono invokeReminder(ActorId actorId, String reminderName, byte[] params) { + return Mono.fromSupplier(() -> { + if (!this.runtimeContext.getActorTypeInformation().isRemindable()) { + return null; + } + + try { + return OBJECT_SERIALIZER.deserialize(params, ActorReminderParams.class); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).flatMap(p -> + invoke(actorId, + ActorMethodContext.createForReminder(reminderName), + actor -> doReminderInvokation((Remindable) actor, reminderName, p))).then(); + } + + /** + * Invokes a timer for a given Actor. + * + * @param actorId Identifier for Actor. + * @param timerName Name of timer being invoked. + * @return Asynchronous void response. + */ + Mono invokeTimer(ActorId actorId, String timerName) { + return Mono.fromSupplier(() -> { + AbstractActor actor = this.activeActors.getOrDefault(actorId, null); + if (actor == null) { + throw new IllegalArgumentException( + String.format("Could not find actor %s of type %s.", + actorId.toString(), + this.runtimeContext.getActorTypeInformation().getName())); + } + + ActorTimer actorTimer = actor.getActorTimer(timerName); + if (actorTimer == null) { + throw new IllegalStateException( + String.format("Could not find timer %s for actor %s.", + timerName, + this.runtimeContext.getActorTypeInformation().getName())); + } + + return actorTimer; + }).flatMap(actorTimer -> invokeMethod( + actorId, + ActorMethodContext.createForTimer(actorTimer.getName()), + actorTimer.getCallback(), + actorTimer.getState())) + .then(); + } + + /** + * Internal callback for when Actor is activated. + * + * @param actorId Actor identifier. + * @param actor Actor's instance. + * @return Asynchronous void response. + */ + private Mono onActivatedActor(ActorId actorId, T actor) { + return Mono.fromRunnable(() -> this.activeActors.put(actorId, actor)); + } + + /** + * Internal method to actually invoke a reminder. + * + * @param actor Actor that owns the reminder. + * @param reminderName Name of the reminder. + * @param reminderParams Params for the reminder. + * @return Asynchronous void response. + */ + private Mono doReminderInvokation( + Remindable actor, + String reminderName, + ActorReminderParams reminderParams) { + return Mono.fromSupplier(() -> { + if (actor == null) { + throw new IllegalArgumentException("actor is mandatory."); + } + if (reminderName == null) { + throw new IllegalArgumentException("reminderName is mandatory."); + } + if (reminderParams == null) { + throw new IllegalArgumentException("reminderParams is mandatory."); + } + + return true; + }).flatMap(x -> { + try { + Object data = this.runtimeContext.getObjectSerializer().deserialize( + reminderParams.getData(), + actor.getStateType()); + return actor.receiveReminder( + reminderName, + data, + reminderParams.getDueTime(), + reminderParams.getPeriod()); + } catch (Exception e) { + return Mono.error(e); + } + }).thenReturn(true); + } + + /** + * Invokes a given method in the Actor. + * + * @param actorId Identifier for Actor being invoked. + * @param methodName Name of method being invoked. + * @param request Input object for the method being invoked. + * @return Asynchronous void response. + */ + Mono invokeMethod(ActorId actorId, String methodName, byte[] request) { + return invokeMethod(actorId, null, methodName, request); + } + + /** + * Internal method to actually invoke Actor's timer method. + * + * @param actorId Identifier for the Actor. + * @param context Method context to be invoked. + * @param methodName Method name to be invoked. + * @param input Input object to be passed in to the invoked method. + * @return Asynchronous void response. + */ + private Mono invokeMethod(ActorId actorId, ActorMethodContext context, String methodName, Object input) { + ActorMethodContext actorMethodContext = context; + if (actorMethodContext == null) { + actorMethodContext = ActorMethodContext.createForActor(methodName); + } + + return this.invoke(actorId, actorMethodContext, actor -> { + try { + // Finds the actor method with the given name and 1 or no parameter. + Method method = this.actorMethods.get(methodName); + + if (method.getReturnType().equals(Mono.class)) { + return invokeMonoMethod(actor, method, input); + } + return invokeMethod(actor, method, input); + } catch (Exception e) { + return Mono.error(e); + } + }); + } + + /** + * Internal method to actually invoke Actor's method. + * + * @param actorId Identifier for the Actor. + * @param context Method context to be invoked. + * @param methodName Method name to be invoked. + * @param request Input object to be passed in to the invoked method. + * @return Asynchronous serialized response. + */ + private Mono invokeMethod(ActorId actorId, ActorMethodContext context, String methodName, byte[] request) { + ActorMethodContext actorMethodContext = context; + if (actorMethodContext == null) { + actorMethodContext = ActorMethodContext.createForActor(methodName); + } + + return this.invoke(actorId, actorMethodContext, actor -> { + try { + // Finds the actor method with the given name and 1 or no parameter. + Method method = this.actorMethods.get(methodName); + + Object input = null; + if (method.getParameterCount() == 1) { + // Actor methods must have a one or no parameter, which is guaranteed at this point. + Class inputClass = method.getParameterTypes()[0]; + input = this.runtimeContext.getObjectSerializer().deserialize(request, inputClass); + } + + if (method.getReturnType().equals(Mono.class)) { + return invokeMonoMethod(actor, method, input); + } + + return invokeMethod(actor, method, input); + } catch (Exception e) { + return Mono.error(e); + } + }).map(r -> { + try { + return this.runtimeContext.getObjectSerializer().serialize(r); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + /** + * Invokes a method that returns a plain object (not Mono). + * + * @param actor Actor to be invoked. + * @param method Method to be invoked. + * @param input Input object for the method (or null). + * @return Asynchronous object response. + */ + private Mono invokeMethod(AbstractActor actor, Method method, Object input) { + return Mono.fromSupplier(() -> { + try { + if (method.getParameterCount() == 0) { + return method.invoke(actor); + } else { + // Actor methods must have a one or no parameter, which is guaranteed at this point. + return method.invoke(actor, input); + } + } catch (Exception e) { + return Mono.error(e); + } + }); + } + + /** + * Invokes a method that returns Mono. + * + * @param actor Actor to be invoked. + * @param method Method to be invoked. + * @param input Input object for the method (or null). + * @return Asynchronous object response. + */ + private Mono invokeMonoMethod(AbstractActor actor, Method method, Object input) { + try { + if (method.getParameterCount() == 0) { + return (Mono) method.invoke(actor); + } else { + // Actor methods must have a one or no parameter, which is guaranteed at this point. + return (Mono) method.invoke(actor, input); + } + } catch (Exception e) { + return Mono.error(e); + } + } + + /** + * Internal call to invoke a method, timer or reminder for an Actor. + * + * @param actorId Actor identifier. + * @param context Context for the method/timer/reminder call. + * @param func Function to perform the method call. + * @param Expected return type for the function call. + * @return Asynchronous response for the returned object. + */ + private Mono invoke(ActorId actorId, ActorMethodContext context, Function> func) { + try { + AbstractActor actor = this.activeActors.getOrDefault(actorId, null); + if (actor == null) { + throw new IllegalArgumentException( + String.format("Could not find actor %s of type %s.", + actorId.toString(), + this.runtimeContext.getActorTypeInformation().getName())); + } + + return actor.onPreActorMethodInternal(context) + .then((Mono) func.apply(actor)) + .switchIfEmpty( + actor.onPostActorMethodInternal(context)) + .flatMap(r -> actor.onPostActorMethodInternal(context).thenReturn(r)) + .onErrorMap(throwable -> { + actor.rollback(); + return throwable; + }) + .map(o -> (T) o); + } catch (Exception e) { + return Mono.error(e); + } + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodContext.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodContext.java new file mode 100644 index 000000000..ed2adb5f6 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodContext.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +/** + * Contains information about the method that is invoked by actor runtime. + */ +public class ActorMethodContext { + + /** + * Method name to be invoked. + */ + private final String methodName; + + /** + * Call type to be used. + */ + private final ActorCallType callType; + + /** + * Constructs a new instance of {@link ActorMethodContext}, representing a call for an Actor. + * + * @param methodName Method name to be invoked. + * @param callType Call type to be used. + */ + private ActorMethodContext(String methodName, ActorCallType callType) { + this.methodName = methodName; + this.callType = callType; + } + + /** + * Gets the name of the method invoked by actor runtime. + * + * @return The method name. + */ + public String getMethodName() { + return this.methodName; + } + + /** + * Gets the call type to be used. + * + * @return Call type. + */ + public ActorCallType getCallType() { + return this.callType; + } + + /** + * Creates a context to invoke an Actor's method. + * + * @param methodName THe method to be invoked. + * @return Context of the method call as {@link ActorMethodContext} + */ + static ActorMethodContext createForActor(String methodName) { + return new ActorMethodContext(methodName, ActorCallType.ACTOR_INTERFACE_METHOD); + } + + /** + * Creates a context to invoke an Actor's timer. + * + * @param methodName THe method to be invoked. + * @return Context of the method call as {@link ActorMethodContext} + */ + static ActorMethodContext createForTimer(String methodName) { + return new ActorMethodContext(methodName, ActorCallType.TIMER_METHOD); + } + + /** + * Creates a context to invoke an Actor's reminder. + * + * @param methodName THe method to be invoked. + * @return Context of the method call as {@link ActorMethodContext} + */ + static ActorMethodContext createForReminder(String methodName) { + return new ActorMethodContext(methodName, ActorCallType.REMINDER_METHOD); + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodInfoMap.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodInfoMap.java new file mode 100644 index 000000000..5a950c310 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorMethodInfoMap.java @@ -0,0 +1,56 @@ +package io.dapr.actors.runtime; + +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Actor method dispatcher map. Holds method_name -> Method for methods defined in Actor interfaces. + */ +class ActorMethodInfoMap { + /** + * Map for methods based on name. + */ + private final Map methods; + + /** + * Instantiates a given Actor map based on the interfaces found in the class. + * + * @param interfaceTypes Interfaces found in the Actor class. + */ + ActorMethodInfoMap(Collection> interfaceTypes) { + Map methods = new HashMap<>(); + + // Find methods which are defined in Actor interface. + for (Class actorInterface : interfaceTypes) { + for (Method methodInfo : actorInterface.getMethods()) { + // Only support methods with 1 or 0 argument. + if (methodInfo.getParameterCount() <= 1) { + // If Actor class uses overloading, then one will win. + // Document this behavior, so users know how to write their code. + methods.put(methodInfo.getName(), methodInfo); + } + } + } + + this.methods = Collections.unmodifiableMap(methods); + } + + /** + * Gets the Actor's method by name. + * + * @param methodName Name of the method. + * @return Method. + * @throws NoSuchMethodException If method is not found. + */ + Method get(String methodName) throws NoSuchMethodException { + Method method = this.methods.get(methodName); + if (method == null) { + throw new NoSuchMethodException(String.format("Could not find method %s.", methodName)); + } + + return method; + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorReminderParams.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorReminderParams.java new file mode 100644 index 000000000..9ab15da24 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorReminderParams.java @@ -0,0 +1,104 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +package io.dapr.actors.runtime; + +import java.time.Duration; + +/** + * Parameters for Actor Reminder. + */ +final class ActorReminderParams { + + /** + * Minimum duration for period. + */ + private static final Duration MIN_TIME_PERIOD = Duration.ofMillis(-1); + + /** + * Data to be passed in as part of the reminder trigger. + */ + private final byte[] data; + + /** + * Time the reminder is due for the 1st time. + */ + private final Duration dueTime; + + /** + * Interval between triggers. + */ + private final Duration period; + + /** + * Instantiates a new instance for the params of a reminder. + * + * @param data Data to be passed in as part of the reminder trigger. + * @param dueTime Time the reminder is due for the 1st time. + * @param period Interval between triggers. + */ + ActorReminderParams(byte[] data, Duration dueTime, Duration period) { + validateDueTime("DueTime", dueTime); + validatePeriod("Period", period); + this.data = data; + this.dueTime = dueTime; + this.period = period; + } + + /** + * Gets the time the reminder is due for the 1st time. + * + * @return Time the reminder is due for the 1st time. + */ + Duration getDueTime() { + return dueTime; + } + + /** + * Gets the interval between triggers. + * + * @return Interval between triggers. + */ + Duration getPeriod() { + return period; + } + + /** + * Gets the data to be passed in as part of the reminder trigger. + * + * @return Data to be passed in as part of the reminder trigger. + */ + byte[] getData() { + return data; + } + + /** + * Validates due time is valid, throws {@link IllegalArgumentException}. + * + * @param argName Name of the argument passed in. + * @param value Vale being checked. + */ + private static void validateDueTime(String argName, Duration value) { + if (value.compareTo(Duration.ZERO) < 0) { + String message = String.format( + "argName: %s - Duration toMillis() - specified value must be greater than %s", argName, Duration.ZERO); + throw new IllegalArgumentException(message); + } + } + + /** + * Validates reminder period is valid, throws {@link IllegalArgumentException}. + * + * @param argName Name of the argument passed in. + * @param value Vale being checked. + */ + private static void validatePeriod(String argName, Duration value) throws IllegalArgumentException { + if (value.compareTo(MIN_TIME_PERIOD) < 0) { + String message = String.format( + "argName: %s - Duration toMillis() - specified value must be greater than %s", argName, MIN_TIME_PERIOD); + throw new IllegalArgumentException(message); + } + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntime.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntime.java new file mode 100644 index 000000000..720389aca --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntime.java @@ -0,0 +1,279 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.ActorTrace; +import io.dapr.client.DaprHttpBuilder; +import io.dapr.serializer.DaprObjectSerializer; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import reactor.core.publisher.Mono; + +/** + * Contains methods to register actor types. Registering the types allows the + * runtime to create instances of the actor. + */ +public class ActorRuntime { + + /** + * Serializer for internal Dapr objects. + */ + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + /** + * A trace type used when logging. + */ + private static final String TRACE_TYPE = "ActorRuntime"; + + /** + * Tracing errors, warnings and info logs. + */ + private static final ActorTrace ACTOR_TRACE = new ActorTrace(); + + /** + * Gets an instance to the ActorRuntime. There is only 1. + */ + private static volatile ActorRuntime instance; + + /** + * Configuration for the Actor runtime. + */ + private final ActorRuntimeConfig config; + + /** + * A client used to communicate from the actor to the Dapr runtime. + */ + private final DaprClient daprClient; + + /** + * Map of ActorType --> ActorManager. + */ + private final Map actorManagers; + + /** + * The default constructor. This should not be called directly. + * + * @throws IllegalStateException If cannot instantiate Runtime. + */ + private ActorRuntime() throws IllegalStateException { + this(new DaprHttpClient(new DaprHttpBuilder().build())); + } + + /** + * Constructor with dependency injection, useful for testing. This should not be called directly. + * + * @param daprClient Client to communicate with Dapr. + * @throws IllegalStateException If class has one instance already. + */ + private ActorRuntime(DaprClient daprClient) throws IllegalStateException { + if (instance != null) { + throw new IllegalStateException("ActorRuntime should only be constructed once"); + } + + this.config = new ActorRuntimeConfig(); + this.actorManagers = Collections.synchronizedMap(new HashMap<>()); + this.daprClient = daprClient; + } + + /** + * Returns an ActorRuntime object. + * + * @return An ActorRuntime object. + */ + public static ActorRuntime getInstance() { + if (instance == null) { + synchronized (ActorRuntime.class) { + if (instance == null) { + instance = new ActorRuntime(); + } + } + } + + return instance; + } + + /** + * Gets the Actor configuration for this runtime. + * + * @return Actor configuration serialized. + * @throws IOException If cannot serialize config. + */ + public byte[] serializeConfig() throws IOException { + return this.INTERNAL_SERIALIZER.serialize(this.config); + } + + /** + * Registers an actor with the runtime. + * + * @param clazz The type of actor. + * @param objectSerializer Serializer for Actor's request and response objects. + * @param stateSerializer Serializer for Actor's state objects. + * @param Actor class type. + */ + public void registerActor( + Class clazz, DaprObjectSerializer objectSerializer, DaprObjectSerializer stateSerializer) { + registerActor(clazz, null, objectSerializer, stateSerializer); + } + + /** + * Registers an actor with the runtime. + * + * @param clazz The type of actor. + * @param actorFactory An optional factory to create actors. This can be used for dependency injection. + * @param objectSerializer Serializer for Actor's request and response objects. + * @param stateSerializer Serializer for Actor's state objects. + * @param Actor class type. + */ + public void registerActor( + Class clazz, ActorFactory actorFactory, + DaprObjectSerializer objectSerializer, + DaprObjectSerializer stateSerializer) { + if (clazz == null) { + throw new IllegalArgumentException("Class is required."); + } + if (objectSerializer == null) { + throw new IllegalArgumentException("Serializer is required."); + } + if (stateSerializer == null) { + throw new IllegalArgumentException("State objectSerializer is required."); + } + + ActorTypeInformation actorTypeInfo = ActorTypeInformation.create(clazz); + + ActorFactory actualActorFactory = actorFactory != null ? actorFactory : new DefaultActorFactory(); + + ActorRuntimeContext context = new ActorRuntimeContext<>( + this, + objectSerializer, + actualActorFactory, + actorTypeInfo, + this.daprClient, + new DaprStateAsyncProvider(this.daprClient, stateSerializer)); + + // Create ActorManagers, override existing entry if registered again. + this.actorManagers.put(actorTypeInfo.getName(), new ActorManager(context)); + this.config.addRegisteredActorType(actorTypeInfo.getName()); + } + + /** + * Activates an actor for an actor type with given actor id. + * + * @param actorTypeName Actor type name to activate the actor for. + * @param actorId Actor id for the actor to be activated. + * @return Async void task. + */ + public Mono activate(String actorTypeName, String actorId) { + return Mono.fromSupplier(() -> this.getActorManager(actorTypeName)) + .flatMap(m -> m.activateActor(new ActorId(actorId))); + } + + /** + * Deactivates an actor for an actor type with given actor id. + * + * @param actorTypeName Actor type name to deactivate the actor for. + * @param actorId Actor id for the actor to be deactivated. + * @return Async void task. + */ + public Mono deactivate(String actorTypeName, String actorId) { + return Mono.fromSupplier(() -> this.getActorManager(actorTypeName)) + .flatMap(m -> m.deactivateActor(new ActorId(actorId))); + } + + /** + * Invokes the specified method for the actor, this is mainly used for cross + * language invocation. + * + * @param actorTypeName Actor type name to invoke the method for. + * @param actorId Actor id for the actor for which method will be invoked. + * @param actorMethodName Method name on actor type which will be invoked. + * @param payload RAW payload for the actor method. + * @return Response for the actor method. + */ + public Mono invoke(String actorTypeName, String actorId, String actorMethodName, byte[] payload) { + return Mono.fromSupplier(() -> this.getActorManager(actorTypeName)) + .flatMap(m -> m.invokeMethod(new ActorId(actorId), actorMethodName, unwrap(payload))) + .map(response -> wrap((byte[]) response)); + } + + /** + * Fires a reminder for the Actor. + * + * @param actorTypeName Actor type name to invoke the method for. + * @param actorId Actor id for the actor for which method will be invoked. + * @param reminderName The name of reminder provided during registration. + * @param params Params for the reminder. + * @return Async void task. + */ + public Mono invokeReminder(String actorTypeName, String actorId, String reminderName, byte[] params) { + return Mono.fromSupplier(() -> this.getActorManager(actorTypeName)) + .flatMap(m -> m.invokeReminder(new ActorId(actorId), reminderName, params)); + } + + /** + * Fires a timer for the Actor. + * + * @param actorTypeName Actor type name to invoke the method for. + * @param actorId Actor id for the actor for which method will be invoked. + * @param timerName The name of timer provided during registration. + * @return Async void task. + */ + public Mono invokeTimer(String actorTypeName, String actorId, String timerName) { + return Mono.fromSupplier(() -> this.getActorManager(actorTypeName)) + .flatMap(m -> m.invokeTimer(new ActorId(actorId), timerName)); + } + + /** + * Finds the actor manager or errors out. + * + * @param actorTypeName Actor type for the actor manager to be found. + * @return Actor manager instance, never null. + * @throws IllegalStateException if cannot find actor's manager. + */ + private ActorManager getActorManager(String actorTypeName) { + ActorManager actorManager = this.actorManagers.get(actorTypeName); + + if (actorManager == null) { + String errorMsg = String.format("Actor type %s is not registered with Actor runtime.", actorTypeName); + ACTOR_TRACE.writeError(TRACE_TYPE, actorTypeName, "Actor type is not registered with runtime."); + throw new IllegalStateException(errorMsg); + } + + return actorManager; + } + + /** + * Extracts the data as String from the Actor's method result. + * + * @param payload String returned by API. + * @return data or null. + * @throws RuntimeException In case it cannot extract data. + */ + private byte[] unwrap(final byte[] payload) { + try { + return INTERNAL_SERIALIZER.unwrapData(payload); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Builds the request to invoke an API for Actors. + * + * @param data Data to be wrapped in the request. + * @return Payload to be sent to Dapr's API. + * @throws RuntimeException In case it cannot generate payload. + */ + private byte[] wrap(final byte[] data) { + try { + return INTERNAL_SERIALIZER.wrapData(data); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeConfig.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeConfig.java new file mode 100644 index 000000000..30f7cd110 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeConfig.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +class ActorRuntimeConfig { + + private Collection registeredActorTypes = new ArrayList<>(); + + ActorRuntimeConfig addRegisteredActorType(String actorTypeName) { + if (actorTypeName == null) { + throw new IllegalArgumentException("Registered actor must have a type name."); + } + + this.registeredActorTypes.add(actorTypeName); + return this; + } + + Collection getRegisteredActorTypes() { + return Collections.unmodifiableCollection(registeredActorTypes); + } + + ActorRuntimeConfig setRegisteredActorTypes(Collection registeredActorTypes) { + this.registeredActorTypes = registeredActorTypes; + return this; + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeContext.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeContext.java new file mode 100644 index 000000000..081048542 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorRuntimeContext.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorTrace; +import io.dapr.serializer.DaprObjectSerializer; + +/** + * Provides the context for the Actor's runtime. + * + * @param Actor's type for the context. + */ +public class ActorRuntimeContext { + + /** + * Runtime. + */ + private final ActorRuntime actorRuntime; + + /** + * Serializer for transient objects. + */ + private final DaprObjectSerializer objectSerializer; + + /** + * Actor factory. + */ + private final ActorFactory actorFactory; + + /** + * Information of the Actor's type. + */ + private final ActorTypeInformation actorTypeInformation; + + /** + * Trace for Actor logs. + */ + private final ActorTrace actorTrace; + + /** + * Client to communicate to Dapr's API. + */ + private final DaprClient daprClient; + + /** + * State provider for given Actor Type. + */ + private final DaprStateAsyncProvider stateProvider; + + /** + * Instantiates a new runtime context for the Actor type. + * + * @param actorRuntime Runtime. + * @param objectSerializer Serializer for transient objects. + * @param actorFactory Factory for Actors. + * @param actorTypeInformation Information for Actor's type. + * @param daprClient Client to communicate to Dapr. + * @param stateProvider State provider for given Actor's type. + */ + ActorRuntimeContext(ActorRuntime actorRuntime, + DaprObjectSerializer objectSerializer, + ActorFactory actorFactory, + ActorTypeInformation actorTypeInformation, + DaprClient daprClient, + DaprStateAsyncProvider stateProvider) { + this.actorRuntime = actorRuntime; + this.objectSerializer = objectSerializer; + this.actorFactory = actorFactory; + this.actorTypeInformation = actorTypeInformation; + this.actorTrace = new ActorTrace(); + this.daprClient = daprClient; + this.stateProvider = stateProvider; + } + + /** + * Gets the Actor's runtime. + * + * @return Actor's runtime. + */ + ActorRuntime getActorRuntime() { + return this.actorRuntime; + } + + /** + * Gets the Actor's serializer for transient objects. + * + * @return Actor's serializer for transient objects. + */ + DaprObjectSerializer getObjectSerializer() { + return this.objectSerializer; + } + + /** + * Gets the Actor's serializer. + * + * @return Actor's serializer. + */ + ActorFactory getActorFactory() { + return this.actorFactory; + } + + /** + * Gets the information about the Actor's type. + * + * @return Information about the Actor's type. + */ + ActorTypeInformation getActorTypeInformation() { + return this.actorTypeInformation; + } + + /** + * Gets the trace for Actor logs. + * + * @return Trace for Actor logs. + */ + ActorTrace getActorTrace() { + return this.actorTrace; + } + + /** + * Gets the client to communicate to Dapr's API. + * + * @return Client to communicate to Dapr's API. + */ + DaprClient getDaprClient() { + return this.daprClient; + } + + /** + * Gets the state provider for given Actor's type. + * + * @return State provider for given Actor's type. + */ + DaprStateAsyncProvider getStateProvider() { + return stateProvider; + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChange.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChange.java new file mode 100644 index 000000000..5aa7a77cf --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChange.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +/** + * Represents a state change for an actor. + */ +public final class ActorStateChange { + + /** + * Name of the state being changed. + */ + private final String stateName; + + /** + * New value for the state being changed. + */ + private final Object value; + + /** + * Type of change {@link ActorStateChangeKind}. + */ + private final ActorStateChangeKind changeKind; + + /** + * Creates an actor state change. + * + * @param stateName Name of the state being changed. + * @param value New value for the state being changed. + * @param changeKind Kind of change. + */ + ActorStateChange(String stateName, Object value, ActorStateChangeKind changeKind) { + this.stateName = stateName; + this.value = value; + this.changeKind = changeKind; + } + + /** + * Gets the name of the state being changed. + * + * @return Name of the state. + */ + String getStateName() { + return stateName; + } + + /** + * Gets the new value of the state being changed. + * + * @return New value. + */ + Object getValue() { + return value; + } + + /** + * Gets the kind of change. + * + * @return Kind of change. + */ + ActorStateChangeKind getChangeKind() { + return changeKind; + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChangeKind.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChangeKind.java new file mode 100644 index 000000000..b64a2f2d9 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateChangeKind.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +/** + * Represents an actor's state change. + */ +public enum ActorStateChangeKind { + + /** + * No change in state. + */ + NONE(""), + + /** + * State needs to be added. + */ + ADD("upsert"), + + /** + * State needs to be updated. + */ + UPDATE("upsert"), + + /** + * State needs to be removed. + */ + REMOVE("delete"); + + /** + * Operation name in Dapr's state management. + */ + private final String daprStateChangeOperation; + + /** + * Creates a kind of actor state change. + * + * @param daprStateChangeOperation Equivalent operation name Dapr's state management + */ + ActorStateChangeKind(String daprStateChangeOperation) { + this.daprStateChangeOperation = daprStateChangeOperation; + } + + /** + * Gets equivalent operation name Dapr's state management. + * + * @return Equivalent operation name Dapr's state management + */ + String getDaprStateChangeOperation() { + return daprStateChangeOperation; + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateManager.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateManager.java new file mode 100644 index 000000000..eaa1d526c --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorStateManager.java @@ -0,0 +1,311 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import reactor.core.publisher.Mono; + +/** + * Manages state changes of a given Actor instance. + * All changes are cached in-memory until save() is called. + */ +public class ActorStateManager { + + /** + * Provides states using a state store. + */ + private final DaprStateAsyncProvider stateProvider; + + /** + * Name of the Actor's type. + */ + private final String actorTypeName; + + /** + * Actor's identifier. + */ + private final ActorId actorId; + + /** + * Cache of state changes in this Actor's instance. + */ + private final Map stateChangeTracker; + + /** + * Instantiates a new state manager for the given Actor's instance. + * + * @param stateProvider State store provider. + * @param actorTypeName Name of Actor's type. + * @param actorId Actor's identifier. + */ + ActorStateManager(DaprStateAsyncProvider stateProvider, String actorTypeName, ActorId actorId) { + this.stateProvider = stateProvider; + this.actorTypeName = actorTypeName; + this.actorId = actorId; + this.stateChangeTracker = new HashMap<>(); + } + + /** + * Adds a given key/value to the Actor's state store's cache. + * + * @param stateName Name of the state being added. + * @param value Value to be added. + * @param Type of the object being added. + * @return Asynchronous void operation. + */ + public Mono add(String stateName, T value) { + return Mono.fromSupplier(() -> { + if (stateName == null) { + throw new IllegalArgumentException("State's name cannot be null."); + } + + return null; + }).then(this.stateProvider.contains(this.actorTypeName, this.actorId, stateName) + .map(exists -> { + if (this.stateChangeTracker.containsKey(stateName)) { + StateChangeMetadata metadata = this.stateChangeTracker.get(stateName); + + if (metadata.kind == ActorStateChangeKind.REMOVE) { + this.stateChangeTracker.put(stateName, new StateChangeMetadata(ActorStateChangeKind.UPDATE, value)); + return true; + } + + throw new IllegalStateException("Duplicate cached state: " + stateName); + } + + if (exists) { + throw new IllegalStateException("Duplicate state: " + stateName); + } + + this.stateChangeTracker.put(stateName, new StateChangeMetadata(ActorStateChangeKind.ADD, value)); + return true; + })) + .then(); + } + + /** + * Fetches the most recent value for the given state, including cached value. + * + * @param stateName Name of the state. + * @param clazz Class type for the value being fetched. + * @param Type being fetched. + * @return Asynchronous response with fetched object. + */ + public Mono get(String stateName, Class clazz) { + return Mono.fromSupplier(() -> { + if (stateName == null) { + throw new IllegalArgumentException("State's name cannot be null."); + } + + if (this.stateChangeTracker.containsKey(stateName)) { + StateChangeMetadata metadata = this.stateChangeTracker.get(stateName); + + if (metadata.kind == ActorStateChangeKind.REMOVE) { + throw new NoSuchElementException("State is marked for removal: " + stateName); + } + + return (T) metadata.value; + } + + return (T) null; + }).switchIfEmpty( + this.stateProvider.load(this.actorTypeName, this.actorId, stateName, clazz) + .switchIfEmpty(Mono.error(new NoSuchElementException("State not found: " + stateName))) + .map(v -> { + this.stateChangeTracker.put(stateName, new StateChangeMetadata(ActorStateChangeKind.NONE, v)); + return (T) v; + })); + } + + /** + * Updates a given key/value pair in the state store's cache. + * + * @param stateName Name of the state being updated. + * @param value Value to be set for given state. + * @param Type of the value being set. + * @return Asynchronous void result. + */ + public Mono set(String stateName, T value) { + return Mono.fromSupplier(() -> { + if (stateName == null) { + throw new IllegalArgumentException("State's name cannot be null."); + } + + if (this.stateChangeTracker.containsKey(stateName)) { + StateChangeMetadata metadata = this.stateChangeTracker.get(stateName); + + ActorStateChangeKind kind = metadata.kind; + if ((kind == ActorStateChangeKind.NONE) || (kind == ActorStateChangeKind.REMOVE)) { + kind = ActorStateChangeKind.UPDATE; + } + + this.stateChangeTracker.put(stateName, new StateChangeMetadata(kind, value)); + return true; + } + + return false; + }).filter(x -> x) + .switchIfEmpty(this.stateProvider.contains(this.actorTypeName, this.actorId, stateName) + .map(exists -> { + this.stateChangeTracker.put(stateName, + new StateChangeMetadata(exists ? ActorStateChangeKind.UPDATE : ActorStateChangeKind.ADD, value)); + return exists; + })) + .then(); + } + + /** + * Removes a given state from state store's cache. + * + * @param stateName State being stored. + * @return Asynchronous void result. + */ + public Mono remove(String stateName) { + return Mono.fromSupplier(() -> { + if (stateName == null) { + throw new IllegalArgumentException("State's name cannot be null."); + } + + if (this.stateChangeTracker.containsKey(stateName)) { + StateChangeMetadata metadata = this.stateChangeTracker.get(stateName); + + if (metadata.kind == ActorStateChangeKind.REMOVE) { + return true; + } + + if (metadata.kind == ActorStateChangeKind.ADD) { + this.stateChangeTracker.remove(stateName); + return true; + } + + this.stateChangeTracker.put(stateName, new StateChangeMetadata(ActorStateChangeKind.REMOVE, null)); + return true; + } + + return false; + }) + .filter(x -> x) + .switchIfEmpty(this.stateProvider.contains(this.actorTypeName, this.actorId, stateName)) + .filter(exists -> exists) + .map(exists -> { + this.stateChangeTracker.put(stateName, new StateChangeMetadata(ActorStateChangeKind.REMOVE, null)); + return exists; + }) + .then(); + } + + /** + * Checks if a given state exists in state store or cache. + * + * @param stateName State being checked. + * @return Asynchronous boolean result indicating whether state is present. + */ + public Mono contains(String stateName) { + return Mono.fromSupplier(() -> { + if (stateName == null) { + throw new IllegalArgumentException("State's name cannot be null."); + } + + if (this.stateChangeTracker.containsKey(stateName)) { + StateChangeMetadata metadata = this.stateChangeTracker.get(stateName); + + if (metadata.kind == ActorStateChangeKind.REMOVE) { + return Boolean.FALSE; + } + + return Boolean.TRUE; + } + + return null; + } + + ).switchIfEmpty(this.stateProvider.contains(this.actorTypeName, this.actorId, stateName)); + } + + /** + * Saves all changes to state store. + * + * @return Asynchronous void result. + */ + public Mono save() { + return Mono.fromSupplier(() -> { + if (this.stateChangeTracker.isEmpty()) { + return null; + } + + List changes = new ArrayList<>(); + List removed = new ArrayList<>(); + for (Map.Entry tuple : this.stateChangeTracker.entrySet()) { + if (tuple.getValue().kind == ActorStateChangeKind.NONE) { + continue; + } + + if (tuple.getValue().kind == ActorStateChangeKind.REMOVE) { + removed.add(tuple.getKey()); + } + + changes.add(new ActorStateChange(tuple.getKey(), tuple.getValue().value, tuple.getValue().kind)); + } + + return changes.toArray(new ActorStateChange[0]); + }).flatMap(changes -> this.stateProvider.apply(this.actorTypeName, this.actorId, changes)) + .then(Mono.fromRunnable(() -> this.flush())); + } + + /** + * Clears all changes not yet saved to state store. + */ + public void clear() { + this.stateChangeTracker.clear(); + } + + /** + * Commits the current cached values after successful save. + */ + private void flush() { + for (Map.Entry tuple : this.stateChangeTracker.entrySet()) { + String stateName = tuple.getKey(); + if (tuple.getValue().kind == ActorStateChangeKind.REMOVE) { + this.stateChangeTracker.remove(stateName); + } else { + StateChangeMetadata metadata = new StateChangeMetadata(ActorStateChangeKind.NONE, tuple.getValue().value); + this.stateChangeTracker.put(stateName, metadata); + } + } + } + + /** + * Internal class to represent value and change kind. + */ + private static final class StateChangeMetadata { + + /** + * Kind of change cached. + */ + private final ActorStateChangeKind kind; + + /** + * Value cached. + */ + private final Object value; + + /** + * Creates a new instance of the metadata on state change. + * + * @param kind Kind of change. + * @param value Value to be set. + */ + private StateChangeMetadata(ActorStateChangeKind kind, Object value) { + this.kind = kind; + this.value = value; + } + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTimer.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTimer.java new file mode 100644 index 000000000..1658ac281 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTimer.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.time.Duration; + +/** + * Represents the timer set on an Actor, to be called once after due time and then every period. + * + * @param State type. + */ +final class ActorTimer { + + /** + * Actor that owns this timer. + */ + private final AbstractActor owner; + + /** + * Name of this timer. + */ + private String name; + + /** + * Name of the method to be called for this timer. + */ + private String callback; + + /** + * State to be sent in the timer. + */ + private T state; + + /** + * Due time for the timer's first trigger. + */ + private Duration dueTime; + + /** + * Period at which the timer will be triggered. + */ + private Duration period; + + /** + * Instantiates a new Actor Timer. + * + * @param owner The Actor that owns this timer. The timer callback will be fired for this Actor. + * @param timerName The name of the timer. + * @param callback The name of the method to be called for this timer. + * @param state information to be used by the callback method + * @param dueTime the time when timer is first due. + * @param period the periodic time when timer will be invoked. + */ + ActorTimer(AbstractActor owner, + String timerName, + String callback, + T state, + Duration dueTime, + Duration period) { + this.owner = owner; + this.name = timerName; + this.callback = callback; + this.state = state; + this.dueTime = dueTime; + this.period = period; + } + + /** + * Gets the name of the Timer. The name is unique per actor. + * + * @return The name of the timer. + */ + public String getName() { + return this.name; + } + + /** + * Gets the name of the method for this Timer. + * + * @return The name of the method for this timer. + */ + public String getCallback() { + return this.callback; + } + + /** + * Gets the time when timer is first due. + * + * @return Time as Duration when timer is first due. + */ + public Duration getDueTime() { + return this.dueTime; + } + + /** + * Gets the periodic time when timer will be invoked. + * + * @return Periodic time as Duration when timer will be invoked. + */ + public Duration getPeriod() { + return this.period; + } + + /** + * Gets state containing information to be used by the callback method, or null. + * + * @return State containing information to be used by the callback method, or null. + */ + public T getState() { + return this.state; + } + +} \ No newline at end of file diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorType.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorType.java new file mode 100644 index 000000000..9cc8f4a40 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorType.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to define Actor class. + */ +@Documented +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +public @interface ActorType { + + /** + * Overrides Actor's name. + * + * @return Actor's name. + */ + String name(); + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeInformation.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeInformation.java new file mode 100644 index 000000000..fac3916d8 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeInformation.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +/** + * Contains the information about the class implementing an actor. + */ +final class ActorTypeInformation { + + /** + * Actor type's name. + */ + private final String name; + + /** + * Actor's implementation class. + */ + private final Class implementationClass; + + /** + * Actor's immediate interfaces. + */ + private final Collection> interfaces; + + /** + * Whether Actor type is abstract. + */ + private final boolean abstractClass; + + /** + * Whether Actor type is remindable. + */ + private final boolean remindable; + + /** + * Instantiates a new {@link ActorTypeInformation}. + * + * @param name Actor type's name. + * @param implementationClass Actor's implementation class. + * @param interfaces Actor's immediate interfaces. + * @param abstractClass Whether Actor type is abstract. + * @param remindable Whether Actor type is remindable. + */ + private ActorTypeInformation(String name, + Class implementationClass, + Collection> interfaces, + boolean abstractClass, + boolean remindable) { + this.name = name; + this.implementationClass = implementationClass; + this.interfaces = interfaces; + this.abstractClass = abstractClass; + this.remindable = remindable; + } + + /** + * Returns the name of this ActorType. + * + * @return ActorType's name. + */ + public String getName() { + return this.name; + } + + /** + * Gets the type of the class implementing the actor. + * + * @return The {@link Class} of implementing the actor. + */ + public Class getImplementationClass() { + return this.implementationClass; + } + + /** + * Gets the actor interfaces that are implemented by actor class. + * + * @return Collection of actor interfaces. + */ + public Collection> getInterfaces() { + return Collections.unmodifiableCollection(this.interfaces); + } + + /** + * Gets a value indicating whether the class implementing actor is abstract. + * + * @return true if the class implementing actor is abstract, otherwise false. + */ + public boolean isAbstractClass() { + return this.abstractClass; + } + + /** + * Gets a value indicating whether the actor class implements + * {@link Remindable}. + * + * @return true if the actor class implements {@link Remindable}. + */ + public boolean isRemindable() { + return this.remindable; + } + + /** + * Creates the {@link ActorTypeInformation} from given Class. + * + * @param actorClass The type of class implementing the actor to create + * ActorTypeInformation for. + * @return ActorTypeInformation if successfully created for actorType or null. + */ + public static ActorTypeInformation tryCreate(Class actorClass) { + try { + return create(actorClass); + } catch (IllegalArgumentException e) { + return null; + } + } + + /** + * Creates an {@link #ActorTypeInformation} from actorType. + * + * @param actorClass The class implementing the actor to create + * ActorTypeInformation for. + * @return {@link #ActorTypeInformation} created from actorType. + */ + public static ActorTypeInformation create(Class actorClass) { + if (!ActorTypeUtilities.isActor(actorClass)) { + throw new IllegalArgumentException( + String.format( + "The type '%s' is not an Actor. An actor class must inherit from '%s'.", + actorClass == null ? "" : actorClass.getCanonicalName(), + AbstractActor.class.getCanonicalName())); + } + + // get all actor interfaces + Class[] actorInterfaces = actorClass.getInterfaces(); + + boolean isAbstract = Modifier.isAbstract(actorClass.getModifiers()); + boolean isRemindable = ActorTypeUtilities.isRemindableActor(actorClass); + ActorType actorTypeAnnotation = actorClass.getAnnotation(ActorType.class); + String typeName = actorTypeAnnotation != null ? actorTypeAnnotation.name() : actorClass.getSimpleName(); + + return new ActorTypeInformation(typeName, actorClass, Arrays.asList(actorInterfaces), isAbstract, isRemindable); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeUtilities.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeUtilities.java new file mode 100644 index 000000000..a74090148 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeUtilities.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.util.Arrays; + +/** + * Utility class to extract information on Actor type. + */ +final class ActorTypeUtilities { + + /** + * Gets all interfaces that extend Actor. + * + * @param clazz Actor class. + * @return Array of Actor interfaces. + */ + public static Class[] getActorInterfaces(Class clazz) { + if (clazz == null) { + return new Class[0]; + } + + return Arrays.stream(clazz.getInterfaces()) + .filter(t -> AbstractActor.class.isAssignableFrom(t)) + .filter(t -> getNonActorParentClass(t) == null) + .toArray(Class[]::new); + } + + /** + * Determines if given class is an Actor interface. + * + * @param clazz Actor interface candidate. + * @return Whether this is an Actor interface. + */ + public static boolean isActorInterface(Class clazz) { + return (clazz != null) && clazz.isInterface() && (getNonActorParentClass(clazz) == null); + } + + /** + * Determines whether this is an Actor class. + * + * @param clazz Actor class candidate. + * @return Whether this is an Actor class. + */ + public static boolean isActor(Class clazz) { + if (clazz == null) { + return false; + } + + return AbstractActor.class.isAssignableFrom(clazz); + } + + /** + * Determines whether this is an remindable Actor. + * + * @param clazz Actor class. + * @return Whether this is an remindable Actor. + */ + public static boolean isRemindableActor(Class clazz) { + return (clazz != null) + && isActor(clazz) + && (Arrays.stream(clazz.getInterfaces()).filter(t -> t.equals(Remindable.class)).count() > 0); + } + + /** + * Returns the parent class if it is not the {@link AbstractActor} parent + * class. + * + * @param clazz Actor class. + * @return Parent class or null if it is {@link AbstractActor}. + */ + public static Class getNonActorParentClass(Class clazz) { + if (clazz == null) { + return null; + } + + Class[] items = Arrays.stream(clazz.getInterfaces()) + .filter(t -> !t.equals(AbstractActor.class)) + .toArray(Class[]::new); + if (items.length == 0) { + return clazz; + } + + for (Class c : items) { + Class nonActorParent = getNonActorParentClass(c); + if (nonActorParent != null) { + return nonActorParent; + } + } + + return null; + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClient.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClient.java new file mode 100644 index 000000000..4e40e3c0f --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprClient.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import reactor.core.publisher.Mono; + +/** + * Generic Client Adapter to be used regardless of the GRPC or the HTTP Client implementation required. + */ +interface DaprClient { + + /** + * Gets a state from Dapr's Actor. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param keyName State name. + * @return Asynchronous result with current state value. + */ + Mono getActorState(String actorType, String actorId, String keyName); + + /** + * Saves state batch to Dapr. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param data State to be saved. + * @return Asynchronous void result. + */ + Mono saveActorStateTransactionally(String actorType, String actorId, byte[] data); + + /** + * Register a reminder. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param reminderName Name of reminder to be registered. + * @param data JSON reminder data as per Dapr's spec. + * @return Asynchronous void result. + */ + Mono registerActorReminder(String actorType, String actorId, String reminderName, byte[] data); + + /** + * Unregisters a reminder. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param reminderName Name of reminder to be unregistered. + * @return Asynchronous void result. + */ + Mono unregisterActorReminder(String actorType, String actorId, String reminderName); + + /** + * Registers a timer. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param timerName Name of timer to be registered. + * @param data JSON reminder data as per Dapr's spec. + * @return Asynchronous void result. + */ + Mono registerActorTimer(String actorType, String actorId, String timerName, byte[] data); + + /** + * Unregisters a timer. + * + * @param actorType Type of actor. + * @param actorId Actor Identifier. + * @param timerName Name of timer to be unregistered. + * @return Asynchronous void result. + */ + Mono unregisterActorTimer(String actorType, String actorId, String timerName); +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprHttpClient.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprHttpClient.java new file mode 100644 index 000000000..245360807 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprHttpClient.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.client.DaprHttp; +import io.dapr.utils.Constants; +import reactor.core.publisher.Mono; + +/** + * A DaprClient over HTTP for Actor's runtime. + */ +class DaprHttpClient implements DaprClient { + + /** + * The HTTP client to be used. + * + * @see DaprHttp + */ + private final DaprHttp client; + + /** + * Internal constructor. + * + * @param client Dapr's http client. + */ + DaprHttpClient(DaprHttp client) { + this.client = client; + } + + /** + * {@inheritDoc} + */ + @Override + public Mono getActorState(String actorType, String actorId, String keyName) { + String url = String.format(Constants.ACTOR_STATE_KEY_RELATIVE_URL_FORMAT, actorType, actorId, keyName); + Mono responseMono = this.client.invokeAPI(DaprHttp.HttpMethods.GET.name(), url, null, "", null); + return responseMono.map(r -> r.getBody()); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveActorStateTransactionally(String actorType, String actorId, byte[] data) { + String url = String.format(Constants.ACTOR_STATE_RELATIVE_URL_FORMAT, actorType, actorId); + return this.client.invokeAPI(DaprHttp.HttpMethods.PUT.name(), url, null, data, null).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono registerActorReminder(String actorType, String actorId, String reminderName, byte[] data) { + String url = String.format(Constants.ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName); + return this.client.invokeAPI(DaprHttp.HttpMethods.PUT.name(), url, null, data, null).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono unregisterActorReminder(String actorType, String actorId, String reminderName) { + String url = String.format(Constants.ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName); + return this.client.invokeAPI(DaprHttp.HttpMethods.DELETE.name(), url, null, null).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono registerActorTimer(String actorType, String actorId, String timerName, byte[] data) { + String url = String.format(Constants.ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName); + return this.client.invokeAPI(DaprHttp.HttpMethods.PUT.name(), url, null, data, null).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono unregisterActorTimer(String actorType, String actorId, String timerName) { + String url = String.format(Constants.ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName); + return this.client.invokeAPI(DaprHttp.HttpMethods.DELETE.name(), url, null, null).then(); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprStateAsyncProvider.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprStateAsyncProvider.java new file mode 100644 index 000000000..54994b281 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/DaprStateAsyncProvider.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import io.dapr.actors.ActorId; +import io.dapr.serializer.DaprObjectSerializer; +import io.dapr.serializer.StringContentType; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import reactor.core.publisher.Mono; + +/** + * State Provider to interact with Dapr runtime to handle state. + */ +class DaprStateAsyncProvider { + + /** + * Shared Json Factory as per Jackson's documentation, used only for this class. + */ + private static final JsonFactory JSON_FACTORY = new JsonFactory(); + + /** + * Dapr's client for Actor runtime. + */ + private final DaprClient daprClient; + + /** + * Serializer for state objects. + */ + private final DaprObjectSerializer stateSerializer; + + /** + * Flag determining if serializer's input and output contains a valid String. + */ + private final boolean isStateString; + + /** + * Instantiates a new Actor's state provider. + * + * @param daprClient Dapr client for Actor runtime. + * @param stateSerializer Serializer for state objects. + */ + DaprStateAsyncProvider(DaprClient daprClient, DaprObjectSerializer stateSerializer) { + this.daprClient = daprClient; + this.stateSerializer = stateSerializer; + this.isStateString = stateSerializer.getClass().getAnnotation(StringContentType.class) != null; + } + + Mono load(String actorType, ActorId actorId, String stateName, Class clazz) { + Mono result = this.daprClient.getActorState(actorType, actorId.toString(), stateName); + + return result.flatMap(s -> { + try { + T response = this.stateSerializer.deserialize(s, clazz); + if (response == null) { + return Mono.empty(); + } + + return Mono.just(response); + } catch (IOException e) { + return Mono.error(new RuntimeException(e)); + } + }); + } + + Mono contains(String actorType, ActorId actorId, String stateName) { + Mono result = this.daprClient.getActorState(actorType, actorId.toString(), stateName); + return result.map(s -> true).defaultIfEmpty(false); + } + + /** + * Saves state changes transactionally. + * [ + * { + * "operation": "upsert", + * "request": { + * "key": "key1", + * "value": "myData" + * } + * }, + * { + * "operation": "delete", + * "request": { + * "key": "key2" + * } + * } + * ] + * + * @param actorType Name of the actor being changed. + * @param actorId Identifier of the actor being changed. + * @param stateChanges Collection of changes to be performed transactionally. + * @return Void. + */ + Mono apply(String actorType, ActorId actorId, ActorStateChange... stateChanges) { + if ((stateChanges == null) || stateChanges.length == 0) { + return Mono.empty(); + } + + int count = 0; + // Constructing the JSON via a stream API to avoid creating transient objects to be instantiated. + byte[] payload = null; + try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(writer); + // Start array + generator.writeStartArray(); + + for (ActorStateChange stateChange : stateChanges) { + if ((stateChange == null) || (stateChange.getChangeKind() == null)) { + continue; + } + + String operationName = stateChange.getChangeKind().getDaprStateChangeOperation(); + if ((operationName == null) || (operationName.length() == 0)) { + continue; + } + + count++; + + // Start operation object. + generator.writeStartObject(); + generator.writeStringField("operation", operationName); + + // Start request object. + generator.writeObjectFieldStart("request"); + generator.writeStringField("key", stateChange.getStateName()); + if ((stateChange.getChangeKind() == ActorStateChangeKind.UPDATE) + || (stateChange.getChangeKind() == ActorStateChangeKind.ADD)) { + byte[] data = this.stateSerializer.serialize(stateChange.getValue()); + if (data != null) { + if (this.isStateString) { + generator.writeStringField("value", new String(data)); + } else { + generator.writeBinaryField("value", data); + } + } + } + // End request object. + generator.writeEndObject(); + + // End operation object. + generator.writeEndObject(); + } + + // End array + generator.writeEndArray(); + + generator.close(); + writer.flush(); + payload = writer.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + return Mono.error(e); + } + + if (count == 0) { + // No-op since there is no operation to be performed. + Mono.empty(); + } + + return this.daprClient.saveActorStateTransactionally(actorType, actorId.toString(), payload); + } +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/DefaultActorFactory.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/DefaultActorFactory.java new file mode 100644 index 000000000..460d78efc --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/DefaultActorFactory.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.ActorTrace; +import java.lang.reflect.Constructor; + +/** + * Instantiates actors by calling their constructor with {@link ActorRuntimeContext} and {@link ActorId}. + * + * @param Actor Type to be created. + */ +class DefaultActorFactory implements ActorFactory { + + /** + * Tracing errors, warnings and info logs. + */ + private static final ActorTrace ACTOR_TRACE = new ActorTrace(); + + /** + * {@inheritDoc} + */ + @Override + public T createActor(ActorRuntimeContext actorRuntimeContext, ActorId actorId) { + try { + if (actorRuntimeContext == null) { + return null; + } + + Constructor constructor = actorRuntimeContext + .getActorTypeInformation() + .getImplementationClass() + .getConstructor(ActorRuntimeContext.class, ActorId.class); + return constructor.newInstance(actorRuntimeContext, actorId); + } catch (Exception e) { + ACTOR_TRACE.writeError( + actorRuntimeContext.getActorTypeInformation().getName(), + actorId.toString(), + "Failed to create actor instance."); + } + return null; + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ObjectSerializer.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ObjectSerializer.java new file mode 100644 index 000000000..9b5fceb7a --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ObjectSerializer.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonNode; +import io.dapr.utils.DurationUtils; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.time.Duration; + +/** + * Serializes and deserializes internal objects. + */ +public class ObjectSerializer extends io.dapr.client.ObjectSerializer { + + /** + * Shared Json Factory as per Jackson's documentation. + */ + private static final JsonFactory JSON_FACTORY = new JsonFactory(); + + /** + * {@inheritDoc} + */ + @Override + public byte[] serialize(Object state) throws IOException { + if (state == null) { + return null; + } + + if (state.getClass() == ActorTimer.class) { + // Special serializer for this internal classes. + return serialize((ActorTimer) state); + } + + if (state.getClass() == ActorReminderParams.class) { + // Special serializer for this internal classes. + return serialize((ActorReminderParams) state); + } + + if (state.getClass() == ActorRuntimeConfig.class) { + // Special serializer for this internal classes. + return serialize((ActorRuntimeConfig) state); + } + + // Is not an special case. + return super.serialize(state); + } + + + /** + * Faster serialization for params of Actor's timer. + * + * @param timer Timer's to be serialized. + * @return JSON String. + * @throws IOException If cannot generate JSON. + */ + private byte[] serialize(ActorTimer timer) throws IOException { + if (timer == null) { + return null; + } + + try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(writer); + generator.writeStartObject(); + generator.writeStringField("dueTime", DurationUtils.ConvertDurationToDaprFormat(timer.getDueTime())); + generator.writeStringField("period", DurationUtils.ConvertDurationToDaprFormat(timer.getPeriod())); + generator.writeStringField("callback", timer.getCallback()); + if (timer.getState() != null) { + generator.writeBinaryField("data", this.serialize(timer.getState())); + } + generator.writeEndObject(); + generator.close(); + writer.flush(); + return writer.toByteArray(); + } + } + + /** + * Faster serialization for Actor's reminder. + * + * @param reminder Reminder to be serialized. + * @return JSON String. + * @throws IOException If cannot generate JSON. + */ + private byte[] serialize(ActorReminderParams reminder) throws IOException { + try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(writer); + generator.writeStartObject(); + generator.writeStringField("dueTime", DurationUtils.ConvertDurationToDaprFormat(reminder.getDueTime())); + generator.writeStringField("period", DurationUtils.ConvertDurationToDaprFormat(reminder.getPeriod())); + if (reminder.getData() != null) { + generator.writeBinaryField("data", reminder.getData()); + } + generator.writeEndObject(); + generator.close(); + writer.flush(); + return writer.toByteArray(); + } + } + + /** + * Faster serialization for Actor's runtime configuration. + * + * @param config Configuration for Dapr's actor runtime. + * @return JSON String. + * @throws IOException If cannot generate JSON. + */ + private byte[] serialize(ActorRuntimeConfig config) throws IOException { + try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(writer); + generator.writeStartObject(); + generator.writeArrayFieldStart("entities"); + for (String actorClass : config.getRegisteredActorTypes()) { + generator.writeString(actorClass); + } + generator.writeEndArray(); + // TODO: handle configuration. + generator.writeEndObject(); + generator.close(); + writer.flush(); + return writer.toByteArray(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public T deserialize(byte[] content, Class clazz) throws IOException { + if (clazz == ActorReminderParams.class) { + // Special serializer for this internal classes. + return (T) deserializeActorReminder(content); + } + + // Is not one of the special cases. + return super.deserialize(content, clazz); + } + + /** + * Extracts the response data from a JSON Payload where data is in "data" attribute. + * + * @param payload JSON payload containing "data". + * @return byte[] instance, null. + * @throws IOException In case it cannot generate String. + */ + public byte[] unwrapData(final byte[] payload) throws IOException { + if (payload == null) { + return null; + } + + JsonNode root = OBJECT_MAPPER.readTree(payload); + if (root == null) { + return null; + } + + JsonNode dataNode = root.get("data"); + if (dataNode == null) { + return null; + } + + return dataNode.binaryValue(); + } + + /** + * Wraps data in the "data" attribute in a JSON object. + * + * @param data bytes to be wrapped into the "data" attribute in a JSON object. + * @return String to be sent to Dapr's API. + * @throws RuntimeException In case it cannot generate String. + */ + public byte[] wrapData(final byte[] data) throws IOException { + try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(output); + generator.writeStartObject(); + if (data != null) { + generator.writeBinaryField("data", data); + } + generator.writeEndObject(); + generator.close(); + output.flush(); + return output.toByteArray(); + } + } + + /** + * Deserializes an Actor Reminder. + * + * @param value Content to be deserialized. + * @return Actor Reminder. + * @throws IOException If cannot parse JSON. + */ + private ActorReminderParams deserializeActorReminder(byte[] value) throws IOException { + if (value == null) { + return null; + } + + JsonNode node = OBJECT_MAPPER.readTree(value); + Duration dueTime = DurationUtils.ConvertDurationFromDaprFormat(node.get("dueTime").asText()); + Duration period = DurationUtils.ConvertDurationFromDaprFormat(node.get("period").asText()); + byte[] data = node.get("data") != null ? node.get("data").binaryValue() : null; + + return new ActorReminderParams(data, dueTime, period); + } + +} diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/Remindable.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/Remindable.java new file mode 100644 index 000000000..c66ff1478 --- /dev/null +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/Remindable.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import java.time.Duration; +import reactor.core.publisher.Mono; + +/** + * Interface that actors must implement to consume reminders registered using RegisterReminderAsync. + */ +public interface Remindable { + + /** + * Gets the class for state object. + * + * @return Class for state object. + */ + Class getStateType(); + + /** + * The reminder call back invoked when an actor reminder is triggered. + * The state of this actor is saved by the actor runtime upon completion of the task returned by this method. + * If an error occurs while saving the state, then all state cached by this actor's {@link ActorStateManager} will + * be discarded and reloaded from previously saved state when the next actor method or reminder invocation occurs. + * + * @param reminderName The name of reminder provided during registration. + * @param state The user state provided during registration. + * @param dueTime The invocation due time provided during registration. + * @param period The invocation period provided during registration. + * @return A task that represents the asynchronous operation performed by this callback. + */ + Mono receiveReminder(String reminderName, T state, Duration dueTime, Duration period); +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/ActorIdTest.java b/sdk-actors/src/test/java/io/dapr/actors/ActorIdTest.java new file mode 100644 index 000000000..fe512ae84 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/ActorIdTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.actors; + +import java.util.*; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Unit tests for ActorId. + */ +public class ActorIdTest { + + @Test(expected = IllegalArgumentException.class) + public void initializeNewActorIdObjectWithNullId() { + ActorId actorId = new ActorId(null); + } + + @Test + public void getId() { + String id = "123"; + ActorId actorId = new ActorId(id); + Assert.assertEquals(id, actorId.toString()); + } + + @Test + public void verifyToString() { + String id = "123"; + ActorId actorId = new ActorId(id); + Assert.assertEquals(id, actorId.toString()); + } + + @Test + public void verifyEqualsByObject() { + List values = createEqualsTestValues(); + for (Wrapper w : values) { + Assert.assertEquals(w.expectedResult, w.item1.equals(w.item2)); + } + } + + @Test + public void verifyEqualsByActorId() { + List values = createEqualsTestValues(); + for (Wrapper w : values) { + ActorId a1 = (ActorId) w.item1; + Object a2 = w.item2; + Assert.assertEquals(w.expectedResult, a1.equals(a2)); + } + } + + @Test + public void verifyCompareTo() { + List values = createComparesToTestValues(); + for (Wrapper w : values) { + ActorId a1 = (ActorId) w.item1; + ActorId a2 = (ActorId) w.item2; + Assert.assertEquals(w.expectedResult, a1.compareTo(a2)); + } + } + + private List createEqualsTestValues() { + List list = new ArrayList(); + list.add(new Wrapper(new ActorId("1"), null, false)); + list.add(new Wrapper(new ActorId("1"), new ActorId("1"), true)); + list.add(new Wrapper(new ActorId("1"), new Object(), false)); + list.add(new Wrapper(new ActorId("1"), new ActorId("2"), false)); + + return list; + } + + private List createComparesToTestValues() { + List list = new ArrayList(); + list.add(new Wrapper(new ActorId("1"), null, 1)); + list.add(new Wrapper(new ActorId("1"), new ActorId("1"), 0)); + list.add(new Wrapper(new ActorId("1"), new ActorId("2"), -1)); + list.add(new Wrapper(new ActorId("2"), new ActorId("1"), 1)); + + return list; + } + + class Wrapper { + + public Object item1; + public Object item2; + public T expectedResult; + + public Wrapper(Object i, Object j, T e) { + this.item1 = i; + this.item2 = j; + this.expectedResult = e; + } + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyBuilderTest.java b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyBuilderTest.java new file mode 100644 index 000000000..c04d68298 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyBuilderTest.java @@ -0,0 +1,48 @@ +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; + +public class ActorProxyBuilderTest { + + @Test(expected = IllegalArgumentException.class) + public void buildWithNullActorId() { + new ActorProxyBuilder("test", new DefaultObjectSerializer()) + .build(null); + + } + + @Test(expected = IllegalArgumentException.class) + public void buildWithEmptyActorType() { + new ActorProxyBuilder("", new DefaultObjectSerializer()) + .build(new ActorId("100")); + + } + + @Test(expected = IllegalArgumentException.class) + public void buildWithNullActorType() { + new ActorProxyBuilder(null, new DefaultObjectSerializer()) + .build(new ActorId("100")); + + } + + @Test(expected = IllegalArgumentException.class) + public void buildWithNullSerializer() { + new ActorProxyBuilder("MyActor", null) + .build(new ActorId("100")); + + } + + @Test() + public void build() { + ActorProxyBuilder builder = new ActorProxyBuilder("test", new DefaultObjectSerializer()); + ActorProxy actorProxy = builder.build(new ActorId("100")); + + Assert.assertNotNull(actorProxy); + Assert.assertEquals("test", actorProxy.getActorType()); + Assert.assertEquals("100", actorProxy.getActorId().toString()); + + } +} \ No newline at end of file diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyForTestsImpl.java b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyForTestsImpl.java new file mode 100644 index 000000000..faa237136 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyForTestsImpl.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DaprObjectSerializer; + +public class ActorProxyForTestsImpl extends ActorProxyImpl { + + public ActorProxyForTestsImpl(String actorType, ActorId actorId, DaprObjectSerializer serializer, DaprClient daprClient) { + super(actorType, actorId, serializer, daprClient); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyImplTest.java b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyImplTest.java new file mode 100644 index 000000000..ac5cf3674 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/client/ActorProxyImplTest.java @@ -0,0 +1,293 @@ +package io.dapr.actors.client; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.serializer.DaprObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import reactor.core.publisher.Mono; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ActorProxyImplTest { + + @Test() + public void constructorActorProxyTest() { + final DaprClient daprClient = mock(DaprClient.class); + final DaprObjectSerializer serializer = mock(DaprObjectSerializer.class); + final ActorProxyImpl actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + serializer, + daprClient); + Assert.assertEquals(actorProxy.getActorId().toString(), "100"); + Assert.assertEquals(actorProxy.getActorType(), "myActorType"); + } + + @Test() + public void invokeActorMethodWithoutDataWithReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + Mono daprResponse = + Mono.just("{\n\t\"data\": \"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"\n}" + .getBytes()); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNull())) + .thenReturn(daprResponse); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData", MyData.class); + MyData myData = result.block(); + Assert.assertNotNull(myData); + Assert.assertEquals("valueA", myData.getPropertyA()); + Assert.assertEquals("valueB", myData.getPropertyB());// propertyB=null + } + + @Test() + public void invokeActorMethodWithoutDataWithEmptyReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNull())) + .thenReturn(Mono.just("".getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData", MyData.class); + MyData myData = result.block(); + Assert.assertNull(myData); + } + + @Test(expected = RuntimeException.class) + public void invokeActorMethodWithIncorrectReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNull())) + .thenReturn(Mono.just("{test}".getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData", MyData.class); + + result.doOnSuccess(x -> + Assert.fail("Not exception was throw")) + .doOnError(Throwable::printStackTrace + ).block(); + + + } + + @Test() + public void invokeActorMethodSavingDataWithReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn( + Mono.just("{\n\t\"data\": \"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"\n}" + .getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + + Mono result = actorProxy.invokeActorMethod("getData", saveData, MyData.class); + MyData myData = result.block(); + Assert.assertNotNull(myData); + Assert.assertEquals("valueA", myData.getPropertyA()); + Assert.assertEquals("valueB", myData.getPropertyB());//propertyB=null + + } + + @Test(expected = RuntimeException.class) + public void invokeActorMethodSavingDataWithIncorrectReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn(Mono.just("{test}".getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + + Mono result = actorProxy.invokeActorMethod("getData", saveData, MyData.class); + result.doOnSuccess(x -> + Assert.fail("Not exception was throw")) + .doOnError(Throwable::printStackTrace + ).block(); + + } + + @Test() + public void invokeActorMethodSavingDataWithEmptyReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn(Mono.just("".getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + + Mono result = actorProxy.invokeActorMethod("getData", saveData, MyData.class); + MyData myData = result.block(); + Assert.assertNull(myData); + } + + + @Test(expected = RuntimeException.class) + public void invokeActorMethodSavingDataWithIncorrectInputType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn(Mono.just("{test}".getBytes())); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + saveData.setMyData(saveData); + + Mono result = actorProxy.invokeActorMethod("getData", saveData, MyData.class); + result.doOnSuccess(x -> + Assert.fail("Not exception was throw")) + .doOnError(Throwable::printStackTrace + ).block(); + + } + + @Test() + public void invokeActorMethodWithDataWithVoidReturnType() { + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn(Mono.empty()); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData", saveData); + Void emptyResponse = result.block(); + Assert.assertNull(emptyResponse); + } + + + @Test(expected = RuntimeException.class) + public void invokeActorMethodWithDataWithVoidIncorrectInputType() { + MyData saveData = new MyData(); + saveData.setPropertyA("valueA"); + saveData.setPropertyB("valueB"); + saveData.setMyData(saveData); + + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNotNull())) + .thenReturn(Mono.empty()); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData", saveData); + Void emptyResponse = result.doOnError(Throwable::printStackTrace).block(); + Assert.assertNull(emptyResponse); + } + + @Test() + public void invokeActorMethodWithoutDataWithVoidReturnType() { + final DaprClient daprClient = mock(DaprClient.class); + when(daprClient.invokeActorMethod(anyString(), anyString(), anyString(), Mockito.isNull())) + .thenReturn(Mono.empty()); + + final ActorProxy actorProxy = new ActorProxyImpl( + "myActorType", + new ActorId("100"), + new DefaultObjectSerializer(), + daprClient); + + Mono result = actorProxy.invokeActorMethod("getData"); + Void emptyResponse = result.block(); + Assert.assertNull(emptyResponse); + } + + static class MyData { + + /// Gets or sets the value for PropertyA. + private String propertyA; + + /// Gets or sets the value for PropertyB. + private String propertyB; + + private MyData myData; + + + public String getPropertyB() { + return propertyB; + } + + public void setPropertyB(String propertyB) { + this.propertyB = propertyB; + } + + public String getPropertyA() { + return propertyA; + } + + public void setPropertyA(String propertyA) { + this.propertyA = propertyA; + } + + @Override + public String toString() { + return "MyData{" + + "propertyA='" + propertyA + '\'' + + ", propertyB='" + propertyB + '\'' + + '}'; + } + + public MyData getMyData() { + return myData; + } + + public void setMyData(MyData myData) { + this.myData = myData; + } + } + +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/DaprClientStub.java b/sdk-actors/src/test/java/io/dapr/actors/client/DaprClientStub.java new file mode 100644 index 000000000..374b61a31 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/client/DaprClientStub.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.client; + +import reactor.core.publisher.Mono; + +public class DaprClientStub implements DaprClient { + + @Override + public Mono invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload) { + return Mono.just(new byte[0]); + } + +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/client/DaprHttpClientTest.java b/sdk-actors/src/test/java/io/dapr/actors/client/DaprHttpClientTest.java new file mode 100644 index 000000000..553b15d3e --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/client/DaprHttpClientTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.actors.client; + +import io.dapr.client.DaprHttp; +import io.dapr.client.DaprHttpProxy; +import okhttp3.OkHttpClient; +import okhttp3.mock.Behavior; +import okhttp3.mock.MockInterceptor; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +public class DaprHttpClientTest { + + private DaprHttpClient DaprHttpClient; + + private OkHttpClient okHttpClient; + + private MockInterceptor mockInterceptor; + + private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; + + @Before + public void setUp() { + mockInterceptor = new MockInterceptor(Behavior.UNORDERED); + okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build(); + } + + @Test + public void invokeActorMethod() { + DaprHttp daprHttpMock = mock(DaprHttp.class); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/actors/DemoActor/1/method/Payment") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = + DaprHttpClient.invokeActorMethod("DemoActor", "1", "Payment", "".getBytes()); + assertEquals(new String(mono.block()), EXPECTED_RESULT); + } + +} \ No newline at end of file diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/BaseIT.java b/sdk-actors/src/test/java/io/dapr/actors/it/BaseIT.java new file mode 100644 index 000000000..5ece13bc0 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/BaseIT.java @@ -0,0 +1,64 @@ +package io.dapr.actors.it; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.contrib.java.lang.system.EnvironmentVariables; +import java.util.Optional; + +public class BaseIT { + + protected static DaprIntegrationTestingRunner daprIntegrationTestingRunner; + + public static DaprIntegrationTestingRunner createDaprIntegrationTestingRunner(String successMessage, Class serviceClass, Boolean useAppPort, Boolean useGrpcPort, Boolean useHttpPort, int sleepTime, boolean isClient) { + return new DaprIntegrationTestingRunner(successMessage, serviceClass, useAppPort, useGrpcPort, useHttpPort, sleepTime, isClient); + } + + @AfterClass + public static void cleanUp() { + Optional.ofNullable(daprIntegrationTestingRunner).ifPresent(daprRunner -> daprRunner.destroyDapr()); + } + + public static class MyData { + + /// Gets or sets the value for PropertyA. + private String propertyA; + + /// Gets or sets the value for PropertyB. + private String propertyB; + + private MyData myData; + + public String getPropertyB() { + return propertyB; + } + + public void setPropertyB(String propertyB) { + this.propertyB = propertyB; + } + + public String getPropertyA() { + return propertyA; + } + + public void setPropertyA(String propertyA) { + this.propertyA = propertyA; + } + + @Override + public String toString() { + return "MyData{" + + "propertyA='" + propertyA + '\'' + + ", propertyB='" + propertyB + '\'' + + '}'; + } + + public MyData getMyData() { + return myData; + } + + public void setMyData(MyData myData) { + this.myData = myData; + } + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/DaprIntegrationTestingRunner.java b/sdk-actors/src/test/java/io/dapr/actors/it/DaprIntegrationTestingRunner.java new file mode 100644 index 000000000..63975b3a2 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/DaprIntegrationTestingRunner.java @@ -0,0 +1,168 @@ +package io.dapr.actors.it; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.contrib.java.lang.system.EnvironmentVariables; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class DaprIntegrationTestingRunner { + + private static AtomicInteger appGeneratorId = new AtomicInteger(); + + @Rule + public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); + public DaprIntegrationTestingRunner.DaprFreePorts DAPR_FREEPORTS; + + private Runtime rt = Runtime.getRuntime(); + private Process proc; + + private String successMessage; + private Class serviceClass; + private Boolean useAppPort; + private Boolean useGrpcPort; + private Boolean useHttpPort; + private int sleepTime; + private String appName; + private boolean appRanOK = Boolean.FALSE; + private boolean isClient = false; + + DaprIntegrationTestingRunner(String successMessage, Class serviceClass, Boolean useAppPort, Boolean useGrpcPort, Boolean useHttpPort, int sleepTime, boolean isClient) { + this.successMessage = successMessage; + this.serviceClass = serviceClass; + this.useAppPort = useAppPort; + this.useGrpcPort = useGrpcPort; + this.useHttpPort = useHttpPort; + this.sleepTime = sleepTime; + this.isClient = isClient; + this.generateAppName(); + try { + DAPR_FREEPORTS = new DaprIntegrationTestingRunner.DaprFreePorts().initPorts(); + environmentVariables.set("DAPR_HTTP_PORT", String.valueOf(DAPR_FREEPORTS.getHttpPort())); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public DaprFreePorts initializeDapr() throws Exception { + String daprCommand=this.buildDaprCommand(); + System.out.println(daprCommand); + proc= rt.exec(daprCommand); + + final Thread stuffToDo = new Thread(() -> { + try { + try (InputStream stdin = proc.getInputStream()) { + try(InputStreamReader isr = new InputStreamReader(stdin)) { + try (BufferedReader br = new BufferedReader(isr)){ + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + if (line.contains(successMessage)) { + this.appRanOK = true; + } + } + } + } + + } + } catch (IOException ex) { + Assert.fail(ex.getMessage()); + } + }); + stuffToDo.start(); + Thread.sleep(sleepTime); + return DAPR_FREEPORTS; + } + + private static final String DAPR_RUN = "dapr run --app-id %s "; + + /** + * The args in -Dexec.args are the App name, and if needed the app's port. + * The args are passed as a CSV due to conflict of parsing a space separated list in different OS + */ + private static final String DAPR_COMMAND = " -- mvn exec:java -Dexec.mainClass=%s -Dexec.classpathScope=test -Dexec.args=\"%s,%s\""; + + private String buildDaprCommand(){ + StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.appName)) + .append(this.useAppPort ? "--app-port " + this.DAPR_FREEPORTS.appPort : "") + .append(this.useGrpcPort ? " --grpc-port " + this.DAPR_FREEPORTS.grpcPort : "") + .append(this.useHttpPort ? " --port " + this.DAPR_FREEPORTS.httpPort : "") + .append(String.format(DAPR_COMMAND, this.serviceClass.getCanonicalName(), this.appName, buildPortsParamCommands())); + return stringBuilder.toString(); + } + + private String buildPortsParamCommands() { + StringBuilder ports = new StringBuilder(); + if (this.useAppPort) { + ports.append(this.DAPR_FREEPORTS.appPort); + } + return ports.toString(); + } + + private void generateAppName(){ + this.appName="DAPRapp" + appGeneratorId.incrementAndGet(); + } + + public boolean isAppRanOK() { + return appRanOK; + } + + public String getAppName() { + return appName; + } + + private static Integer findRandomOpenPortOnAllLocalInterfaces() throws Exception { + try ( + ServerSocket socket = new ServerSocket(0) + ) { + return socket.getLocalPort(); + } + } + + public void destroyDapr() { + Optional.ofNullable(rt).ifPresent( runtime -> { + try { + runtime.exec("dapr stop --app-id " + this.appName); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + Optional.ofNullable(proc).ifPresent(process -> process.destroy()); + } + + public static class DaprFreePorts { + private int grpcPort; + private int httpPort; + private int appPort; + + public DaprFreePorts initPorts() throws Exception { + this.appPort = findRandomOpenPortOnAllLocalInterfaces(); + this.grpcPort = findRandomOpenPortOnAllLocalInterfaces(); + this.httpPort = findRandomOpenPortOnAllLocalInterfaces(); + return this; + } + + public int getGrpcPort() { + return grpcPort; + } + + public int getHttpPort() { + return httpPort; + } + + public int getAppPort() { + return appPort; + } + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/actors/ActivationDeactiviationIT.java b/sdk-actors/src/test/java/io/dapr/actors/it/actors/ActivationDeactiviationIT.java new file mode 100644 index 000000000..d5ee58d00 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/actors/ActivationDeactiviationIT.java @@ -0,0 +1,105 @@ +package io.dapr.actors.it.actors; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyBuilder; +import io.dapr.actors.it.BaseIT; +import io.dapr.actors.it.DaprIntegrationTestingRunner; +import io.dapr.actors.it.services.springboot.ActorService; +import io.dapr.actors.it.services.springboot.EmptyService; +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.domain.Verb; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.*; +import org.junit.contrib.java.lang.system.EnvironmentVariables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.*; + +public class ActivationDeactiviationIT extends BaseIT { + + private static Logger logger = LoggerFactory.getLogger(ActivationDeactiviationIT.class); + + private static final AtomicInteger atomicInteger = new AtomicInteger(1); + + private final String BASE_URL = "actors/%s/%s"; + + private final DefaultObjectSerializer serializer = new DefaultObjectSerializer(); + + private DaprIntegrationTestingRunner clientDaprIntegrationTestingRunner; + + @Rule + public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); + + @After + public void cleanUpTestCase() { + Optional.ofNullable(clientDaprIntegrationTestingRunner).ifPresent(daprRunner -> daprRunner.destroyDapr()); + } + + @BeforeClass + public static void init() throws Exception { + daprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "dapr initialized", + ActorService.class, + true, + true, + true, + 30000, + false + ); + daprIntegrationTestingRunner.initializeDapr(); + } + + @Test + public void testThatWhenInvokingMethodActorActivatesItselfAndDeactivesIteselfAfterElepsedTime() throws Exception { + Thread.sleep(20000); + assertTrue("Service App did not started sucessfully", daprIntegrationTestingRunner.isAppRanOK()); + clientDaprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "BUILD SUCCESS", + EmptyService.class, + false, + false, + true, + 20000, + true + ); + clientDaprIntegrationTestingRunner.initializeDapr(); + environmentVariables.set("DAPR_HTTP_PORT", String.valueOf(clientDaprIntegrationTestingRunner.DAPR_FREEPORTS.getHttpPort())); + final AtomicInteger atomicInteger = new AtomicInteger(1); + String actorType = "DemoActorTest"; + DefaultObjectSerializer serializer = new DefaultObjectSerializer(); + logger.debug("Creating proxy builder"); + ActorProxyBuilder proxyBuilder = new ActorProxyBuilder(actorType, serializer); + logger.debug("Creating actorId"); + ActorId actorId1 = new ActorId(Integer.toString(atomicInteger.getAndIncrement())); + logger.debug("Building proxy"); + ActorProxy proxy = proxyBuilder.build(actorId1); + + logger.debug("Invoking Say from Proxy"); + String sayResponse = proxy.invokeActorMethod("say", "message", String.class).block(); + logger.debug("asserting not null response: [" + sayResponse + "]"); + assertNotNull(sayResponse); + + logger.debug("Retrieving active Actors"); + List activeActors = proxy.invokeActorMethod("retrieveActiveActors", null, List.class).block(); + logger.debug("Active actors: [" + activeActors.toString() + "]"); + assertTrue("Expecting actorId:[" + actorId1.toString() + "]", activeActors.contains(actorId1.toString())); + + logger.debug("Waitng for 15 seconds so actor deactives itself"); + Thread.sleep(15000); + + ActorId actorId2 = new ActorId(Integer.toString(atomicInteger.getAndIncrement())); + ActorProxy proxy2 = proxyBuilder.build(actorId2); + List activeActorsSecondtry = proxy2.invokeActorMethod("retrieveActiveActors", null, List.class).block(); + logger.debug("Active actors: [" + activeActorsSecondtry.toString() + "]"); + assertFalse("NOT Expecting actorId:[" + actorId1.toString() + "]", activeActorsSecondtry.contains(actorId1.toString())); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/ActorService.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/ActorService.java new file mode 100644 index 000000000..40e6c0df4 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/ActorService.java @@ -0,0 +1,26 @@ +package io.dapr.actors.it.services.springboot; + +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.runtime.ActorRuntime; +import io.dapr.serializer.DefaultObjectSerializer; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +public class ActorService { + + /** + * Starts the service. + * @param args Expects the port: -p PORT + * @throws Exception If cannot start service. + */ + public static void main(String[] args) throws Exception { + + // If port string is not valid, it will throw an exception. + long port = Long.parseLong(args[0].split(",")[1]); + ActorRuntime.getInstance().registerActor(DemoActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + + DaprApplication.start(port); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprApplication.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprApplication.java new file mode 100644 index 000000000..c987186b8 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprApplication.java @@ -0,0 +1,21 @@ +package io.dapr.actors.it.services.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Dapr's HTTP callback implementation via SpringBoot. + */ +@SpringBootApplication(scanBasePackages = {"io.dapr.actors.it.services.springboot"}) +public class DaprApplication { + + /** + * Starts Dapr's callback in a given port. + * @param port Port to listen to. + */ + public static void start(long port) { + SpringApplication app = new SpringApplication(DaprApplication.class); + app.run(String.format("--server.port=%d", port)); + } + +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprController.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprController.java new file mode 100644 index 000000000..bc6725740 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DaprController.java @@ -0,0 +1,68 @@ +package io.dapr.actors.it.services.springboot; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.actors.runtime.ActorManagerTest; +import io.dapr.actors.runtime.ActorRuntime; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Map; +import java.util.TimeZone; + +/** + * SpringBoot Controller to handle callback APIs for Dapr. + */ +@RestController +public class DaprController { + + @GetMapping("/") + public String index() { + return "Greetings from Dapr!"; + } + + @GetMapping("/dapr/config") + public String daprConfig() throws Exception { + return "{\"actorIdleTimeout\":\"5s\",\"actorScanInterval\":\"2s\",\"drainOngoingCallTimeout\":\"1s\",\"drainBalancedActors\":true,\"entities\":[\"DemoActorTest\"]}"; + } + + @PostMapping(path = "/actors/{type}/{id}") + public Mono activateActor(@PathVariable("type") String type, + @PathVariable("id") String id) throws Exception { + return ActorRuntime.getInstance().activate(type, id); + } + + @DeleteMapping(path = "/actors/{type}/{id}") + public Mono deactivateActor(@PathVariable("type") String type, + @PathVariable("id") String id) throws Exception { + return ActorRuntime.getInstance().deactivate(type, id); + } + + @PutMapping(path = "/actors/{type}/{id}/method/{method}") + public Mono invokeActorMethod(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("method") String method, + @RequestBody(required = false) byte[] body) { + return ActorRuntime.getInstance().invoke(type, id, method, body); + } + + @PutMapping(path = "/actors/{type}/{id}/method/timer/{timer}") + public Mono invokeActorTimer(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("timer") String timer) { + return ActorRuntime.getInstance().invokeTimer(type, id, timer); + } + + @PutMapping(path = "/actors/{type}/{id}/method/remind/{reminder}") + public Mono invokeActorReminder(@PathVariable("type") String type, + @PathVariable("id") String id, + @PathVariable("reminder") String reminder, + @RequestBody(required = false) byte[] body) { + return ActorRuntime.getInstance().invokeReminder(type, id, reminder, body); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActor.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActor.java new file mode 100644 index 000000000..6c960c74d --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActor.java @@ -0,0 +1,9 @@ +package io.dapr.actors.it.services.springboot; + +import java.util.List; + +public interface DemoActor { + String say(String something); + + List retrieveActiveActors(); +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActorImpl.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActorImpl.java new file mode 100644 index 000000000..c5043305c --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/DemoActorImpl.java @@ -0,0 +1,56 @@ +package io.dapr.actors.it.services.springboot; + +import io.dapr.actors.ActorId; +import io.dapr.actors.runtime.AbstractActor; +import io.dapr.actors.runtime.ActorRuntimeContext; +import io.dapr.actors.runtime.ActorType; +import reactor.core.publisher.Mono; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.util.*; + +@ActorType(name = "DemoActorTest") +public class DemoActorImpl extends AbstractActor implements DemoActor { + + public static final List ACTIVE_ACTOR = new ArrayList<>(); + + public DemoActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + } + + /** + * Format to output date and time. + */ + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + + @Override + public String say(String something) { + Calendar utcNow = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + String utcNowAsString = DATE_FORMAT.format(utcNow.getTime()); + + // Handles the request by printing message. + System.out.println("Server say method for actor " + + super.getId() + ": " + + (something == null ? "" : something + " @ " + utcNowAsString)); + + // Now respond with current timestamp. + return utcNowAsString; + } + + @Override + public List retrieveActiveActors() { + return Collections.unmodifiableList(ACTIVE_ACTOR); + } + + @Override + protected Mono onActivate() { + return Mono.fromRunnable(() -> ACTIVE_ACTOR.add(super.getId().toString())).then(super.onActivate()); + } + + @Override + protected Mono onDeactivate() { + return Mono.fromRunnable(() -> ACTIVE_ACTOR.remove(super.getId().toString())).then(super.onDeactivate()); + } +} \ No newline at end of file diff --git a/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/EmptyService.java b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/EmptyService.java new file mode 100644 index 000000000..7fd5ac606 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/it/services/springboot/EmptyService.java @@ -0,0 +1,14 @@ +package io.dapr.actors.it.services.springboot; + +/** + * Use this class in order to run DAPR with any needed services, like states. + * + * To run manually, from repo root: + * 1. mvn clean install + * 2. dapr run --grpc-port 41707 --port 32851 -- mvn exec:java -Dexec.mainClass=io.dapr.it.services.EmptyService -Dexec.classpathScope="test" -Dexec.args="-p 44511 -grpcPort 41707 -httpPort 32851" -pl=sdk + */ +public class EmptyService { + public static void main(String[] args) { + System.out.println("Hello from EmptyService"); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorCustomSerializerTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorCustomSerializerTest.java new file mode 100644 index 000000000..ffdd1c9d9 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorCustomSerializerTest.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyForTestsImpl; +import io.dapr.actors.client.DaprClientStub; +import io.dapr.serializer.DaprObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.Serializable; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ActorCustomSerializerTest { + + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final DaprObjectSerializer CUSTOM_SERIALIZER = new JavaSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + private final ActorRuntimeContext context = createContext(); + + private ActorManager manager = new ActorManager<>(context); + + public interface MyActor { + Mono intInIntOut(int input); + + Mono stringInStringOut(String input); + + Mono classInClassOut(MyData input); + } + + @ActorType(name = "MyActor") + public static class ActorImpl extends AbstractActor implements MyActor { + + //public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + public ActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + } + + @Override + public Mono intInIntOut(int input) { + return Mono.fromSupplier(() -> input + input); + } + + @Override + public Mono stringInStringOut(String input) { + return Mono.fromSupplier(() -> input + input); + } + + @Override + public Mono classInClassOut(MyData input) { + return Mono.fromSupplier(() -> new MyData( + input.getName() + input.getName(), + input.getNum() + input.getNum()) + ); + } + } + + static class MyData implements Serializable { + private String name; + private int num; + + public MyData() { + this.name = ""; + this.num = 0; + } + + public MyData(String name, int num) { + this.name = name; + this.num = num; + } + + public String getName() { + return this.name; + } + + public int getNum() { + return this.num; + } + } + + @Test + public void classInClassOut() { + ActorProxy actorProxy = createActorProxy(); + MyData d = new MyData("hi", 3); + + MyData response = actorProxy.invokeActorMethod("classInClassOut", d, MyData.class).block(); + + Assert.assertEquals("hihi", response.getName()); + Assert.assertEquals(6, response.getNum()); + } + + @Test + public void stringInStringOut() { + ActorProxy actorProxy = createActorProxy(); + String response = actorProxy.invokeActorMethod("stringInStringOut", "oi", String.class).block(); + + Assert.assertEquals("oioi", response); + } + + @Test + public void intInIntOut() { + ActorProxy actorProxy = createActorProxy(); + int response = actorProxy.invokeActorMethod("intInIntOut", 2, int.class).block(); + + Assert.assertEquals(4, response); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private ActorProxy createActorProxy() { + ActorId actorId = newActorId(); + + // Mock daprClient for ActorProxy only, not for runtime. + DaprClientStub daprClient = mock(DaprClientStub.class); + + when(daprClient.invokeActorMethod( + eq(context.getActorTypeInformation().getName()), + eq(actorId.toString()), + any(), + any())) + .thenAnswer(invocationOnMock -> + this.manager.invokeMethod( + new ActorId(invocationOnMock.getArgument(1, String.class)), + invocationOnMock.getArgument(2, String.class), + INTERNAL_SERIALIZER.unwrapData(invocationOnMock.getArgument(3, byte[].class))) + .map(s -> { + try { + return INTERNAL_SERIALIZER.wrapData(s); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + + this.manager.activateActor(actorId).block(); + + return new ActorProxyForTestsImpl( + context.getActorTypeInformation().getName(), + actorId, + CUSTOM_SERIALIZER, + daprClient); + } + + private static ActorRuntimeContext createContext() { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + CUSTOM_SERIALIZER, + new DefaultActorFactory(), + ActorTypeInformation.create(ActorImpl.class), + daprClient, + mock(DaprStateAsyncProvider.class) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java new file mode 100644 index 000000000..9dbc50df1 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java @@ -0,0 +1,217 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.time.Duration; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Unit tests for Actor Manager + */ +public class ActorManagerTest { + + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + interface MyActor { + String say(String something); + + int getCount(); + + void incrementCount(int delta); + } + + public static class NotRemindableActor extends AbstractActor { + public NotRemindableActor(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + } + } + + @ActorType(name = "MyActor") + public static class MyActorImpl extends AbstractActor implements MyActor, Remindable { + + private int timeCount = 0; + + @Override + public String say(String something) { + return executeSayMethod(something); + } + + @Override + public int getCount() { + return this.timeCount; + } + + @Override + public void incrementCount(int delta) { + this.timeCount = timeCount + delta; + } + + public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + super.registerActorTimer( + "count", + "incrementCount", + 2, + Duration.ofSeconds(1), + Duration.ofSeconds(1) + ).block(); + } + + @Override + public Class getStateType() { + return String.class; + } + + @Override + public Mono receiveReminder(String reminderName, String state, Duration dueTime, Duration period) { + return Mono.empty(); + } + } + + private ActorRuntimeContext context = createContext(MyActorImpl.class); + + private ActorManager manager = new ActorManager<>(context); + + @Test(expected = IllegalArgumentException.class) + public void invokeBeforeActivate() throws Exception { + ActorId actorId = newActorId(); + String message = "something"; + this.manager.invokeMethod(actorId, "say", message.getBytes()).block(); + } + + @Test + public void activateThenInvoke() throws Exception { + ActorId actorId = newActorId(); + byte[] message = this.context.getObjectSerializer().serialize("something"); + this.manager.activateActor(actorId).block(); + byte[] response = this.manager.invokeMethod(actorId, "say", message).block(); + Assert.assertEquals(executeSayMethod( + this.context.getObjectSerializer().deserialize(message, String.class)), + this.context.getObjectSerializer().deserialize(response, String.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void activateInvokeDeactivateThenInvoke() throws Exception { + ActorId actorId = newActorId(); + byte[] message = this.context.getObjectSerializer().serialize("something"); + this.manager.activateActor(actorId).block(); + byte[] response = this.manager.invokeMethod(actorId, "say", message).block(); + Assert.assertEquals(executeSayMethod( + this.context.getObjectSerializer().deserialize(message, String.class)), + this.context.getObjectSerializer().deserialize(response, String.class)); + + this.manager.deactivateActor(actorId).block(); + this.manager.invokeMethod(actorId, "say", message).block(); + } + + @Test + public void invokeReminderNotRemindable() throws Exception { + ActorId actorId = newActorId(); + ActorRuntimeContext context = createContext(NotRemindableActor.class); + ActorManager manager = new ActorManager<>(context); + manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block(); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeReminderBeforeActivate() throws Exception { + ActorId actorId = newActorId(); + this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block(); + } + + @Test + public void activateThenInvokeReminder() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block(); + } + + @Test(expected = IllegalArgumentException.class) + public void activateDeactivateThenInvokeReminder() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + this.manager.deactivateActor(actorId).block();; + this.manager.invokeReminder(actorId, "myremind", createReminderParams("hello")).block(); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeTimerBeforeActivate() { + ActorId actorId = newActorId(); + this.manager.invokeTimer(actorId, "count").block(); + } + + @Test(expected = IllegalStateException.class) + public void activateThenInvokeTimerBeforeRegister() { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + this.manager.invokeTimer(actorId, "unknown").block(); + } + + @Test + public void activateThenInvokeTimer() { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + this.manager.invokeTimer(actorId, "count").block(); + byte[] response = this.manager.invokeMethod(actorId, "getCount", null).block(); + Assert.assertEquals("2", new String(response)); + } + + @Test(expected = IllegalArgumentException.class) + public void activateInvokeTimerDeactivateThenInvokeTimer() { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + this.manager.invokeTimer(actorId, "count").block(); + byte[] response = this.manager.invokeMethod(actorId, "getCount", null).block(); + Assert.assertEquals("2", new String(response)); + + this.manager.deactivateActor(actorId).block(); + this.manager.invokeTimer(actorId, "count").block(); + } + + private byte[] createReminderParams(String data) throws IOException { + byte[] serializedData = this.context.getObjectSerializer().serialize(data); + ActorReminderParams params = new ActorReminderParams(serializedData, Duration.ofSeconds(1), Duration.ofSeconds(1)); + return INTERNAL_SERIALIZER.serialize(params); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private static String executeSayMethod(String something) { + return "Said: " + (something == null ? "" : something); + } + + private static ActorRuntimeContext createContext(Class clazz) { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + new DefaultObjectSerializer(), + new DefaultActorFactory(), + ActorTypeInformation.create(clazz), + daprClient, + mock(DaprStateAsyncProvider.class) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorMethodInfoMapTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorMethodInfoMapTest.java new file mode 100644 index 000000000..bcd888de4 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorMethodInfoMapTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.ArrayList; + +/** + * Unit tests for ActorMethodInfoMap. + */ +public class ActorMethodInfoMapTest { + + @Test + public void normalUsage() { + ArrayList> interfaceTypes = new ArrayList<>(); + interfaceTypes.add(TestActor.class); + ActorMethodInfoMap m = new ActorMethodInfoMap(interfaceTypes); + + try { + Method m1 = m.get("getData"); + Assert.assertEquals("getData", m1.getName()); + Class c = m1.getReturnType(); + Assert.assertEquals(c.getClass(), String.class.getClass()); + Parameter[] p = m1.getParameters(); + Assert.assertEquals(p[0].getType().getClass(), String.class.getClass()); + } catch (Exception e) { + Assert.fail("Exception not expected."); + } + } + + @Test(expected = NoSuchMethodException.class) + public void lookUpNonExistingMethod() throws NoSuchMethodException { + ArrayList> interfaceTypes = new ArrayList<>(); + interfaceTypes.add(TestActor.class); + ActorMethodInfoMap m = new ActorMethodInfoMap(interfaceTypes); + + m.get("thisMethodDoesNotExist"); + } + + /** + * Only used for this test. + */ + public interface TestActor { + String getData(String key); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorNoStateTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorNoStateTest.java new file mode 100644 index 000000000..2360b2fa1 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorNoStateTest.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyForTestsImpl; +import io.dapr.actors.client.DaprClientStub; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ActorNoStateTest { + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + private final ActorRuntimeContext context = createContext(); + + private ActorManager manager = new ActorManager<>(context); + + public interface MyActor { + // The test will only call the versions of this in a derived class to the user code base class. + // The user code base class version will throw. + Mono stringInStringOut(String input); + Mono stringInBooleanOut(String input); + Mono stringInVoidOutIntentionallyThrows(String input); + Mono classInClassOut(MyData input); + } + + @ActorType(name = "MyActor") + public static class ActorImpl extends AbstractActor implements MyActor { + private final ActorId id; + private boolean activated; + private boolean methodReturningVoidInvoked; + + //public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + public ActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + this.methodReturningVoidInvoked = false; + } + + @Override + public Mono stringInStringOut(String s) { + return Mono.fromSupplier(() -> { + return s + s; + } + ); + } + + @Override + public Mono stringInBooleanOut(String s) { + return Mono.fromSupplier(() -> { + if (s.equals("true")) { + return true; + } else { + return false; + } + }); + } + + @Override + public Mono stringInVoidOutIntentionallyThrows(String input) { + return Mono.fromRunnable(() -> { + // IllegalMonitorStateException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new IllegalMonitorStateException("IntentionalException"); + }); + } + + @Override + public Mono classInClassOut(MyData input) { + return Mono.fromSupplier(() -> { + return new MyData( + input.getName() + input.getName(), + input.getNum() + input.getNum()); + }); + } + } + + static class MyData { + private String name; + private int num; + + public MyData() { + this.name = ""; + this.num = 0; + } + + public MyData(String name, int num) { + this.name = name; + this.num = num; + } + + public String getName() { + return this.name; + } + + public int getNum() { + return this.num; + } + } + + @Test + public void stringInStringOut() { + ActorProxy proxy = createActorProxy(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + "abcabc", + proxy.invokeActorMethod("stringInStringOut", "abc", String.class).block()); + } + + @Test + public void stringInBooleanOut() { + ActorProxy proxy = createActorProxy(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + false, + proxy.invokeActorMethod("stringInBooleanOut", "hello world", Boolean.class).block()); + + Assert.assertEquals( + true, + proxy.invokeActorMethod("stringInBooleanOut", "true", Boolean.class).block()); + } + + @Test(expected = IllegalMonitorStateException.class) + public void stringInVoidOutIntentionallyThrows() { + ActorProxy actorProxy = createActorProxy(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + actorProxy.invokeActorMethod("stringInVoidOutIntentionallyThrows", "hello world").block(); + } + + @Test + public void classInClassOut() { + ActorProxy actorProxy = createActorProxy(); + MyData d = new MyData("hi", 3); + + // this should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + MyData response = actorProxy.invokeActorMethod("classInClassOut", d, MyData.class).block(); + + Assert.assertEquals( + "hihi", + response.getName()); + Assert.assertEquals( + 6, + response.getNum()); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private ActorProxy createActorProxy() { + ActorId actorId = newActorId(); + + // Mock daprClient for ActorProxy only, not for runtime. + DaprClientStub daprClient = mock(DaprClientStub.class); + + when(daprClient.invokeActorMethod( + eq(context.getActorTypeInformation().getName()), + eq(actorId.toString()), + any(), + any())) + .thenAnswer(invocationOnMock -> + this.manager.invokeMethod( + new ActorId(invocationOnMock.getArgument(1, String.class)), + invocationOnMock.getArgument(2, String.class), + INTERNAL_SERIALIZER.unwrapData(invocationOnMock.getArgument(3, byte[].class))) + .map(s -> { + try { + return INTERNAL_SERIALIZER.wrapData(s); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + + this.manager.activateActor(actorId).block(); + + return new ActorProxyForTestsImpl( + context.getActorTypeInformation().getName(), + actorId, + new DefaultObjectSerializer(), + daprClient); + } + + private static ActorRuntimeContext createContext() { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + new DefaultObjectSerializer(), + new DefaultActorFactory(), + ActorTypeInformation.create(ActorImpl.class), + daprClient, + mock(DaprStateAsyncProvider.class) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorReminderParamsTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorReminderParamsTest.java new file mode 100644 index 000000000..ebdf12407 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorReminderParamsTest.java @@ -0,0 +1,63 @@ +package io.dapr.actors.runtime; + +import org.junit.Assert; +import org.junit.Test; + +import java.time.Duration; + +public class ActorReminderParamsTest { + + private static final ObjectSerializer SERIALIZER = new ObjectSerializer(); + + @Test(expected = IllegalArgumentException.class) + public void outOfRangeDueTime() { + ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusSeconds(-10), Duration.ZERO.plusMinutes(1)); + } + + @Test + public void negativePeriod() { + // this is ok + ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusMinutes(1), Duration.ZERO.plusMillis(-1)); + } + + @Test(expected = IllegalArgumentException.class) + public void outOfRangePeriod() { + ActorReminderParams info = new ActorReminderParams(null, Duration.ZERO.plusMinutes(1), Duration.ZERO.plusMinutes(-10)); + } + + @Test + public void noState() { + ActorReminderParams original = new ActorReminderParams(null, Duration.ZERO.plusMinutes(2), Duration.ZERO.plusMinutes((5))); + ActorReminderParams recreated = null; + try { + byte[] serialized = SERIALIZER.serialize(original); + recreated = SERIALIZER.deserialize(serialized, ActorReminderParams.class); + } + catch(Exception e) { + System.out.println("The error is: " + e); + Assert.fail(); + } + + Assert.assertArrayEquals(original.getData(), recreated.getData()); + Assert.assertEquals(original.getDueTime(), recreated.getDueTime()); + Assert.assertEquals(original.getPeriod(), recreated.getPeriod()); + } + + @Test + public void withState() { + ActorReminderParams original = new ActorReminderParams("maru".getBytes(), Duration.ZERO.plusMinutes(2), Duration.ZERO.plusMinutes((5))); + ActorReminderParams recreated = null; + try { + byte[] serialized = SERIALIZER.serialize(original); + recreated = SERIALIZER.deserialize(serialized, ActorReminderParams.class); + } + catch(Exception e) { + System.out.println("The error is: " + e); + Assert.fail(); + } + + Assert.assertArrayEquals(original.getData(), recreated.getData()); + Assert.assertEquals(original.getDueTime(), recreated.getDueTime()); + Assert.assertEquals(original.getPeriod(), recreated.getPeriod()); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorRuntimeTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorRuntimeTest.java new file mode 100644 index 000000000..ae6fc5839 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorRuntimeTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.lang.reflect.Constructor; +import java.util.Arrays; +import java.util.UUID; + +import static org.mockito.Mockito.mock; + +public class ActorRuntimeTest { + + private static final String ACTOR_NAME = "MyGreatActor"; + + public interface MyActor { + String say(); + } + + @ActorType(name = ACTOR_NAME) + public static class MyActorImpl extends AbstractActor implements MyActor { + + public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + } + + public String say() { + return "Nothing to say."; + } + } + + private static final ObjectSerializer ACTOR_STATE_SERIALIZER = new ObjectSerializer(); + + private static Constructor constructor; + + private DaprClient mockDaprClient; + + private ActorRuntime runtime; + + @BeforeClass + public static void beforeAll() throws Exception { + constructor = (Constructor) Arrays.stream(ActorRuntime.class.getDeclaredConstructors()) + .filter(c -> c.getParameters().length == 1) + .map(c -> { + c.setAccessible(true); + return c; + }) + .findFirst() + .get(); + } + + @Before + public void setup() throws Exception { + this.mockDaprClient = mock(DaprClient.class); + this.runtime = constructor.newInstance(this.mockDaprClient); + } + + @Test + public void registerActor() throws Exception { + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + Assert.assertTrue(new String(this.runtime.serializeConfig()).contains(ACTOR_NAME)); + } + + @Test + public void activateActor() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.activate(ACTOR_NAME, actorId).block(); + } + + @Test + public void invokeActor() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.activate(ACTOR_NAME, actorId).block(); + + byte[] response = this.runtime.invoke(ACTOR_NAME, actorId, "say", null).block(); + String message = ACTOR_STATE_SERIALIZER.deserialize(ACTOR_STATE_SERIALIZER.unwrapData(response), String.class); + Assert.assertEquals("Nothing to say.", message); + } + + @Test + public void activateThendeactivateActor() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.activate(ACTOR_NAME, actorId).block(); + this.runtime.deactivate(ACTOR_NAME, actorId).block(); + } + + @Test + public void deactivateActor() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.deactivate(ACTOR_NAME, actorId).block(); + } + + @Test + public void lazyActivate() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.activate(ACTOR_NAME, actorId).block(); + + this.runtime.invoke(ACTOR_NAME, actorId, "say", null) + .doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor"))) + .doOnSuccess(s -> Assert.fail()) + .onErrorReturn("".getBytes()) + .block(); + } + + @Test + public void lazyDeactivate() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + this.runtime.activate(ACTOR_NAME, actorId).block(); + + Mono deacticateCall = this.runtime.deactivate(ACTOR_NAME, actorId); + + this.runtime.invoke(ACTOR_NAME, actorId, "say", null).block(); + + deacticateCall.block(); + + this.runtime.invoke(ACTOR_NAME, actorId, "say", null) + .doOnError(e -> Assert.assertTrue(e.getMessage().contains("Could not find actor"))) + .doOnSuccess(s -> Assert.fail()) + .onErrorReturn("".getBytes()) + .block(); + } + + @Test + public void lazyInvoke() throws Exception { + String actorId = UUID.randomUUID().toString(); + this.runtime.registerActor(MyActorImpl.class, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + + Mono invokeCall = this.runtime.invoke(ACTOR_NAME, actorId, "say", null); + + this.runtime.activate(ACTOR_NAME, actorId).block(); + + invokeCall.block(); + } + +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorStatefulTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorStatefulTest.java new file mode 100644 index 000000000..05f945103 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorStatefulTest.java @@ -0,0 +1,665 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyForTestsImpl; +import io.dapr.actors.client.DaprClientStub; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.io.Serializable; +import java.nio.charset.IllegalCharsetNameException; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ActorStatefulTest { + + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + private static final Collection DEACTIVATED_ACTOR_IDS = Collections.synchronizedList(new ArrayList<>()); + + private final ActorRuntimeContext context = createContext(); + + private ActorManager manager = new ActorManager<>(context); + + public interface MyActor { + Mono isActive(); + + MyMethodContext getPreCallMethodContext(); + + MyMethodContext getPostCallMethodContext(); + + Mono unregisterTimerAndReminder(); + + Mono incrementAndGetCount(int increment) throws Exception; + + Mono getCountButThrowsException(); + + Mono addMessage(String message); + + Mono setMessage(String message); + + Mono getMessage(); + + Mono hasMessage(); + + Mono deleteMessage(); + + Mono forceDuplicateException(); + + Mono forcePartialChange(); + + Mono throwsWithoutSaving(); + + Mono setMethodContext(MyMethodContext context); + + Mono getMethodContext(); + + String getIdString(); + } + + @ActorType(name = "MyActor") + public static class MyActorImpl extends AbstractActor implements MyActor, Remindable { + + private final ActorId id; + + private boolean activated; + + private MyMethodContext preMethodCalled; + + private MyMethodContext postMethodCalled; + + public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + } + + @Override + public Mono isActive() { + return Mono.fromSupplier(() -> this.activated); + } + + @Override + public Mono onActivate() { + return Mono + .fromRunnable(() -> this.activated = true) + .then(super.registerActorTimer( + "mytimer", + "hasMessage", + null, + Duration.ofSeconds(1), + Duration.ofSeconds(1))) + .then(super.registerReminder( + "myreminder", + null, + Duration.ofSeconds(1), + Duration.ofSeconds(1) + )); + } + + @Override + public Mono onDeactivate() { + return Mono.fromRunnable(() -> DEACTIVATED_ACTOR_IDS.add(this.id.toString())); + } + + @Override + public Mono onPreActorMethod(ActorMethodContext context) { + // Only keep the first one to make sure we can validate it via another method invocation. + return Mono.fromRunnable(() -> { + this.preMethodCalled = this.preMethodCalled != null ? this.preMethodCalled : new MyMethodContext() + .setName(context.getMethodName()) + .setType(context.getCallType().toString()); + }); + } + + @Override + public Mono onPostActorMethod(ActorMethodContext context) { + // Only keep the first one to make sure we can validate it via another method invocation. + return Mono.fromRunnable(() -> { + this.postMethodCalled = this.postMethodCalled != null ? this.postMethodCalled : new MyMethodContext() + .setName(context.getMethodName()) + .setType(context.getCallType().toString()); + }); + } + + @Override + public MyMethodContext getPreCallMethodContext() { + return this.preMethodCalled; + } + + @Override + public MyMethodContext getPostCallMethodContext() { + return this.postMethodCalled; + } + + @Override + public Mono unregisterTimerAndReminder() { + return super.unregisterReminder("UnknownReminder") + .then(super.unregisterTimer("UnknownTimer")) + .then(super.unregisterReminder("myreminder")) + .then(super.unregisterTimer("mytimer")); + } + + @Override + public Mono incrementAndGetCount(int increment) { + return Mono.fromRunnable(() -> { + if (increment == 0) { + // Artificial exception case for testing. + throw new NumberFormatException("increment cannot be zero."); + } + }) + .then(super.getActorStateManager().contains("counter")) + .flatMap(contains -> { + if (!contains) { + return Mono.just(0); + } + + return super.getActorStateManager().get("counter", int.class); + }) + .map(count -> count + increment) + .flatMap(count -> super.getActorStateManager().set("counter", count).thenReturn(count)); + } + + @Override + public Mono getCountButThrowsException() { + return super.getActorStateManager().get("counter_WRONG_NAME", int.class); + } + + @Override + public Mono addMessage(String message) { + return super.getActorStateManager().add("message", message); + } + + @Override + public Mono setMessage(String message) { + return super.getActorStateManager().set("message", message).thenReturn(executeSayMethod(message)); + } + + @Override + public Mono getMessage() { + return super.getActorStateManager().get("message", String.class); + } + + @Override + public Mono hasMessage() { + return super.getActorStateManager().contains("message"); + } + + @Override + public Mono deleteMessage() { + return super.getActorStateManager().remove("message"); + } + + @Override + public Mono forceDuplicateException() { + // Second add should throw exception. + return super.getActorStateManager().add("message", "anything") + .then(super.getActorStateManager().add("message", "something else")); + } + + @Override + public Mono forcePartialChange() { + return super.getActorStateManager().add("message", "first message") + .then(super.saveState()) + .then(super.getActorStateManager().add("message", "second message")); + } + + @Override + public Mono throwsWithoutSaving() { + return super.getActorStateManager().add("message", "first message") + .then(Mono.error(new IllegalCharsetNameException("random"))); + } + + @Override + public Mono setMethodContext(MyMethodContext context) { + return super.getActorStateManager().set("context", context); + } + + @Override + public Mono getMethodContext() { + return super.getActorStateManager().get("context", MyMethodContext.class); + } + + // Blocking methods are also supported for Actors. Mono is not required. + @Override + public String getIdString() { + return this.id.toString(); + } + + @Override + public Class getStateType() { + // Remindable type. + return String.class; + } + + @Override + public Mono receiveReminder(String reminderName, String state, Duration dueTime, Duration period) { + return Mono.empty(); + } + } + + // Class used to validate serialization/deserialization + public static class MyMethodContext implements Serializable { + + private String type; + + private String name; + + public String getType() { + return type; + } + + public MyMethodContext setType(String type) { + this.type = type; + return this; + } + + public String getName() { + return name; + } + + public MyMethodContext setName(String name) { + this.name = name; + return this; + } + } + + @Test + public void happyGetSetDeleteContains() { + ActorProxy proxy = newActorProxy(); + Assert.assertEquals( + proxy.getActorId().toString(), proxy.invokeActorMethod("getIdString", String.class).block()); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + proxy.invokeActorMethod("setMessage", "hello world").block(); + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + Assert.assertEquals( + "hello world", proxy.invokeActorMethod("getMessage", String.class).block()); + + Assert.assertEquals( + executeSayMethod("hello world"), + proxy.invokeActorMethod("setMessage", "hello world", String.class).block()); + + proxy.invokeActorMethod("deleteMessage").block(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test(expected = IllegalStateException.class) + public void lazyGet() { + ActorProxy proxy = newActorProxy(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + proxy.invokeActorMethod("setMessage", "first message").block(); + + // Creates the mono plan but does not call it yet. + Mono getMessageCall = proxy.invokeActorMethod("getMessage", String.class); + + proxy.invokeActorMethod("deleteMessage").block(); + + // Call should fail because the message was deleted. + getMessageCall.block(); + } + + @Test + public void lazySet() { + ActorProxy proxy = newActorProxy(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Creates the mono plan but does not call it yet. + Mono setMessageCall = proxy.invokeActorMethod("setMessage", "first message"); + + // No call executed yet, so message should not be set. + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + setMessageCall.block(); + + // Now the message has been set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test + public void lazyContains() { + ActorProxy proxy = newActorProxy(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Creates the mono plan but does not call it yet. + Mono hasMessageCall = proxy.invokeActorMethod("hasMessage", Boolean.class); + + // Sets the message. + proxy.invokeActorMethod("setMessage", "hello world").block(); + + // Now we check if message is set. + hasMessageCall.block(); + + // Now the message should be set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test + public void lazyDelete() { + ActorProxy proxy = newActorProxy(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + proxy.invokeActorMethod("setMessage", "first message").block(); + + // Message is set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Created the mono plan but does not execute it yet. + Mono deleteMessageCall = proxy.invokeActorMethod("deleteMessage"); + + // Message is still set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + deleteMessageCall.block(); + + // Now message is not set. + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test + public void lazyAdd() { + ActorProxy proxy = newActorProxy(); + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + proxy.invokeActorMethod("setMessage", "first message").block(); + + // Message is set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Created the mono plan but does not execute it yet. + Mono addMessageCall = proxy.invokeActorMethod("addMessage", "second message"); + + // Message is still set. + Assert.assertEquals("first message", + proxy.invokeActorMethod("getMessage", String.class).block()); + + // Delete message + proxy.invokeActorMethod("deleteMessage").block(); + + // Should work since previous message was deleted. + addMessageCall.block(); + + // New message is still set. + Assert.assertEquals("second message", + proxy.invokeActorMethod("getMessage", String.class).block()); + } + + @Test + public void onActivateAndOnDeactivate() { + ActorProxy proxy = newActorProxy(); + + Assert.assertTrue(proxy.invokeActorMethod("isActive", Boolean.class).block()); + Assert.assertFalse(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString())); + + proxy.invokeActorMethod("hasMessage", Boolean.class).block(); + + this.manager.deactivateActor(proxy.getActorId()).block(); + + Assert.assertTrue(DEACTIVATED_ACTOR_IDS.contains(proxy.getActorId().toString())); + } + + @Test + public void onPreMethodAndOnPostMethod() { + ActorProxy proxy = newActorProxy(); + + proxy.invokeActorMethod("hasMessage", Boolean.class).block(); + + MyMethodContext preContext = + proxy.invokeActorMethod("getPreCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("hasMessage", preContext.getName()); + Assert.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), preContext.getType()); + + MyMethodContext postContext = + proxy.invokeActorMethod("getPostCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("hasMessage", postContext.getName()); + Assert.assertEquals(ActorCallType.ACTOR_INTERFACE_METHOD.toString(), postContext.getType()); + } + + @Test + public void invokeTimer() { + ActorProxy proxy = newActorProxy(); + + this.manager.invokeTimer(proxy.getActorId(), "mytimer").block(); + + MyMethodContext preContext = + proxy.invokeActorMethod("getPreCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("mytimer", preContext.getName()); + Assert.assertEquals(ActorCallType.TIMER_METHOD.toString(), preContext.getType()); + + MyMethodContext postContext = + proxy.invokeActorMethod("getPostCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("mytimer", postContext.getName()); + Assert.assertEquals(ActorCallType.TIMER_METHOD.toString(), postContext.getType()); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeTimerAfterDeactivate() { + ActorProxy proxy = newActorProxy(); + + this.manager.deactivateActor(proxy.getActorId()).block(); + + this.manager.invokeTimer(proxy.getActorId(), "mytimer").block(); + } + + @Test(expected = IllegalStateException.class) + public void invokeTimerAfterUnregister() { + ActorProxy proxy = newActorProxy(); + + proxy.invokeActorMethod("unregisterTimerAndReminder").block(); + + this.manager.invokeTimer(proxy.getActorId(), "mytimer").block(); + } + + @Test(expected = IllegalStateException.class) + public void invokeUnknownTimer() { + ActorProxy proxy = newActorProxy(); + + this.manager.invokeTimer(proxy.getActorId(), "unknown").block(); + } + + @Test + public void invokeReminder() throws Exception { + ActorProxy proxy = newActorProxy(); + + byte[] params = createReminderParams("anything"); + + this.manager.invokeReminder(proxy.getActorId(), "myreminder", params).block(); + + MyMethodContext preContext = + proxy.invokeActorMethod("getPreCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("myreminder", preContext.getName()); + Assert.assertEquals(ActorCallType.REMINDER_METHOD.toString(), preContext.getType()); + + MyMethodContext postContext = + proxy.invokeActorMethod("getPostCallMethodContext", MyMethodContext.class).block(); + Assert.assertEquals("myreminder", postContext.getName()); + Assert.assertEquals(ActorCallType.REMINDER_METHOD.toString(), postContext.getType()); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeReminderAfterDeactivate() throws Exception { + ActorProxy proxy = newActorProxy(); + + this.manager.deactivateActor(proxy.getActorId()).block(); + + byte[] params = createReminderParams("anything"); + + this.manager.invokeReminder(proxy.getActorId(), "myreminder", params).block(); + } + + @Test + public void classTypeRequestResponseInStateStore() { + ActorProxy proxy = newActorProxy(); + + MyMethodContext expectedContext = new MyMethodContext().setName("MyName").setType("MyType"); + + proxy.invokeActorMethod("setMethodContext", expectedContext).block(); + MyMethodContext context = proxy.invokeActorMethod("getMethodContext", MyMethodContext.class).block(); + + Assert.assertEquals(expectedContext.getName(), context.getName()); + Assert.assertEquals(expectedContext.getType(), context.getType()); + } + + @Test + public void intTypeRequestResponseInStateStore() { + ActorProxy proxy = newActorProxy(); + + Assert.assertEquals(1, (int)proxy.invokeActorMethod("incrementAndGetCount", 1, int.class).block()); + Assert.assertEquals(6, (int)proxy.invokeActorMethod("incrementAndGetCount", 5, int.class).block()); + } + + @Test(expected = NumberFormatException.class) + public void intTypeWithMethodException() { + ActorProxy proxy = newActorProxy(); + + // Zero is a magic input that will make method throw an exception. + proxy.invokeActorMethod("incrementAndGetCount", 0, int.class).block(); + } + + @Test(expected = IllegalStateException.class) + public void intTypeWithRuntimeException() { + ActorProxy proxy = newActorProxy(); + + proxy.invokeActorMethod("getCountButThrowsException", int.class).block(); + } + + @Test(expected = IllegalStateException.class) + public void actorRuntimeException() { + ActorProxy proxy = newActorProxy(); + + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + proxy.invokeActorMethod("forceDuplicateException").block(); + } + + @Test(expected = IllegalCharsetNameException.class) + public void actorMethodException() { + ActorProxy proxy = newActorProxy(); + + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + proxy.invokeActorMethod("throwsWithoutSaving").block(); + + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test + public void rollbackChanges() { + ActorProxy proxy = newActorProxy(); + + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Runs a method that will add one message but fail because tries to add a second one. + proxy.invokeActorMethod("forceDuplicateException") + .onErrorResume(throwable -> Mono.empty()) + .block(); + + // No message is set + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + } + + @Test + public void partialChanges() { + ActorProxy proxy = newActorProxy(); + + Assert.assertFalse(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // Runs a method that will add one message, commit but fail because tries to add a second one. + proxy.invokeActorMethod("forcePartialChange") + .onErrorResume(throwable -> Mono.empty()) + .block(); + + // Message is set. + Assert.assertTrue(proxy.invokeActorMethod("hasMessage", Boolean.class).block()); + + // It is first message and not the second due to a save() in the middle but an exception in the end. + Assert.assertEquals("first message", + proxy.invokeActorMethod("getMessage", String.class).block()); + } + + private ActorProxy newActorProxy() { + ActorId actorId = newActorId(); + + // Mock daprClient for ActorProxy only, not for runtime. + DaprClientStub daprClient = mock(DaprClientStub.class); + + when(daprClient.invokeActorMethod( + eq(context.getActorTypeInformation().getName()), + eq(actorId.toString()), + any(), + any())) + .thenAnswer(invocationOnMock -> + this.manager.invokeMethod( + new ActorId(invocationOnMock.getArgument(1, String.class)), + invocationOnMock.getArgument(2, String.class), + INTERNAL_SERIALIZER.unwrapData( + invocationOnMock.getArgument(3, byte[].class))) + .map(s -> { + try { + return INTERNAL_SERIALIZER.wrapData(s); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + + this.manager.activateActor(actorId).block(); + + return new ActorProxyForTestsImpl( + context.getActorTypeInformation().getName(), + actorId, + new DefaultObjectSerializer(), + daprClient); + } + + private byte[] createReminderParams(String data) throws IOException { + byte[] serialized = this.context.getObjectSerializer().serialize(data); + ActorReminderParams params = new ActorReminderParams(serialized, Duration.ofSeconds(1), Duration.ofSeconds(1)); + return INTERNAL_SERIALIZER.serialize(params); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private static String executeSayMethod(String something) { + return "Said: " + (something == null ? "" : something); + } + + private static ActorRuntimeContext createContext() { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + new DefaultObjectSerializer(), + new DefaultActorFactory(), + ActorTypeInformation.create(MyActorImpl.class), + daprClient, + new DaprInMemoryStateProvider(new JavaSerializer()) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTimerTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTimerTest.java new file mode 100644 index 000000000..756912ebe --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTimerTest.java @@ -0,0 +1,63 @@ +package io.dapr.actors.runtime; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.time.Duration; + +public class ActorTimerTest { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @Test + public void serialize() throws IOException { + Duration dueTime = Duration.ZERO + .plusMinutes(7) + .plusSeconds(17); + + Duration period = Duration.ZERO + .plusHours(1) + .plusSeconds(3); + + ActorTimer timer = new ActorTimer( + null, + "testTimer", + "myfunction", + null, + dueTime, + period); + byte[] s = new ObjectSerializer().serialize(timer); + + String expected = "{\"period\":\"1h0m3s0ms\",\"dueTime\":\"0h7m17s0ms\", \"callback\": \"myfunction\"}"; + // Deep comparison via JsonNode.equals method. + Assert.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s)); + } + + @Test + public void serializeWithOneTimePeriod() throws IOException { + Duration dueTime = Duration.ZERO + .plusMinutes(7) + .plusSeconds(17); + + // this is intentionally negative + Duration period = Duration.ZERO + .minusHours(1) + .minusMinutes(3); + + ActorTimer timer = new ActorTimer( + null, + "testTimer", + "myfunction", + null, + dueTime, + period); + byte[] s = new ObjectSerializer().serialize(timer); + + // A negative period will be serialized to an empty string which is interpreted by Dapr to mean fire once only. + String expected = "{\"period\":\"\",\"dueTime\":\"0h7m17s0ms\", \"callback\": \"myfunction\"}"; + // Deep comparison via JsonNode.equals method. + Assert.assertEquals(OBJECT_MAPPER.readTree(expected), OBJECT_MAPPER.readTree(s)); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTypeInformationTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTypeInformationTest.java new file mode 100644 index 000000000..e2f03328f --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorTypeInformationTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +/** + * Unit tests for ActorTypeInformation. + */ +public class ActorTypeInformationTest { + + /** + * Actor interfaced used in this test only. + */ + private interface MyActor { + } + + /** + * Checks information for a non-remindable actor. + */ + @Test + public void notRemindable() { + + class A extends AbstractActor implements MyActor { + A() { + super(null, null); + } + } + + ActorTypeInformation info = ActorTypeInformation.create(A.class); + Assert.assertNotNull(info); + Assert.assertEquals("A", info.getName()); + Assert.assertEquals(A.class, info.getImplementationClass()); + Assert.assertFalse(info.isAbstractClass()); + Assert.assertFalse(info.isRemindable()); + Assert.assertEquals(1, info.getInterfaces().size()); + Assert.assertTrue(info.getInterfaces().contains(MyActor.class)); + } + + /** + * Checks information for a remindable actor. + */ + @Test + public void remindable() { + + class A extends AbstractActor implements MyActor, Remindable { + A() { + super(null, null); + } + + @Override + public Class getStateType() { + return null; + } + + @Override + public Mono receiveReminder(String reminderName, Object state, Duration dueTime, Duration period) { + return null; + } + } + + ActorTypeInformation info = ActorTypeInformation.create(A.class); + Assert.assertNotNull(info); + Assert.assertEquals("A", info.getName()); + Assert.assertEquals(A.class, info.getImplementationClass()); + Assert.assertFalse(info.isAbstractClass()); + Assert.assertTrue(info.isRemindable()); + Assert.assertEquals(2, info.getInterfaces().size()); + Assert.assertTrue(info.getInterfaces().contains(Remindable.class)); + Assert.assertTrue(info.getInterfaces().contains(MyActor.class)); + } + + /** + * Checks information for an actor renamed via annotation. + */ + @Test + public void renamedWithAnnotation() { + @ActorType(name = "B") + class A extends AbstractActor implements MyActor { + A() { + super(null, null); + } + } + + ActorTypeInformation info = ActorTypeInformation.create(A.class); + Assert.assertNotNull(info); + Assert.assertEquals("B", info.getName()); + Assert.assertEquals(A.class, info.getImplementationClass()); + Assert.assertFalse(info.isAbstractClass()); + Assert.assertFalse(info.isRemindable()); + Assert.assertEquals(1, info.getInterfaces().size()); + Assert.assertTrue(info.getInterfaces().contains(MyActor.class)); + } + + /** + * Checks information for an actor is invalid due to an non-actor parent. + */ + @Test + public void nonActorParentClass() { + abstract class MyAbstractClass implements MyActor { + } + + class A extends MyAbstractClass { + } + + ActorTypeInformation info = ActorTypeInformation.tryCreate(A.class); + Assert.assertNull(info); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprHttpClientTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprHttpClientTest.java new file mode 100644 index 000000000..46c2597dd --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprHttpClientTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.actors.runtime; + +import io.dapr.client.DaprHttp; +import io.dapr.client.DaprHttpProxy; +import okhttp3.OkHttpClient; +import okhttp3.mock.Behavior; +import okhttp3.mock.MockInterceptor; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class DaprHttpClientTest { + + private DaprHttpClient DaprHttpClient; + + private OkHttpClient okHttpClient; + + private MockInterceptor mockInterceptor; + + private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; + + @Before + public void setUp() throws Exception { + mockInterceptor = new MockInterceptor(Behavior.UNORDERED); + okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build(); + } + + @Test + public void getActorState() { + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/actors/DemoActor/1/state/order") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = DaprHttpClient.getActorState("DemoActor", "1", "order"); + assertEquals(new String(mono.block()), EXPECTED_RESULT); + } + + + @Test + public void saveActorStateTransactionally() { + mockInterceptor.addRule() + .put("http://localhost:3000/v1.0/actors/DemoActor/1/state") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = + DaprHttpClient.saveActorStateTransactionally("DemoActor", "1", "".getBytes()); + assertNull(mono.block()); + } + + @Test + public void registerActorReminder() { + mockInterceptor.addRule() + .put("http://localhost:3000/v1.0/actors/DemoActor/1/reminders/reminder") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = + DaprHttpClient.registerActorReminder("DemoActor", "1", "reminder", "".getBytes()); + assertNull(mono.block()); + } + + @Test + public void unregisterActorReminder() { + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/actors/DemoActor/1/reminders/reminder") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = DaprHttpClient.unregisterActorReminder("DemoActor", "1", "reminder"); + assertNull(mono.block()); + } + + @Test + public void registerActorTimer() { + mockInterceptor.addRule() + .put("http://localhost:3000/v1.0/actors/DemoActor/1/timers/timer") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = + DaprHttpClient.registerActorTimer("DemoActor", "1", "timer", "".getBytes()); + assertNull(mono.block()); + } + + @Test + public void unregisterActorTimer() { + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/actors/DemoActor/1/timers/timer") + .respond(EXPECTED_RESULT); + DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient); + DaprHttpClient = new DaprHttpClient(daprHttp); + Mono mono = DaprHttpClient.unregisterActorTimer("DemoActor", "1", "timer"); + assertNull(mono.block()); + } + +} \ No newline at end of file diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprInMemoryStateProvider.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprInMemoryStateProvider.java new file mode 100644 index 000000000..9fde33352 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprInMemoryStateProvider.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DaprObjectSerializer; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Fake state provider for tests in Actors - data is kept in memory only. + */ +public class DaprInMemoryStateProvider extends DaprStateAsyncProvider { + + private static final Map stateStore = new HashMap<>(); + + private final DaprObjectSerializer serializer; + + DaprInMemoryStateProvider(DaprObjectSerializer serializer) { + super(null, serializer /* just to avoid NPE */); + this.serializer = serializer; + } + + @Override + Mono load(String actorType, ActorId actorId, String stateName, Class clazz) { + return Mono.fromSupplier(() -> { + try { + String stateId = this.buildId(actorType, actorId, stateName); + if (!stateStore.containsKey(stateId)) { + throw new IllegalStateException("State not found."); + } + + return this.serializer.deserialize(this.stateStore.get(stateId), clazz); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + + @Override + Mono contains(String actorType, ActorId actorId, String stateName) { + return Mono.fromSupplier(() -> stateStore.containsKey(this.buildId(actorType, actorId, stateName))); + } + + @Override + Mono apply(String actorType, ActorId actorId, ActorStateChange... stateChanges) { + return Mono.fromRunnable(() -> { + try { + for (ActorStateChange stateChange : stateChanges) { + String stateId = buildId(actorType, actorId, stateChange.getStateName()); + switch (stateChange.getChangeKind()) { + case REMOVE: + stateStore.remove(stateId); + break; + case ADD: + case UPDATE: + byte[] raw = this.serializer.serialize(stateChange.getValue()); + stateStore.put(stateId, raw); + break; + } + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + private static final String buildId(String actorType, ActorId actorId, String stateName) { + return String.format("%s||%s||%s", actorType, actorId.toString(), stateName); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprStateAsyncProviderTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprStateAsyncProviderTest.java new file mode 100644 index 000000000..79a761832 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DaprStateAsyncProviderTest.java @@ -0,0 +1,251 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.actors.ActorId; +import io.dapr.serializer.DaprObjectSerializer; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; + +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +/** + * Tests for the state store facade. + */ +public class DaprStateAsyncProviderTest { + + private static final DaprObjectSerializer SERIALIZER = new DefaultObjectSerializer(); + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + private static final double EPSILON = 1e-10; + + /** + * Class used to test JSON serialization. + */ + public static final class Customer { + + private int id; + + private String name; + + public int getId() { + return id; + } + + public Customer setId(int id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public Customer setName(String name) { + this.name = name; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Customer customer = (Customer) o; + return id == customer.id && + Objects.equals(name, customer.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + } + + @Test + public void happyCaseApply() { + DaprClient daprClient = mock(DaprClient.class); + when(daprClient + .saveActorStateTransactionally( + eq("MyActor"), + eq("123"), + argThat(s -> { + try { + JsonNode node = OBJECT_MAPPER.readTree(s); + if (node == null) { + return false; + } + + if (node.size() != 3) { + return false; + } + + boolean foundInsertName = false; + boolean foundUpdateZipcode = false; + boolean foundDeleteFlag = false; + for (JsonNode operation : node) { + if (operation.get("operation") == null) { + return false; + } + if (operation.get("request") == null) { + return false; + } + + String opName = operation.get("operation").asText(); + String key = operation.get("request").get("key").asText(); + JsonNode valueNode = operation.get("request").get("value"); + + byte[] value = (valueNode == null) ? null : valueNode.textValue().getBytes(); + foundInsertName |= "upsert".equals(opName) && + "name".equals(key) && + Arrays.equals(SERIALIZER.serialize("Jon Doe"), value); + foundUpdateZipcode |= "upsert".equals(opName) && + "zipcode".equals(key) && + Arrays.equals(SERIALIZER.serialize(98011), value); + foundDeleteFlag |= "delete".equals(opName) && + "flag".equals(key) && + (value == null); + } + + return foundInsertName && foundUpdateZipcode && foundDeleteFlag; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + }))) + .thenReturn(Mono.empty()); + + DaprStateAsyncProvider provider = new DaprStateAsyncProvider(daprClient, SERIALIZER); + provider.apply("MyActor", + new ActorId("123"), + createInsertChange("name", "Jon Doe"), + createUpdateChange("zipcode", 98011), + createDeleteChange("flag")) + .block(); + + verify(daprClient).saveActorStateTransactionally(eq("MyActor"), eq("123"), any()); + } + + @Test + public void happyCaseLoad() throws Exception { + DaprClient daprClient = mock(DaprClient.class); + when(daprClient + .getActorState(any(), any(), eq("name"))) + .thenReturn(Mono.just(SERIALIZER.serialize("Jon Doe"))); + when(daprClient + .getActorState(any(), any(), eq("zipcode"))) + .thenReturn(Mono.just(SERIALIZER.serialize(98021))); + when(daprClient + .getActorState(any(), any(), eq("goals"))) + .thenReturn(Mono.just(SERIALIZER.serialize(98))); + when(daprClient + .getActorState(any(), any(), eq("balance"))) + .thenReturn(Mono.just(SERIALIZER.serialize(46.55))); + when(daprClient + .getActorState(any(), any(), eq("active"))) + .thenReturn(Mono.just(SERIALIZER.serialize(true))); + when(daprClient + .getActorState(any(), any(), eq("customer"))) + .thenReturn(Mono.just("{ \"id\": 1000, \"name\": \"Roxane\"}".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("anotherCustomer"))) + .thenReturn(Mono.just("{ \"id\": 2000, \"name\": \"Max\"}".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("nullCustomer"))) + .thenReturn(Mono.empty()); + + DaprStateAsyncProvider provider = new DaprStateAsyncProvider(daprClient, SERIALIZER); + + Assert.assertEquals("Jon Doe", + provider.load("MyActor", new ActorId("123"), "name", String.class).block()); + Assert.assertEquals(98021, + (int)provider.load("MyActor", new ActorId("123"), "zipcode", int.class).block()); + Assert.assertEquals(98, + (int) provider.load("MyActor", new ActorId("123"), "goals", int.class).block()); + Assert.assertEquals(98, + (int) provider.load("MyActor", new ActorId("123"), "goals", int.class).block()); + Assert.assertEquals(46.55, + (double) provider.load("MyActor", new ActorId("123"), "balance", double.class).block(), + EPSILON); + Assert.assertEquals(true, + (boolean) provider.load("MyActor", new ActorId("123"), "active", boolean.class).block()); + Assert.assertEquals(new Customer().setId(1000).setName("Roxane"), + provider.load("MyActor", new ActorId("123"), "customer", Customer.class).block()); + Assert.assertNotEquals(new Customer().setId(1000).setName("Roxane"), + provider.load("MyActor", new ActorId("123"), "anotherCustomer", Customer.class).block()); + Assert.assertNull(provider.load("MyActor", new ActorId("123"), "nullCustomer", Customer.class).block()); + } + + @Test + public void happyCaseContains() { + DaprClient daprClient = mock(DaprClient.class); + + // Keys that exists. + when(daprClient + .getActorState(any(), any(), eq("name"))) + .thenReturn(Mono.just("Jon Doe".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("zipcode"))) + .thenReturn(Mono.just("98021".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("goals"))) + .thenReturn(Mono.just("98".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("balance"))) + .thenReturn(Mono.just("46.55".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("active"))) + .thenReturn(Mono.just("true".getBytes())); + when(daprClient + .getActorState(any(), any(), eq("customer"))) + .thenReturn(Mono.just("{ \"id\": \"3000\", \"name\": \"Ely\" }".getBytes())); + + // Keys that do not exist. + when(daprClient + .getActorState(any(), any(), eq("Does not exist"))) + .thenReturn(Mono.empty()); + when(daprClient + .getActorState(any(), any(), eq("NAME"))) + .thenReturn(Mono.empty()); + when(daprClient + .getActorState(any(), any(), eq(null))) + .thenReturn(Mono.empty()); + + DaprStateAsyncProvider provider = new DaprStateAsyncProvider(daprClient, SERIALIZER); + + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "name").block()); + Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), "NAME").block()); + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "zipcode").block()); + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "goals").block()); + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "balance").block()); + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "active").block()); + Assert.assertTrue(provider.contains("MyActor", new ActorId("123"), "customer").block()); + Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), "Does not exist").block()); + Assert.assertFalse(provider.contains("MyActor", new ActorId("123"), null).block()); + } + + private final ActorStateChange createInsertChange(String name, T value) { + return new ActorStateChange(name, value, ActorStateChangeKind.ADD); + } + + private final ActorStateChange createUpdateChange(String name, T value) { + return new ActorStateChange(name, value, ActorStateChangeKind.UPDATE); + } + + private final ActorStateChange createDeleteChange(String name) { + return new ActorStateChange(name, null, ActorStateChangeKind.REMOVE); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DefaultActorFactoryTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DefaultActorFactoryTest.java new file mode 100644 index 000000000..0a14a1a86 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DefaultActorFactoryTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.serializer.DaprObjectSerializer; +import org.junit.Assert; +import org.junit.Test; + +import static org.mockito.Mockito.mock; + +/** + * Testing the default constructor of an Actor. + */ +public class DefaultActorFactoryTest { + + /** + * A compliant implementation of Actor to be used in the tests below. + */ + static class MyActor extends AbstractActor { + + ActorRuntimeContext context; + + ActorId actorId; + + public MyActor(ActorRuntimeContext context, ActorId actorId) { + super(context, actorId); + this.context = context; + this.actorId = actorId; + } + } + + /** + * A non-compliant implementation of Actor to be used in the tests below. + */ + static class InvalidActor extends AbstractActor { + InvalidActor() { + super(null, null); + } + } + + /** + * Happy case. + */ + @Test + public void happyActor() { + DefaultActorFactory factory = new DefaultActorFactory<>(); + + ActorId actorId = ActorId.createRandom(); + MyActor actor = factory.createActor(createActorRuntimeContext(MyActor.class), actorId); + + Assert.assertEquals(actorId, actor.actorId); + Assert.assertNotNull(actor.context); + } + + /** + * Class is not an actor. + */ + @Test + public void noValidConstructor() { + DefaultActorFactory factory = new DefaultActorFactory<>(); + + ActorId actorId = ActorId.createRandom(); + InvalidActor actor = factory.createActor(createActorRuntimeContext(InvalidActor.class), actorId); + + Assert.assertNull(actor); + } + + private static ActorRuntimeContext createActorRuntimeContext(Class clazz) { + return new ActorRuntimeContext( + mock(ActorRuntime.class), + mock(DaprObjectSerializer.class), + mock(ActorFactory.class), + ActorTypeInformation.create(clazz), + mock(DaprClient.class), + mock(DaprStateAsyncProvider.class)); + } + +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/DerivedActorTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/DerivedActorTest.java new file mode 100644 index 000000000..d0b1c64e9 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/DerivedActorTest.java @@ -0,0 +1,374 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyForTestsImpl; +import io.dapr.actors.client.DaprClientStub; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DerivedActorTest { + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + private final ActorRuntimeContext context = createContext(); + + private ActorManager manager = new ActorManager<>(context); + + public interface MyActor { + + // These 4 will be implemented in the user code class that extends AbstractActor, but it + // will not be implemented in another class that will inherit that. + Mono onlyImplementedInParentStringInStringOut(String input); + Mono onlyImplementedInParentStringInBooleanOut(String input); + Mono onlyImplementedInParentStringInVoidOut(String input); + Mono onlyImplementedInParentClassInClassOut(MyData input); + + // used to validate onlyImplementedInParentStringInVoidOut() was called + boolean methodReturningVoidInvoked(); + + // The test will only call the versions of this in a derived class to the user code base class. + // The user code base class version will throw. + Mono stringInStringOut(String input); + Mono stringInBooleanOut(String input); + Mono stringInVoidOut(String input); + Mono stringInVoidOutIntentionallyThrows(String input); + Mono classInClassOut(MyData input); + } + + @ActorType(name = "MyActor") + public static class ActorParent extends AbstractActor implements MyActor { + private final ActorId id; + private boolean activated; + private boolean methodReturningVoidInvoked; + + public ActorParent(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + this.methodReturningVoidInvoked = false; + } + + @Override + public Mono onlyImplementedInParentStringInStringOut(String input) { + return Mono.fromSupplier(() -> { + return input + input + input; + }); + } + + @Override + public Mono onlyImplementedInParentStringInBooleanOut(String input) { + return Mono.fromSupplier(() -> { + if (input.equals("icecream")) { + return true; + } else { + return false; + } + }); + } + + @Override + public Mono onlyImplementedInParentStringInVoidOut(String input) { + return Mono.fromRunnable(() -> { + this.methodReturningVoidInvoked = true; + System.out.println("Received " + input); + }); + } + + @Override + public Mono onlyImplementedInParentClassInClassOut(MyData input) { + return Mono.fromSupplier(() -> { + return new MyData( + input.getName() + input.getName() + input.getName(), + input.getNum() + input.getNum() + input.getNum()); + }); + } + + @Override + public boolean methodReturningVoidInvoked() { + return this.methodReturningVoidInvoked; + } + + @Override + public Mono stringInStringOut(String s) { + return Mono.fromSupplier(() -> { + // In the cases below we intentionally only call the derived version of this. + // ArithmeticException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new ArithmeticException("This method should not have been called"); + } + ); + } + + @Override + public Mono stringInBooleanOut(String s) { + return Mono.fromSupplier(() -> { + // In the cases below we intentionally only call the derived version of this. + // ArithmeticException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new ArithmeticException("This method should not have been called"); + }); + } + + @Override + public Mono stringInVoidOut(String input) { + return Mono.fromRunnable(() -> { + this.methodReturningVoidInvoked = true; + System.out.println("Received " + input); + }); + } + + @Override + public Mono stringInVoidOutIntentionallyThrows(String input) { + return Mono.fromRunnable(() -> { + // IllegalMonitorStateException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new IllegalMonitorStateException("IntentionalException"); + }); + } + + @Override + public Mono classInClassOut(MyData input) { + return Mono.fromSupplier(() -> { + // In the cases below we intentionally only call the derived version of this. + // ArithmeticException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new ArithmeticException("This method should not have been called"); + }); + } + } + + public static class ActorChild extends ActorParent implements MyActor { + private final ActorId id; + private boolean activated; + + public ActorChild(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + } + + @Override + public Mono stringInStringOut(String s) { + return Mono.fromSupplier(() -> { + return s + s; + } + ); + } + + @Override + public Mono stringInBooleanOut(String s) { + return Mono.fromSupplier(() -> { + if (s.equals("true")) { + return true; + } else { + return false; + } + }); + } + + @Override + public Mono classInClassOut(MyData input) { + return Mono.fromSupplier(() -> { + return new MyData( + input.getName() + input.getName(), + input.getNum() + input.getNum()); + }); + } + } + + static class MyData { + private String name; + private int num; + + public MyData() { + this.name = ""; + this.num = 0; + } + + public MyData(String name, int num) { + this.name = name; + this.num = num; + } + + public String getName() { + return this.name; + } + + public int getNum() { + return this.num; + } + } + + @Test + public void stringInStringOut() { + ActorProxy proxy = createActorProxyForActorChild(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + "abcabc", + proxy.invokeActorMethod("stringInStringOut", "abc", String.class).block()); + } + + @Test + public void stringInBooleanOut() { + ActorProxy proxy = createActorProxyForActorChild(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + false, + proxy.invokeActorMethod("stringInBooleanOut", "hello world", Boolean.class).block()); + + Assert.assertEquals( + true, + proxy.invokeActorMethod("stringInBooleanOut", "true", Boolean.class).block()); + } + + @Test + public void stringInVoidOut() { + ActorProxy actorProxy = createActorProxyForActorChild(); + + // stringInVoidOut() has not been invoked so this is false + Assert.assertEquals( + false, + actorProxy.invokeActorMethod("methodReturningVoidInvoked", Boolean.class).block()); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + actorProxy.invokeActorMethod("stringInVoidOut", "hello world").block(); + + Assert.assertEquals( + true, + actorProxy.invokeActorMethod("methodReturningVoidInvoked", Boolean.class).block()); + } + + @Test(expected = IllegalMonitorStateException.class) + public void stringInVoidOutIntentionallyThrows() { + ActorProxy actorProxy = createActorProxyForActorChild(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + actorProxy.invokeActorMethod("stringInVoidOutIntentionallyThrows", "hello world").block(); + } + + @Test + public void classInClassOut() { + ActorProxy actorProxy = createActorProxyForActorChild(); + MyData d = new MyData("hi", 3); + + // this should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + MyData response = actorProxy.invokeActorMethod("classInClassOut", d, MyData.class).block(); + + Assert.assertEquals( + "hihi", + response.getName()); + Assert.assertEquals( + 6, + response.getNum()); + } + + // The actor methods this test invokes are all implemented in ActorParent only. We're asserting it's callable when the actor proxy is for an ActorChild. + @Test + public void testInheritedActorMethods() { + ActorProxy actorProxy = createActorProxyForActorChild(); + + Assert.assertEquals( + "www", + actorProxy.invokeActorMethod("onlyImplementedInParentStringInStringOut", "w", String.class).block()); + + Assert.assertEquals( + true, + actorProxy.invokeActorMethod("onlyImplementedInParentStringInBooleanOut", "icecream", Boolean.class).block()); + + // onlyImplementedInParentStringInVoidOut() has not been invoked so this is false + Assert.assertEquals( + false, + actorProxy.invokeActorMethod("methodReturningVoidInvoked", Boolean.class).block()); + + actorProxy.invokeActorMethod("onlyImplementedInParentStringInVoidOut", "icecream", Boolean.class).block(); + + // now it should return true. + Assert.assertEquals( + true, + actorProxy.invokeActorMethod("methodReturningVoidInvoked", Boolean.class).block()); + + MyData d = new MyData("hi", 3); + MyData response = actorProxy.invokeActorMethod("onlyImplementedInParentClassInClassOut", d, MyData.class).block(); + + Assert.assertEquals( + "hihihi", + response.getName()); + Assert.assertEquals( + 9, + response.getNum()); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private ActorProxy createActorProxyForActorChild() { + ActorId actorId = newActorId(); + + // Mock daprClient for ActorProxy only, not for runtime. + DaprClientStub daprClient = mock(DaprClientStub.class); + + when(daprClient.invokeActorMethod( + eq(context.getActorTypeInformation().getName()), + eq(actorId.toString()), + any(), + any())) + .thenAnswer(invocationOnMock -> + this.manager.invokeMethod( + new ActorId(invocationOnMock.getArgument(1, String.class)), + invocationOnMock.getArgument(2, String.class), + INTERNAL_SERIALIZER.unwrapData( + invocationOnMock.getArgument(3, byte[].class))) + .map(s -> { + try { + return INTERNAL_SERIALIZER.wrapData(s); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + + this.manager.activateActor(actorId).block(); + + return new ActorProxyForTestsImpl( + context.getActorTypeInformation().getName(), + actorId, + new DefaultObjectSerializer(), + daprClient); + } + + private static ActorRuntimeContext createContext() { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + new DefaultObjectSerializer(), + new DefaultActorFactory(), + ActorTypeInformation.create(ActorChild.class), + daprClient, + mock(DaprStateAsyncProvider.class) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/JavaSerializer.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/JavaSerializer.java new file mode 100644 index 000000000..b62afc0d0 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/JavaSerializer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.serializer.DaprObjectSerializer; + +import java.io.*; + +/** + * Class used to test different serializer implementations. + */ +public class JavaSerializer implements DaprObjectSerializer { + + /** + * {@inheritDoc} + */ + @Override + public byte[] serialize(Object o) throws IOException { + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + try (ObjectOutputStream oos = new ObjectOutputStream(bos)) { + oos.writeObject(o); + oos.flush(); + return bos.toByteArray(); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public T deserialize(byte[] data, Class clazz) throws IOException { + try (ByteArrayInputStream bis = new ByteArrayInputStream(data)) { + try (ObjectInputStream ois = new ObjectInputStream(bis)) { + try { + return (T) ois.readObject(); + } catch (Exception e) { + throw new IOException("Could not deserialize Java object.", e); + } + } + } + } +} diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ThrowFromPreAndPostActorMethodsTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ThrowFromPreAndPostActorMethodsTest.java new file mode 100644 index 000000000..6b2c4a106 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ThrowFromPreAndPostActorMethodsTest.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.actors.runtime; + +import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorProxy; +import io.dapr.actors.client.ActorProxyForTestsImpl; +import io.dapr.actors.client.DaprClientStub; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.Assert; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ThrowFromPreAndPostActorMethodsTest { + + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + private static final AtomicInteger ACTOR_ID_COUNT = new AtomicInteger(); + + private final ActorRuntimeContext context = createContext(); + + private ActorManager manager = new ActorManager<>(context); + + public interface MyActor { + Mono stringInBooleanOut(String input); + } + + @ActorType(name = "MyActor") + public static class ActorParent extends AbstractActor implements MyActor { + private final ActorId id; + private boolean activated; + private boolean methodReturningVoidInvoked; + + public ActorParent(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + this.methodReturningVoidInvoked = false; + } + + @Override + public Mono onPreActorMethodInternal(ActorMethodContext actorMethodContext) { + // IllegalMonitorStateException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new IllegalMonitorStateException("Intentional throw from onPreActorMethodInternal"); + } + + @Override + public Mono stringInBooleanOut(String s) { + return Mono.fromSupplier(() -> { + // In the cases below we intentionally only call the derived version of this. + // ArithmeticException is being thrown only because it's un unusual exception so it's unlikely + // to collide with something else. + throw new ArithmeticException("This method should not have been called"); + }); + } + } + + public static class ActorChild extends ActorParent implements MyActor { + private final ActorId id; + private boolean activated; + + public ActorChild(ActorRuntimeContext runtimeContext, ActorId id) { + super(runtimeContext, id); + this.id = id; + this.activated = true; + } + + @Override + public Mono stringInBooleanOut(String s) { + return Mono.fromSupplier(() -> { + if (s.equals("true")) { + return true; + } else { + return false; + } + }); + } + } + + static class MyData { + private String name; + private int num; + + public MyData() { + this.name = ""; + this.num = 0; + } + + public MyData(String name, int num) { + this.name = name; + this.num = num; + } + + public String getName() { + return this.name; + } + + public int getNum() { + return this.num; + } + } + + // IllegalMonitorStateException should be intentionally thrown. This type was chosen for this test just because + // it is unlikely to collide. + @Test(expected = IllegalMonitorStateException.class) + public void stringInBooleanOut1() { + ActorProxy proxy = createActorProxyForActorChild(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + false, + proxy.invokeActorMethod("stringInBooleanOut", "hello world", Boolean.class).block()); + } + + // IllegalMonitorStateException should be intentionally thrown. This type was chosen for this test just because + // it is unlikely to collide. + @Test(expected = IllegalMonitorStateException.class) + public void stringInBooleanOut2() { + ActorProxy proxy = createActorProxyForActorChild(); + + // these should only call the actor methods for ActorChild. The implementations in ActorParent will throw. + Assert.assertEquals( + true, + proxy.invokeActorMethod("stringInBooleanOut", "true", Boolean.class).block()); + } + + private static ActorId newActorId() { + return new ActorId(Integer.toString(ACTOR_ID_COUNT.incrementAndGet())); + } + + private ActorProxy createActorProxyForActorChild() { + ActorId actorId = newActorId(); + + // Mock daprClient for ActorProxy only, not for runtime. + DaprClientStub daprClient = mock(DaprClientStub.class); + + when(daprClient.invokeActorMethod( + eq(context.getActorTypeInformation().getName()), + eq(actorId.toString()), + any(), + any())) + .thenAnswer(invocationOnMock -> + this.manager.invokeMethod( + new ActorId(invocationOnMock.getArgument(1, String.class)), + invocationOnMock.getArgument(2, String.class), + INTERNAL_SERIALIZER.unwrapData( + invocationOnMock.getArgument(3, byte[].class))) + .map(s -> { + try { + return INTERNAL_SERIALIZER.wrapData(s); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + + this.manager.activateActor(actorId).block(); + + return new ActorProxyForTestsImpl( + context.getActorTypeInformation().getName(), + actorId, + new DefaultObjectSerializer(), + daprClient); + } + + private static ActorRuntimeContext createContext() { + DaprClient daprClient = mock(DaprClient.class); + + when(daprClient.registerActorTimer(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.registerActorReminder(any(), any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorTimer(any(), any(), any())).thenReturn(Mono.empty()); + when(daprClient.unregisterActorReminder(any(), any(), any())).thenReturn(Mono.empty()); + + return new ActorRuntimeContext( + mock(ActorRuntime.class), + new DefaultObjectSerializer(), + new DefaultActorFactory(), + ActorTypeInformation.create(ActorChild.class), + daprClient, + mock(DaprStateAsyncProvider.class) + ); + } +} diff --git a/sdk-actors/src/test/java/io/dapr/client/DaprHttpProxy.java b/sdk-actors/src/test/java/io/dapr/client/DaprHttpProxy.java new file mode 100644 index 000000000..fe8bb8873 --- /dev/null +++ b/sdk-actors/src/test/java/io/dapr/client/DaprHttpProxy.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.client; + +import okhttp3.OkHttpClient; + +public class DaprHttpProxy extends io.dapr.client.DaprHttp { + + public DaprHttpProxy(int port, OkHttpClient httpClient) { + super(port, httpClient); + } + +} diff --git a/sdk-autogen/pom.xml b/sdk-autogen/pom.xml new file mode 100644 index 000000000..98e2498a8 --- /dev/null +++ b/sdk-autogen/pom.xml @@ -0,0 +1,114 @@ + + 4.0.0 + + + io.dapr + dapr-sdk-parent + 0.2.0-SNAPSHOT + + + dapr-sdk-autogen + jar + 0.2.0-SNAPSHOT + dapr-sdk-autogen + Auto-generated SDK for Dapr + + + ${project.build.directory}/generated-sources + ${project.parent.basedir}/proto + false + + + + + javax.annotation + javax.annotation-api + provided + + + io.grpc + grpc-netty-shaded + runtime + + + io.grpc + grpc-protobuf + + + io.grpc + grpc-stub + + + io.grpc + grpc-testing + test + + + com.google.protobuf + protobuf-java-util + ${protobuf.version} + + + com.github.os72 + protoc-jar-maven-plugin + 3.10.1 + + + + + + + com.github.os72 + protoc-jar-maven-plugin + 3.10.1 + + + generate-sources + + run + + + ${protobuf.version} + inputs + direct + true + + ${protobuf.input.directory}/dapr + ${protobuf.input.directory}/daprclient + + + + java + ${protobuf.output.directory} + + + grpc-java + ${protobuf.output.directory} + io.grpc:protoc-gen-grpc-java:${grpc.version} + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar-no-fork + + + + + + + + diff --git a/sdk-autogen/src/main/java/.keepme b/sdk-autogen/src/main/java/.keepme new file mode 100644 index 000000000..e69de29bb diff --git a/sdk-autogen/src/test/java/.keepme b/sdk-autogen/src/test/java/.keepme new file mode 100644 index 000000000..e69de29bb diff --git a/sdk/pom.xml b/sdk/pom.xml index 553fead27..a2d816c77 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -1,55 +1,63 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 io.dapr dapr-sdk-parent - 0.3.0-alpha + 0.2.0-SNAPSHOT dapr-sdk jar - 0.3.0-alpha + 0.2.0-SNAPSHOT dapr-sdk SDK for Dapr + + + + + false + + central + libs-release + https://repo.spring.io/libs-release + + - generated-proto - ${project.parent.basedir}/proto + false + false - io.grpc - grpc-netty-shaded - runtime + io.dapr + dapr-sdk-autogen + ${project.version} - io.grpc - grpc-protobuf + com.fasterxml.jackson.core + jackson-databind + 2.9.9 - io.grpc - grpc-stub + io.projectreactor + reactor-core + 3.3.1.RELEASE + + + com.squareup.okhttp3 + okhttp + 4.2.1 javax.annotation javax.annotation-api provided - - io.grpc - grpc-testing - test - - - com.google.protobuf - protobuf-java-util - ${protobuf.version} - junit junit @@ -61,49 +69,45 @@ test - com.github.os72 - protoc-jar-maven-plugin - 3.10.1 + commons-cli + commons-cli + 1.4 + test + + + com.github.gmazzo + okhttp-mock + 1.3.2 + test + + + com.github.stefanbirkner + system-rules + 1.19.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.5.2 + test + + + org.springframework.boot + spring-boot-starter-web + 2.2.2.RELEASE + test + + + org.springframework.boot + spring-boot-autoconfigure + 2.2.2.RELEASE + test - - com.github.os72 - protoc-jar-maven-plugin - 3.10.1 - - - generate-sources - - run - - - ${protobuf.version} - inputs - direct - true - - ${protobuf.input.directory}/dapr - ${protobuf.input.directory}/daprclient - - - - java - ${project.build.sourceDirectory} - - - grpc-java - ${project.build.sourceDirectory} - io.grpc:protoc-gen-grpc-java:${grpc.version} - - - - - - - org.apache.maven.plugins maven-source-plugin @@ -131,6 +135,53 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.4 + + + default-prepare-agent + + prepare-agent + + + + report + test + + report + + + target/jacoco-report/ + + + + check + + check + + + + + BUNDLE + + + LINE + COVEREDRATIO + 80% + + + + io.dapr.utils.Constants + + + + + + + + diff --git a/sdk/src/main/java/io/dapr/DaprClientGrpc.java b/sdk/src/main/java/io/dapr/DaprClientGrpc.java deleted file mode 100644 index 147e13eae..000000000 --- a/sdk/src/main/java/io/dapr/DaprClientGrpc.java +++ /dev/null @@ -1,590 +0,0 @@ -package io.dapr; - -import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -/** - *
- * User Code definitions
- * 
- */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.25.0)", - comments = "Source: daprclient.proto") -public final class DaprClientGrpc { - - private DaprClientGrpc() {} - - public static final String SERVICE_NAME = "daprclient.DaprClient"; - - // Static method descriptors that strictly reflect the proto. - private static volatile io.grpc.MethodDescriptor getOnInvokeMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "OnInvoke", - requestType = io.dapr.DaprClientProtos.InvokeEnvelope.class, - responseType = com.google.protobuf.Any.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getOnInvokeMethod() { - io.grpc.MethodDescriptor getOnInvokeMethod; - if ((getOnInvokeMethod = DaprClientGrpc.getOnInvokeMethod) == null) { - synchronized (DaprClientGrpc.class) { - if ((getOnInvokeMethod = DaprClientGrpc.getOnInvokeMethod) == null) { - DaprClientGrpc.getOnInvokeMethod = getOnInvokeMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "OnInvoke")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.InvokeEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Any.getDefaultInstance())) - .setSchemaDescriptor(new DaprClientMethodDescriptorSupplier("OnInvoke")) - .build(); - } - } - } - return getOnInvokeMethod; - } - - private static volatile io.grpc.MethodDescriptor getGetTopicSubscriptionsMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "GetTopicSubscriptions", - requestType = com.google.protobuf.Empty.class, - responseType = io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getGetTopicSubscriptionsMethod() { - io.grpc.MethodDescriptor getGetTopicSubscriptionsMethod; - if ((getGetTopicSubscriptionsMethod = DaprClientGrpc.getGetTopicSubscriptionsMethod) == null) { - synchronized (DaprClientGrpc.class) { - if ((getGetTopicSubscriptionsMethod = DaprClientGrpc.getGetTopicSubscriptionsMethod) == null) { - DaprClientGrpc.getGetTopicSubscriptionsMethod = getGetTopicSubscriptionsMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetTopicSubscriptions")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.getDefaultInstance())) - .setSchemaDescriptor(new DaprClientMethodDescriptorSupplier("GetTopicSubscriptions")) - .build(); - } - } - } - return getGetTopicSubscriptionsMethod; - } - - private static volatile io.grpc.MethodDescriptor getGetBindingsSubscriptionsMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "GetBindingsSubscriptions", - requestType = com.google.protobuf.Empty.class, - responseType = io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getGetBindingsSubscriptionsMethod() { - io.grpc.MethodDescriptor getGetBindingsSubscriptionsMethod; - if ((getGetBindingsSubscriptionsMethod = DaprClientGrpc.getGetBindingsSubscriptionsMethod) == null) { - synchronized (DaprClientGrpc.class) { - if ((getGetBindingsSubscriptionsMethod = DaprClientGrpc.getGetBindingsSubscriptionsMethod) == null) { - DaprClientGrpc.getGetBindingsSubscriptionsMethod = getGetBindingsSubscriptionsMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetBindingsSubscriptions")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.getDefaultInstance())) - .setSchemaDescriptor(new DaprClientMethodDescriptorSupplier("GetBindingsSubscriptions")) - .build(); - } - } - } - return getGetBindingsSubscriptionsMethod; - } - - private static volatile io.grpc.MethodDescriptor getOnBindingEventMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "OnBindingEvent", - requestType = io.dapr.DaprClientProtos.BindingEventEnvelope.class, - responseType = io.dapr.DaprClientProtos.BindingResponseEnvelope.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getOnBindingEventMethod() { - io.grpc.MethodDescriptor getOnBindingEventMethod; - if ((getOnBindingEventMethod = DaprClientGrpc.getOnBindingEventMethod) == null) { - synchronized (DaprClientGrpc.class) { - if ((getOnBindingEventMethod = DaprClientGrpc.getOnBindingEventMethod) == null) { - DaprClientGrpc.getOnBindingEventMethod = getOnBindingEventMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "OnBindingEvent")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.BindingEventEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.BindingResponseEnvelope.getDefaultInstance())) - .setSchemaDescriptor(new DaprClientMethodDescriptorSupplier("OnBindingEvent")) - .build(); - } - } - } - return getOnBindingEventMethod; - } - - private static volatile io.grpc.MethodDescriptor getOnTopicEventMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "OnTopicEvent", - requestType = io.dapr.DaprClientProtos.CloudEventEnvelope.class, - responseType = com.google.protobuf.Empty.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getOnTopicEventMethod() { - io.grpc.MethodDescriptor getOnTopicEventMethod; - if ((getOnTopicEventMethod = DaprClientGrpc.getOnTopicEventMethod) == null) { - synchronized (DaprClientGrpc.class) { - if ((getOnTopicEventMethod = DaprClientGrpc.getOnTopicEventMethod) == null) { - DaprClientGrpc.getOnTopicEventMethod = getOnTopicEventMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "OnTopicEvent")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprClientProtos.CloudEventEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setSchemaDescriptor(new DaprClientMethodDescriptorSupplier("OnTopicEvent")) - .build(); - } - } - } - return getOnTopicEventMethod; - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static DaprClientStub newStub(io.grpc.Channel channel) { - return new DaprClientStub(channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static DaprClientBlockingStub newBlockingStub( - io.grpc.Channel channel) { - return new DaprClientBlockingStub(channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static DaprClientFutureStub newFutureStub( - io.grpc.Channel channel) { - return new DaprClientFutureStub(channel); - } - - /** - *
-   * User Code definitions
-   * 
- */ - public static abstract class DaprClientImplBase implements io.grpc.BindableService { - - /** - */ - public void onInvoke(io.dapr.DaprClientProtos.InvokeEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getOnInvokeMethod(), responseObserver); - } - - /** - */ - public void getTopicSubscriptions(com.google.protobuf.Empty request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getGetTopicSubscriptionsMethod(), responseObserver); - } - - /** - */ - public void getBindingsSubscriptions(com.google.protobuf.Empty request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getGetBindingsSubscriptionsMethod(), responseObserver); - } - - /** - */ - public void onBindingEvent(io.dapr.DaprClientProtos.BindingEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getOnBindingEventMethod(), responseObserver); - } - - /** - */ - public void onTopicEvent(io.dapr.DaprClientProtos.CloudEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getOnTopicEventMethod(), responseObserver); - } - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getOnInvokeMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprClientProtos.InvokeEnvelope, - com.google.protobuf.Any>( - this, METHODID_ON_INVOKE))) - .addMethod( - getGetTopicSubscriptionsMethod(), - asyncUnaryCall( - new MethodHandlers< - com.google.protobuf.Empty, - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope>( - this, METHODID_GET_TOPIC_SUBSCRIPTIONS))) - .addMethod( - getGetBindingsSubscriptionsMethod(), - asyncUnaryCall( - new MethodHandlers< - com.google.protobuf.Empty, - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope>( - this, METHODID_GET_BINDINGS_SUBSCRIPTIONS))) - .addMethod( - getOnBindingEventMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprClientProtos.BindingEventEnvelope, - io.dapr.DaprClientProtos.BindingResponseEnvelope>( - this, METHODID_ON_BINDING_EVENT))) - .addMethod( - getOnTopicEventMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprClientProtos.CloudEventEnvelope, - com.google.protobuf.Empty>( - this, METHODID_ON_TOPIC_EVENT))) - .build(); - } - } - - /** - *
-   * User Code definitions
-   * 
- */ - public static final class DaprClientStub extends io.grpc.stub.AbstractStub { - private DaprClientStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprClientStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprClientStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprClientStub(channel, callOptions); - } - - /** - */ - public void onInvoke(io.dapr.DaprClientProtos.InvokeEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getOnInvokeMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void getTopicSubscriptions(com.google.protobuf.Empty request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getGetTopicSubscriptionsMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void getBindingsSubscriptions(com.google.protobuf.Empty request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getGetBindingsSubscriptionsMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void onBindingEvent(io.dapr.DaprClientProtos.BindingEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getOnBindingEventMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void onTopicEvent(io.dapr.DaprClientProtos.CloudEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getOnTopicEventMethod(), getCallOptions()), request, responseObserver); - } - } - - /** - *
-   * User Code definitions
-   * 
- */ - public static final class DaprClientBlockingStub extends io.grpc.stub.AbstractStub { - private DaprClientBlockingStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprClientBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprClientBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprClientBlockingStub(channel, callOptions); - } - - /** - */ - public com.google.protobuf.Any onInvoke(io.dapr.DaprClientProtos.InvokeEnvelope request) { - return blockingUnaryCall( - getChannel(), getOnInvokeMethod(), getCallOptions(), request); - } - - /** - */ - public io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope getTopicSubscriptions(com.google.protobuf.Empty request) { - return blockingUnaryCall( - getChannel(), getGetTopicSubscriptionsMethod(), getCallOptions(), request); - } - - /** - */ - public io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope getBindingsSubscriptions(com.google.protobuf.Empty request) { - return blockingUnaryCall( - getChannel(), getGetBindingsSubscriptionsMethod(), getCallOptions(), request); - } - - /** - */ - public io.dapr.DaprClientProtos.BindingResponseEnvelope onBindingEvent(io.dapr.DaprClientProtos.BindingEventEnvelope request) { - return blockingUnaryCall( - getChannel(), getOnBindingEventMethod(), getCallOptions(), request); - } - - /** - */ - public com.google.protobuf.Empty onTopicEvent(io.dapr.DaprClientProtos.CloudEventEnvelope request) { - return blockingUnaryCall( - getChannel(), getOnTopicEventMethod(), getCallOptions(), request); - } - } - - /** - *
-   * User Code definitions
-   * 
- */ - public static final class DaprClientFutureStub extends io.grpc.stub.AbstractStub { - private DaprClientFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprClientFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprClientFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprClientFutureStub(channel, callOptions); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture onInvoke( - io.dapr.DaprClientProtos.InvokeEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getOnInvokeMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture getTopicSubscriptions( - com.google.protobuf.Empty request) { - return futureUnaryCall( - getChannel().newCall(getGetTopicSubscriptionsMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture getBindingsSubscriptions( - com.google.protobuf.Empty request) { - return futureUnaryCall( - getChannel().newCall(getGetBindingsSubscriptionsMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture onBindingEvent( - io.dapr.DaprClientProtos.BindingEventEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getOnBindingEventMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture onTopicEvent( - io.dapr.DaprClientProtos.CloudEventEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getOnTopicEventMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_ON_INVOKE = 0; - private static final int METHODID_GET_TOPIC_SUBSCRIPTIONS = 1; - private static final int METHODID_GET_BINDINGS_SUBSCRIPTIONS = 2; - private static final int METHODID_ON_BINDING_EVENT = 3; - private static final int METHODID_ON_TOPIC_EVENT = 4; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final DaprClientImplBase serviceImpl; - private final int methodId; - - MethodHandlers(DaprClientImplBase serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_ON_INVOKE: - serviceImpl.onInvoke((io.dapr.DaprClientProtos.InvokeEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_GET_TOPIC_SUBSCRIPTIONS: - serviceImpl.getTopicSubscriptions((com.google.protobuf.Empty) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_GET_BINDINGS_SUBSCRIPTIONS: - serviceImpl.getBindingsSubscriptions((com.google.protobuf.Empty) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_ON_BINDING_EVENT: - serviceImpl.onBindingEvent((io.dapr.DaprClientProtos.BindingEventEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_ON_TOPIC_EVENT: - serviceImpl.onTopicEvent((io.dapr.DaprClientProtos.CloudEventEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - private static abstract class DaprClientBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { - DaprClientBaseDescriptorSupplier() {} - - @java.lang.Override - public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return io.dapr.DaprClientProtos.getDescriptor(); - } - - @java.lang.Override - public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { - return getFileDescriptor().findServiceByName("DaprClient"); - } - } - - private static final class DaprClientFileDescriptorSupplier - extends DaprClientBaseDescriptorSupplier { - DaprClientFileDescriptorSupplier() {} - } - - private static final class DaprClientMethodDescriptorSupplier - extends DaprClientBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final String methodName; - - DaprClientMethodDescriptorSupplier(String methodName) { - this.methodName = methodName; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { - return getServiceDescriptor().findMethodByName(methodName); - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (DaprClientGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .setSchemaDescriptor(new DaprClientFileDescriptorSupplier()) - .addMethod(getOnInvokeMethod()) - .addMethod(getGetTopicSubscriptionsMethod()) - .addMethod(getGetBindingsSubscriptionsMethod()) - .addMethod(getOnBindingEventMethod()) - .addMethod(getOnTopicEventMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/sdk/src/main/java/io/dapr/DaprClientProtos.java b/sdk/src/main/java/io/dapr/DaprClientProtos.java deleted file mode 100644 index 74bf6849c..000000000 --- a/sdk/src/main/java/io/dapr/DaprClientProtos.java +++ /dev/null @@ -1,9676 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: daprclient.proto - -package io.dapr; - -public final class DaprClientProtos { - private DaprClientProtos() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface CloudEventEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.CloudEventEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string id = 1; - * @return The id. - */ - java.lang.String getId(); - /** - * string id = 1; - * @return The bytes for id. - */ - com.google.protobuf.ByteString - getIdBytes(); - - /** - * string source = 2; - * @return The source. - */ - java.lang.String getSource(); - /** - * string source = 2; - * @return The bytes for source. - */ - com.google.protobuf.ByteString - getSourceBytes(); - - /** - * string type = 3; - * @return The type. - */ - java.lang.String getType(); - /** - * string type = 3; - * @return The bytes for type. - */ - com.google.protobuf.ByteString - getTypeBytes(); - - /** - * string specVersion = 4; - * @return The specVersion. - */ - java.lang.String getSpecVersion(); - /** - * string specVersion = 4; - * @return The bytes for specVersion. - */ - com.google.protobuf.ByteString - getSpecVersionBytes(); - - /** - * string dataContentType = 5; - * @return The dataContentType. - */ - java.lang.String getDataContentType(); - /** - * string dataContentType = 5; - * @return The bytes for dataContentType. - */ - com.google.protobuf.ByteString - getDataContentTypeBytes(); - - /** - * string topic = 6; - * @return The topic. - */ - java.lang.String getTopic(); - /** - * string topic = 6; - * @return The bytes for topic. - */ - com.google.protobuf.ByteString - getTopicBytes(); - - /** - * .google.protobuf.Any data = 7; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 7; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 7; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - } - /** - * Protobuf type {@code daprclient.CloudEventEnvelope} - */ - public static final class CloudEventEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.CloudEventEnvelope) - CloudEventEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use CloudEventEnvelope.newBuilder() to construct. - private CloudEventEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private CloudEventEnvelope() { - id_ = ""; - source_ = ""; - type_ = ""; - specVersion_ = ""; - dataContentType_ = ""; - topic_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new CloudEventEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private CloudEventEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - id_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - source_ = s; - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - type_ = s; - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); - - specVersion_ = s; - break; - } - case 42: { - java.lang.String s = input.readStringRequireUtf8(); - - dataContentType_ = s; - break; - } - case 50: { - java.lang.String s = input.readStringRequireUtf8(); - - topic_ = s; - break; - } - case 58: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_CloudEventEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_CloudEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.CloudEventEnvelope.class, io.dapr.DaprClientProtos.CloudEventEnvelope.Builder.class); - } - - public static final int ID_FIELD_NUMBER = 1; - private volatile java.lang.Object id_; - /** - * string id = 1; - * @return The id. - */ - public java.lang.String getId() { - java.lang.Object ref = id_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - id_ = s; - return s; - } - } - /** - * string id = 1; - * @return The bytes for id. - */ - public com.google.protobuf.ByteString - getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int SOURCE_FIELD_NUMBER = 2; - private volatile java.lang.Object source_; - /** - * string source = 2; - * @return The source. - */ - public java.lang.String getSource() { - java.lang.Object ref = source_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - source_ = s; - return s; - } - } - /** - * string source = 2; - * @return The bytes for source. - */ - public com.google.protobuf.ByteString - getSourceBytes() { - java.lang.Object ref = source_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - source_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int TYPE_FIELD_NUMBER = 3; - private volatile java.lang.Object type_; - /** - * string type = 3; - * @return The type. - */ - public java.lang.String getType() { - java.lang.Object ref = type_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - type_ = s; - return s; - } - } - /** - * string type = 3; - * @return The bytes for type. - */ - public com.google.protobuf.ByteString - getTypeBytes() { - java.lang.Object ref = type_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - type_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int SPECVERSION_FIELD_NUMBER = 4; - private volatile java.lang.Object specVersion_; - /** - * string specVersion = 4; - * @return The specVersion. - */ - public java.lang.String getSpecVersion() { - java.lang.Object ref = specVersion_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - specVersion_ = s; - return s; - } - } - /** - * string specVersion = 4; - * @return The bytes for specVersion. - */ - public com.google.protobuf.ByteString - getSpecVersionBytes() { - java.lang.Object ref = specVersion_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - specVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATACONTENTTYPE_FIELD_NUMBER = 5; - private volatile java.lang.Object dataContentType_; - /** - * string dataContentType = 5; - * @return The dataContentType. - */ - public java.lang.String getDataContentType() { - java.lang.Object ref = dataContentType_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dataContentType_ = s; - return s; - } - } - /** - * string dataContentType = 5; - * @return The bytes for dataContentType. - */ - public com.google.protobuf.ByteString - getDataContentTypeBytes() { - java.lang.Object ref = dataContentType_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dataContentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int TOPIC_FIELD_NUMBER = 6; - private volatile java.lang.Object topic_; - /** - * string topic = 6; - * @return The topic. - */ - public java.lang.String getTopic() { - java.lang.Object ref = topic_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - topic_ = s; - return s; - } - } - /** - * string topic = 6; - * @return The bytes for topic. - */ - public com.google.protobuf.ByteString - getTopicBytes() { - java.lang.Object ref = topic_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - topic_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 7; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 7; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 7; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 7; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getIdBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, id_); - } - if (!getSourceBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, source_); - } - if (!getTypeBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, type_); - } - if (!getSpecVersionBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, specVersion_); - } - if (!getDataContentTypeBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, dataContentType_); - } - if (!getTopicBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, topic_); - } - if (data_ != null) { - output.writeMessage(7, getData()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getIdBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, id_); - } - if (!getSourceBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, source_); - } - if (!getTypeBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, type_); - } - if (!getSpecVersionBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, specVersion_); - } - if (!getDataContentTypeBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, dataContentType_); - } - if (!getTopicBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, topic_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(7, getData()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.CloudEventEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.CloudEventEnvelope other = (io.dapr.DaprClientProtos.CloudEventEnvelope) obj; - - if (!getId() - .equals(other.getId())) return false; - if (!getSource() - .equals(other.getSource())) return false; - if (!getType() - .equals(other.getType())) return false; - if (!getSpecVersion() - .equals(other.getSpecVersion())) return false; - if (!getDataContentType() - .equals(other.getDataContentType())) return false; - if (!getTopic() - .equals(other.getTopic())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + ID_FIELD_NUMBER; - hash = (53 * hash) + getId().hashCode(); - hash = (37 * hash) + SOURCE_FIELD_NUMBER; - hash = (53 * hash) + getSource().hashCode(); - hash = (37 * hash) + TYPE_FIELD_NUMBER; - hash = (53 * hash) + getType().hashCode(); - hash = (37 * hash) + SPECVERSION_FIELD_NUMBER; - hash = (53 * hash) + getSpecVersion().hashCode(); - hash = (37 * hash) + DATACONTENTTYPE_FIELD_NUMBER; - hash = (53 * hash) + getDataContentType().hashCode(); - hash = (37 * hash) + TOPIC_FIELD_NUMBER; - hash = (53 * hash) + getTopic().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.CloudEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.CloudEventEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.CloudEventEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.CloudEventEnvelope) - io.dapr.DaprClientProtos.CloudEventEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_CloudEventEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_CloudEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.CloudEventEnvelope.class, io.dapr.DaprClientProtos.CloudEventEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.CloudEventEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - id_ = ""; - - source_ = ""; - - type_ = ""; - - specVersion_ = ""; - - dataContentType_ = ""; - - topic_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_CloudEventEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.CloudEventEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.CloudEventEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.CloudEventEnvelope build() { - io.dapr.DaprClientProtos.CloudEventEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.CloudEventEnvelope buildPartial() { - io.dapr.DaprClientProtos.CloudEventEnvelope result = new io.dapr.DaprClientProtos.CloudEventEnvelope(this); - result.id_ = id_; - result.source_ = source_; - result.type_ = type_; - result.specVersion_ = specVersion_; - result.dataContentType_ = dataContentType_; - result.topic_ = topic_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.CloudEventEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.CloudEventEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.CloudEventEnvelope other) { - if (other == io.dapr.DaprClientProtos.CloudEventEnvelope.getDefaultInstance()) return this; - if (!other.getId().isEmpty()) { - id_ = other.id_; - onChanged(); - } - if (!other.getSource().isEmpty()) { - source_ = other.source_; - onChanged(); - } - if (!other.getType().isEmpty()) { - type_ = other.type_; - onChanged(); - } - if (!other.getSpecVersion().isEmpty()) { - specVersion_ = other.specVersion_; - onChanged(); - } - if (!other.getDataContentType().isEmpty()) { - dataContentType_ = other.dataContentType_; - onChanged(); - } - if (!other.getTopic().isEmpty()) { - topic_ = other.topic_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.CloudEventEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.CloudEventEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object id_ = ""; - /** - * string id = 1; - * @return The id. - */ - public java.lang.String getId() { - java.lang.Object ref = id_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - id_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string id = 1; - * @return The bytes for id. - */ - public com.google.protobuf.ByteString - getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string id = 1; - * @param value The id to set. - * @return This builder for chaining. - */ - public Builder setId( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - id_ = value; - onChanged(); - return this; - } - /** - * string id = 1; - * @return This builder for chaining. - */ - public Builder clearId() { - - id_ = getDefaultInstance().getId(); - onChanged(); - return this; - } - /** - * string id = 1; - * @param value The bytes for id to set. - * @return This builder for chaining. - */ - public Builder setIdBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - id_ = value; - onChanged(); - return this; - } - - private java.lang.Object source_ = ""; - /** - * string source = 2; - * @return The source. - */ - public java.lang.String getSource() { - java.lang.Object ref = source_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - source_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string source = 2; - * @return The bytes for source. - */ - public com.google.protobuf.ByteString - getSourceBytes() { - java.lang.Object ref = source_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - source_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string source = 2; - * @param value The source to set. - * @return This builder for chaining. - */ - public Builder setSource( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - source_ = value; - onChanged(); - return this; - } - /** - * string source = 2; - * @return This builder for chaining. - */ - public Builder clearSource() { - - source_ = getDefaultInstance().getSource(); - onChanged(); - return this; - } - /** - * string source = 2; - * @param value The bytes for source to set. - * @return This builder for chaining. - */ - public Builder setSourceBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - source_ = value; - onChanged(); - return this; - } - - private java.lang.Object type_ = ""; - /** - * string type = 3; - * @return The type. - */ - public java.lang.String getType() { - java.lang.Object ref = type_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - type_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string type = 3; - * @return The bytes for type. - */ - public com.google.protobuf.ByteString - getTypeBytes() { - java.lang.Object ref = type_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - type_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string type = 3; - * @param value The type to set. - * @return This builder for chaining. - */ - public Builder setType( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - type_ = value; - onChanged(); - return this; - } - /** - * string type = 3; - * @return This builder for chaining. - */ - public Builder clearType() { - - type_ = getDefaultInstance().getType(); - onChanged(); - return this; - } - /** - * string type = 3; - * @param value The bytes for type to set. - * @return This builder for chaining. - */ - public Builder setTypeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - type_ = value; - onChanged(); - return this; - } - - private java.lang.Object specVersion_ = ""; - /** - * string specVersion = 4; - * @return The specVersion. - */ - public java.lang.String getSpecVersion() { - java.lang.Object ref = specVersion_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - specVersion_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string specVersion = 4; - * @return The bytes for specVersion. - */ - public com.google.protobuf.ByteString - getSpecVersionBytes() { - java.lang.Object ref = specVersion_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - specVersion_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string specVersion = 4; - * @param value The specVersion to set. - * @return This builder for chaining. - */ - public Builder setSpecVersion( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - specVersion_ = value; - onChanged(); - return this; - } - /** - * string specVersion = 4; - * @return This builder for chaining. - */ - public Builder clearSpecVersion() { - - specVersion_ = getDefaultInstance().getSpecVersion(); - onChanged(); - return this; - } - /** - * string specVersion = 4; - * @param value The bytes for specVersion to set. - * @return This builder for chaining. - */ - public Builder setSpecVersionBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - specVersion_ = value; - onChanged(); - return this; - } - - private java.lang.Object dataContentType_ = ""; - /** - * string dataContentType = 5; - * @return The dataContentType. - */ - public java.lang.String getDataContentType() { - java.lang.Object ref = dataContentType_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - dataContentType_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string dataContentType = 5; - * @return The bytes for dataContentType. - */ - public com.google.protobuf.ByteString - getDataContentTypeBytes() { - java.lang.Object ref = dataContentType_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - dataContentType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string dataContentType = 5; - * @param value The dataContentType to set. - * @return This builder for chaining. - */ - public Builder setDataContentType( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - dataContentType_ = value; - onChanged(); - return this; - } - /** - * string dataContentType = 5; - * @return This builder for chaining. - */ - public Builder clearDataContentType() { - - dataContentType_ = getDefaultInstance().getDataContentType(); - onChanged(); - return this; - } - /** - * string dataContentType = 5; - * @param value The bytes for dataContentType to set. - * @return This builder for chaining. - */ - public Builder setDataContentTypeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - dataContentType_ = value; - onChanged(); - return this; - } - - private java.lang.Object topic_ = ""; - /** - * string topic = 6; - * @return The topic. - */ - public java.lang.String getTopic() { - java.lang.Object ref = topic_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - topic_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string topic = 6; - * @return The bytes for topic. - */ - public com.google.protobuf.ByteString - getTopicBytes() { - java.lang.Object ref = topic_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - topic_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string topic = 6; - * @param value The topic to set. - * @return This builder for chaining. - */ - public Builder setTopic( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - topic_ = value; - onChanged(); - return this; - } - /** - * string topic = 6; - * @return This builder for chaining. - */ - public Builder clearTopic() { - - topic_ = getDefaultInstance().getTopic(); - onChanged(); - return this; - } - /** - * string topic = 6; - * @param value The bytes for topic to set. - * @return This builder for chaining. - */ - public Builder setTopicBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - topic_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 7; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 7; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 7; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 7; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 7; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 7; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 7; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 7; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 7; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.CloudEventEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.CloudEventEnvelope) - private static final io.dapr.DaprClientProtos.CloudEventEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.CloudEventEnvelope(); - } - - public static io.dapr.DaprClientProtos.CloudEventEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public CloudEventEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new CloudEventEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.CloudEventEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface BindingEventEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.BindingEventEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string name = 1; - * @return The name. - */ - java.lang.String getName(); - /** - * string name = 1; - * @return The bytes for name. - */ - com.google.protobuf.ByteString - getNameBytes(); - - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 2; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * map<string, string> metadata = 3; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 3; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 3; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - } - /** - * Protobuf type {@code daprclient.BindingEventEnvelope} - */ - public static final class BindingEventEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.BindingEventEnvelope) - BindingEventEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use BindingEventEnvelope.newBuilder() to construct. - private BindingEventEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private BindingEventEnvelope() { - name_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new BindingEventEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private BindingEventEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - name_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.BindingEventEnvelope.class, io.dapr.DaprClientProtos.BindingEventEnvelope.Builder.class); - } - - public static final int NAME_FIELD_NUMBER = 1; - private volatile java.lang.Object name_; - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - } - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 2; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int METADATA_FIELD_NUMBER = 3; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); - } - if (data_ != null) { - output.writeMessage(2, getData()); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 3); - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getData()); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, metadata__); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.BindingEventEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.BindingEventEnvelope other = (io.dapr.DaprClientProtos.BindingEventEnvelope) obj; - - if (!getName() - .equals(other.getName())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + NAME_FIELD_NUMBER; - hash = (53 * hash) + getName().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.BindingEventEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.BindingEventEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.BindingEventEnvelope) - io.dapr.DaprClientProtos.BindingEventEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 3: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.BindingEventEnvelope.class, io.dapr.DaprClientProtos.BindingEventEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.BindingEventEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - name_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - internalGetMutableMetadata().clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingEventEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingEventEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.BindingEventEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingEventEnvelope build() { - io.dapr.DaprClientProtos.BindingEventEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingEventEnvelope buildPartial() { - io.dapr.DaprClientProtos.BindingEventEnvelope result = new io.dapr.DaprClientProtos.BindingEventEnvelope(this); - int from_bitField0_ = bitField0_; - result.name_ = name_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.BindingEventEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.BindingEventEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.BindingEventEnvelope other) { - if (other == io.dapr.DaprClientProtos.BindingEventEnvelope.getDefaultInstance()) return this; - if (!other.getName().isEmpty()) { - name_ = other.name_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.BindingEventEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.BindingEventEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object name_ = ""; - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string name = 1; - * @param value The name to set. - * @return This builder for chaining. - */ - public Builder setName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - name_ = value; - onChanged(); - return this; - } - /** - * string name = 1; - * @return This builder for chaining. - */ - public Builder clearName() { - - name_ = getDefaultInstance().getName(); - onChanged(); - return this; - } - /** - * string name = 1; - * @param value The bytes for name to set. - * @return This builder for chaining. - */ - public Builder setNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - name_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 3; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.BindingEventEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.BindingEventEnvelope) - private static final io.dapr.DaprClientProtos.BindingEventEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.BindingEventEnvelope(); - } - - public static io.dapr.DaprClientProtos.BindingEventEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public BindingEventEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new BindingEventEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingEventEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface BindingResponseEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.BindingResponseEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 1; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * repeated string to = 2; - * @return A list containing the to. - */ - java.util.List - getToList(); - /** - * repeated string to = 2; - * @return The count of to. - */ - int getToCount(); - /** - * repeated string to = 2; - * @param index The index of the element to return. - * @return The to at the given index. - */ - java.lang.String getTo(int index); - /** - * repeated string to = 2; - * @param index The index of the value to return. - * @return The bytes of the to at the given index. - */ - com.google.protobuf.ByteString - getToBytes(int index); - - /** - * repeated .daprclient.State state = 3; - */ - java.util.List - getStateList(); - /** - * repeated .daprclient.State state = 3; - */ - io.dapr.DaprClientProtos.State getState(int index); - /** - * repeated .daprclient.State state = 3; - */ - int getStateCount(); - /** - * repeated .daprclient.State state = 3; - */ - java.util.List - getStateOrBuilderList(); - /** - * repeated .daprclient.State state = 3; - */ - io.dapr.DaprClientProtos.StateOrBuilder getStateOrBuilder( - int index); - - /** - * string concurrency = 4; - * @return The concurrency. - */ - java.lang.String getConcurrency(); - /** - * string concurrency = 4; - * @return The bytes for concurrency. - */ - com.google.protobuf.ByteString - getConcurrencyBytes(); - } - /** - * Protobuf type {@code daprclient.BindingResponseEnvelope} - */ - public static final class BindingResponseEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.BindingResponseEnvelope) - BindingResponseEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use BindingResponseEnvelope.newBuilder() to construct. - private BindingResponseEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private BindingResponseEnvelope() { - to_ = com.google.protobuf.LazyStringArrayList.EMPTY; - state_ = java.util.Collections.emptyList(); - concurrency_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new BindingResponseEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private BindingResponseEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - to_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; - } - to_.add(s); - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000002) != 0)) { - state_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000002; - } - state_.add( - input.readMessage(io.dapr.DaprClientProtos.State.parser(), extensionRegistry)); - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); - - concurrency_ = s; - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) != 0)) { - to_ = to_.getUnmodifiableView(); - } - if (((mutable_bitField0_ & 0x00000002) != 0)) { - state_ = java.util.Collections.unmodifiableList(state_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingResponseEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.BindingResponseEnvelope.class, io.dapr.DaprClientProtos.BindingResponseEnvelope.Builder.class); - } - - public static final int DATA_FIELD_NUMBER = 1; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int TO_FIELD_NUMBER = 2; - private com.google.protobuf.LazyStringList to_; - /** - * repeated string to = 2; - * @return A list containing the to. - */ - public com.google.protobuf.ProtocolStringList - getToList() { - return to_; - } - /** - * repeated string to = 2; - * @return The count of to. - */ - public int getToCount() { - return to_.size(); - } - /** - * repeated string to = 2; - * @param index The index of the element to return. - * @return The to at the given index. - */ - public java.lang.String getTo(int index) { - return to_.get(index); - } - /** - * repeated string to = 2; - * @param index The index of the value to return. - * @return The bytes of the to at the given index. - */ - public com.google.protobuf.ByteString - getToBytes(int index) { - return to_.getByteString(index); - } - - public static final int STATE_FIELD_NUMBER = 3; - private java.util.List state_; - /** - * repeated .daprclient.State state = 3; - */ - public java.util.List getStateList() { - return state_; - } - /** - * repeated .daprclient.State state = 3; - */ - public java.util.List - getStateOrBuilderList() { - return state_; - } - /** - * repeated .daprclient.State state = 3; - */ - public int getStateCount() { - return state_.size(); - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.State getState(int index) { - return state_.get(index); - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.StateOrBuilder getStateOrBuilder( - int index) { - return state_.get(index); - } - - public static final int CONCURRENCY_FIELD_NUMBER = 4; - private volatile java.lang.Object concurrency_; - /** - * string concurrency = 4; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } - } - /** - * string concurrency = 4; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (data_ != null) { - output.writeMessage(1, getData()); - } - for (int i = 0; i < to_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, to_.getRaw(i)); - } - for (int i = 0; i < state_.size(); i++) { - output.writeMessage(3, state_.get(i)); - } - if (!getConcurrencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, concurrency_); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, getData()); - } - { - int dataSize = 0; - for (int i = 0; i < to_.size(); i++) { - dataSize += computeStringSizeNoTag(to_.getRaw(i)); - } - size += dataSize; - size += 1 * getToList().size(); - } - for (int i = 0; i < state_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, state_.get(i)); - } - if (!getConcurrencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, concurrency_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.BindingResponseEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.BindingResponseEnvelope other = (io.dapr.DaprClientProtos.BindingResponseEnvelope) obj; - - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!getToList() - .equals(other.getToList())) return false; - if (!getStateList() - .equals(other.getStateList())) return false; - if (!getConcurrency() - .equals(other.getConcurrency())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (getToCount() > 0) { - hash = (37 * hash) + TO_FIELD_NUMBER; - hash = (53 * hash) + getToList().hashCode(); - } - if (getStateCount() > 0) { - hash = (37 * hash) + STATE_FIELD_NUMBER; - hash = (53 * hash) + getStateList().hashCode(); - } - hash = (37 * hash) + CONCURRENCY_FIELD_NUMBER; - hash = (53 * hash) + getConcurrency().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.BindingResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.BindingResponseEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.BindingResponseEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.BindingResponseEnvelope) - io.dapr.DaprClientProtos.BindingResponseEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingResponseEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.BindingResponseEnvelope.class, io.dapr.DaprClientProtos.BindingResponseEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.BindingResponseEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - getStateFieldBuilder(); - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - to_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - if (stateBuilder_ == null) { - state_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); - } else { - stateBuilder_.clear(); - } - concurrency_ = ""; - - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_BindingResponseEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingResponseEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.BindingResponseEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingResponseEnvelope build() { - io.dapr.DaprClientProtos.BindingResponseEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingResponseEnvelope buildPartial() { - io.dapr.DaprClientProtos.BindingResponseEnvelope result = new io.dapr.DaprClientProtos.BindingResponseEnvelope(this); - int from_bitField0_ = bitField0_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - if (((bitField0_ & 0x00000001) != 0)) { - to_ = to_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.to_ = to_; - if (stateBuilder_ == null) { - if (((bitField0_ & 0x00000002) != 0)) { - state_ = java.util.Collections.unmodifiableList(state_); - bitField0_ = (bitField0_ & ~0x00000002); - } - result.state_ = state_; - } else { - result.state_ = stateBuilder_.build(); - } - result.concurrency_ = concurrency_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.BindingResponseEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.BindingResponseEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.BindingResponseEnvelope other) { - if (other == io.dapr.DaprClientProtos.BindingResponseEnvelope.getDefaultInstance()) return this; - if (other.hasData()) { - mergeData(other.getData()); - } - if (!other.to_.isEmpty()) { - if (to_.isEmpty()) { - to_ = other.to_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureToIsMutable(); - to_.addAll(other.to_); - } - onChanged(); - } - if (stateBuilder_ == null) { - if (!other.state_.isEmpty()) { - if (state_.isEmpty()) { - state_ = other.state_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureStateIsMutable(); - state_.addAll(other.state_); - } - onChanged(); - } - } else { - if (!other.state_.isEmpty()) { - if (stateBuilder_.isEmpty()) { - stateBuilder_.dispose(); - stateBuilder_ = null; - state_ = other.state_; - bitField0_ = (bitField0_ & ~0x00000002); - stateBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? - getStateFieldBuilder() : null; - } else { - stateBuilder_.addAllMessages(other.state_); - } - } - } - if (!other.getConcurrency().isEmpty()) { - concurrency_ = other.concurrency_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.BindingResponseEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.BindingResponseEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 1; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.LazyStringList to_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureToIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - to_ = new com.google.protobuf.LazyStringArrayList(to_); - bitField0_ |= 0x00000001; - } - } - /** - * repeated string to = 2; - * @return A list containing the to. - */ - public com.google.protobuf.ProtocolStringList - getToList() { - return to_.getUnmodifiableView(); - } - /** - * repeated string to = 2; - * @return The count of to. - */ - public int getToCount() { - return to_.size(); - } - /** - * repeated string to = 2; - * @param index The index of the element to return. - * @return The to at the given index. - */ - public java.lang.String getTo(int index) { - return to_.get(index); - } - /** - * repeated string to = 2; - * @param index The index of the value to return. - * @return The bytes of the to at the given index. - */ - public com.google.protobuf.ByteString - getToBytes(int index) { - return to_.getByteString(index); - } - /** - * repeated string to = 2; - * @param index The index to set the value at. - * @param value The to to set. - * @return This builder for chaining. - */ - public Builder setTo( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureToIsMutable(); - to_.set(index, value); - onChanged(); - return this; - } - /** - * repeated string to = 2; - * @param value The to to add. - * @return This builder for chaining. - */ - public Builder addTo( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureToIsMutable(); - to_.add(value); - onChanged(); - return this; - } - /** - * repeated string to = 2; - * @param values The to to add. - * @return This builder for chaining. - */ - public Builder addAllTo( - java.lang.Iterable values) { - ensureToIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, to_); - onChanged(); - return this; - } - /** - * repeated string to = 2; - * @return This builder for chaining. - */ - public Builder clearTo() { - to_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - * repeated string to = 2; - * @param value The bytes of the to to add. - * @return This builder for chaining. - */ - public Builder addToBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureToIsMutable(); - to_.add(value); - onChanged(); - return this; - } - - private java.util.List state_ = - java.util.Collections.emptyList(); - private void ensureStateIsMutable() { - if (!((bitField0_ & 0x00000002) != 0)) { - state_ = new java.util.ArrayList(state_); - bitField0_ |= 0x00000002; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprClientProtos.State, io.dapr.DaprClientProtos.State.Builder, io.dapr.DaprClientProtos.StateOrBuilder> stateBuilder_; - - /** - * repeated .daprclient.State state = 3; - */ - public java.util.List getStateList() { - if (stateBuilder_ == null) { - return java.util.Collections.unmodifiableList(state_); - } else { - return stateBuilder_.getMessageList(); - } - } - /** - * repeated .daprclient.State state = 3; - */ - public int getStateCount() { - if (stateBuilder_ == null) { - return state_.size(); - } else { - return stateBuilder_.getCount(); - } - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.State getState(int index) { - if (stateBuilder_ == null) { - return state_.get(index); - } else { - return stateBuilder_.getMessage(index); - } - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder setState( - int index, io.dapr.DaprClientProtos.State value) { - if (stateBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStateIsMutable(); - state_.set(index, value); - onChanged(); - } else { - stateBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder setState( - int index, io.dapr.DaprClientProtos.State.Builder builderForValue) { - if (stateBuilder_ == null) { - ensureStateIsMutable(); - state_.set(index, builderForValue.build()); - onChanged(); - } else { - stateBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder addState(io.dapr.DaprClientProtos.State value) { - if (stateBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStateIsMutable(); - state_.add(value); - onChanged(); - } else { - stateBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder addState( - int index, io.dapr.DaprClientProtos.State value) { - if (stateBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureStateIsMutable(); - state_.add(index, value); - onChanged(); - } else { - stateBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder addState( - io.dapr.DaprClientProtos.State.Builder builderForValue) { - if (stateBuilder_ == null) { - ensureStateIsMutable(); - state_.add(builderForValue.build()); - onChanged(); - } else { - stateBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder addState( - int index, io.dapr.DaprClientProtos.State.Builder builderForValue) { - if (stateBuilder_ == null) { - ensureStateIsMutable(); - state_.add(index, builderForValue.build()); - onChanged(); - } else { - stateBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder addAllState( - java.lang.Iterable values) { - if (stateBuilder_ == null) { - ensureStateIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, state_); - onChanged(); - } else { - stateBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder clearState() { - if (stateBuilder_ == null) { - state_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - } else { - stateBuilder_.clear(); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public Builder removeState(int index) { - if (stateBuilder_ == null) { - ensureStateIsMutable(); - state_.remove(index); - onChanged(); - } else { - stateBuilder_.remove(index); - } - return this; - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.State.Builder getStateBuilder( - int index) { - return getStateFieldBuilder().getBuilder(index); - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.StateOrBuilder getStateOrBuilder( - int index) { - if (stateBuilder_ == null) { - return state_.get(index); } else { - return stateBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .daprclient.State state = 3; - */ - public java.util.List - getStateOrBuilderList() { - if (stateBuilder_ != null) { - return stateBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(state_); - } - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.State.Builder addStateBuilder() { - return getStateFieldBuilder().addBuilder( - io.dapr.DaprClientProtos.State.getDefaultInstance()); - } - /** - * repeated .daprclient.State state = 3; - */ - public io.dapr.DaprClientProtos.State.Builder addStateBuilder( - int index) { - return getStateFieldBuilder().addBuilder( - index, io.dapr.DaprClientProtos.State.getDefaultInstance()); - } - /** - * repeated .daprclient.State state = 3; - */ - public java.util.List - getStateBuilderList() { - return getStateFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprClientProtos.State, io.dapr.DaprClientProtos.State.Builder, io.dapr.DaprClientProtos.StateOrBuilder> - getStateFieldBuilder() { - if (stateBuilder_ == null) { - stateBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprClientProtos.State, io.dapr.DaprClientProtos.State.Builder, io.dapr.DaprClientProtos.StateOrBuilder>( - state_, - ((bitField0_ & 0x00000002) != 0), - getParentForChildren(), - isClean()); - state_ = null; - } - return stateBuilder_; - } - - private java.lang.Object concurrency_ = ""; - /** - * string concurrency = 4; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string concurrency = 4; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string concurrency = 4; - * @param value The concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - concurrency_ = value; - onChanged(); - return this; - } - /** - * string concurrency = 4; - * @return This builder for chaining. - */ - public Builder clearConcurrency() { - - concurrency_ = getDefaultInstance().getConcurrency(); - onChanged(); - return this; - } - /** - * string concurrency = 4; - * @param value The bytes for concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - concurrency_ = value; - onChanged(); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.BindingResponseEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.BindingResponseEnvelope) - private static final io.dapr.DaprClientProtos.BindingResponseEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.BindingResponseEnvelope(); - } - - public static io.dapr.DaprClientProtos.BindingResponseEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public BindingResponseEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new BindingResponseEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.BindingResponseEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface InvokeEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.InvokeEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string method = 1; - * @return The method. - */ - java.lang.String getMethod(); - /** - * string method = 1; - * @return The bytes for method. - */ - com.google.protobuf.ByteString - getMethodBytes(); - - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 2; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * map<string, string> metadata = 3; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 3; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 3; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - } - /** - * Protobuf type {@code daprclient.InvokeEnvelope} - */ - public static final class InvokeEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.InvokeEnvelope) - InvokeEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use InvokeEnvelope.newBuilder() to construct. - private InvokeEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private InvokeEnvelope() { - method_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new InvokeEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private InvokeEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - method_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.InvokeEnvelope.class, io.dapr.DaprClientProtos.InvokeEnvelope.Builder.class); - } - - public static final int METHOD_FIELD_NUMBER = 1; - private volatile java.lang.Object method_; - /** - * string method = 1; - * @return The method. - */ - public java.lang.String getMethod() { - java.lang.Object ref = method_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - method_ = s; - return s; - } - } - /** - * string method = 1; - * @return The bytes for method. - */ - public com.google.protobuf.ByteString - getMethodBytes() { - java.lang.Object ref = method_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - method_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 2; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int METADATA_FIELD_NUMBER = 3; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getMethodBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, method_); - } - if (data_ != null) { - output.writeMessage(2, getData()); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 3); - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getMethodBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, method_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getData()); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, metadata__); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.InvokeEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.InvokeEnvelope other = (io.dapr.DaprClientProtos.InvokeEnvelope) obj; - - if (!getMethod() - .equals(other.getMethod())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + METHOD_FIELD_NUMBER; - hash = (53 * hash) + getMethod().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.InvokeEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.InvokeEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.InvokeEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.InvokeEnvelope) - io.dapr.DaprClientProtos.InvokeEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 3: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.InvokeEnvelope.class, io.dapr.DaprClientProtos.InvokeEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.InvokeEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - method_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - internalGetMutableMetadata().clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_InvokeEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.InvokeEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.InvokeEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.InvokeEnvelope build() { - io.dapr.DaprClientProtos.InvokeEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.InvokeEnvelope buildPartial() { - io.dapr.DaprClientProtos.InvokeEnvelope result = new io.dapr.DaprClientProtos.InvokeEnvelope(this); - int from_bitField0_ = bitField0_; - result.method_ = method_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.InvokeEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.InvokeEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.InvokeEnvelope other) { - if (other == io.dapr.DaprClientProtos.InvokeEnvelope.getDefaultInstance()) return this; - if (!other.getMethod().isEmpty()) { - method_ = other.method_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.InvokeEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.InvokeEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object method_ = ""; - /** - * string method = 1; - * @return The method. - */ - public java.lang.String getMethod() { - java.lang.Object ref = method_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - method_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string method = 1; - * @return The bytes for method. - */ - public com.google.protobuf.ByteString - getMethodBytes() { - java.lang.Object ref = method_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - method_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string method = 1; - * @param value The method to set. - * @return This builder for chaining. - */ - public Builder setMethod( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - method_ = value; - onChanged(); - return this; - } - /** - * string method = 1; - * @return This builder for chaining. - */ - public Builder clearMethod() { - - method_ = getDefaultInstance().getMethod(); - onChanged(); - return this; - } - /** - * string method = 1; - * @param value The bytes for method to set. - * @return This builder for chaining. - */ - public Builder setMethodBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - method_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 3; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.InvokeEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.InvokeEnvelope) - private static final io.dapr.DaprClientProtos.InvokeEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.InvokeEnvelope(); - } - - public static io.dapr.DaprClientProtos.InvokeEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public InvokeEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new InvokeEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.InvokeEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface GetTopicSubscriptionsEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.GetTopicSubscriptionsEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * repeated string topics = 1; - * @return A list containing the topics. - */ - java.util.List - getTopicsList(); - /** - * repeated string topics = 1; - * @return The count of topics. - */ - int getTopicsCount(); - /** - * repeated string topics = 1; - * @param index The index of the element to return. - * @return The topics at the given index. - */ - java.lang.String getTopics(int index); - /** - * repeated string topics = 1; - * @param index The index of the value to return. - * @return The bytes of the topics at the given index. - */ - com.google.protobuf.ByteString - getTopicsBytes(int index); - } - /** - * Protobuf type {@code daprclient.GetTopicSubscriptionsEnvelope} - */ - public static final class GetTopicSubscriptionsEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.GetTopicSubscriptionsEnvelope) - GetTopicSubscriptionsEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use GetTopicSubscriptionsEnvelope.newBuilder() to construct. - private GetTopicSubscriptionsEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private GetTopicSubscriptionsEnvelope() { - topics_ = com.google.protobuf.LazyStringArrayList.EMPTY; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new GetTopicSubscriptionsEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private GetTopicSubscriptionsEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - topics_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; - } - topics_.add(s); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) != 0)) { - topics_ = topics_.getUnmodifiableView(); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetTopicSubscriptionsEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.class, io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.Builder.class); - } - - public static final int TOPICS_FIELD_NUMBER = 1; - private com.google.protobuf.LazyStringList topics_; - /** - * repeated string topics = 1; - * @return A list containing the topics. - */ - public com.google.protobuf.ProtocolStringList - getTopicsList() { - return topics_; - } - /** - * repeated string topics = 1; - * @return The count of topics. - */ - public int getTopicsCount() { - return topics_.size(); - } - /** - * repeated string topics = 1; - * @param index The index of the element to return. - * @return The topics at the given index. - */ - public java.lang.String getTopics(int index) { - return topics_.get(index); - } - /** - * repeated string topics = 1; - * @param index The index of the value to return. - * @return The bytes of the topics at the given index. - */ - public com.google.protobuf.ByteString - getTopicsBytes(int index) { - return topics_.getByteString(index); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < topics_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, topics_.getRaw(i)); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - { - int dataSize = 0; - for (int i = 0; i < topics_.size(); i++) { - dataSize += computeStringSizeNoTag(topics_.getRaw(i)); - } - size += dataSize; - size += 1 * getTopicsList().size(); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope other = (io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope) obj; - - if (!getTopicsList() - .equals(other.getTopicsList())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (getTopicsCount() > 0) { - hash = (37 * hash) + TOPICS_FIELD_NUMBER; - hash = (53 * hash) + getTopicsList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.GetTopicSubscriptionsEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.GetTopicSubscriptionsEnvelope) - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetTopicSubscriptionsEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.class, io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - topics_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope build() { - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope buildPartial() { - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope result = new io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope(this); - int from_bitField0_ = bitField0_; - if (((bitField0_ & 0x00000001) != 0)) { - topics_ = topics_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.topics_ = topics_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope other) { - if (other == io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope.getDefaultInstance()) return this; - if (!other.topics_.isEmpty()) { - if (topics_.isEmpty()) { - topics_ = other.topics_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureTopicsIsMutable(); - topics_.addAll(other.topics_); - } - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.LazyStringList topics_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureTopicsIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - topics_ = new com.google.protobuf.LazyStringArrayList(topics_); - bitField0_ |= 0x00000001; - } - } - /** - * repeated string topics = 1; - * @return A list containing the topics. - */ - public com.google.protobuf.ProtocolStringList - getTopicsList() { - return topics_.getUnmodifiableView(); - } - /** - * repeated string topics = 1; - * @return The count of topics. - */ - public int getTopicsCount() { - return topics_.size(); - } - /** - * repeated string topics = 1; - * @param index The index of the element to return. - * @return The topics at the given index. - */ - public java.lang.String getTopics(int index) { - return topics_.get(index); - } - /** - * repeated string topics = 1; - * @param index The index of the value to return. - * @return The bytes of the topics at the given index. - */ - public com.google.protobuf.ByteString - getTopicsBytes(int index) { - return topics_.getByteString(index); - } - /** - * repeated string topics = 1; - * @param index The index to set the value at. - * @param value The topics to set. - * @return This builder for chaining. - */ - public Builder setTopics( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureTopicsIsMutable(); - topics_.set(index, value); - onChanged(); - return this; - } - /** - * repeated string topics = 1; - * @param value The topics to add. - * @return This builder for chaining. - */ - public Builder addTopics( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureTopicsIsMutable(); - topics_.add(value); - onChanged(); - return this; - } - /** - * repeated string topics = 1; - * @param values The topics to add. - * @return This builder for chaining. - */ - public Builder addAllTopics( - java.lang.Iterable values) { - ensureTopicsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, topics_); - onChanged(); - return this; - } - /** - * repeated string topics = 1; - * @return This builder for chaining. - */ - public Builder clearTopics() { - topics_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - * repeated string topics = 1; - * @param value The bytes of the topics to add. - * @return This builder for chaining. - */ - public Builder addTopicsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureTopicsIsMutable(); - topics_.add(value); - onChanged(); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.GetTopicSubscriptionsEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.GetTopicSubscriptionsEnvelope) - private static final io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope(); - } - - public static io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public GetTopicSubscriptionsEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new GetTopicSubscriptionsEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetTopicSubscriptionsEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface GetBindingsSubscriptionsEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.GetBindingsSubscriptionsEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * repeated string bindings = 1; - * @return A list containing the bindings. - */ - java.util.List - getBindingsList(); - /** - * repeated string bindings = 1; - * @return The count of bindings. - */ - int getBindingsCount(); - /** - * repeated string bindings = 1; - * @param index The index of the element to return. - * @return The bindings at the given index. - */ - java.lang.String getBindings(int index); - /** - * repeated string bindings = 1; - * @param index The index of the value to return. - * @return The bytes of the bindings at the given index. - */ - com.google.protobuf.ByteString - getBindingsBytes(int index); - } - /** - * Protobuf type {@code daprclient.GetBindingsSubscriptionsEnvelope} - */ - public static final class GetBindingsSubscriptionsEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.GetBindingsSubscriptionsEnvelope) - GetBindingsSubscriptionsEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use GetBindingsSubscriptionsEnvelope.newBuilder() to construct. - private GetBindingsSubscriptionsEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private GetBindingsSubscriptionsEnvelope() { - bindings_ = com.google.protobuf.LazyStringArrayList.EMPTY; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new GetBindingsSubscriptionsEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private GetBindingsSubscriptionsEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - bindings_ = new com.google.protobuf.LazyStringArrayList(); - mutable_bitField0_ |= 0x00000001; - } - bindings_.add(s); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) != 0)) { - bindings_ = bindings_.getUnmodifiableView(); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetBindingsSubscriptionsEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.class, io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.Builder.class); - } - - public static final int BINDINGS_FIELD_NUMBER = 1; - private com.google.protobuf.LazyStringList bindings_; - /** - * repeated string bindings = 1; - * @return A list containing the bindings. - */ - public com.google.protobuf.ProtocolStringList - getBindingsList() { - return bindings_; - } - /** - * repeated string bindings = 1; - * @return The count of bindings. - */ - public int getBindingsCount() { - return bindings_.size(); - } - /** - * repeated string bindings = 1; - * @param index The index of the element to return. - * @return The bindings at the given index. - */ - public java.lang.String getBindings(int index) { - return bindings_.get(index); - } - /** - * repeated string bindings = 1; - * @param index The index of the value to return. - * @return The bytes of the bindings at the given index. - */ - public com.google.protobuf.ByteString - getBindingsBytes(int index) { - return bindings_.getByteString(index); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < bindings_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, bindings_.getRaw(i)); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - { - int dataSize = 0; - for (int i = 0; i < bindings_.size(); i++) { - dataSize += computeStringSizeNoTag(bindings_.getRaw(i)); - } - size += dataSize; - size += 1 * getBindingsList().size(); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope other = (io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope) obj; - - if (!getBindingsList() - .equals(other.getBindingsList())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (getBindingsCount() > 0) { - hash = (37 * hash) + BINDINGS_FIELD_NUMBER; - hash = (53 * hash) + getBindingsList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.GetBindingsSubscriptionsEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.GetBindingsSubscriptionsEnvelope) - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetBindingsSubscriptionsEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.class, io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - bindings_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope build() { - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope buildPartial() { - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope result = new io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope(this); - int from_bitField0_ = bitField0_; - if (((bitField0_ & 0x00000001) != 0)) { - bindings_ = bindings_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.bindings_ = bindings_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope) { - return mergeFrom((io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope other) { - if (other == io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope.getDefaultInstance()) return this; - if (!other.bindings_.isEmpty()) { - if (bindings_.isEmpty()) { - bindings_ = other.bindings_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureBindingsIsMutable(); - bindings_.addAll(other.bindings_); - } - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.LazyStringList bindings_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureBindingsIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - bindings_ = new com.google.protobuf.LazyStringArrayList(bindings_); - bitField0_ |= 0x00000001; - } - } - /** - * repeated string bindings = 1; - * @return A list containing the bindings. - */ - public com.google.protobuf.ProtocolStringList - getBindingsList() { - return bindings_.getUnmodifiableView(); - } - /** - * repeated string bindings = 1; - * @return The count of bindings. - */ - public int getBindingsCount() { - return bindings_.size(); - } - /** - * repeated string bindings = 1; - * @param index The index of the element to return. - * @return The bindings at the given index. - */ - public java.lang.String getBindings(int index) { - return bindings_.get(index); - } - /** - * repeated string bindings = 1; - * @param index The index of the value to return. - * @return The bytes of the bindings at the given index. - */ - public com.google.protobuf.ByteString - getBindingsBytes(int index) { - return bindings_.getByteString(index); - } - /** - * repeated string bindings = 1; - * @param index The index to set the value at. - * @param value The bindings to set. - * @return This builder for chaining. - */ - public Builder setBindings( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureBindingsIsMutable(); - bindings_.set(index, value); - onChanged(); - return this; - } - /** - * repeated string bindings = 1; - * @param value The bindings to add. - * @return This builder for chaining. - */ - public Builder addBindings( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureBindingsIsMutable(); - bindings_.add(value); - onChanged(); - return this; - } - /** - * repeated string bindings = 1; - * @param values The bindings to add. - * @return This builder for chaining. - */ - public Builder addAllBindings( - java.lang.Iterable values) { - ensureBindingsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, bindings_); - onChanged(); - return this; - } - /** - * repeated string bindings = 1; - * @return This builder for chaining. - */ - public Builder clearBindings() { - bindings_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - return this; - } - /** - * repeated string bindings = 1; - * @param value The bytes of the bindings to add. - * @return This builder for chaining. - */ - public Builder addBindingsBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - ensureBindingsIsMutable(); - bindings_.add(value); - onChanged(); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.GetBindingsSubscriptionsEnvelope) - } - - // @@protoc_insertion_point(class_scope:daprclient.GetBindingsSubscriptionsEnvelope) - private static final io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope(); - } - - public static io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public GetBindingsSubscriptionsEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new GetBindingsSubscriptionsEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.GetBindingsSubscriptionsEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.State) - com.google.protobuf.MessageOrBuilder { - - /** - * string key = 1; - * @return The key. - */ - java.lang.String getKey(); - /** - * string key = 1; - * @return The bytes for key. - */ - com.google.protobuf.ByteString - getKeyBytes(); - - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - boolean hasValue(); - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - com.google.protobuf.Any getValue(); - /** - * .google.protobuf.Any value = 2; - */ - com.google.protobuf.AnyOrBuilder getValueOrBuilder(); - - /** - * string etag = 3; - * @return The etag. - */ - java.lang.String getEtag(); - /** - * string etag = 3; - * @return The bytes for etag. - */ - com.google.protobuf.ByteString - getEtagBytes(); - - /** - * map<string, string> metadata = 4; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 4; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 4; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - - /** - * .daprclient.StateOptions options = 5; - * @return Whether the options field is set. - */ - boolean hasOptions(); - /** - * .daprclient.StateOptions options = 5; - * @return The options. - */ - io.dapr.DaprClientProtos.StateOptions getOptions(); - /** - * .daprclient.StateOptions options = 5; - */ - io.dapr.DaprClientProtos.StateOptionsOrBuilder getOptionsOrBuilder(); - } - /** - * Protobuf type {@code daprclient.State} - */ - public static final class State extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.State) - StateOrBuilder { - private static final long serialVersionUID = 0L; - // Use State.newBuilder() to construct. - private State(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private State() { - key_ = ""; - etag_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new State(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private State( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - key_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (value_ != null) { - subBuilder = value_.toBuilder(); - } - value_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(value_); - value_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - etag_ = s; - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - case 42: { - io.dapr.DaprClientProtos.StateOptions.Builder subBuilder = null; - if (options_ != null) { - subBuilder = options_.toBuilder(); - } - options_ = input.readMessage(io.dapr.DaprClientProtos.StateOptions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(options_); - options_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_State_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_State_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.State.class, io.dapr.DaprClientProtos.State.Builder.class); - } - - public static final int KEY_FIELD_NUMBER = 1; - private volatile java.lang.Object key_; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int VALUE_FIELD_NUMBER = 2; - private com.google.protobuf.Any value_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - return getValue(); - } - - public static final int ETAG_FIELD_NUMBER = 3; - private volatile java.lang.Object etag_; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int METADATA_FIELD_NUMBER = 4; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprClientProtos.internal_static_daprclient_State_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public static final int OPTIONS_FIELD_NUMBER = 5; - private io.dapr.DaprClientProtos.StateOptions options_; - /** - * .daprclient.StateOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return options_ != null; - } - /** - * .daprclient.StateOptions options = 5; - * @return The options. - */ - public io.dapr.DaprClientProtos.StateOptions getOptions() { - return options_ == null ? io.dapr.DaprClientProtos.StateOptions.getDefaultInstance() : options_; - } - /** - * .daprclient.StateOptions options = 5; - */ - public io.dapr.DaprClientProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - return getOptions(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getKeyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); - } - if (value_ != null) { - output.writeMessage(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, etag_); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 4); - if (options_ != null) { - output.writeMessage(5, getOptions()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getKeyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); - } - if (value_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, etag_); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, metadata__); - } - if (options_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getOptions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.State)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.State other = (io.dapr.DaprClientProtos.State) obj; - - if (!getKey() - .equals(other.getKey())) return false; - if (hasValue() != other.hasValue()) return false; - if (hasValue()) { - if (!getValue() - .equals(other.getValue())) return false; - } - if (!getEtag() - .equals(other.getEtag())) return false; - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (hasOptions() != other.hasOptions()) return false; - if (hasOptions()) { - if (!getOptions() - .equals(other.getOptions())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + KEY_FIELD_NUMBER; - hash = (53 * hash) + getKey().hashCode(); - if (hasValue()) { - hash = (37 * hash) + VALUE_FIELD_NUMBER; - hash = (53 * hash) + getValue().hashCode(); - } - hash = (37 * hash) + ETAG_FIELD_NUMBER; - hash = (53 * hash) + getEtag().hashCode(); - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - if (hasOptions()) { - hash = (37 * hash) + OPTIONS_FIELD_NUMBER; - hash = (53 * hash) + getOptions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.State parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.State parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.State parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.State parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.State parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.State parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.State parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.State parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.State parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.State parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.State parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.State parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.State prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.State} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.State) - io.dapr.DaprClientProtos.StateOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_State_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 4: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_State_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.State.class, io.dapr.DaprClientProtos.State.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.State.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - key_ = ""; - - if (valueBuilder_ == null) { - value_ = null; - } else { - value_ = null; - valueBuilder_ = null; - } - etag_ = ""; - - internalGetMutableMetadata().clear(); - if (optionsBuilder_ == null) { - options_ = null; - } else { - options_ = null; - optionsBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_State_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.State getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.State.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.State build() { - io.dapr.DaprClientProtos.State result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.State buildPartial() { - io.dapr.DaprClientProtos.State result = new io.dapr.DaprClientProtos.State(this); - int from_bitField0_ = bitField0_; - result.key_ = key_; - if (valueBuilder_ == null) { - result.value_ = value_; - } else { - result.value_ = valueBuilder_.build(); - } - result.etag_ = etag_; - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - if (optionsBuilder_ == null) { - result.options_ = options_; - } else { - result.options_ = optionsBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.State) { - return mergeFrom((io.dapr.DaprClientProtos.State)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.State other) { - if (other == io.dapr.DaprClientProtos.State.getDefaultInstance()) return this; - if (!other.getKey().isEmpty()) { - key_ = other.key_; - onChanged(); - } - if (other.hasValue()) { - mergeValue(other.getValue()); - } - if (!other.getEtag().isEmpty()) { - etag_ = other.etag_; - onChanged(); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - if (other.hasOptions()) { - mergeOptions(other.getOptions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.State parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.State) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object key_ = ""; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string key = 1; - * @param value The key to set. - * @return This builder for chaining. - */ - public Builder setKey( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - key_ = value; - onChanged(); - return this; - } - /** - * string key = 1; - * @return This builder for chaining. - */ - public Builder clearKey() { - - key_ = getDefaultInstance().getKey(); - onChanged(); - return this; - } - /** - * string key = 1; - * @param value The bytes for key to set. - * @return This builder for chaining. - */ - public Builder setKeyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - key_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any value_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> valueBuilder_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return valueBuilder_ != null || value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - if (valueBuilder_ == null) { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } else { - return valueBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - value_ = value; - onChanged(); - } else { - valueBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue( - com.google.protobuf.Any.Builder builderForValue) { - if (valueBuilder_ == null) { - value_ = builderForValue.build(); - onChanged(); - } else { - valueBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder mergeValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value_ != null) { - value_ = - com.google.protobuf.Any.newBuilder(value_).mergeFrom(value).buildPartial(); - } else { - value_ = value; - } - onChanged(); - } else { - valueBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder clearValue() { - if (valueBuilder_ == null) { - value_ = null; - onChanged(); - } else { - value_ = null; - valueBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.Any.Builder getValueBuilder() { - - onChanged(); - return getValueFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - if (valueBuilder_ != null) { - return valueBuilder_.getMessageOrBuilder(); - } else { - return value_ == null ? - com.google.protobuf.Any.getDefaultInstance() : value_; - } - } - /** - * .google.protobuf.Any value = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getValueFieldBuilder() { - if (valueBuilder_ == null) { - valueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getValue(), - getParentForChildren(), - isClean()); - value_ = null; - } - return valueBuilder_; - } - - private java.lang.Object etag_ = ""; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string etag = 3; - * @param value The etag to set. - * @return This builder for chaining. - */ - public Builder setEtag( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - etag_ = value; - onChanged(); - return this; - } - /** - * string etag = 3; - * @return This builder for chaining. - */ - public Builder clearEtag() { - - etag_ = getDefaultInstance().getEtag(); - onChanged(); - return this; - } - /** - * string etag = 3; - * @param value The bytes for etag to set. - * @return This builder for chaining. - */ - public Builder setEtagBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - etag_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 4; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - - private io.dapr.DaprClientProtos.StateOptions options_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.StateOptions, io.dapr.DaprClientProtos.StateOptions.Builder, io.dapr.DaprClientProtos.StateOptionsOrBuilder> optionsBuilder_; - /** - * .daprclient.StateOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return optionsBuilder_ != null || options_ != null; - } - /** - * .daprclient.StateOptions options = 5; - * @return The options. - */ - public io.dapr.DaprClientProtos.StateOptions getOptions() { - if (optionsBuilder_ == null) { - return options_ == null ? io.dapr.DaprClientProtos.StateOptions.getDefaultInstance() : options_; - } else { - return optionsBuilder_.getMessage(); - } - } - /** - * .daprclient.StateOptions options = 5; - */ - public Builder setOptions(io.dapr.DaprClientProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - options_ = value; - onChanged(); - } else { - optionsBuilder_.setMessage(value); - } - - return this; - } - /** - * .daprclient.StateOptions options = 5; - */ - public Builder setOptions( - io.dapr.DaprClientProtos.StateOptions.Builder builderForValue) { - if (optionsBuilder_ == null) { - options_ = builderForValue.build(); - onChanged(); - } else { - optionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .daprclient.StateOptions options = 5; - */ - public Builder mergeOptions(io.dapr.DaprClientProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (options_ != null) { - options_ = - io.dapr.DaprClientProtos.StateOptions.newBuilder(options_).mergeFrom(value).buildPartial(); - } else { - options_ = value; - } - onChanged(); - } else { - optionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .daprclient.StateOptions options = 5; - */ - public Builder clearOptions() { - if (optionsBuilder_ == null) { - options_ = null; - onChanged(); - } else { - options_ = null; - optionsBuilder_ = null; - } - - return this; - } - /** - * .daprclient.StateOptions options = 5; - */ - public io.dapr.DaprClientProtos.StateOptions.Builder getOptionsBuilder() { - - onChanged(); - return getOptionsFieldBuilder().getBuilder(); - } - /** - * .daprclient.StateOptions options = 5; - */ - public io.dapr.DaprClientProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - if (optionsBuilder_ != null) { - return optionsBuilder_.getMessageOrBuilder(); - } else { - return options_ == null ? - io.dapr.DaprClientProtos.StateOptions.getDefaultInstance() : options_; - } - } - /** - * .daprclient.StateOptions options = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.StateOptions, io.dapr.DaprClientProtos.StateOptions.Builder, io.dapr.DaprClientProtos.StateOptionsOrBuilder> - getOptionsFieldBuilder() { - if (optionsBuilder_ == null) { - optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.StateOptions, io.dapr.DaprClientProtos.StateOptions.Builder, io.dapr.DaprClientProtos.StateOptionsOrBuilder>( - getOptions(), - getParentForChildren(), - isClean()); - options_ = null; - } - return optionsBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.State) - } - - // @@protoc_insertion_point(class_scope:daprclient.State) - private static final io.dapr.DaprClientProtos.State DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.State(); - } - - public static io.dapr.DaprClientProtos.State getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public State parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new State(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.State getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateOptionsOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.StateOptions) - com.google.protobuf.MessageOrBuilder { - - /** - * string concurrency = 1; - * @return The concurrency. - */ - java.lang.String getConcurrency(); - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - com.google.protobuf.ByteString - getConcurrencyBytes(); - - /** - * string consistency = 2; - * @return The consistency. - */ - java.lang.String getConsistency(); - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - com.google.protobuf.ByteString - getConsistencyBytes(); - - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - boolean hasRetryPolicy(); - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - io.dapr.DaprClientProtos.RetryPolicy getRetryPolicy(); - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - io.dapr.DaprClientProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder(); - } - /** - * Protobuf type {@code daprclient.StateOptions} - */ - public static final class StateOptions extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.StateOptions) - StateOptionsOrBuilder { - private static final long serialVersionUID = 0L; - // Use StateOptions.newBuilder() to construct. - private StateOptions(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StateOptions() { - concurrency_ = ""; - consistency_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new StateOptions(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StateOptions( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - concurrency_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - consistency_ = s; - break; - } - case 26: { - io.dapr.DaprClientProtos.RetryPolicy.Builder subBuilder = null; - if (retryPolicy_ != null) { - subBuilder = retryPolicy_.toBuilder(); - } - retryPolicy_ = input.readMessage(io.dapr.DaprClientProtos.RetryPolicy.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(retryPolicy_); - retryPolicy_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_StateOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_StateOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.StateOptions.class, io.dapr.DaprClientProtos.StateOptions.Builder.class); - } - - public static final int CONCURRENCY_FIELD_NUMBER = 1; - private volatile java.lang.Object concurrency_; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int CONSISTENCY_FIELD_NUMBER = 2; - private volatile java.lang.Object consistency_; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RETRYPOLICY_FIELD_NUMBER = 3; - private io.dapr.DaprClientProtos.RetryPolicy retryPolicy_; - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicy_ != null; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprClientProtos.RetryPolicy getRetryPolicy() { - return retryPolicy_ == null ? io.dapr.DaprClientProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprClientProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder() { - return getRetryPolicy(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getConcurrencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, consistency_); - } - if (retryPolicy_ != null) { - output.writeMessage(3, getRetryPolicy()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getConcurrencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, consistency_); - } - if (retryPolicy_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getRetryPolicy()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.StateOptions)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.StateOptions other = (io.dapr.DaprClientProtos.StateOptions) obj; - - if (!getConcurrency() - .equals(other.getConcurrency())) return false; - if (!getConsistency() - .equals(other.getConsistency())) return false; - if (hasRetryPolicy() != other.hasRetryPolicy()) return false; - if (hasRetryPolicy()) { - if (!getRetryPolicy() - .equals(other.getRetryPolicy())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + CONCURRENCY_FIELD_NUMBER; - hash = (53 * hash) + getConcurrency().hashCode(); - hash = (37 * hash) + CONSISTENCY_FIELD_NUMBER; - hash = (53 * hash) + getConsistency().hashCode(); - if (hasRetryPolicy()) { - hash = (37 * hash) + RETRYPOLICY_FIELD_NUMBER; - hash = (53 * hash) + getRetryPolicy().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.StateOptions parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.StateOptions parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.StateOptions parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.StateOptions prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.StateOptions} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.StateOptions) - io.dapr.DaprClientProtos.StateOptionsOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_StateOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_StateOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.StateOptions.class, io.dapr.DaprClientProtos.StateOptions.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.StateOptions.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - concurrency_ = ""; - - consistency_ = ""; - - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_StateOptions_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.StateOptions getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.StateOptions.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.StateOptions build() { - io.dapr.DaprClientProtos.StateOptions result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.StateOptions buildPartial() { - io.dapr.DaprClientProtos.StateOptions result = new io.dapr.DaprClientProtos.StateOptions(this); - result.concurrency_ = concurrency_; - result.consistency_ = consistency_; - if (retryPolicyBuilder_ == null) { - result.retryPolicy_ = retryPolicy_; - } else { - result.retryPolicy_ = retryPolicyBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.StateOptions) { - return mergeFrom((io.dapr.DaprClientProtos.StateOptions)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.StateOptions other) { - if (other == io.dapr.DaprClientProtos.StateOptions.getDefaultInstance()) return this; - if (!other.getConcurrency().isEmpty()) { - concurrency_ = other.concurrency_; - onChanged(); - } - if (!other.getConsistency().isEmpty()) { - consistency_ = other.consistency_; - onChanged(); - } - if (other.hasRetryPolicy()) { - mergeRetryPolicy(other.getRetryPolicy()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.StateOptions parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.StateOptions) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object concurrency_ = ""; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string concurrency = 1; - * @param value The concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - concurrency_ = value; - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @return This builder for chaining. - */ - public Builder clearConcurrency() { - - concurrency_ = getDefaultInstance().getConcurrency(); - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @param value The bytes for concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - concurrency_ = value; - onChanged(); - return this; - } - - private java.lang.Object consistency_ = ""; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string consistency = 2; - * @param value The consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - consistency_ = value; - onChanged(); - return this; - } - /** - * string consistency = 2; - * @return This builder for chaining. - */ - public Builder clearConsistency() { - - consistency_ = getDefaultInstance().getConsistency(); - onChanged(); - return this; - } - /** - * string consistency = 2; - * @param value The bytes for consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - consistency_ = value; - onChanged(); - return this; - } - - private io.dapr.DaprClientProtos.RetryPolicy retryPolicy_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.RetryPolicy, io.dapr.DaprClientProtos.RetryPolicy.Builder, io.dapr.DaprClientProtos.RetryPolicyOrBuilder> retryPolicyBuilder_; - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicyBuilder_ != null || retryPolicy_ != null; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprClientProtos.RetryPolicy getRetryPolicy() { - if (retryPolicyBuilder_ == null) { - return retryPolicy_ == null ? io.dapr.DaprClientProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } else { - return retryPolicyBuilder_.getMessage(); - } - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy(io.dapr.DaprClientProtos.RetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - retryPolicy_ = value; - onChanged(); - } else { - retryPolicyBuilder_.setMessage(value); - } - - return this; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy( - io.dapr.DaprClientProtos.RetryPolicy.Builder builderForValue) { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = builderForValue.build(); - onChanged(); - } else { - retryPolicyBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public Builder mergeRetryPolicy(io.dapr.DaprClientProtos.RetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (retryPolicy_ != null) { - retryPolicy_ = - io.dapr.DaprClientProtos.RetryPolicy.newBuilder(retryPolicy_).mergeFrom(value).buildPartial(); - } else { - retryPolicy_ = value; - } - onChanged(); - } else { - retryPolicyBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public Builder clearRetryPolicy() { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - onChanged(); - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - - return this; - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprClientProtos.RetryPolicy.Builder getRetryPolicyBuilder() { - - onChanged(); - return getRetryPolicyFieldBuilder().getBuilder(); - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprClientProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder() { - if (retryPolicyBuilder_ != null) { - return retryPolicyBuilder_.getMessageOrBuilder(); - } else { - return retryPolicy_ == null ? - io.dapr.DaprClientProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } - } - /** - * .daprclient.RetryPolicy retryPolicy = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.RetryPolicy, io.dapr.DaprClientProtos.RetryPolicy.Builder, io.dapr.DaprClientProtos.RetryPolicyOrBuilder> - getRetryPolicyFieldBuilder() { - if (retryPolicyBuilder_ == null) { - retryPolicyBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprClientProtos.RetryPolicy, io.dapr.DaprClientProtos.RetryPolicy.Builder, io.dapr.DaprClientProtos.RetryPolicyOrBuilder>( - getRetryPolicy(), - getParentForChildren(), - isClean()); - retryPolicy_ = null; - } - return retryPolicyBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.StateOptions) - } - - // @@protoc_insertion_point(class_scope:daprclient.StateOptions) - private static final io.dapr.DaprClientProtos.StateOptions DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.StateOptions(); - } - - public static io.dapr.DaprClientProtos.StateOptions getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public StateOptions parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StateOptions(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.StateOptions getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface RetryPolicyOrBuilder extends - // @@protoc_insertion_point(interface_extends:daprclient.RetryPolicy) - com.google.protobuf.MessageOrBuilder { - - /** - * int32 threshold = 1; - * @return The threshold. - */ - int getThreshold(); - - /** - * string pattern = 2; - * @return The pattern. - */ - java.lang.String getPattern(); - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - com.google.protobuf.ByteString - getPatternBytes(); - - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - boolean hasInterval(); - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - com.google.protobuf.Duration getInterval(); - /** - * .google.protobuf.Duration interval = 3; - */ - com.google.protobuf.DurationOrBuilder getIntervalOrBuilder(); - } - /** - * Protobuf type {@code daprclient.RetryPolicy} - */ - public static final class RetryPolicy extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:daprclient.RetryPolicy) - RetryPolicyOrBuilder { - private static final long serialVersionUID = 0L; - // Use RetryPolicy.newBuilder() to construct. - private RetryPolicy(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private RetryPolicy() { - pattern_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new RetryPolicy(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private RetryPolicy( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 8: { - - threshold_ = input.readInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - pattern_ = s; - break; - } - case 26: { - com.google.protobuf.Duration.Builder subBuilder = null; - if (interval_ != null) { - subBuilder = interval_.toBuilder(); - } - interval_ = input.readMessage(com.google.protobuf.Duration.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(interval_); - interval_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_RetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_RetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.RetryPolicy.class, io.dapr.DaprClientProtos.RetryPolicy.Builder.class); - } - - public static final int THRESHOLD_FIELD_NUMBER = 1; - private int threshold_; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - - public static final int PATTERN_FIELD_NUMBER = 2; - private volatile java.lang.Object pattern_; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int INTERVAL_FIELD_NUMBER = 3; - private com.google.protobuf.Duration interval_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - return getInterval(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (threshold_ != 0) { - output.writeInt32(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, pattern_); - } - if (interval_ != null) { - output.writeMessage(3, getInterval()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (threshold_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, pattern_); - } - if (interval_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getInterval()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprClientProtos.RetryPolicy)) { - return super.equals(obj); - } - io.dapr.DaprClientProtos.RetryPolicy other = (io.dapr.DaprClientProtos.RetryPolicy) obj; - - if (getThreshold() - != other.getThreshold()) return false; - if (!getPattern() - .equals(other.getPattern())) return false; - if (hasInterval() != other.hasInterval()) return false; - if (hasInterval()) { - if (!getInterval() - .equals(other.getInterval())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + THRESHOLD_FIELD_NUMBER; - hash = (53 * hash) + getThreshold(); - hash = (37 * hash) + PATTERN_FIELD_NUMBER; - hash = (53 * hash) + getPattern().hashCode(); - if (hasInterval()) { - hash = (37 * hash) + INTERVAL_FIELD_NUMBER; - hash = (53 * hash) + getInterval().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprClientProtos.RetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprClientProtos.RetryPolicy prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code daprclient.RetryPolicy} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:daprclient.RetryPolicy) - io.dapr.DaprClientProtos.RetryPolicyOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprClientProtos.internal_static_daprclient_RetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprClientProtos.internal_static_daprclient_RetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprClientProtos.RetryPolicy.class, io.dapr.DaprClientProtos.RetryPolicy.Builder.class); - } - - // Construct using io.dapr.DaprClientProtos.RetryPolicy.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - threshold_ = 0; - - pattern_ = ""; - - if (intervalBuilder_ == null) { - interval_ = null; - } else { - interval_ = null; - intervalBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprClientProtos.internal_static_daprclient_RetryPolicy_descriptor; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.RetryPolicy getDefaultInstanceForType() { - return io.dapr.DaprClientProtos.RetryPolicy.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprClientProtos.RetryPolicy build() { - io.dapr.DaprClientProtos.RetryPolicy result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.RetryPolicy buildPartial() { - io.dapr.DaprClientProtos.RetryPolicy result = new io.dapr.DaprClientProtos.RetryPolicy(this); - result.threshold_ = threshold_; - result.pattern_ = pattern_; - if (intervalBuilder_ == null) { - result.interval_ = interval_; - } else { - result.interval_ = intervalBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprClientProtos.RetryPolicy) { - return mergeFrom((io.dapr.DaprClientProtos.RetryPolicy)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprClientProtos.RetryPolicy other) { - if (other == io.dapr.DaprClientProtos.RetryPolicy.getDefaultInstance()) return this; - if (other.getThreshold() != 0) { - setThreshold(other.getThreshold()); - } - if (!other.getPattern().isEmpty()) { - pattern_ = other.pattern_; - onChanged(); - } - if (other.hasInterval()) { - mergeInterval(other.getInterval()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprClientProtos.RetryPolicy parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprClientProtos.RetryPolicy) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int threshold_ ; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - /** - * int32 threshold = 1; - * @param value The threshold to set. - * @return This builder for chaining. - */ - public Builder setThreshold(int value) { - - threshold_ = value; - onChanged(); - return this; - } - /** - * int32 threshold = 1; - * @return This builder for chaining. - */ - public Builder clearThreshold() { - - threshold_ = 0; - onChanged(); - return this; - } - - private java.lang.Object pattern_ = ""; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string pattern = 2; - * @param value The pattern to set. - * @return This builder for chaining. - */ - public Builder setPattern( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - pattern_ = value; - onChanged(); - return this; - } - /** - * string pattern = 2; - * @return This builder for chaining. - */ - public Builder clearPattern() { - - pattern_ = getDefaultInstance().getPattern(); - onChanged(); - return this; - } - /** - * string pattern = 2; - * @param value The bytes for pattern to set. - * @return This builder for chaining. - */ - public Builder setPatternBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - pattern_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Duration interval_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> intervalBuilder_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return intervalBuilder_ != null || interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - if (intervalBuilder_ == null) { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } else { - return intervalBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - interval_ = value; - onChanged(); - } else { - intervalBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval( - com.google.protobuf.Duration.Builder builderForValue) { - if (intervalBuilder_ == null) { - interval_ = builderForValue.build(); - onChanged(); - } else { - intervalBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder mergeInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (interval_ != null) { - interval_ = - com.google.protobuf.Duration.newBuilder(interval_).mergeFrom(value).buildPartial(); - } else { - interval_ = value; - } - onChanged(); - } else { - intervalBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder clearInterval() { - if (intervalBuilder_ == null) { - interval_ = null; - onChanged(); - } else { - interval_ = null; - intervalBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.Duration.Builder getIntervalBuilder() { - - onChanged(); - return getIntervalFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - if (intervalBuilder_ != null) { - return intervalBuilder_.getMessageOrBuilder(); - } else { - return interval_ == null ? - com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> - getIntervalFieldBuilder() { - if (intervalBuilder_ == null) { - intervalBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder>( - getInterval(), - getParentForChildren(), - isClean()); - interval_ = null; - } - return intervalBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:daprclient.RetryPolicy) - } - - // @@protoc_insertion_point(class_scope:daprclient.RetryPolicy) - private static final io.dapr.DaprClientProtos.RetryPolicy DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprClientProtos.RetryPolicy(); - } - - public static io.dapr.DaprClientProtos.RetryPolicy getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public RetryPolicy parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new RetryPolicy(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprClientProtos.RetryPolicy getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_CloudEventEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_CloudEventEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_BindingEventEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_BindingEventEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_BindingEventEnvelope_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_BindingEventEnvelope_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_BindingResponseEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_BindingResponseEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_InvokeEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_InvokeEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_InvokeEnvelope_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_InvokeEnvelope_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_GetTopicSubscriptionsEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_GetBindingsSubscriptionsEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_State_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_State_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_State_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_State_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_StateOptions_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_StateOptions_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_daprclient_RetryPolicy_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_daprclient_RetryPolicy_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\020daprclient.proto\022\ndaprclient\032\031google/p" + - "rotobuf/any.proto\032\033google/protobuf/empty" + - ".proto\032\036google/protobuf/duration.proto\"\237" + - "\001\n\022CloudEventEnvelope\022\n\n\002id\030\001 \001(\t\022\016\n\006sou" + - "rce\030\002 \001(\t\022\014\n\004type\030\003 \001(\t\022\023\n\013specVersion\030\004" + - " \001(\t\022\027\n\017dataContentType\030\005 \001(\t\022\r\n\005topic\030\006" + - " \001(\t\022\"\n\004data\030\007 \001(\0132\024.google.protobuf.Any" + - "\"\273\001\n\024BindingEventEnvelope\022\014\n\004name\030\001 \001(\t\022" + - "\"\n\004data\030\002 \001(\0132\024.google.protobuf.Any\022@\n\010m" + - "etadata\030\003 \003(\0132..daprclient.BindingEventE" + - "nvelope.MetadataEntry\032/\n\rMetadataEntry\022\013" + - "\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"\200\001\n\027Bindi" + - "ngResponseEnvelope\022\"\n\004data\030\001 \001(\0132\024.googl" + - "e.protobuf.Any\022\n\n\002to\030\002 \003(\t\022 \n\005state\030\003 \003(" + - "\0132\021.daprclient.State\022\023\n\013concurrency\030\004 \001(" + - "\t\"\261\001\n\016InvokeEnvelope\022\016\n\006method\030\001 \001(\t\022\"\n\004" + - "data\030\002 \001(\0132\024.google.protobuf.Any\022:\n\010meta" + - "data\030\003 \003(\0132(.daprclient.InvokeEnvelope.M" + - "etadataEntry\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001" + - "(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"/\n\035GetTopicSubscri" + - "ptionsEnvelope\022\016\n\006topics\030\001 \003(\t\"4\n GetBin" + - "dingsSubscriptionsEnvelope\022\020\n\010bindings\030\001" + - " \003(\t\"\326\001\n\005State\022\013\n\003key\030\001 \001(\t\022#\n\005value\030\002 \001" + - "(\0132\024.google.protobuf.Any\022\014\n\004etag\030\003 \001(\t\0221" + - "\n\010metadata\030\004 \003(\0132\037.daprclient.State.Meta" + - "dataEntry\022)\n\007options\030\005 \001(\0132\030.daprclient." + - "StateOptions\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001" + - "(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"f\n\014StateOptions\022\023\n" + - "\013concurrency\030\001 \001(\t\022\023\n\013consistency\030\002 \001(\t\022" + - ",\n\013retryPolicy\030\003 \001(\0132\027.daprclient.RetryP" + - "olicy\"^\n\013RetryPolicy\022\021\n\tthreshold\030\001 \001(\005\022" + - "\017\n\007pattern\030\002 \001(\t\022+\n\010interval\030\003 \001(\0132\031.goo" + - "gle.protobuf.Duration2\263\003\n\nDaprClient\022>\n\010" + - "OnInvoke\022\032.daprclient.InvokeEnvelope\032\024.g" + - "oogle.protobuf.Any\"\000\022\\\n\025GetTopicSubscrip" + - "tions\022\026.google.protobuf.Empty\032).daprclie" + - "nt.GetTopicSubscriptionsEnvelope\"\000\022b\n\030Ge" + - "tBindingsSubscriptions\022\026.google.protobuf" + - ".Empty\032,.daprclient.GetBindingsSubscript" + - "ionsEnvelope\"\000\022Y\n\016OnBindingEvent\022 .daprc" + - "lient.BindingEventEnvelope\032#.daprclient." + - "BindingResponseEnvelope\"\000\022H\n\014OnTopicEven" + - "t\022\036.daprclient.CloudEventEnvelope\032\026.goog" + - "le.protobuf.Empty\"\000B\033\n\007io.daprB\020DaprClie" + - "ntProtosb\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - com.google.protobuf.AnyProto.getDescriptor(), - com.google.protobuf.EmptyProto.getDescriptor(), - com.google.protobuf.DurationProto.getDescriptor(), - }); - internal_static_daprclient_CloudEventEnvelope_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_daprclient_CloudEventEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_CloudEventEnvelope_descriptor, - new java.lang.String[] { "Id", "Source", "Type", "SpecVersion", "DataContentType", "Topic", "Data", }); - internal_static_daprclient_BindingEventEnvelope_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_daprclient_BindingEventEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_BindingEventEnvelope_descriptor, - new java.lang.String[] { "Name", "Data", "Metadata", }); - internal_static_daprclient_BindingEventEnvelope_MetadataEntry_descriptor = - internal_static_daprclient_BindingEventEnvelope_descriptor.getNestedTypes().get(0); - internal_static_daprclient_BindingEventEnvelope_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_BindingEventEnvelope_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_daprclient_BindingResponseEnvelope_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_daprclient_BindingResponseEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_BindingResponseEnvelope_descriptor, - new java.lang.String[] { "Data", "To", "State", "Concurrency", }); - internal_static_daprclient_InvokeEnvelope_descriptor = - getDescriptor().getMessageTypes().get(3); - internal_static_daprclient_InvokeEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_InvokeEnvelope_descriptor, - new java.lang.String[] { "Method", "Data", "Metadata", }); - internal_static_daprclient_InvokeEnvelope_MetadataEntry_descriptor = - internal_static_daprclient_InvokeEnvelope_descriptor.getNestedTypes().get(0); - internal_static_daprclient_InvokeEnvelope_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_InvokeEnvelope_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor = - getDescriptor().getMessageTypes().get(4); - internal_static_daprclient_GetTopicSubscriptionsEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_GetTopicSubscriptionsEnvelope_descriptor, - new java.lang.String[] { "Topics", }); - internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor = - getDescriptor().getMessageTypes().get(5); - internal_static_daprclient_GetBindingsSubscriptionsEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_GetBindingsSubscriptionsEnvelope_descriptor, - new java.lang.String[] { "Bindings", }); - internal_static_daprclient_State_descriptor = - getDescriptor().getMessageTypes().get(6); - internal_static_daprclient_State_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_State_descriptor, - new java.lang.String[] { "Key", "Value", "Etag", "Metadata", "Options", }); - internal_static_daprclient_State_MetadataEntry_descriptor = - internal_static_daprclient_State_descriptor.getNestedTypes().get(0); - internal_static_daprclient_State_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_State_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_daprclient_StateOptions_descriptor = - getDescriptor().getMessageTypes().get(7); - internal_static_daprclient_StateOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_StateOptions_descriptor, - new java.lang.String[] { "Concurrency", "Consistency", "RetryPolicy", }); - internal_static_daprclient_RetryPolicy_descriptor = - getDescriptor().getMessageTypes().get(8); - internal_static_daprclient_RetryPolicy_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_daprclient_RetryPolicy_descriptor, - new java.lang.String[] { "Threshold", "Pattern", "Interval", }); - com.google.protobuf.AnyProto.getDescriptor(); - com.google.protobuf.EmptyProto.getDescriptor(); - com.google.protobuf.DurationProto.getDescriptor(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/sdk/src/main/java/io/dapr/DaprGrpc.java b/sdk/src/main/java/io/dapr/DaprGrpc.java deleted file mode 100644 index 78c3cc2fd..000000000 --- a/sdk/src/main/java/io/dapr/DaprGrpc.java +++ /dev/null @@ -1,664 +0,0 @@ -package io.dapr; - -import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -/** - *
- * Dapr definitions
- * 
- */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.25.0)", - comments = "Source: dapr.proto") -public final class DaprGrpc { - - private DaprGrpc() {} - - public static final String SERVICE_NAME = "dapr.Dapr"; - - // Static method descriptors that strictly reflect the proto. - private static volatile io.grpc.MethodDescriptor getPublishEventMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "PublishEvent", - requestType = io.dapr.DaprProtos.PublishEventEnvelope.class, - responseType = com.google.protobuf.Empty.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getPublishEventMethod() { - io.grpc.MethodDescriptor getPublishEventMethod; - if ((getPublishEventMethod = DaprGrpc.getPublishEventMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getPublishEventMethod = DaprGrpc.getPublishEventMethod) == null) { - DaprGrpc.getPublishEventMethod = getPublishEventMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "PublishEvent")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.PublishEventEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("PublishEvent")) - .build(); - } - } - } - return getPublishEventMethod; - } - - private static volatile io.grpc.MethodDescriptor getInvokeServiceMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "InvokeService", - requestType = io.dapr.DaprProtos.InvokeServiceEnvelope.class, - responseType = io.dapr.DaprProtos.InvokeServiceResponseEnvelope.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getInvokeServiceMethod() { - io.grpc.MethodDescriptor getInvokeServiceMethod; - if ((getInvokeServiceMethod = DaprGrpc.getInvokeServiceMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getInvokeServiceMethod = DaprGrpc.getInvokeServiceMethod) == null) { - DaprGrpc.getInvokeServiceMethod = getInvokeServiceMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "InvokeService")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.InvokeServiceEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.InvokeServiceResponseEnvelope.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("InvokeService")) - .build(); - } - } - } - return getInvokeServiceMethod; - } - - private static volatile io.grpc.MethodDescriptor getInvokeBindingMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "InvokeBinding", - requestType = io.dapr.DaprProtos.InvokeBindingEnvelope.class, - responseType = com.google.protobuf.Empty.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getInvokeBindingMethod() { - io.grpc.MethodDescriptor getInvokeBindingMethod; - if ((getInvokeBindingMethod = DaprGrpc.getInvokeBindingMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getInvokeBindingMethod = DaprGrpc.getInvokeBindingMethod) == null) { - DaprGrpc.getInvokeBindingMethod = getInvokeBindingMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "InvokeBinding")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.InvokeBindingEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("InvokeBinding")) - .build(); - } - } - } - return getInvokeBindingMethod; - } - - private static volatile io.grpc.MethodDescriptor getGetStateMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "GetState", - requestType = io.dapr.DaprProtos.GetStateEnvelope.class, - responseType = io.dapr.DaprProtos.GetStateResponseEnvelope.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getGetStateMethod() { - io.grpc.MethodDescriptor getGetStateMethod; - if ((getGetStateMethod = DaprGrpc.getGetStateMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getGetStateMethod = DaprGrpc.getGetStateMethod) == null) { - DaprGrpc.getGetStateMethod = getGetStateMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "GetState")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.GetStateEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.GetStateResponseEnvelope.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("GetState")) - .build(); - } - } - } - return getGetStateMethod; - } - - private static volatile io.grpc.MethodDescriptor getSaveStateMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "SaveState", - requestType = io.dapr.DaprProtos.SaveStateEnvelope.class, - responseType = com.google.protobuf.Empty.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getSaveStateMethod() { - io.grpc.MethodDescriptor getSaveStateMethod; - if ((getSaveStateMethod = DaprGrpc.getSaveStateMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getSaveStateMethod = DaprGrpc.getSaveStateMethod) == null) { - DaprGrpc.getSaveStateMethod = getSaveStateMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "SaveState")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.SaveStateEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("SaveState")) - .build(); - } - } - } - return getSaveStateMethod; - } - - private static volatile io.grpc.MethodDescriptor getDeleteStateMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "DeleteState", - requestType = io.dapr.DaprProtos.DeleteStateEnvelope.class, - responseType = com.google.protobuf.Empty.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getDeleteStateMethod() { - io.grpc.MethodDescriptor getDeleteStateMethod; - if ((getDeleteStateMethod = DaprGrpc.getDeleteStateMethod) == null) { - synchronized (DaprGrpc.class) { - if ((getDeleteStateMethod = DaprGrpc.getDeleteStateMethod) == null) { - DaprGrpc.getDeleteStateMethod = getDeleteStateMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "DeleteState")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.dapr.DaprProtos.DeleteStateEnvelope.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - com.google.protobuf.Empty.getDefaultInstance())) - .setSchemaDescriptor(new DaprMethodDescriptorSupplier("DeleteState")) - .build(); - } - } - } - return getDeleteStateMethod; - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static DaprStub newStub(io.grpc.Channel channel) { - return new DaprStub(channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static DaprBlockingStub newBlockingStub( - io.grpc.Channel channel) { - return new DaprBlockingStub(channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static DaprFutureStub newFutureStub( - io.grpc.Channel channel) { - return new DaprFutureStub(channel); - } - - /** - *
-   * Dapr definitions
-   * 
- */ - public static abstract class DaprImplBase implements io.grpc.BindableService { - - /** - */ - public void publishEvent(io.dapr.DaprProtos.PublishEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getPublishEventMethod(), responseObserver); - } - - /** - */ - public void invokeService(io.dapr.DaprProtos.InvokeServiceEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getInvokeServiceMethod(), responseObserver); - } - - /** - */ - public void invokeBinding(io.dapr.DaprProtos.InvokeBindingEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getInvokeBindingMethod(), responseObserver); - } - - /** - */ - public void getState(io.dapr.DaprProtos.GetStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getGetStateMethod(), responseObserver); - } - - /** - */ - public void saveState(io.dapr.DaprProtos.SaveStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getSaveStateMethod(), responseObserver); - } - - /** - */ - public void deleteState(io.dapr.DaprProtos.DeleteStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getDeleteStateMethod(), responseObserver); - } - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getPublishEventMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.PublishEventEnvelope, - com.google.protobuf.Empty>( - this, METHODID_PUBLISH_EVENT))) - .addMethod( - getInvokeServiceMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.InvokeServiceEnvelope, - io.dapr.DaprProtos.InvokeServiceResponseEnvelope>( - this, METHODID_INVOKE_SERVICE))) - .addMethod( - getInvokeBindingMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.InvokeBindingEnvelope, - com.google.protobuf.Empty>( - this, METHODID_INVOKE_BINDING))) - .addMethod( - getGetStateMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.GetStateEnvelope, - io.dapr.DaprProtos.GetStateResponseEnvelope>( - this, METHODID_GET_STATE))) - .addMethod( - getSaveStateMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.SaveStateEnvelope, - com.google.protobuf.Empty>( - this, METHODID_SAVE_STATE))) - .addMethod( - getDeleteStateMethod(), - asyncUnaryCall( - new MethodHandlers< - io.dapr.DaprProtos.DeleteStateEnvelope, - com.google.protobuf.Empty>( - this, METHODID_DELETE_STATE))) - .build(); - } - } - - /** - *
-   * Dapr definitions
-   * 
- */ - public static final class DaprStub extends io.grpc.stub.AbstractStub { - private DaprStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprStub(channel, callOptions); - } - - /** - */ - public void publishEvent(io.dapr.DaprProtos.PublishEventEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getPublishEventMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void invokeService(io.dapr.DaprProtos.InvokeServiceEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getInvokeServiceMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void invokeBinding(io.dapr.DaprProtos.InvokeBindingEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getInvokeBindingMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void getState(io.dapr.DaprProtos.GetStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getGetStateMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void saveState(io.dapr.DaprProtos.SaveStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getSaveStateMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void deleteState(io.dapr.DaprProtos.DeleteStateEnvelope request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getDeleteStateMethod(), getCallOptions()), request, responseObserver); - } - } - - /** - *
-   * Dapr definitions
-   * 
- */ - public static final class DaprBlockingStub extends io.grpc.stub.AbstractStub { - private DaprBlockingStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprBlockingStub(channel, callOptions); - } - - /** - */ - public com.google.protobuf.Empty publishEvent(io.dapr.DaprProtos.PublishEventEnvelope request) { - return blockingUnaryCall( - getChannel(), getPublishEventMethod(), getCallOptions(), request); - } - - /** - */ - public io.dapr.DaprProtos.InvokeServiceResponseEnvelope invokeService(io.dapr.DaprProtos.InvokeServiceEnvelope request) { - return blockingUnaryCall( - getChannel(), getInvokeServiceMethod(), getCallOptions(), request); - } - - /** - */ - public com.google.protobuf.Empty invokeBinding(io.dapr.DaprProtos.InvokeBindingEnvelope request) { - return blockingUnaryCall( - getChannel(), getInvokeBindingMethod(), getCallOptions(), request); - } - - /** - */ - public io.dapr.DaprProtos.GetStateResponseEnvelope getState(io.dapr.DaprProtos.GetStateEnvelope request) { - return blockingUnaryCall( - getChannel(), getGetStateMethod(), getCallOptions(), request); - } - - /** - */ - public com.google.protobuf.Empty saveState(io.dapr.DaprProtos.SaveStateEnvelope request) { - return blockingUnaryCall( - getChannel(), getSaveStateMethod(), getCallOptions(), request); - } - - /** - */ - public com.google.protobuf.Empty deleteState(io.dapr.DaprProtos.DeleteStateEnvelope request) { - return blockingUnaryCall( - getChannel(), getDeleteStateMethod(), getCallOptions(), request); - } - } - - /** - *
-   * Dapr definitions
-   * 
- */ - public static final class DaprFutureStub extends io.grpc.stub.AbstractStub { - private DaprFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private DaprFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected DaprFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new DaprFutureStub(channel, callOptions); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture publishEvent( - io.dapr.DaprProtos.PublishEventEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getPublishEventMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture invokeService( - io.dapr.DaprProtos.InvokeServiceEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getInvokeServiceMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture invokeBinding( - io.dapr.DaprProtos.InvokeBindingEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getInvokeBindingMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture getState( - io.dapr.DaprProtos.GetStateEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getGetStateMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture saveState( - io.dapr.DaprProtos.SaveStateEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getSaveStateMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture deleteState( - io.dapr.DaprProtos.DeleteStateEnvelope request) { - return futureUnaryCall( - getChannel().newCall(getDeleteStateMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_PUBLISH_EVENT = 0; - private static final int METHODID_INVOKE_SERVICE = 1; - private static final int METHODID_INVOKE_BINDING = 2; - private static final int METHODID_GET_STATE = 3; - private static final int METHODID_SAVE_STATE = 4; - private static final int METHODID_DELETE_STATE = 5; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final DaprImplBase serviceImpl; - private final int methodId; - - MethodHandlers(DaprImplBase serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_PUBLISH_EVENT: - serviceImpl.publishEvent((io.dapr.DaprProtos.PublishEventEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_INVOKE_SERVICE: - serviceImpl.invokeService((io.dapr.DaprProtos.InvokeServiceEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_INVOKE_BINDING: - serviceImpl.invokeBinding((io.dapr.DaprProtos.InvokeBindingEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_GET_STATE: - serviceImpl.getState((io.dapr.DaprProtos.GetStateEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_SAVE_STATE: - serviceImpl.saveState((io.dapr.DaprProtos.SaveStateEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_DELETE_STATE: - serviceImpl.deleteState((io.dapr.DaprProtos.DeleteStateEnvelope) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - private static abstract class DaprBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { - DaprBaseDescriptorSupplier() {} - - @java.lang.Override - public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return io.dapr.DaprProtos.getDescriptor(); - } - - @java.lang.Override - public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { - return getFileDescriptor().findServiceByName("Dapr"); - } - } - - private static final class DaprFileDescriptorSupplier - extends DaprBaseDescriptorSupplier { - DaprFileDescriptorSupplier() {} - } - - private static final class DaprMethodDescriptorSupplier - extends DaprBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final String methodName; - - DaprMethodDescriptorSupplier(String methodName) { - this.methodName = methodName; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { - return getServiceDescriptor().findMethodByName(methodName); - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (DaprGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .setSchemaDescriptor(new DaprFileDescriptorSupplier()) - .addMethod(getPublishEventMethod()) - .addMethod(getInvokeServiceMethod()) - .addMethod(getInvokeBindingMethod()) - .addMethod(getGetStateMethod()) - .addMethod(getSaveStateMethod()) - .addMethod(getDeleteStateMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/sdk/src/main/java/io/dapr/DaprProtos.java b/sdk/src/main/java/io/dapr/DaprProtos.java deleted file mode 100644 index 7da2fc280..000000000 --- a/sdk/src/main/java/io/dapr/DaprProtos.java +++ /dev/null @@ -1,13828 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: dapr.proto - -package io.dapr; - -public final class DaprProtos { - private DaprProtos() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface InvokeServiceResponseEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.InvokeServiceResponseEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 1; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * map<string, string> metadata = 2; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 2; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 2; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 2; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 2; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - } - /** - * Protobuf type {@code dapr.InvokeServiceResponseEnvelope} - */ - public static final class InvokeServiceResponseEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.InvokeServiceResponseEnvelope) - InvokeServiceResponseEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use InvokeServiceResponseEnvelope.newBuilder() to construct. - private InvokeServiceResponseEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private InvokeServiceResponseEnvelope() { - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new InvokeServiceResponseEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private InvokeServiceResponseEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 2: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeServiceResponseEnvelope.class, io.dapr.DaprProtos.InvokeServiceResponseEnvelope.Builder.class); - } - - public static final int DATA_FIELD_NUMBER = 1; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int METADATA_FIELD_NUMBER = 2; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 2; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 2; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 2; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 2; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (data_ != null) { - output.writeMessage(1, getData()); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 2); - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, getData()); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, metadata__); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.InvokeServiceResponseEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.InvokeServiceResponseEnvelope other = (io.dapr.DaprProtos.InvokeServiceResponseEnvelope) obj; - - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.InvokeServiceResponseEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.InvokeServiceResponseEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.InvokeServiceResponseEnvelope) - io.dapr.DaprProtos.InvokeServiceResponseEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 2: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 2: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeServiceResponseEnvelope.class, io.dapr.DaprProtos.InvokeServiceResponseEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.InvokeServiceResponseEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - internalGetMutableMetadata().clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceResponseEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceResponseEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.InvokeServiceResponseEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceResponseEnvelope build() { - io.dapr.DaprProtos.InvokeServiceResponseEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceResponseEnvelope buildPartial() { - io.dapr.DaprProtos.InvokeServiceResponseEnvelope result = new io.dapr.DaprProtos.InvokeServiceResponseEnvelope(this); - int from_bitField0_ = bitField0_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.InvokeServiceResponseEnvelope) { - return mergeFrom((io.dapr.DaprProtos.InvokeServiceResponseEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.InvokeServiceResponseEnvelope other) { - if (other == io.dapr.DaprProtos.InvokeServiceResponseEnvelope.getDefaultInstance()) return this; - if (other.hasData()) { - mergeData(other.getData()); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.InvokeServiceResponseEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.InvokeServiceResponseEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 1; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 2; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 2; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 2; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 2; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 2; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 2; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 2; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.InvokeServiceResponseEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.InvokeServiceResponseEnvelope) - private static final io.dapr.DaprProtos.InvokeServiceResponseEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.InvokeServiceResponseEnvelope(); - } - - public static io.dapr.DaprProtos.InvokeServiceResponseEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public InvokeServiceResponseEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new InvokeServiceResponseEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceResponseEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface DeleteStateEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.DeleteStateEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string key = 1; - * @return The key. - */ - java.lang.String getKey(); - /** - * string key = 1; - * @return The bytes for key. - */ - com.google.protobuf.ByteString - getKeyBytes(); - - /** - * string etag = 2; - * @return The etag. - */ - java.lang.String getEtag(); - /** - * string etag = 2; - * @return The bytes for etag. - */ - com.google.protobuf.ByteString - getEtagBytes(); - - /** - * .dapr.StateOptions options = 3; - * @return Whether the options field is set. - */ - boolean hasOptions(); - /** - * .dapr.StateOptions options = 3; - * @return The options. - */ - io.dapr.DaprProtos.StateOptions getOptions(); - /** - * .dapr.StateOptions options = 3; - */ - io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder(); - } - /** - * Protobuf type {@code dapr.DeleteStateEnvelope} - */ - public static final class DeleteStateEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.DeleteStateEnvelope) - DeleteStateEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use DeleteStateEnvelope.newBuilder() to construct. - private DeleteStateEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private DeleteStateEnvelope() { - key_ = ""; - etag_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new DeleteStateEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private DeleteStateEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - key_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - etag_ = s; - break; - } - case 26: { - io.dapr.DaprProtos.StateOptions.Builder subBuilder = null; - if (options_ != null) { - subBuilder = options_.toBuilder(); - } - options_ = input.readMessage(io.dapr.DaprProtos.StateOptions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(options_); - options_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_DeleteStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_DeleteStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.DeleteStateEnvelope.class, io.dapr.DaprProtos.DeleteStateEnvelope.Builder.class); - } - - public static final int KEY_FIELD_NUMBER = 1; - private volatile java.lang.Object key_; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int ETAG_FIELD_NUMBER = 2; - private volatile java.lang.Object etag_; - /** - * string etag = 2; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } - } - /** - * string etag = 2; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int OPTIONS_FIELD_NUMBER = 3; - private io.dapr.DaprProtos.StateOptions options_; - /** - * .dapr.StateOptions options = 3; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return options_ != null; - } - /** - * .dapr.StateOptions options = 3; - * @return The options. - */ - public io.dapr.DaprProtos.StateOptions getOptions() { - return options_ == null ? io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } - /** - * .dapr.StateOptions options = 3; - */ - public io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - return getOptions(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getKeyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); - } - if (!getEtagBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, etag_); - } - if (options_ != null) { - output.writeMessage(3, getOptions()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getKeyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); - } - if (!getEtagBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, etag_); - } - if (options_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getOptions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.DeleteStateEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.DeleteStateEnvelope other = (io.dapr.DaprProtos.DeleteStateEnvelope) obj; - - if (!getKey() - .equals(other.getKey())) return false; - if (!getEtag() - .equals(other.getEtag())) return false; - if (hasOptions() != other.hasOptions()) return false; - if (hasOptions()) { - if (!getOptions() - .equals(other.getOptions())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + KEY_FIELD_NUMBER; - hash = (53 * hash) + getKey().hashCode(); - hash = (37 * hash) + ETAG_FIELD_NUMBER; - hash = (53 * hash) + getEtag().hashCode(); - if (hasOptions()) { - hash = (37 * hash) + OPTIONS_FIELD_NUMBER; - hash = (53 * hash) + getOptions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.DeleteStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.DeleteStateEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.DeleteStateEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.DeleteStateEnvelope) - io.dapr.DaprProtos.DeleteStateEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_DeleteStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_DeleteStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.DeleteStateEnvelope.class, io.dapr.DaprProtos.DeleteStateEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.DeleteStateEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - key_ = ""; - - etag_ = ""; - - if (optionsBuilder_ == null) { - options_ = null; - } else { - options_ = null; - optionsBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_DeleteStateEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.DeleteStateEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.DeleteStateEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.DeleteStateEnvelope build() { - io.dapr.DaprProtos.DeleteStateEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.DeleteStateEnvelope buildPartial() { - io.dapr.DaprProtos.DeleteStateEnvelope result = new io.dapr.DaprProtos.DeleteStateEnvelope(this); - result.key_ = key_; - result.etag_ = etag_; - if (optionsBuilder_ == null) { - result.options_ = options_; - } else { - result.options_ = optionsBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.DeleteStateEnvelope) { - return mergeFrom((io.dapr.DaprProtos.DeleteStateEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.DeleteStateEnvelope other) { - if (other == io.dapr.DaprProtos.DeleteStateEnvelope.getDefaultInstance()) return this; - if (!other.getKey().isEmpty()) { - key_ = other.key_; - onChanged(); - } - if (!other.getEtag().isEmpty()) { - etag_ = other.etag_; - onChanged(); - } - if (other.hasOptions()) { - mergeOptions(other.getOptions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.DeleteStateEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.DeleteStateEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object key_ = ""; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string key = 1; - * @param value The key to set. - * @return This builder for chaining. - */ - public Builder setKey( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - key_ = value; - onChanged(); - return this; - } - /** - * string key = 1; - * @return This builder for chaining. - */ - public Builder clearKey() { - - key_ = getDefaultInstance().getKey(); - onChanged(); - return this; - } - /** - * string key = 1; - * @param value The bytes for key to set. - * @return This builder for chaining. - */ - public Builder setKeyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - key_ = value; - onChanged(); - return this; - } - - private java.lang.Object etag_ = ""; - /** - * string etag = 2; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string etag = 2; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string etag = 2; - * @param value The etag to set. - * @return This builder for chaining. - */ - public Builder setEtag( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - etag_ = value; - onChanged(); - return this; - } - /** - * string etag = 2; - * @return This builder for chaining. - */ - public Builder clearEtag() { - - etag_ = getDefaultInstance().getEtag(); - onChanged(); - return this; - } - /** - * string etag = 2; - * @param value The bytes for etag to set. - * @return This builder for chaining. - */ - public Builder setEtagBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - etag_ = value; - onChanged(); - return this; - } - - private io.dapr.DaprProtos.StateOptions options_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder> optionsBuilder_; - /** - * .dapr.StateOptions options = 3; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return optionsBuilder_ != null || options_ != null; - } - /** - * .dapr.StateOptions options = 3; - * @return The options. - */ - public io.dapr.DaprProtos.StateOptions getOptions() { - if (optionsBuilder_ == null) { - return options_ == null ? io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } else { - return optionsBuilder_.getMessage(); - } - } - /** - * .dapr.StateOptions options = 3; - */ - public Builder setOptions(io.dapr.DaprProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - options_ = value; - onChanged(); - } else { - optionsBuilder_.setMessage(value); - } - - return this; - } - /** - * .dapr.StateOptions options = 3; - */ - public Builder setOptions( - io.dapr.DaprProtos.StateOptions.Builder builderForValue) { - if (optionsBuilder_ == null) { - options_ = builderForValue.build(); - onChanged(); - } else { - optionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .dapr.StateOptions options = 3; - */ - public Builder mergeOptions(io.dapr.DaprProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (options_ != null) { - options_ = - io.dapr.DaprProtos.StateOptions.newBuilder(options_).mergeFrom(value).buildPartial(); - } else { - options_ = value; - } - onChanged(); - } else { - optionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .dapr.StateOptions options = 3; - */ - public Builder clearOptions() { - if (optionsBuilder_ == null) { - options_ = null; - onChanged(); - } else { - options_ = null; - optionsBuilder_ = null; - } - - return this; - } - /** - * .dapr.StateOptions options = 3; - */ - public io.dapr.DaprProtos.StateOptions.Builder getOptionsBuilder() { - - onChanged(); - return getOptionsFieldBuilder().getBuilder(); - } - /** - * .dapr.StateOptions options = 3; - */ - public io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - if (optionsBuilder_ != null) { - return optionsBuilder_.getMessageOrBuilder(); - } else { - return options_ == null ? - io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } - } - /** - * .dapr.StateOptions options = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder> - getOptionsFieldBuilder() { - if (optionsBuilder_ == null) { - optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder>( - getOptions(), - getParentForChildren(), - isClean()); - options_ = null; - } - return optionsBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.DeleteStateEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.DeleteStateEnvelope) - private static final io.dapr.DaprProtos.DeleteStateEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.DeleteStateEnvelope(); - } - - public static io.dapr.DaprProtos.DeleteStateEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public DeleteStateEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new DeleteStateEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.DeleteStateEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface SaveStateEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.SaveStateEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * repeated .dapr.StateRequest requests = 1; - */ - java.util.List - getRequestsList(); - /** - * repeated .dapr.StateRequest requests = 1; - */ - io.dapr.DaprProtos.StateRequest getRequests(int index); - /** - * repeated .dapr.StateRequest requests = 1; - */ - int getRequestsCount(); - /** - * repeated .dapr.StateRequest requests = 1; - */ - java.util.List - getRequestsOrBuilderList(); - /** - * repeated .dapr.StateRequest requests = 1; - */ - io.dapr.DaprProtos.StateRequestOrBuilder getRequestsOrBuilder( - int index); - } - /** - * Protobuf type {@code dapr.SaveStateEnvelope} - */ - public static final class SaveStateEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.SaveStateEnvelope) - SaveStateEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use SaveStateEnvelope.newBuilder() to construct. - private SaveStateEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SaveStateEnvelope() { - requests_ = java.util.Collections.emptyList(); - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new SaveStateEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SaveStateEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - requests_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000001; - } - requests_.add( - input.readMessage(io.dapr.DaprProtos.StateRequest.parser(), extensionRegistry)); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) != 0)) { - requests_ = java.util.Collections.unmodifiableList(requests_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_SaveStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_SaveStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.SaveStateEnvelope.class, io.dapr.DaprProtos.SaveStateEnvelope.Builder.class); - } - - public static final int REQUESTS_FIELD_NUMBER = 1; - private java.util.List requests_; - /** - * repeated .dapr.StateRequest requests = 1; - */ - public java.util.List getRequestsList() { - return requests_; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public java.util.List - getRequestsOrBuilderList() { - return requests_; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public int getRequestsCount() { - return requests_.size(); - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequest getRequests(int index) { - return requests_.get(index); - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequestOrBuilder getRequestsOrBuilder( - int index) { - return requests_.get(index); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < requests_.size(); i++) { - output.writeMessage(1, requests_.get(i)); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - for (int i = 0; i < requests_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, requests_.get(i)); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.SaveStateEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.SaveStateEnvelope other = (io.dapr.DaprProtos.SaveStateEnvelope) obj; - - if (!getRequestsList() - .equals(other.getRequestsList())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (getRequestsCount() > 0) { - hash = (37 * hash) + REQUESTS_FIELD_NUMBER; - hash = (53 * hash) + getRequestsList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.SaveStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.SaveStateEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.SaveStateEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.SaveStateEnvelope) - io.dapr.DaprProtos.SaveStateEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_SaveStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_SaveStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.SaveStateEnvelope.class, io.dapr.DaprProtos.SaveStateEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.SaveStateEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - getRequestsFieldBuilder(); - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - if (requestsBuilder_ == null) { - requests_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - } else { - requestsBuilder_.clear(); - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_SaveStateEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.SaveStateEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.SaveStateEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.SaveStateEnvelope build() { - io.dapr.DaprProtos.SaveStateEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.SaveStateEnvelope buildPartial() { - io.dapr.DaprProtos.SaveStateEnvelope result = new io.dapr.DaprProtos.SaveStateEnvelope(this); - int from_bitField0_ = bitField0_; - if (requestsBuilder_ == null) { - if (((bitField0_ & 0x00000001) != 0)) { - requests_ = java.util.Collections.unmodifiableList(requests_); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.requests_ = requests_; - } else { - result.requests_ = requestsBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.SaveStateEnvelope) { - return mergeFrom((io.dapr.DaprProtos.SaveStateEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.SaveStateEnvelope other) { - if (other == io.dapr.DaprProtos.SaveStateEnvelope.getDefaultInstance()) return this; - if (requestsBuilder_ == null) { - if (!other.requests_.isEmpty()) { - if (requests_.isEmpty()) { - requests_ = other.requests_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureRequestsIsMutable(); - requests_.addAll(other.requests_); - } - onChanged(); - } - } else { - if (!other.requests_.isEmpty()) { - if (requestsBuilder_.isEmpty()) { - requestsBuilder_.dispose(); - requestsBuilder_ = null; - requests_ = other.requests_; - bitField0_ = (bitField0_ & ~0x00000001); - requestsBuilder_ = - com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? - getRequestsFieldBuilder() : null; - } else { - requestsBuilder_.addAllMessages(other.requests_); - } - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.SaveStateEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.SaveStateEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.util.List requests_ = - java.util.Collections.emptyList(); - private void ensureRequestsIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - requests_ = new java.util.ArrayList(requests_); - bitField0_ |= 0x00000001; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprProtos.StateRequest, io.dapr.DaprProtos.StateRequest.Builder, io.dapr.DaprProtos.StateRequestOrBuilder> requestsBuilder_; - - /** - * repeated .dapr.StateRequest requests = 1; - */ - public java.util.List getRequestsList() { - if (requestsBuilder_ == null) { - return java.util.Collections.unmodifiableList(requests_); - } else { - return requestsBuilder_.getMessageList(); - } - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public int getRequestsCount() { - if (requestsBuilder_ == null) { - return requests_.size(); - } else { - return requestsBuilder_.getCount(); - } - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequest getRequests(int index) { - if (requestsBuilder_ == null) { - return requests_.get(index); - } else { - return requestsBuilder_.getMessage(index); - } - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder setRequests( - int index, io.dapr.DaprProtos.StateRequest value) { - if (requestsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureRequestsIsMutable(); - requests_.set(index, value); - onChanged(); - } else { - requestsBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder setRequests( - int index, io.dapr.DaprProtos.StateRequest.Builder builderForValue) { - if (requestsBuilder_ == null) { - ensureRequestsIsMutable(); - requests_.set(index, builderForValue.build()); - onChanged(); - } else { - requestsBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder addRequests(io.dapr.DaprProtos.StateRequest value) { - if (requestsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureRequestsIsMutable(); - requests_.add(value); - onChanged(); - } else { - requestsBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder addRequests( - int index, io.dapr.DaprProtos.StateRequest value) { - if (requestsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureRequestsIsMutable(); - requests_.add(index, value); - onChanged(); - } else { - requestsBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder addRequests( - io.dapr.DaprProtos.StateRequest.Builder builderForValue) { - if (requestsBuilder_ == null) { - ensureRequestsIsMutable(); - requests_.add(builderForValue.build()); - onChanged(); - } else { - requestsBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder addRequests( - int index, io.dapr.DaprProtos.StateRequest.Builder builderForValue) { - if (requestsBuilder_ == null) { - ensureRequestsIsMutable(); - requests_.add(index, builderForValue.build()); - onChanged(); - } else { - requestsBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder addAllRequests( - java.lang.Iterable values) { - if (requestsBuilder_ == null) { - ensureRequestsIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, requests_); - onChanged(); - } else { - requestsBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder clearRequests() { - if (requestsBuilder_ == null) { - requests_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - } else { - requestsBuilder_.clear(); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public Builder removeRequests(int index) { - if (requestsBuilder_ == null) { - ensureRequestsIsMutable(); - requests_.remove(index); - onChanged(); - } else { - requestsBuilder_.remove(index); - } - return this; - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequest.Builder getRequestsBuilder( - int index) { - return getRequestsFieldBuilder().getBuilder(index); - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequestOrBuilder getRequestsOrBuilder( - int index) { - if (requestsBuilder_ == null) { - return requests_.get(index); } else { - return requestsBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public java.util.List - getRequestsOrBuilderList() { - if (requestsBuilder_ != null) { - return requestsBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(requests_); - } - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequest.Builder addRequestsBuilder() { - return getRequestsFieldBuilder().addBuilder( - io.dapr.DaprProtos.StateRequest.getDefaultInstance()); - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public io.dapr.DaprProtos.StateRequest.Builder addRequestsBuilder( - int index) { - return getRequestsFieldBuilder().addBuilder( - index, io.dapr.DaprProtos.StateRequest.getDefaultInstance()); - } - /** - * repeated .dapr.StateRequest requests = 1; - */ - public java.util.List - getRequestsBuilderList() { - return getRequestsFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprProtos.StateRequest, io.dapr.DaprProtos.StateRequest.Builder, io.dapr.DaprProtos.StateRequestOrBuilder> - getRequestsFieldBuilder() { - if (requestsBuilder_ == null) { - requestsBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - io.dapr.DaprProtos.StateRequest, io.dapr.DaprProtos.StateRequest.Builder, io.dapr.DaprProtos.StateRequestOrBuilder>( - requests_, - ((bitField0_ & 0x00000001) != 0), - getParentForChildren(), - isClean()); - requests_ = null; - } - return requestsBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.SaveStateEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.SaveStateEnvelope) - private static final io.dapr.DaprProtos.SaveStateEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.SaveStateEnvelope(); - } - - public static io.dapr.DaprProtos.SaveStateEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public SaveStateEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SaveStateEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.SaveStateEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface GetStateEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.GetStateEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string key = 1; - * @return The key. - */ - java.lang.String getKey(); - /** - * string key = 1; - * @return The bytes for key. - */ - com.google.protobuf.ByteString - getKeyBytes(); - - /** - * string consistency = 2; - * @return The consistency. - */ - java.lang.String getConsistency(); - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - com.google.protobuf.ByteString - getConsistencyBytes(); - } - /** - * Protobuf type {@code dapr.GetStateEnvelope} - */ - public static final class GetStateEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.GetStateEnvelope) - GetStateEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use GetStateEnvelope.newBuilder() to construct. - private GetStateEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private GetStateEnvelope() { - key_ = ""; - consistency_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new GetStateEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private GetStateEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - key_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - consistency_ = s; - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.GetStateEnvelope.class, io.dapr.DaprProtos.GetStateEnvelope.Builder.class); - } - - public static final int KEY_FIELD_NUMBER = 1; - private volatile java.lang.Object key_; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int CONSISTENCY_FIELD_NUMBER = 2; - private volatile java.lang.Object consistency_; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getKeyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); - } - if (!getConsistencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, consistency_); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getKeyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); - } - if (!getConsistencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, consistency_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.GetStateEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.GetStateEnvelope other = (io.dapr.DaprProtos.GetStateEnvelope) obj; - - if (!getKey() - .equals(other.getKey())) return false; - if (!getConsistency() - .equals(other.getConsistency())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + KEY_FIELD_NUMBER; - hash = (53 * hash) + getKey().hashCode(); - hash = (37 * hash) + CONSISTENCY_FIELD_NUMBER; - hash = (53 * hash) + getConsistency().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.GetStateEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.GetStateEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.GetStateEnvelope) - io.dapr.DaprProtos.GetStateEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.GetStateEnvelope.class, io.dapr.DaprProtos.GetStateEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.GetStateEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - key_ = ""; - - consistency_ = ""; - - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.GetStateEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateEnvelope build() { - io.dapr.DaprProtos.GetStateEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateEnvelope buildPartial() { - io.dapr.DaprProtos.GetStateEnvelope result = new io.dapr.DaprProtos.GetStateEnvelope(this); - result.key_ = key_; - result.consistency_ = consistency_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.GetStateEnvelope) { - return mergeFrom((io.dapr.DaprProtos.GetStateEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.GetStateEnvelope other) { - if (other == io.dapr.DaprProtos.GetStateEnvelope.getDefaultInstance()) return this; - if (!other.getKey().isEmpty()) { - key_ = other.key_; - onChanged(); - } - if (!other.getConsistency().isEmpty()) { - consistency_ = other.consistency_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.GetStateEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.GetStateEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object key_ = ""; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string key = 1; - * @param value The key to set. - * @return This builder for chaining. - */ - public Builder setKey( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - key_ = value; - onChanged(); - return this; - } - /** - * string key = 1; - * @return This builder for chaining. - */ - public Builder clearKey() { - - key_ = getDefaultInstance().getKey(); - onChanged(); - return this; - } - /** - * string key = 1; - * @param value The bytes for key to set. - * @return This builder for chaining. - */ - public Builder setKeyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - key_ = value; - onChanged(); - return this; - } - - private java.lang.Object consistency_ = ""; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string consistency = 2; - * @param value The consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - consistency_ = value; - onChanged(); - return this; - } - /** - * string consistency = 2; - * @return This builder for chaining. - */ - public Builder clearConsistency() { - - consistency_ = getDefaultInstance().getConsistency(); - onChanged(); - return this; - } - /** - * string consistency = 2; - * @param value The bytes for consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - consistency_ = value; - onChanged(); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.GetStateEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.GetStateEnvelope) - private static final io.dapr.DaprProtos.GetStateEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.GetStateEnvelope(); - } - - public static io.dapr.DaprProtos.GetStateEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public GetStateEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new GetStateEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface GetStateResponseEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.GetStateResponseEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 1; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * string etag = 2; - * @return The etag. - */ - java.lang.String getEtag(); - /** - * string etag = 2; - * @return The bytes for etag. - */ - com.google.protobuf.ByteString - getEtagBytes(); - } - /** - * Protobuf type {@code dapr.GetStateResponseEnvelope} - */ - public static final class GetStateResponseEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.GetStateResponseEnvelope) - GetStateResponseEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use GetStateResponseEnvelope.newBuilder() to construct. - private GetStateResponseEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private GetStateResponseEnvelope() { - etag_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new GetStateResponseEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private GetStateResponseEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - etag_ = s; - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateResponseEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.GetStateResponseEnvelope.class, io.dapr.DaprProtos.GetStateResponseEnvelope.Builder.class); - } - - public static final int DATA_FIELD_NUMBER = 1; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int ETAG_FIELD_NUMBER = 2; - private volatile java.lang.Object etag_; - /** - * string etag = 2; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } - } - /** - * string etag = 2; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (data_ != null) { - output.writeMessage(1, getData()); - } - if (!getEtagBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, etag_); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, getData()); - } - if (!getEtagBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, etag_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.GetStateResponseEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.GetStateResponseEnvelope other = (io.dapr.DaprProtos.GetStateResponseEnvelope) obj; - - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!getEtag() - .equals(other.getEtag())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - hash = (37 * hash) + ETAG_FIELD_NUMBER; - hash = (53 * hash) + getEtag().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.GetStateResponseEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.GetStateResponseEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.GetStateResponseEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.GetStateResponseEnvelope) - io.dapr.DaprProtos.GetStateResponseEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateResponseEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateResponseEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.GetStateResponseEnvelope.class, io.dapr.DaprProtos.GetStateResponseEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.GetStateResponseEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - etag_ = ""; - - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_GetStateResponseEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateResponseEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.GetStateResponseEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateResponseEnvelope build() { - io.dapr.DaprProtos.GetStateResponseEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateResponseEnvelope buildPartial() { - io.dapr.DaprProtos.GetStateResponseEnvelope result = new io.dapr.DaprProtos.GetStateResponseEnvelope(this); - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.etag_ = etag_; - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.GetStateResponseEnvelope) { - return mergeFrom((io.dapr.DaprProtos.GetStateResponseEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.GetStateResponseEnvelope other) { - if (other == io.dapr.DaprProtos.GetStateResponseEnvelope.getDefaultInstance()) return this; - if (other.hasData()) { - mergeData(other.getData()); - } - if (!other.getEtag().isEmpty()) { - etag_ = other.etag_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.GetStateResponseEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.GetStateResponseEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 1; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 1; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 1; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 1; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private java.lang.Object etag_ = ""; - /** - * string etag = 2; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string etag = 2; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string etag = 2; - * @param value The etag to set. - * @return This builder for chaining. - */ - public Builder setEtag( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - etag_ = value; - onChanged(); - return this; - } - /** - * string etag = 2; - * @return This builder for chaining. - */ - public Builder clearEtag() { - - etag_ = getDefaultInstance().getEtag(); - onChanged(); - return this; - } - /** - * string etag = 2; - * @param value The bytes for etag to set. - * @return This builder for chaining. - */ - public Builder setEtagBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - etag_ = value; - onChanged(); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.GetStateResponseEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.GetStateResponseEnvelope) - private static final io.dapr.DaprProtos.GetStateResponseEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.GetStateResponseEnvelope(); - } - - public static io.dapr.DaprProtos.GetStateResponseEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public GetStateResponseEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new GetStateResponseEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.GetStateResponseEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface InvokeBindingEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.InvokeBindingEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string name = 1; - * @return The name. - */ - java.lang.String getName(); - /** - * string name = 1; - * @return The bytes for name. - */ - com.google.protobuf.ByteString - getNameBytes(); - - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 2; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * map<string, string> metadata = 3; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 3; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 3; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 3; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - } - /** - * Protobuf type {@code dapr.InvokeBindingEnvelope} - */ - public static final class InvokeBindingEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.InvokeBindingEnvelope) - InvokeBindingEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use InvokeBindingEnvelope.newBuilder() to construct. - private InvokeBindingEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private InvokeBindingEnvelope() { - name_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new InvokeBindingEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private InvokeBindingEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - name_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeBindingEnvelope.class, io.dapr.DaprProtos.InvokeBindingEnvelope.Builder.class); - } - - public static final int NAME_FIELD_NUMBER = 1; - private volatile java.lang.Object name_; - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - } - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 2; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int METADATA_FIELD_NUMBER = 3; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); - } - if (data_ != null) { - output.writeMessage(2, getData()); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 3); - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getData()); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, metadata__); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.InvokeBindingEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.InvokeBindingEnvelope other = (io.dapr.DaprProtos.InvokeBindingEnvelope) obj; - - if (!getName() - .equals(other.getName())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + NAME_FIELD_NUMBER; - hash = (53 * hash) + getName().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeBindingEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.InvokeBindingEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.InvokeBindingEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.InvokeBindingEnvelope) - io.dapr.DaprProtos.InvokeBindingEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 3: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 3: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeBindingEnvelope.class, io.dapr.DaprProtos.InvokeBindingEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.InvokeBindingEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - name_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - internalGetMutableMetadata().clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeBindingEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeBindingEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.InvokeBindingEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeBindingEnvelope build() { - io.dapr.DaprProtos.InvokeBindingEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeBindingEnvelope buildPartial() { - io.dapr.DaprProtos.InvokeBindingEnvelope result = new io.dapr.DaprProtos.InvokeBindingEnvelope(this); - int from_bitField0_ = bitField0_; - result.name_ = name_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.InvokeBindingEnvelope) { - return mergeFrom((io.dapr.DaprProtos.InvokeBindingEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.InvokeBindingEnvelope other) { - if (other == io.dapr.DaprProtos.InvokeBindingEnvelope.getDefaultInstance()) return this; - if (!other.getName().isEmpty()) { - name_ = other.name_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.InvokeBindingEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.InvokeBindingEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object name_ = ""; - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string name = 1; - * @param value The name to set. - * @return This builder for chaining. - */ - public Builder setName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - name_ = value; - onChanged(); - return this; - } - /** - * string name = 1; - * @return This builder for chaining. - */ - public Builder clearName() { - - name_ = getDefaultInstance().getName(); - onChanged(); - return this; - } - /** - * string name = 1; - * @param value The bytes for name to set. - * @return This builder for chaining. - */ - public Builder setNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - name_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 3; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 3; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 3; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 3; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.InvokeBindingEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.InvokeBindingEnvelope) - private static final io.dapr.DaprProtos.InvokeBindingEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.InvokeBindingEnvelope(); - } - - public static io.dapr.DaprProtos.InvokeBindingEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public InvokeBindingEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new InvokeBindingEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeBindingEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface InvokeServiceEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.InvokeServiceEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string id = 1; - * @return The id. - */ - java.lang.String getId(); - /** - * string id = 1; - * @return The bytes for id. - */ - com.google.protobuf.ByteString - getIdBytes(); - - /** - * string method = 2; - * @return The method. - */ - java.lang.String getMethod(); - /** - * string method = 2; - * @return The bytes for method. - */ - com.google.protobuf.ByteString - getMethodBytes(); - - /** - * .google.protobuf.Any data = 3; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 3; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 3; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - - /** - * map<string, string> metadata = 4; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 4; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 4; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - } - /** - * Protobuf type {@code dapr.InvokeServiceEnvelope} - */ - public static final class InvokeServiceEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.InvokeServiceEnvelope) - InvokeServiceEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use InvokeServiceEnvelope.newBuilder() to construct. - private InvokeServiceEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private InvokeServiceEnvelope() { - id_ = ""; - method_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new InvokeServiceEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private InvokeServiceEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - id_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - method_ = s; - break; - } - case 26: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeServiceEnvelope.class, io.dapr.DaprProtos.InvokeServiceEnvelope.Builder.class); - } - - public static final int ID_FIELD_NUMBER = 1; - private volatile java.lang.Object id_; - /** - * string id = 1; - * @return The id. - */ - public java.lang.String getId() { - java.lang.Object ref = id_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - id_ = s; - return s; - } - } - /** - * string id = 1; - * @return The bytes for id. - */ - public com.google.protobuf.ByteString - getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int METHOD_FIELD_NUMBER = 2; - private volatile java.lang.Object method_; - /** - * string method = 2; - * @return The method. - */ - public java.lang.String getMethod() { - java.lang.Object ref = method_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - method_ = s; - return s; - } - } - /** - * string method = 2; - * @return The bytes for method. - */ - public com.google.protobuf.ByteString - getMethodBytes() { - java.lang.Object ref = method_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - method_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 3; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 3; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 3; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 3; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - public static final int METADATA_FIELD_NUMBER = 4; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getIdBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, id_); - } - if (!getMethodBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, method_); - } - if (data_ != null) { - output.writeMessage(3, getData()); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 4); - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getIdBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, id_); - } - if (!getMethodBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, method_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getData()); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, metadata__); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.InvokeServiceEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.InvokeServiceEnvelope other = (io.dapr.DaprProtos.InvokeServiceEnvelope) obj; - - if (!getId() - .equals(other.getId())) return false; - if (!getMethod() - .equals(other.getMethod())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + ID_FIELD_NUMBER; - hash = (53 * hash) + getId().hashCode(); - hash = (37 * hash) + METHOD_FIELD_NUMBER; - hash = (53 * hash) + getMethod().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.InvokeServiceEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.InvokeServiceEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.InvokeServiceEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.InvokeServiceEnvelope) - io.dapr.DaprProtos.InvokeServiceEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 4: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.InvokeServiceEnvelope.class, io.dapr.DaprProtos.InvokeServiceEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.InvokeServiceEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - id_ = ""; - - method_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - internalGetMutableMetadata().clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_InvokeServiceEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.InvokeServiceEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceEnvelope build() { - io.dapr.DaprProtos.InvokeServiceEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceEnvelope buildPartial() { - io.dapr.DaprProtos.InvokeServiceEnvelope result = new io.dapr.DaprProtos.InvokeServiceEnvelope(this); - int from_bitField0_ = bitField0_; - result.id_ = id_; - result.method_ = method_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.InvokeServiceEnvelope) { - return mergeFrom((io.dapr.DaprProtos.InvokeServiceEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.InvokeServiceEnvelope other) { - if (other == io.dapr.DaprProtos.InvokeServiceEnvelope.getDefaultInstance()) return this; - if (!other.getId().isEmpty()) { - id_ = other.id_; - onChanged(); - } - if (!other.getMethod().isEmpty()) { - method_ = other.method_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.InvokeServiceEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.InvokeServiceEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object id_ = ""; - /** - * string id = 1; - * @return The id. - */ - public java.lang.String getId() { - java.lang.Object ref = id_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - id_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string id = 1; - * @return The bytes for id. - */ - public com.google.protobuf.ByteString - getIdBytes() { - java.lang.Object ref = id_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - id_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string id = 1; - * @param value The id to set. - * @return This builder for chaining. - */ - public Builder setId( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - id_ = value; - onChanged(); - return this; - } - /** - * string id = 1; - * @return This builder for chaining. - */ - public Builder clearId() { - - id_ = getDefaultInstance().getId(); - onChanged(); - return this; - } - /** - * string id = 1; - * @param value The bytes for id to set. - * @return This builder for chaining. - */ - public Builder setIdBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - id_ = value; - onChanged(); - return this; - } - - private java.lang.Object method_ = ""; - /** - * string method = 2; - * @return The method. - */ - public java.lang.String getMethod() { - java.lang.Object ref = method_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - method_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string method = 2; - * @return The bytes for method. - */ - public com.google.protobuf.ByteString - getMethodBytes() { - java.lang.Object ref = method_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - method_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string method = 2; - * @param value The method to set. - * @return This builder for chaining. - */ - public Builder setMethod( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - method_ = value; - onChanged(); - return this; - } - /** - * string method = 2; - * @return This builder for chaining. - */ - public Builder clearMethod() { - - method_ = getDefaultInstance().getMethod(); - onChanged(); - return this; - } - /** - * string method = 2; - * @param value The bytes for method to set. - * @return This builder for chaining. - */ - public Builder setMethodBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - method_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 3; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 3; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 3; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 3; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 3; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 3; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 3; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 3; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 4; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.InvokeServiceEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.InvokeServiceEnvelope) - private static final io.dapr.DaprProtos.InvokeServiceEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.InvokeServiceEnvelope(); - } - - public static io.dapr.DaprProtos.InvokeServiceEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public InvokeServiceEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new InvokeServiceEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.InvokeServiceEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface PublishEventEnvelopeOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.PublishEventEnvelope) - com.google.protobuf.MessageOrBuilder { - - /** - * string topic = 1; - * @return The topic. - */ - java.lang.String getTopic(); - /** - * string topic = 1; - * @return The bytes for topic. - */ - com.google.protobuf.ByteString - getTopicBytes(); - - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - boolean hasData(); - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - com.google.protobuf.Any getData(); - /** - * .google.protobuf.Any data = 2; - */ - com.google.protobuf.AnyOrBuilder getDataOrBuilder(); - } - /** - * Protobuf type {@code dapr.PublishEventEnvelope} - */ - public static final class PublishEventEnvelope extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.PublishEventEnvelope) - PublishEventEnvelopeOrBuilder { - private static final long serialVersionUID = 0L; - // Use PublishEventEnvelope.newBuilder() to construct. - private PublishEventEnvelope(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private PublishEventEnvelope() { - topic_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new PublishEventEnvelope(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private PublishEventEnvelope( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - topic_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (data_ != null) { - subBuilder = data_.toBuilder(); - } - data_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(data_); - data_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_PublishEventEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_PublishEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.PublishEventEnvelope.class, io.dapr.DaprProtos.PublishEventEnvelope.Builder.class); - } - - public static final int TOPIC_FIELD_NUMBER = 1; - private volatile java.lang.Object topic_; - /** - * string topic = 1; - * @return The topic. - */ - public java.lang.String getTopic() { - java.lang.Object ref = topic_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - topic_ = s; - return s; - } - } - /** - * string topic = 1; - * @return The bytes for topic. - */ - public com.google.protobuf.ByteString - getTopicBytes() { - java.lang.Object ref = topic_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - topic_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int DATA_FIELD_NUMBER = 2; - private com.google.protobuf.Any data_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - return getData(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getTopicBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, topic_); - } - if (data_ != null) { - output.writeMessage(2, getData()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getTopicBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, topic_); - } - if (data_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getData()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.PublishEventEnvelope)) { - return super.equals(obj); - } - io.dapr.DaprProtos.PublishEventEnvelope other = (io.dapr.DaprProtos.PublishEventEnvelope) obj; - - if (!getTopic() - .equals(other.getTopic())) return false; - if (hasData() != other.hasData()) return false; - if (hasData()) { - if (!getData() - .equals(other.getData())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + TOPIC_FIELD_NUMBER; - hash = (53 * hash) + getTopic().hashCode(); - if (hasData()) { - hash = (37 * hash) + DATA_FIELD_NUMBER; - hash = (53 * hash) + getData().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.PublishEventEnvelope parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.PublishEventEnvelope prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.PublishEventEnvelope} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.PublishEventEnvelope) - io.dapr.DaprProtos.PublishEventEnvelopeOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_PublishEventEnvelope_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_PublishEventEnvelope_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.PublishEventEnvelope.class, io.dapr.DaprProtos.PublishEventEnvelope.Builder.class); - } - - // Construct using io.dapr.DaprProtos.PublishEventEnvelope.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - topic_ = ""; - - if (dataBuilder_ == null) { - data_ = null; - } else { - data_ = null; - dataBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_PublishEventEnvelope_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.PublishEventEnvelope getDefaultInstanceForType() { - return io.dapr.DaprProtos.PublishEventEnvelope.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.PublishEventEnvelope build() { - io.dapr.DaprProtos.PublishEventEnvelope result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.PublishEventEnvelope buildPartial() { - io.dapr.DaprProtos.PublishEventEnvelope result = new io.dapr.DaprProtos.PublishEventEnvelope(this); - result.topic_ = topic_; - if (dataBuilder_ == null) { - result.data_ = data_; - } else { - result.data_ = dataBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.PublishEventEnvelope) { - return mergeFrom((io.dapr.DaprProtos.PublishEventEnvelope)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.PublishEventEnvelope other) { - if (other == io.dapr.DaprProtos.PublishEventEnvelope.getDefaultInstance()) return this; - if (!other.getTopic().isEmpty()) { - topic_ = other.topic_; - onChanged(); - } - if (other.hasData()) { - mergeData(other.getData()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.PublishEventEnvelope parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.PublishEventEnvelope) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object topic_ = ""; - /** - * string topic = 1; - * @return The topic. - */ - public java.lang.String getTopic() { - java.lang.Object ref = topic_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - topic_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string topic = 1; - * @return The bytes for topic. - */ - public com.google.protobuf.ByteString - getTopicBytes() { - java.lang.Object ref = topic_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - topic_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string topic = 1; - * @param value The topic to set. - * @return This builder for chaining. - */ - public Builder setTopic( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - topic_ = value; - onChanged(); - return this; - } - /** - * string topic = 1; - * @return This builder for chaining. - */ - public Builder clearTopic() { - - topic_ = getDefaultInstance().getTopic(); - onChanged(); - return this; - } - /** - * string topic = 1; - * @param value The bytes for topic to set. - * @return This builder for chaining. - */ - public Builder setTopicBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - topic_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any data_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> dataBuilder_; - /** - * .google.protobuf.Any data = 2; - * @return Whether the data field is set. - */ - public boolean hasData() { - return dataBuilder_ != null || data_ != null; - } - /** - * .google.protobuf.Any data = 2; - * @return The data. - */ - public com.google.protobuf.Any getData() { - if (dataBuilder_ == null) { - return data_ == null ? com.google.protobuf.Any.getDefaultInstance() : data_; - } else { - return dataBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - data_ = value; - onChanged(); - } else { - dataBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder setData( - com.google.protobuf.Any.Builder builderForValue) { - if (dataBuilder_ == null) { - data_ = builderForValue.build(); - onChanged(); - } else { - dataBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder mergeData(com.google.protobuf.Any value) { - if (dataBuilder_ == null) { - if (data_ != null) { - data_ = - com.google.protobuf.Any.newBuilder(data_).mergeFrom(value).buildPartial(); - } else { - data_ = value; - } - onChanged(); - } else { - dataBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public Builder clearData() { - if (dataBuilder_ == null) { - data_ = null; - onChanged(); - } else { - data_ = null; - dataBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.Any.Builder getDataBuilder() { - - onChanged(); - return getDataFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any data = 2; - */ - public com.google.protobuf.AnyOrBuilder getDataOrBuilder() { - if (dataBuilder_ != null) { - return dataBuilder_.getMessageOrBuilder(); - } else { - return data_ == null ? - com.google.protobuf.Any.getDefaultInstance() : data_; - } - } - /** - * .google.protobuf.Any data = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getDataFieldBuilder() { - if (dataBuilder_ == null) { - dataBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getData(), - getParentForChildren(), - isClean()); - data_ = null; - } - return dataBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.PublishEventEnvelope) - } - - // @@protoc_insertion_point(class_scope:dapr.PublishEventEnvelope) - private static final io.dapr.DaprProtos.PublishEventEnvelope DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.PublishEventEnvelope(); - } - - public static io.dapr.DaprProtos.PublishEventEnvelope getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public PublishEventEnvelope parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new PublishEventEnvelope(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.PublishEventEnvelope getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.State) - com.google.protobuf.MessageOrBuilder { - - /** - * string key = 1; - * @return The key. - */ - java.lang.String getKey(); - /** - * string key = 1; - * @return The bytes for key. - */ - com.google.protobuf.ByteString - getKeyBytes(); - - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - boolean hasValue(); - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - com.google.protobuf.Any getValue(); - /** - * .google.protobuf.Any value = 2; - */ - com.google.protobuf.AnyOrBuilder getValueOrBuilder(); - - /** - * string etag = 3; - * @return The etag. - */ - java.lang.String getEtag(); - /** - * string etag = 3; - * @return The bytes for etag. - */ - com.google.protobuf.ByteString - getEtagBytes(); - - /** - * map<string, string> metadata = 4; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 4; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 4; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - - /** - * .dapr.StateOptions options = 5; - * @return Whether the options field is set. - */ - boolean hasOptions(); - /** - * .dapr.StateOptions options = 5; - * @return The options. - */ - io.dapr.DaprProtos.StateOptions getOptions(); - /** - * .dapr.StateOptions options = 5; - */ - io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder(); - } - /** - * Protobuf type {@code dapr.State} - */ - public static final class State extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.State) - StateOrBuilder { - private static final long serialVersionUID = 0L; - // Use State.newBuilder() to construct. - private State(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private State() { - key_ = ""; - etag_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new State(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private State( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - key_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (value_ != null) { - subBuilder = value_.toBuilder(); - } - value_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(value_); - value_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - etag_ = s; - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - case 42: { - io.dapr.DaprProtos.StateOptions.Builder subBuilder = null; - if (options_ != null) { - subBuilder = options_.toBuilder(); - } - options_ = input.readMessage(io.dapr.DaprProtos.StateOptions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(options_); - options_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_State_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_State_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.State.class, io.dapr.DaprProtos.State.Builder.class); - } - - public static final int KEY_FIELD_NUMBER = 1; - private volatile java.lang.Object key_; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int VALUE_FIELD_NUMBER = 2; - private com.google.protobuf.Any value_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - return getValue(); - } - - public static final int ETAG_FIELD_NUMBER = 3; - private volatile java.lang.Object etag_; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int METADATA_FIELD_NUMBER = 4; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprProtos.internal_static_dapr_State_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public static final int OPTIONS_FIELD_NUMBER = 5; - private io.dapr.DaprProtos.StateOptions options_; - /** - * .dapr.StateOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return options_ != null; - } - /** - * .dapr.StateOptions options = 5; - * @return The options. - */ - public io.dapr.DaprProtos.StateOptions getOptions() { - return options_ == null ? io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } - /** - * .dapr.StateOptions options = 5; - */ - public io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - return getOptions(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getKeyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); - } - if (value_ != null) { - output.writeMessage(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, etag_); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 4); - if (options_ != null) { - output.writeMessage(5, getOptions()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getKeyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); - } - if (value_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, etag_); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, metadata__); - } - if (options_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getOptions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.State)) { - return super.equals(obj); - } - io.dapr.DaprProtos.State other = (io.dapr.DaprProtos.State) obj; - - if (!getKey() - .equals(other.getKey())) return false; - if (hasValue() != other.hasValue()) return false; - if (hasValue()) { - if (!getValue() - .equals(other.getValue())) return false; - } - if (!getEtag() - .equals(other.getEtag())) return false; - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (hasOptions() != other.hasOptions()) return false; - if (hasOptions()) { - if (!getOptions() - .equals(other.getOptions())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + KEY_FIELD_NUMBER; - hash = (53 * hash) + getKey().hashCode(); - if (hasValue()) { - hash = (37 * hash) + VALUE_FIELD_NUMBER; - hash = (53 * hash) + getValue().hashCode(); - } - hash = (37 * hash) + ETAG_FIELD_NUMBER; - hash = (53 * hash) + getEtag().hashCode(); - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - if (hasOptions()) { - hash = (37 * hash) + OPTIONS_FIELD_NUMBER; - hash = (53 * hash) + getOptions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.State parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.State parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.State parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.State parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.State parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.State parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.State parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.State parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.State parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.State parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.State parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.State parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.State prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.State} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.State) - io.dapr.DaprProtos.StateOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_State_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 4: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_State_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.State.class, io.dapr.DaprProtos.State.Builder.class); - } - - // Construct using io.dapr.DaprProtos.State.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - key_ = ""; - - if (valueBuilder_ == null) { - value_ = null; - } else { - value_ = null; - valueBuilder_ = null; - } - etag_ = ""; - - internalGetMutableMetadata().clear(); - if (optionsBuilder_ == null) { - options_ = null; - } else { - options_ = null; - optionsBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_State_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.State getDefaultInstanceForType() { - return io.dapr.DaprProtos.State.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.State build() { - io.dapr.DaprProtos.State result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.State buildPartial() { - io.dapr.DaprProtos.State result = new io.dapr.DaprProtos.State(this); - int from_bitField0_ = bitField0_; - result.key_ = key_; - if (valueBuilder_ == null) { - result.value_ = value_; - } else { - result.value_ = valueBuilder_.build(); - } - result.etag_ = etag_; - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - if (optionsBuilder_ == null) { - result.options_ = options_; - } else { - result.options_ = optionsBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.State) { - return mergeFrom((io.dapr.DaprProtos.State)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.State other) { - if (other == io.dapr.DaprProtos.State.getDefaultInstance()) return this; - if (!other.getKey().isEmpty()) { - key_ = other.key_; - onChanged(); - } - if (other.hasValue()) { - mergeValue(other.getValue()); - } - if (!other.getEtag().isEmpty()) { - etag_ = other.etag_; - onChanged(); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - if (other.hasOptions()) { - mergeOptions(other.getOptions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.State parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.State) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object key_ = ""; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string key = 1; - * @param value The key to set. - * @return This builder for chaining. - */ - public Builder setKey( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - key_ = value; - onChanged(); - return this; - } - /** - * string key = 1; - * @return This builder for chaining. - */ - public Builder clearKey() { - - key_ = getDefaultInstance().getKey(); - onChanged(); - return this; - } - /** - * string key = 1; - * @param value The bytes for key to set. - * @return This builder for chaining. - */ - public Builder setKeyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - key_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any value_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> valueBuilder_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return valueBuilder_ != null || value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - if (valueBuilder_ == null) { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } else { - return valueBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - value_ = value; - onChanged(); - } else { - valueBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue( - com.google.protobuf.Any.Builder builderForValue) { - if (valueBuilder_ == null) { - value_ = builderForValue.build(); - onChanged(); - } else { - valueBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder mergeValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value_ != null) { - value_ = - com.google.protobuf.Any.newBuilder(value_).mergeFrom(value).buildPartial(); - } else { - value_ = value; - } - onChanged(); - } else { - valueBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder clearValue() { - if (valueBuilder_ == null) { - value_ = null; - onChanged(); - } else { - value_ = null; - valueBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.Any.Builder getValueBuilder() { - - onChanged(); - return getValueFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - if (valueBuilder_ != null) { - return valueBuilder_.getMessageOrBuilder(); - } else { - return value_ == null ? - com.google.protobuf.Any.getDefaultInstance() : value_; - } - } - /** - * .google.protobuf.Any value = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getValueFieldBuilder() { - if (valueBuilder_ == null) { - valueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getValue(), - getParentForChildren(), - isClean()); - value_ = null; - } - return valueBuilder_; - } - - private java.lang.Object etag_ = ""; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string etag = 3; - * @param value The etag to set. - * @return This builder for chaining. - */ - public Builder setEtag( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - etag_ = value; - onChanged(); - return this; - } - /** - * string etag = 3; - * @return This builder for chaining. - */ - public Builder clearEtag() { - - etag_ = getDefaultInstance().getEtag(); - onChanged(); - return this; - } - /** - * string etag = 3; - * @param value The bytes for etag to set. - * @return This builder for chaining. - */ - public Builder setEtagBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - etag_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 4; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - - private io.dapr.DaprProtos.StateOptions options_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder> optionsBuilder_; - /** - * .dapr.StateOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return optionsBuilder_ != null || options_ != null; - } - /** - * .dapr.StateOptions options = 5; - * @return The options. - */ - public io.dapr.DaprProtos.StateOptions getOptions() { - if (optionsBuilder_ == null) { - return options_ == null ? io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } else { - return optionsBuilder_.getMessage(); - } - } - /** - * .dapr.StateOptions options = 5; - */ - public Builder setOptions(io.dapr.DaprProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - options_ = value; - onChanged(); - } else { - optionsBuilder_.setMessage(value); - } - - return this; - } - /** - * .dapr.StateOptions options = 5; - */ - public Builder setOptions( - io.dapr.DaprProtos.StateOptions.Builder builderForValue) { - if (optionsBuilder_ == null) { - options_ = builderForValue.build(); - onChanged(); - } else { - optionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .dapr.StateOptions options = 5; - */ - public Builder mergeOptions(io.dapr.DaprProtos.StateOptions value) { - if (optionsBuilder_ == null) { - if (options_ != null) { - options_ = - io.dapr.DaprProtos.StateOptions.newBuilder(options_).mergeFrom(value).buildPartial(); - } else { - options_ = value; - } - onChanged(); - } else { - optionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .dapr.StateOptions options = 5; - */ - public Builder clearOptions() { - if (optionsBuilder_ == null) { - options_ = null; - onChanged(); - } else { - options_ = null; - optionsBuilder_ = null; - } - - return this; - } - /** - * .dapr.StateOptions options = 5; - */ - public io.dapr.DaprProtos.StateOptions.Builder getOptionsBuilder() { - - onChanged(); - return getOptionsFieldBuilder().getBuilder(); - } - /** - * .dapr.StateOptions options = 5; - */ - public io.dapr.DaprProtos.StateOptionsOrBuilder getOptionsOrBuilder() { - if (optionsBuilder_ != null) { - return optionsBuilder_.getMessageOrBuilder(); - } else { - return options_ == null ? - io.dapr.DaprProtos.StateOptions.getDefaultInstance() : options_; - } - } - /** - * .dapr.StateOptions options = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder> - getOptionsFieldBuilder() { - if (optionsBuilder_ == null) { - optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateOptions, io.dapr.DaprProtos.StateOptions.Builder, io.dapr.DaprProtos.StateOptionsOrBuilder>( - getOptions(), - getParentForChildren(), - isClean()); - options_ = null; - } - return optionsBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.State) - } - - // @@protoc_insertion_point(class_scope:dapr.State) - private static final io.dapr.DaprProtos.State DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.State(); - } - - public static io.dapr.DaprProtos.State getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public State parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new State(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.State getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateOptionsOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.StateOptions) - com.google.protobuf.MessageOrBuilder { - - /** - * string concurrency = 1; - * @return The concurrency. - */ - java.lang.String getConcurrency(); - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - com.google.protobuf.ByteString - getConcurrencyBytes(); - - /** - * string consistency = 2; - * @return The consistency. - */ - java.lang.String getConsistency(); - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - com.google.protobuf.ByteString - getConsistencyBytes(); - - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - boolean hasRetryPolicy(); - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - io.dapr.DaprProtos.RetryPolicy getRetryPolicy(); - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - io.dapr.DaprProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder(); - } - /** - * Protobuf type {@code dapr.StateOptions} - */ - public static final class StateOptions extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.StateOptions) - StateOptionsOrBuilder { - private static final long serialVersionUID = 0L; - // Use StateOptions.newBuilder() to construct. - private StateOptions(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StateOptions() { - concurrency_ = ""; - consistency_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new StateOptions(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StateOptions( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - concurrency_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - consistency_ = s; - break; - } - case 26: { - io.dapr.DaprProtos.RetryPolicy.Builder subBuilder = null; - if (retryPolicy_ != null) { - subBuilder = retryPolicy_.toBuilder(); - } - retryPolicy_ = input.readMessage(io.dapr.DaprProtos.RetryPolicy.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(retryPolicy_); - retryPolicy_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateOptions.class, io.dapr.DaprProtos.StateOptions.Builder.class); - } - - public static final int CONCURRENCY_FIELD_NUMBER = 1; - private volatile java.lang.Object concurrency_; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int CONSISTENCY_FIELD_NUMBER = 2; - private volatile java.lang.Object consistency_; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RETRYPOLICY_FIELD_NUMBER = 3; - private io.dapr.DaprProtos.RetryPolicy retryPolicy_; - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicy_ != null; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprProtos.RetryPolicy getRetryPolicy() { - return retryPolicy_ == null ? io.dapr.DaprProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder() { - return getRetryPolicy(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getConcurrencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, consistency_); - } - if (retryPolicy_ != null) { - output.writeMessage(3, getRetryPolicy()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getConcurrencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, consistency_); - } - if (retryPolicy_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getRetryPolicy()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.StateOptions)) { - return super.equals(obj); - } - io.dapr.DaprProtos.StateOptions other = (io.dapr.DaprProtos.StateOptions) obj; - - if (!getConcurrency() - .equals(other.getConcurrency())) return false; - if (!getConsistency() - .equals(other.getConsistency())) return false; - if (hasRetryPolicy() != other.hasRetryPolicy()) return false; - if (hasRetryPolicy()) { - if (!getRetryPolicy() - .equals(other.getRetryPolicy())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + CONCURRENCY_FIELD_NUMBER; - hash = (53 * hash) + getConcurrency().hashCode(); - hash = (37 * hash) + CONSISTENCY_FIELD_NUMBER; - hash = (53 * hash) + getConsistency().hashCode(); - if (hasRetryPolicy()) { - hash = (37 * hash) + RETRYPOLICY_FIELD_NUMBER; - hash = (53 * hash) + getRetryPolicy().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.StateOptions parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateOptions parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateOptions parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateOptions parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateOptions parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateOptions parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.StateOptions prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.StateOptions} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.StateOptions) - io.dapr.DaprProtos.StateOptionsOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateOptions.class, io.dapr.DaprProtos.StateOptions.Builder.class); - } - - // Construct using io.dapr.DaprProtos.StateOptions.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - concurrency_ = ""; - - consistency_ = ""; - - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_StateOptions_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateOptions getDefaultInstanceForType() { - return io.dapr.DaprProtos.StateOptions.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.StateOptions build() { - io.dapr.DaprProtos.StateOptions result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateOptions buildPartial() { - io.dapr.DaprProtos.StateOptions result = new io.dapr.DaprProtos.StateOptions(this); - result.concurrency_ = concurrency_; - result.consistency_ = consistency_; - if (retryPolicyBuilder_ == null) { - result.retryPolicy_ = retryPolicy_; - } else { - result.retryPolicy_ = retryPolicyBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.StateOptions) { - return mergeFrom((io.dapr.DaprProtos.StateOptions)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.StateOptions other) { - if (other == io.dapr.DaprProtos.StateOptions.getDefaultInstance()) return this; - if (!other.getConcurrency().isEmpty()) { - concurrency_ = other.concurrency_; - onChanged(); - } - if (!other.getConsistency().isEmpty()) { - consistency_ = other.consistency_; - onChanged(); - } - if (other.hasRetryPolicy()) { - mergeRetryPolicy(other.getRetryPolicy()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.StateOptions parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.StateOptions) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object concurrency_ = ""; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string concurrency = 1; - * @param value The concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - concurrency_ = value; - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @return This builder for chaining. - */ - public Builder clearConcurrency() { - - concurrency_ = getDefaultInstance().getConcurrency(); - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @param value The bytes for concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - concurrency_ = value; - onChanged(); - return this; - } - - private java.lang.Object consistency_ = ""; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string consistency = 2; - * @param value The consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - consistency_ = value; - onChanged(); - return this; - } - /** - * string consistency = 2; - * @return This builder for chaining. - */ - public Builder clearConsistency() { - - consistency_ = getDefaultInstance().getConsistency(); - onChanged(); - return this; - } - /** - * string consistency = 2; - * @param value The bytes for consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - consistency_ = value; - onChanged(); - return this; - } - - private io.dapr.DaprProtos.RetryPolicy retryPolicy_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.RetryPolicy, io.dapr.DaprProtos.RetryPolicy.Builder, io.dapr.DaprProtos.RetryPolicyOrBuilder> retryPolicyBuilder_; - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicyBuilder_ != null || retryPolicy_ != null; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprProtos.RetryPolicy getRetryPolicy() { - if (retryPolicyBuilder_ == null) { - return retryPolicy_ == null ? io.dapr.DaprProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } else { - return retryPolicyBuilder_.getMessage(); - } - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy(io.dapr.DaprProtos.RetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - retryPolicy_ = value; - onChanged(); - } else { - retryPolicyBuilder_.setMessage(value); - } - - return this; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy( - io.dapr.DaprProtos.RetryPolicy.Builder builderForValue) { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = builderForValue.build(); - onChanged(); - } else { - retryPolicyBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public Builder mergeRetryPolicy(io.dapr.DaprProtos.RetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (retryPolicy_ != null) { - retryPolicy_ = - io.dapr.DaprProtos.RetryPolicy.newBuilder(retryPolicy_).mergeFrom(value).buildPartial(); - } else { - retryPolicy_ = value; - } - onChanged(); - } else { - retryPolicyBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public Builder clearRetryPolicy() { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - onChanged(); - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - - return this; - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.RetryPolicy.Builder getRetryPolicyBuilder() { - - onChanged(); - return getRetryPolicyFieldBuilder().getBuilder(); - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.RetryPolicyOrBuilder getRetryPolicyOrBuilder() { - if (retryPolicyBuilder_ != null) { - return retryPolicyBuilder_.getMessageOrBuilder(); - } else { - return retryPolicy_ == null ? - io.dapr.DaprProtos.RetryPolicy.getDefaultInstance() : retryPolicy_; - } - } - /** - * .dapr.RetryPolicy retryPolicy = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.RetryPolicy, io.dapr.DaprProtos.RetryPolicy.Builder, io.dapr.DaprProtos.RetryPolicyOrBuilder> - getRetryPolicyFieldBuilder() { - if (retryPolicyBuilder_ == null) { - retryPolicyBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.RetryPolicy, io.dapr.DaprProtos.RetryPolicy.Builder, io.dapr.DaprProtos.RetryPolicyOrBuilder>( - getRetryPolicy(), - getParentForChildren(), - isClean()); - retryPolicy_ = null; - } - return retryPolicyBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.StateOptions) - } - - // @@protoc_insertion_point(class_scope:dapr.StateOptions) - private static final io.dapr.DaprProtos.StateOptions DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.StateOptions(); - } - - public static io.dapr.DaprProtos.StateOptions getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public StateOptions parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StateOptions(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateOptions getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface RetryPolicyOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.RetryPolicy) - com.google.protobuf.MessageOrBuilder { - - /** - * int32 threshold = 1; - * @return The threshold. - */ - int getThreshold(); - - /** - * string pattern = 2; - * @return The pattern. - */ - java.lang.String getPattern(); - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - com.google.protobuf.ByteString - getPatternBytes(); - - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - boolean hasInterval(); - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - com.google.protobuf.Duration getInterval(); - /** - * .google.protobuf.Duration interval = 3; - */ - com.google.protobuf.DurationOrBuilder getIntervalOrBuilder(); - } - /** - * Protobuf type {@code dapr.RetryPolicy} - */ - public static final class RetryPolicy extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.RetryPolicy) - RetryPolicyOrBuilder { - private static final long serialVersionUID = 0L; - // Use RetryPolicy.newBuilder() to construct. - private RetryPolicy(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private RetryPolicy() { - pattern_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new RetryPolicy(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private RetryPolicy( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 8: { - - threshold_ = input.readInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - pattern_ = s; - break; - } - case 26: { - com.google.protobuf.Duration.Builder subBuilder = null; - if (interval_ != null) { - subBuilder = interval_.toBuilder(); - } - interval_ = input.readMessage(com.google.protobuf.Duration.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(interval_); - interval_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_RetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_RetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.RetryPolicy.class, io.dapr.DaprProtos.RetryPolicy.Builder.class); - } - - public static final int THRESHOLD_FIELD_NUMBER = 1; - private int threshold_; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - - public static final int PATTERN_FIELD_NUMBER = 2; - private volatile java.lang.Object pattern_; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int INTERVAL_FIELD_NUMBER = 3; - private com.google.protobuf.Duration interval_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - return getInterval(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (threshold_ != 0) { - output.writeInt32(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, pattern_); - } - if (interval_ != null) { - output.writeMessage(3, getInterval()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (threshold_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, pattern_); - } - if (interval_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getInterval()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.RetryPolicy)) { - return super.equals(obj); - } - io.dapr.DaprProtos.RetryPolicy other = (io.dapr.DaprProtos.RetryPolicy) obj; - - if (getThreshold() - != other.getThreshold()) return false; - if (!getPattern() - .equals(other.getPattern())) return false; - if (hasInterval() != other.hasInterval()) return false; - if (hasInterval()) { - if (!getInterval() - .equals(other.getInterval())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + THRESHOLD_FIELD_NUMBER; - hash = (53 * hash) + getThreshold(); - hash = (37 * hash) + PATTERN_FIELD_NUMBER; - hash = (53 * hash) + getPattern().hashCode(); - if (hasInterval()) { - hash = (37 * hash) + INTERVAL_FIELD_NUMBER; - hash = (53 * hash) + getInterval().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.RetryPolicy parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.RetryPolicy parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.RetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.RetryPolicy prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.RetryPolicy} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.RetryPolicy) - io.dapr.DaprProtos.RetryPolicyOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_RetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_RetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.RetryPolicy.class, io.dapr.DaprProtos.RetryPolicy.Builder.class); - } - - // Construct using io.dapr.DaprProtos.RetryPolicy.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - threshold_ = 0; - - pattern_ = ""; - - if (intervalBuilder_ == null) { - interval_ = null; - } else { - interval_ = null; - intervalBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_RetryPolicy_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.RetryPolicy getDefaultInstanceForType() { - return io.dapr.DaprProtos.RetryPolicy.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.RetryPolicy build() { - io.dapr.DaprProtos.RetryPolicy result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.RetryPolicy buildPartial() { - io.dapr.DaprProtos.RetryPolicy result = new io.dapr.DaprProtos.RetryPolicy(this); - result.threshold_ = threshold_; - result.pattern_ = pattern_; - if (intervalBuilder_ == null) { - result.interval_ = interval_; - } else { - result.interval_ = intervalBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.RetryPolicy) { - return mergeFrom((io.dapr.DaprProtos.RetryPolicy)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.RetryPolicy other) { - if (other == io.dapr.DaprProtos.RetryPolicy.getDefaultInstance()) return this; - if (other.getThreshold() != 0) { - setThreshold(other.getThreshold()); - } - if (!other.getPattern().isEmpty()) { - pattern_ = other.pattern_; - onChanged(); - } - if (other.hasInterval()) { - mergeInterval(other.getInterval()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.RetryPolicy parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.RetryPolicy) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int threshold_ ; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - /** - * int32 threshold = 1; - * @param value The threshold to set. - * @return This builder for chaining. - */ - public Builder setThreshold(int value) { - - threshold_ = value; - onChanged(); - return this; - } - /** - * int32 threshold = 1; - * @return This builder for chaining. - */ - public Builder clearThreshold() { - - threshold_ = 0; - onChanged(); - return this; - } - - private java.lang.Object pattern_ = ""; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string pattern = 2; - * @param value The pattern to set. - * @return This builder for chaining. - */ - public Builder setPattern( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - pattern_ = value; - onChanged(); - return this; - } - /** - * string pattern = 2; - * @return This builder for chaining. - */ - public Builder clearPattern() { - - pattern_ = getDefaultInstance().getPattern(); - onChanged(); - return this; - } - /** - * string pattern = 2; - * @param value The bytes for pattern to set. - * @return This builder for chaining. - */ - public Builder setPatternBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - pattern_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Duration interval_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> intervalBuilder_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return intervalBuilder_ != null || interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - if (intervalBuilder_ == null) { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } else { - return intervalBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - interval_ = value; - onChanged(); - } else { - intervalBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval( - com.google.protobuf.Duration.Builder builderForValue) { - if (intervalBuilder_ == null) { - interval_ = builderForValue.build(); - onChanged(); - } else { - intervalBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder mergeInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (interval_ != null) { - interval_ = - com.google.protobuf.Duration.newBuilder(interval_).mergeFrom(value).buildPartial(); - } else { - interval_ = value; - } - onChanged(); - } else { - intervalBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder clearInterval() { - if (intervalBuilder_ == null) { - interval_ = null; - onChanged(); - } else { - interval_ = null; - intervalBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.Duration.Builder getIntervalBuilder() { - - onChanged(); - return getIntervalFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - if (intervalBuilder_ != null) { - return intervalBuilder_.getMessageOrBuilder(); - } else { - return interval_ == null ? - com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> - getIntervalFieldBuilder() { - if (intervalBuilder_ == null) { - intervalBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder>( - getInterval(), - getParentForChildren(), - isClean()); - interval_ = null; - } - return intervalBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.RetryPolicy) - } - - // @@protoc_insertion_point(class_scope:dapr.RetryPolicy) - private static final io.dapr.DaprProtos.RetryPolicy DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.RetryPolicy(); - } - - public static io.dapr.DaprProtos.RetryPolicy getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public RetryPolicy parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new RetryPolicy(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.RetryPolicy getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.StateRequest) - com.google.protobuf.MessageOrBuilder { - - /** - * string key = 1; - * @return The key. - */ - java.lang.String getKey(); - /** - * string key = 1; - * @return The bytes for key. - */ - com.google.protobuf.ByteString - getKeyBytes(); - - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - boolean hasValue(); - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - com.google.protobuf.Any getValue(); - /** - * .google.protobuf.Any value = 2; - */ - com.google.protobuf.AnyOrBuilder getValueOrBuilder(); - - /** - * string etag = 3; - * @return The etag. - */ - java.lang.String getEtag(); - /** - * string etag = 3; - * @return The bytes for etag. - */ - com.google.protobuf.ByteString - getEtagBytes(); - - /** - * map<string, string> metadata = 4; - */ - int getMetadataCount(); - /** - * map<string, string> metadata = 4; - */ - boolean containsMetadata( - java.lang.String key); - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - java.util.Map - getMetadata(); - /** - * map<string, string> metadata = 4; - */ - java.util.Map - getMetadataMap(); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue); - /** - * map<string, string> metadata = 4; - */ - - java.lang.String getMetadataOrThrow( - java.lang.String key); - - /** - * .dapr.StateRequestOptions options = 5; - * @return Whether the options field is set. - */ - boolean hasOptions(); - /** - * .dapr.StateRequestOptions options = 5; - * @return The options. - */ - io.dapr.DaprProtos.StateRequestOptions getOptions(); - /** - * .dapr.StateRequestOptions options = 5; - */ - io.dapr.DaprProtos.StateRequestOptionsOrBuilder getOptionsOrBuilder(); - } - /** - * Protobuf type {@code dapr.StateRequest} - */ - public static final class StateRequest extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.StateRequest) - StateRequestOrBuilder { - private static final long serialVersionUID = 0L; - // Use StateRequest.newBuilder() to construct. - private StateRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StateRequest() { - key_ = ""; - etag_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new StateRequest(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StateRequest( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - key_ = s; - break; - } - case 18: { - com.google.protobuf.Any.Builder subBuilder = null; - if (value_ != null) { - subBuilder = value_.toBuilder(); - } - value_ = input.readMessage(com.google.protobuf.Any.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(value_); - value_ = subBuilder.buildPartial(); - } - - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - etag_ = s; - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000001) != 0)) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - mutable_bitField0_ |= 0x00000001; - } - com.google.protobuf.MapEntry - metadata__ = input.readMessage( - MetadataDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); - metadata_.getMutableMap().put( - metadata__.getKey(), metadata__.getValue()); - break; - } - case 42: { - io.dapr.DaprProtos.StateRequestOptions.Builder subBuilder = null; - if (options_ != null) { - subBuilder = options_.toBuilder(); - } - options_ = input.readMessage(io.dapr.DaprProtos.StateRequestOptions.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(options_); - options_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequest_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - @java.lang.Override - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRequest.class, io.dapr.DaprProtos.StateRequest.Builder.class); - } - - public static final int KEY_FIELD_NUMBER = 1; - private volatile java.lang.Object key_; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int VALUE_FIELD_NUMBER = 2; - private com.google.protobuf.Any value_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - return getValue(); - } - - public static final int ETAG_FIELD_NUMBER = 3; - private volatile java.lang.Object etag_; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int METADATA_FIELD_NUMBER = 4; - private static final class MetadataDefaultEntryHolder { - static final com.google.protobuf.MapEntry< - java.lang.String, java.lang.String> defaultEntry = - com.google.protobuf.MapEntry - .newDefaultInstance( - io.dapr.DaprProtos.internal_static_dapr_StateRequest_MetadataEntry_descriptor, - com.google.protobuf.WireFormat.FieldType.STRING, - "", - com.google.protobuf.WireFormat.FieldType.STRING, - ""); - } - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public static final int OPTIONS_FIELD_NUMBER = 5; - private io.dapr.DaprProtos.StateRequestOptions options_; - /** - * .dapr.StateRequestOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return options_ != null; - } - /** - * .dapr.StateRequestOptions options = 5; - * @return The options. - */ - public io.dapr.DaprProtos.StateRequestOptions getOptions() { - return options_ == null ? io.dapr.DaprProtos.StateRequestOptions.getDefaultInstance() : options_; - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public io.dapr.DaprProtos.StateRequestOptionsOrBuilder getOptionsOrBuilder() { - return getOptions(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getKeyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); - } - if (value_ != null) { - output.writeMessage(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, etag_); - } - com.google.protobuf.GeneratedMessageV3 - .serializeStringMapTo( - output, - internalGetMetadata(), - MetadataDefaultEntryHolder.defaultEntry, - 4); - if (options_ != null) { - output.writeMessage(5, getOptions()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getKeyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); - } - if (value_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, getValue()); - } - if (!getEtagBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, etag_); - } - for (java.util.Map.Entry entry - : internalGetMetadata().getMap().entrySet()) { - com.google.protobuf.MapEntry - metadata__ = MetadataDefaultEntryHolder.defaultEntry.newBuilderForType() - .setKey(entry.getKey()) - .setValue(entry.getValue()) - .build(); - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, metadata__); - } - if (options_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(5, getOptions()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.StateRequest)) { - return super.equals(obj); - } - io.dapr.DaprProtos.StateRequest other = (io.dapr.DaprProtos.StateRequest) obj; - - if (!getKey() - .equals(other.getKey())) return false; - if (hasValue() != other.hasValue()) return false; - if (hasValue()) { - if (!getValue() - .equals(other.getValue())) return false; - } - if (!getEtag() - .equals(other.getEtag())) return false; - if (!internalGetMetadata().equals( - other.internalGetMetadata())) return false; - if (hasOptions() != other.hasOptions()) return false; - if (hasOptions()) { - if (!getOptions() - .equals(other.getOptions())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + KEY_FIELD_NUMBER; - hash = (53 * hash) + getKey().hashCode(); - if (hasValue()) { - hash = (37 * hash) + VALUE_FIELD_NUMBER; - hash = (53 * hash) + getValue().hashCode(); - } - hash = (37 * hash) + ETAG_FIELD_NUMBER; - hash = (53 * hash) + getEtag().hashCode(); - if (!internalGetMetadata().getMap().isEmpty()) { - hash = (37 * hash) + METADATA_FIELD_NUMBER; - hash = (53 * hash) + internalGetMetadata().hashCode(); - } - if (hasOptions()) { - hash = (37 * hash) + OPTIONS_FIELD_NUMBER; - hash = (53 * hash) + getOptions().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.StateRequest parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.StateRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.StateRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.StateRequest) - io.dapr.DaprProtos.StateRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequest_descriptor; - } - - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMapField( - int number) { - switch (number) { - case 4: - return internalGetMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @SuppressWarnings({"rawtypes"}) - protected com.google.protobuf.MapField internalGetMutableMapField( - int number) { - switch (number) { - case 4: - return internalGetMutableMetadata(); - default: - throw new RuntimeException( - "Invalid map field number: " + number); - } - } - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRequest.class, io.dapr.DaprProtos.StateRequest.Builder.class); - } - - // Construct using io.dapr.DaprProtos.StateRequest.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - key_ = ""; - - if (valueBuilder_ == null) { - value_ = null; - } else { - value_ = null; - valueBuilder_ = null; - } - etag_ = ""; - - internalGetMutableMetadata().clear(); - if (optionsBuilder_ == null) { - options_ = null; - } else { - options_ = null; - optionsBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequest_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequest getDefaultInstanceForType() { - return io.dapr.DaprProtos.StateRequest.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequest build() { - io.dapr.DaprProtos.StateRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequest buildPartial() { - io.dapr.DaprProtos.StateRequest result = new io.dapr.DaprProtos.StateRequest(this); - int from_bitField0_ = bitField0_; - result.key_ = key_; - if (valueBuilder_ == null) { - result.value_ = value_; - } else { - result.value_ = valueBuilder_.build(); - } - result.etag_ = etag_; - result.metadata_ = internalGetMetadata(); - result.metadata_.makeImmutable(); - if (optionsBuilder_ == null) { - result.options_ = options_; - } else { - result.options_ = optionsBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.StateRequest) { - return mergeFrom((io.dapr.DaprProtos.StateRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.StateRequest other) { - if (other == io.dapr.DaprProtos.StateRequest.getDefaultInstance()) return this; - if (!other.getKey().isEmpty()) { - key_ = other.key_; - onChanged(); - } - if (other.hasValue()) { - mergeValue(other.getValue()); - } - if (!other.getEtag().isEmpty()) { - etag_ = other.etag_; - onChanged(); - } - internalGetMutableMetadata().mergeFrom( - other.internalGetMetadata()); - if (other.hasOptions()) { - mergeOptions(other.getOptions()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.StateRequest parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.StateRequest) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object key_ = ""; - /** - * string key = 1; - * @return The key. - */ - public java.lang.String getKey() { - java.lang.Object ref = key_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - key_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string key = 1; - * @return The bytes for key. - */ - public com.google.protobuf.ByteString - getKeyBytes() { - java.lang.Object ref = key_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - key_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string key = 1; - * @param value The key to set. - * @return This builder for chaining. - */ - public Builder setKey( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - key_ = value; - onChanged(); - return this; - } - /** - * string key = 1; - * @return This builder for chaining. - */ - public Builder clearKey() { - - key_ = getDefaultInstance().getKey(); - onChanged(); - return this; - } - /** - * string key = 1; - * @param value The bytes for key to set. - * @return This builder for chaining. - */ - public Builder setKeyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - key_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Any value_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> valueBuilder_; - /** - * .google.protobuf.Any value = 2; - * @return Whether the value field is set. - */ - public boolean hasValue() { - return valueBuilder_ != null || value_ != null; - } - /** - * .google.protobuf.Any value = 2; - * @return The value. - */ - public com.google.protobuf.Any getValue() { - if (valueBuilder_ == null) { - return value_ == null ? com.google.protobuf.Any.getDefaultInstance() : value_; - } else { - return valueBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - value_ = value; - onChanged(); - } else { - valueBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder setValue( - com.google.protobuf.Any.Builder builderForValue) { - if (valueBuilder_ == null) { - value_ = builderForValue.build(); - onChanged(); - } else { - valueBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder mergeValue(com.google.protobuf.Any value) { - if (valueBuilder_ == null) { - if (value_ != null) { - value_ = - com.google.protobuf.Any.newBuilder(value_).mergeFrom(value).buildPartial(); - } else { - value_ = value; - } - onChanged(); - } else { - valueBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public Builder clearValue() { - if (valueBuilder_ == null) { - value_ = null; - onChanged(); - } else { - value_ = null; - valueBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.Any.Builder getValueBuilder() { - - onChanged(); - return getValueFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Any value = 2; - */ - public com.google.protobuf.AnyOrBuilder getValueOrBuilder() { - if (valueBuilder_ != null) { - return valueBuilder_.getMessageOrBuilder(); - } else { - return value_ == null ? - com.google.protobuf.Any.getDefaultInstance() : value_; - } - } - /** - * .google.protobuf.Any value = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder> - getValueFieldBuilder() { - if (valueBuilder_ == null) { - valueBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Any, com.google.protobuf.Any.Builder, com.google.protobuf.AnyOrBuilder>( - getValue(), - getParentForChildren(), - isClean()); - value_ = null; - } - return valueBuilder_; - } - - private java.lang.Object etag_ = ""; - /** - * string etag = 3; - * @return The etag. - */ - public java.lang.String getEtag() { - java.lang.Object ref = etag_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - etag_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string etag = 3; - * @return The bytes for etag. - */ - public com.google.protobuf.ByteString - getEtagBytes() { - java.lang.Object ref = etag_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - etag_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string etag = 3; - * @param value The etag to set. - * @return This builder for chaining. - */ - public Builder setEtag( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - etag_ = value; - onChanged(); - return this; - } - /** - * string etag = 3; - * @return This builder for chaining. - */ - public Builder clearEtag() { - - etag_ = getDefaultInstance().getEtag(); - onChanged(); - return this; - } - /** - * string etag = 3; - * @param value The bytes for etag to set. - * @return This builder for chaining. - */ - public Builder setEtagBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - etag_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.MapField< - java.lang.String, java.lang.String> metadata_; - private com.google.protobuf.MapField - internalGetMetadata() { - if (metadata_ == null) { - return com.google.protobuf.MapField.emptyMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - return metadata_; - } - private com.google.protobuf.MapField - internalGetMutableMetadata() { - onChanged();; - if (metadata_ == null) { - metadata_ = com.google.protobuf.MapField.newMapField( - MetadataDefaultEntryHolder.defaultEntry); - } - if (!metadata_.isMutable()) { - metadata_ = metadata_.copy(); - } - return metadata_; - } - - public int getMetadataCount() { - return internalGetMetadata().getMap().size(); - } - /** - * map<string, string> metadata = 4; - */ - - public boolean containsMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - return internalGetMetadata().getMap().containsKey(key); - } - /** - * Use {@link #getMetadataMap()} instead. - */ - @java.lang.Deprecated - public java.util.Map getMetadata() { - return getMetadataMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.util.Map getMetadataMap() { - return internalGetMetadata().getMap(); - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrDefault( - java.lang.String key, - java.lang.String defaultValue) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - return map.containsKey(key) ? map.get(key) : defaultValue; - } - /** - * map<string, string> metadata = 4; - */ - - public java.lang.String getMetadataOrThrow( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - java.util.Map map = - internalGetMetadata().getMap(); - if (!map.containsKey(key)) { - throw new java.lang.IllegalArgumentException(); - } - return map.get(key); - } - - public Builder clearMetadata() { - internalGetMutableMetadata().getMutableMap() - .clear(); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder removeMetadata( - java.lang.String key) { - if (key == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .remove(key); - return this; - } - /** - * Use alternate mutation accessors instead. - */ - @java.lang.Deprecated - public java.util.Map - getMutableMetadata() { - return internalGetMutableMetadata().getMutableMap(); - } - /** - * map<string, string> metadata = 4; - */ - public Builder putMetadata( - java.lang.String key, - java.lang.String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } - internalGetMutableMetadata().getMutableMap() - .put(key, value); - return this; - } - /** - * map<string, string> metadata = 4; - */ - - public Builder putAllMetadata( - java.util.Map values) { - internalGetMutableMetadata().getMutableMap() - .putAll(values); - return this; - } - - private io.dapr.DaprProtos.StateRequestOptions options_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRequestOptions, io.dapr.DaprProtos.StateRequestOptions.Builder, io.dapr.DaprProtos.StateRequestOptionsOrBuilder> optionsBuilder_; - /** - * .dapr.StateRequestOptions options = 5; - * @return Whether the options field is set. - */ - public boolean hasOptions() { - return optionsBuilder_ != null || options_ != null; - } - /** - * .dapr.StateRequestOptions options = 5; - * @return The options. - */ - public io.dapr.DaprProtos.StateRequestOptions getOptions() { - if (optionsBuilder_ == null) { - return options_ == null ? io.dapr.DaprProtos.StateRequestOptions.getDefaultInstance() : options_; - } else { - return optionsBuilder_.getMessage(); - } - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public Builder setOptions(io.dapr.DaprProtos.StateRequestOptions value) { - if (optionsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - options_ = value; - onChanged(); - } else { - optionsBuilder_.setMessage(value); - } - - return this; - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public Builder setOptions( - io.dapr.DaprProtos.StateRequestOptions.Builder builderForValue) { - if (optionsBuilder_ == null) { - options_ = builderForValue.build(); - onChanged(); - } else { - optionsBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public Builder mergeOptions(io.dapr.DaprProtos.StateRequestOptions value) { - if (optionsBuilder_ == null) { - if (options_ != null) { - options_ = - io.dapr.DaprProtos.StateRequestOptions.newBuilder(options_).mergeFrom(value).buildPartial(); - } else { - options_ = value; - } - onChanged(); - } else { - optionsBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public Builder clearOptions() { - if (optionsBuilder_ == null) { - options_ = null; - onChanged(); - } else { - options_ = null; - optionsBuilder_ = null; - } - - return this; - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public io.dapr.DaprProtos.StateRequestOptions.Builder getOptionsBuilder() { - - onChanged(); - return getOptionsFieldBuilder().getBuilder(); - } - /** - * .dapr.StateRequestOptions options = 5; - */ - public io.dapr.DaprProtos.StateRequestOptionsOrBuilder getOptionsOrBuilder() { - if (optionsBuilder_ != null) { - return optionsBuilder_.getMessageOrBuilder(); - } else { - return options_ == null ? - io.dapr.DaprProtos.StateRequestOptions.getDefaultInstance() : options_; - } - } - /** - * .dapr.StateRequestOptions options = 5; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRequestOptions, io.dapr.DaprProtos.StateRequestOptions.Builder, io.dapr.DaprProtos.StateRequestOptionsOrBuilder> - getOptionsFieldBuilder() { - if (optionsBuilder_ == null) { - optionsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRequestOptions, io.dapr.DaprProtos.StateRequestOptions.Builder, io.dapr.DaprProtos.StateRequestOptionsOrBuilder>( - getOptions(), - getParentForChildren(), - isClean()); - options_ = null; - } - return optionsBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.StateRequest) - } - - // @@protoc_insertion_point(class_scope:dapr.StateRequest) - private static final io.dapr.DaprProtos.StateRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.StateRequest(); - } - - public static io.dapr.DaprProtos.StateRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public StateRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StateRequest(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateRequestOptionsOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.StateRequestOptions) - com.google.protobuf.MessageOrBuilder { - - /** - * string concurrency = 1; - * @return The concurrency. - */ - java.lang.String getConcurrency(); - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - com.google.protobuf.ByteString - getConcurrencyBytes(); - - /** - * string consistency = 2; - * @return The consistency. - */ - java.lang.String getConsistency(); - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - com.google.protobuf.ByteString - getConsistencyBytes(); - - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - boolean hasRetryPolicy(); - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - io.dapr.DaprProtos.StateRetryPolicy getRetryPolicy(); - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - io.dapr.DaprProtos.StateRetryPolicyOrBuilder getRetryPolicyOrBuilder(); - } - /** - * Protobuf type {@code dapr.StateRequestOptions} - */ - public static final class StateRequestOptions extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.StateRequestOptions) - StateRequestOptionsOrBuilder { - private static final long serialVersionUID = 0L; - // Use StateRequestOptions.newBuilder() to construct. - private StateRequestOptions(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StateRequestOptions() { - concurrency_ = ""; - consistency_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new StateRequestOptions(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StateRequestOptions( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - concurrency_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - consistency_ = s; - break; - } - case 26: { - io.dapr.DaprProtos.StateRetryPolicy.Builder subBuilder = null; - if (retryPolicy_ != null) { - subBuilder = retryPolicy_.toBuilder(); - } - retryPolicy_ = input.readMessage(io.dapr.DaprProtos.StateRetryPolicy.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(retryPolicy_); - retryPolicy_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequestOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequestOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRequestOptions.class, io.dapr.DaprProtos.StateRequestOptions.Builder.class); - } - - public static final int CONCURRENCY_FIELD_NUMBER = 1; - private volatile java.lang.Object concurrency_; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int CONSISTENCY_FIELD_NUMBER = 2; - private volatile java.lang.Object consistency_; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int RETRYPOLICY_FIELD_NUMBER = 3; - private io.dapr.DaprProtos.StateRetryPolicy retryPolicy_; - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicy_ != null; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprProtos.StateRetryPolicy getRetryPolicy() { - return retryPolicy_ == null ? io.dapr.DaprProtos.StateRetryPolicy.getDefaultInstance() : retryPolicy_; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.StateRetryPolicyOrBuilder getRetryPolicyOrBuilder() { - return getRetryPolicy(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getConcurrencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, consistency_); - } - if (retryPolicy_ != null) { - output.writeMessage(3, getRetryPolicy()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getConcurrencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, concurrency_); - } - if (!getConsistencyBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, consistency_); - } - if (retryPolicy_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getRetryPolicy()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.StateRequestOptions)) { - return super.equals(obj); - } - io.dapr.DaprProtos.StateRequestOptions other = (io.dapr.DaprProtos.StateRequestOptions) obj; - - if (!getConcurrency() - .equals(other.getConcurrency())) return false; - if (!getConsistency() - .equals(other.getConsistency())) return false; - if (hasRetryPolicy() != other.hasRetryPolicy()) return false; - if (hasRetryPolicy()) { - if (!getRetryPolicy() - .equals(other.getRetryPolicy())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + CONCURRENCY_FIELD_NUMBER; - hash = (53 * hash) + getConcurrency().hashCode(); - hash = (37 * hash) + CONSISTENCY_FIELD_NUMBER; - hash = (53 * hash) + getConsistency().hashCode(); - if (hasRetryPolicy()) { - hash = (37 * hash) + RETRYPOLICY_FIELD_NUMBER; - hash = (53 * hash) + getRetryPolicy().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequestOptions parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequestOptions parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRequestOptions parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.StateRequestOptions prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.StateRequestOptions} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.StateRequestOptions) - io.dapr.DaprProtos.StateRequestOptionsOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequestOptions_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequestOptions_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRequestOptions.class, io.dapr.DaprProtos.StateRequestOptions.Builder.class); - } - - // Construct using io.dapr.DaprProtos.StateRequestOptions.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - concurrency_ = ""; - - consistency_ = ""; - - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_StateRequestOptions_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequestOptions getDefaultInstanceForType() { - return io.dapr.DaprProtos.StateRequestOptions.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequestOptions build() { - io.dapr.DaprProtos.StateRequestOptions result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequestOptions buildPartial() { - io.dapr.DaprProtos.StateRequestOptions result = new io.dapr.DaprProtos.StateRequestOptions(this); - result.concurrency_ = concurrency_; - result.consistency_ = consistency_; - if (retryPolicyBuilder_ == null) { - result.retryPolicy_ = retryPolicy_; - } else { - result.retryPolicy_ = retryPolicyBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.StateRequestOptions) { - return mergeFrom((io.dapr.DaprProtos.StateRequestOptions)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.StateRequestOptions other) { - if (other == io.dapr.DaprProtos.StateRequestOptions.getDefaultInstance()) return this; - if (!other.getConcurrency().isEmpty()) { - concurrency_ = other.concurrency_; - onChanged(); - } - if (!other.getConsistency().isEmpty()) { - consistency_ = other.consistency_; - onChanged(); - } - if (other.hasRetryPolicy()) { - mergeRetryPolicy(other.getRetryPolicy()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.StateRequestOptions parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.StateRequestOptions) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object concurrency_ = ""; - /** - * string concurrency = 1; - * @return The concurrency. - */ - public java.lang.String getConcurrency() { - java.lang.Object ref = concurrency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - concurrency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string concurrency = 1; - * @return The bytes for concurrency. - */ - public com.google.protobuf.ByteString - getConcurrencyBytes() { - java.lang.Object ref = concurrency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - concurrency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string concurrency = 1; - * @param value The concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - concurrency_ = value; - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @return This builder for chaining. - */ - public Builder clearConcurrency() { - - concurrency_ = getDefaultInstance().getConcurrency(); - onChanged(); - return this; - } - /** - * string concurrency = 1; - * @param value The bytes for concurrency to set. - * @return This builder for chaining. - */ - public Builder setConcurrencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - concurrency_ = value; - onChanged(); - return this; - } - - private java.lang.Object consistency_ = ""; - /** - * string consistency = 2; - * @return The consistency. - */ - public java.lang.String getConsistency() { - java.lang.Object ref = consistency_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - consistency_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string consistency = 2; - * @return The bytes for consistency. - */ - public com.google.protobuf.ByteString - getConsistencyBytes() { - java.lang.Object ref = consistency_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - consistency_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string consistency = 2; - * @param value The consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistency( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - consistency_ = value; - onChanged(); - return this; - } - /** - * string consistency = 2; - * @return This builder for chaining. - */ - public Builder clearConsistency() { - - consistency_ = getDefaultInstance().getConsistency(); - onChanged(); - return this; - } - /** - * string consistency = 2; - * @param value The bytes for consistency to set. - * @return This builder for chaining. - */ - public Builder setConsistencyBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - consistency_ = value; - onChanged(); - return this; - } - - private io.dapr.DaprProtos.StateRetryPolicy retryPolicy_; - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRetryPolicy, io.dapr.DaprProtos.StateRetryPolicy.Builder, io.dapr.DaprProtos.StateRetryPolicyOrBuilder> retryPolicyBuilder_; - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return Whether the retryPolicy field is set. - */ - public boolean hasRetryPolicy() { - return retryPolicyBuilder_ != null || retryPolicy_ != null; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - * @return The retryPolicy. - */ - public io.dapr.DaprProtos.StateRetryPolicy getRetryPolicy() { - if (retryPolicyBuilder_ == null) { - return retryPolicy_ == null ? io.dapr.DaprProtos.StateRetryPolicy.getDefaultInstance() : retryPolicy_; - } else { - return retryPolicyBuilder_.getMessage(); - } - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy(io.dapr.DaprProtos.StateRetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - retryPolicy_ = value; - onChanged(); - } else { - retryPolicyBuilder_.setMessage(value); - } - - return this; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public Builder setRetryPolicy( - io.dapr.DaprProtos.StateRetryPolicy.Builder builderForValue) { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = builderForValue.build(); - onChanged(); - } else { - retryPolicyBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public Builder mergeRetryPolicy(io.dapr.DaprProtos.StateRetryPolicy value) { - if (retryPolicyBuilder_ == null) { - if (retryPolicy_ != null) { - retryPolicy_ = - io.dapr.DaprProtos.StateRetryPolicy.newBuilder(retryPolicy_).mergeFrom(value).buildPartial(); - } else { - retryPolicy_ = value; - } - onChanged(); - } else { - retryPolicyBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public Builder clearRetryPolicy() { - if (retryPolicyBuilder_ == null) { - retryPolicy_ = null; - onChanged(); - } else { - retryPolicy_ = null; - retryPolicyBuilder_ = null; - } - - return this; - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.StateRetryPolicy.Builder getRetryPolicyBuilder() { - - onChanged(); - return getRetryPolicyFieldBuilder().getBuilder(); - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - public io.dapr.DaprProtos.StateRetryPolicyOrBuilder getRetryPolicyOrBuilder() { - if (retryPolicyBuilder_ != null) { - return retryPolicyBuilder_.getMessageOrBuilder(); - } else { - return retryPolicy_ == null ? - io.dapr.DaprProtos.StateRetryPolicy.getDefaultInstance() : retryPolicy_; - } - } - /** - * .dapr.StateRetryPolicy retryPolicy = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRetryPolicy, io.dapr.DaprProtos.StateRetryPolicy.Builder, io.dapr.DaprProtos.StateRetryPolicyOrBuilder> - getRetryPolicyFieldBuilder() { - if (retryPolicyBuilder_ == null) { - retryPolicyBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - io.dapr.DaprProtos.StateRetryPolicy, io.dapr.DaprProtos.StateRetryPolicy.Builder, io.dapr.DaprProtos.StateRetryPolicyOrBuilder>( - getRetryPolicy(), - getParentForChildren(), - isClean()); - retryPolicy_ = null; - } - return retryPolicyBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.StateRequestOptions) - } - - // @@protoc_insertion_point(class_scope:dapr.StateRequestOptions) - private static final io.dapr.DaprProtos.StateRequestOptions DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.StateRequestOptions(); - } - - public static io.dapr.DaprProtos.StateRequestOptions getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public StateRequestOptions parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StateRequestOptions(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRequestOptions getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface StateRetryPolicyOrBuilder extends - // @@protoc_insertion_point(interface_extends:dapr.StateRetryPolicy) - com.google.protobuf.MessageOrBuilder { - - /** - * int32 threshold = 1; - * @return The threshold. - */ - int getThreshold(); - - /** - * string pattern = 2; - * @return The pattern. - */ - java.lang.String getPattern(); - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - com.google.protobuf.ByteString - getPatternBytes(); - - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - boolean hasInterval(); - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - com.google.protobuf.Duration getInterval(); - /** - * .google.protobuf.Duration interval = 3; - */ - com.google.protobuf.DurationOrBuilder getIntervalOrBuilder(); - } - /** - * Protobuf type {@code dapr.StateRetryPolicy} - */ - public static final class StateRetryPolicy extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:dapr.StateRetryPolicy) - StateRetryPolicyOrBuilder { - private static final long serialVersionUID = 0L; - // Use StateRetryPolicy.newBuilder() to construct. - private StateRetryPolicy(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private StateRetryPolicy() { - pattern_ = ""; - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new StateRetryPolicy(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private StateRetryPolicy( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 8: { - - threshold_ = input.readInt32(); - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - pattern_ = s; - break; - } - case 26: { - com.google.protobuf.Duration.Builder subBuilder = null; - if (interval_ != null) { - subBuilder = interval_.toBuilder(); - } - interval_ = input.readMessage(com.google.protobuf.Duration.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(interval_); - interval_ = subBuilder.buildPartial(); - } - - break; - } - default: { - if (!parseUnknownField( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRetryPolicy.class, io.dapr.DaprProtos.StateRetryPolicy.Builder.class); - } - - public static final int THRESHOLD_FIELD_NUMBER = 1; - private int threshold_; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - - public static final int PATTERN_FIELD_NUMBER = 2; - private volatile java.lang.Object pattern_; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int INTERVAL_FIELD_NUMBER = 3; - private com.google.protobuf.Duration interval_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - return getInterval(); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (threshold_ != 0) { - output.writeInt32(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, pattern_); - } - if (interval_ != null) { - output.writeMessage(3, getInterval()); - } - unknownFields.writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (threshold_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, threshold_); - } - if (!getPatternBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, pattern_); - } - if (interval_ != null) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, getInterval()); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.dapr.DaprProtos.StateRetryPolicy)) { - return super.equals(obj); - } - io.dapr.DaprProtos.StateRetryPolicy other = (io.dapr.DaprProtos.StateRetryPolicy) obj; - - if (getThreshold() - != other.getThreshold()) return false; - if (!getPattern() - .equals(other.getPattern())) return false; - if (hasInterval() != other.hasInterval()) return false; - if (hasInterval()) { - if (!getInterval() - .equals(other.getInterval())) return false; - } - if (!unknownFields.equals(other.unknownFields)) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + THRESHOLD_FIELD_NUMBER; - hash = (53 * hash) + getThreshold(); - hash = (37 * hash) + PATTERN_FIELD_NUMBER; - hash = (53 * hash) + getPattern().hashCode(); - if (hasInterval()) { - hash = (37 * hash) + INTERVAL_FIELD_NUMBER; - hash = (53 * hash) + getInterval().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.dapr.DaprProtos.StateRetryPolicy parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.dapr.DaprProtos.StateRetryPolicy prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code dapr.StateRetryPolicy} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:dapr.StateRetryPolicy) - io.dapr.DaprProtos.StateRetryPolicyOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.dapr.DaprProtos.internal_static_dapr_StateRetryPolicy_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.dapr.DaprProtos.internal_static_dapr_StateRetryPolicy_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.dapr.DaprProtos.StateRetryPolicy.class, io.dapr.DaprProtos.StateRetryPolicy.Builder.class); - } - - // Construct using io.dapr.DaprProtos.StateRetryPolicy.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - @java.lang.Override - public Builder clear() { - super.clear(); - threshold_ = 0; - - pattern_ = ""; - - if (intervalBuilder_ == null) { - interval_ = null; - } else { - interval_ = null; - intervalBuilder_ = null; - } - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.dapr.DaprProtos.internal_static_dapr_StateRetryPolicy_descriptor; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRetryPolicy getDefaultInstanceForType() { - return io.dapr.DaprProtos.StateRetryPolicy.getDefaultInstance(); - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRetryPolicy build() { - io.dapr.DaprProtos.StateRetryPolicy result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRetryPolicy buildPartial() { - io.dapr.DaprProtos.StateRetryPolicy result = new io.dapr.DaprProtos.StateRetryPolicy(this); - result.threshold_ = threshold_; - result.pattern_ = pattern_; - if (intervalBuilder_ == null) { - result.interval_ = interval_; - } else { - result.interval_ = intervalBuilder_.build(); - } - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.dapr.DaprProtos.StateRetryPolicy) { - return mergeFrom((io.dapr.DaprProtos.StateRetryPolicy)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.dapr.DaprProtos.StateRetryPolicy other) { - if (other == io.dapr.DaprProtos.StateRetryPolicy.getDefaultInstance()) return this; - if (other.getThreshold() != 0) { - setThreshold(other.getThreshold()); - } - if (!other.getPattern().isEmpty()) { - pattern_ = other.pattern_; - onChanged(); - } - if (other.hasInterval()) { - mergeInterval(other.getInterval()); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - io.dapr.DaprProtos.StateRetryPolicy parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (io.dapr.DaprProtos.StateRetryPolicy) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int threshold_ ; - /** - * int32 threshold = 1; - * @return The threshold. - */ - public int getThreshold() { - return threshold_; - } - /** - * int32 threshold = 1; - * @param value The threshold to set. - * @return This builder for chaining. - */ - public Builder setThreshold(int value) { - - threshold_ = value; - onChanged(); - return this; - } - /** - * int32 threshold = 1; - * @return This builder for chaining. - */ - public Builder clearThreshold() { - - threshold_ = 0; - onChanged(); - return this; - } - - private java.lang.Object pattern_ = ""; - /** - * string pattern = 2; - * @return The pattern. - */ - public java.lang.String getPattern() { - java.lang.Object ref = pattern_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - pattern_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string pattern = 2; - * @return The bytes for pattern. - */ - public com.google.protobuf.ByteString - getPatternBytes() { - java.lang.Object ref = pattern_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - pattern_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string pattern = 2; - * @param value The pattern to set. - * @return This builder for chaining. - */ - public Builder setPattern( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - pattern_ = value; - onChanged(); - return this; - } - /** - * string pattern = 2; - * @return This builder for chaining. - */ - public Builder clearPattern() { - - pattern_ = getDefaultInstance().getPattern(); - onChanged(); - return this; - } - /** - * string pattern = 2; - * @param value The bytes for pattern to set. - * @return This builder for chaining. - */ - public Builder setPatternBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - pattern_ = value; - onChanged(); - return this; - } - - private com.google.protobuf.Duration interval_; - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> intervalBuilder_; - /** - * .google.protobuf.Duration interval = 3; - * @return Whether the interval field is set. - */ - public boolean hasInterval() { - return intervalBuilder_ != null || interval_ != null; - } - /** - * .google.protobuf.Duration interval = 3; - * @return The interval. - */ - public com.google.protobuf.Duration getInterval() { - if (intervalBuilder_ == null) { - return interval_ == null ? com.google.protobuf.Duration.getDefaultInstance() : interval_; - } else { - return intervalBuilder_.getMessage(); - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - interval_ = value; - onChanged(); - } else { - intervalBuilder_.setMessage(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder setInterval( - com.google.protobuf.Duration.Builder builderForValue) { - if (intervalBuilder_ == null) { - interval_ = builderForValue.build(); - onChanged(); - } else { - intervalBuilder_.setMessage(builderForValue.build()); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder mergeInterval(com.google.protobuf.Duration value) { - if (intervalBuilder_ == null) { - if (interval_ != null) { - interval_ = - com.google.protobuf.Duration.newBuilder(interval_).mergeFrom(value).buildPartial(); - } else { - interval_ = value; - } - onChanged(); - } else { - intervalBuilder_.mergeFrom(value); - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public Builder clearInterval() { - if (intervalBuilder_ == null) { - interval_ = null; - onChanged(); - } else { - interval_ = null; - intervalBuilder_ = null; - } - - return this; - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.Duration.Builder getIntervalBuilder() { - - onChanged(); - return getIntervalFieldBuilder().getBuilder(); - } - /** - * .google.protobuf.Duration interval = 3; - */ - public com.google.protobuf.DurationOrBuilder getIntervalOrBuilder() { - if (intervalBuilder_ != null) { - return intervalBuilder_.getMessageOrBuilder(); - } else { - return interval_ == null ? - com.google.protobuf.Duration.getDefaultInstance() : interval_; - } - } - /** - * .google.protobuf.Duration interval = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder> - getIntervalFieldBuilder() { - if (intervalBuilder_ == null) { - intervalBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - com.google.protobuf.Duration, com.google.protobuf.Duration.Builder, com.google.protobuf.DurationOrBuilder>( - getInterval(), - getParentForChildren(), - isClean()); - interval_ = null; - } - return intervalBuilder_; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:dapr.StateRetryPolicy) - } - - // @@protoc_insertion_point(class_scope:dapr.StateRetryPolicy) - private static final io.dapr.DaprProtos.StateRetryPolicy DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.dapr.DaprProtos.StateRetryPolicy(); - } - - public static io.dapr.DaprProtos.StateRetryPolicy getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public StateRetryPolicy parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new StateRetryPolicy(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.dapr.DaprProtos.StateRetryPolicy getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeServiceResponseEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeServiceResponseEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_DeleteStateEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_DeleteStateEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_SaveStateEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_SaveStateEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_GetStateEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_GetStateEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_GetStateResponseEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_GetStateResponseEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeBindingEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeBindingEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeServiceEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeServiceEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_PublishEventEnvelope_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_PublishEventEnvelope_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_State_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_State_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_State_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_State_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_StateOptions_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_StateOptions_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_RetryPolicy_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_RetryPolicy_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_StateRequest_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_StateRequest_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_StateRequest_MetadataEntry_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_StateRequest_MetadataEntry_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_StateRequestOptions_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_StateRequestOptions_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_dapr_StateRetryPolicy_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_dapr_StateRetryPolicy_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\ndapr.proto\022\004dapr\032\031google/protobuf/any." + - "proto\032\033google/protobuf/empty.proto\032\036goog" + - "le/protobuf/duration.proto\"\271\001\n\035InvokeSer" + - "viceResponseEnvelope\022\"\n\004data\030\001 \001(\0132\024.goo" + - "gle.protobuf.Any\022C\n\010metadata\030\002 \003(\01321.dap" + - "r.InvokeServiceResponseEnvelope.Metadata" + - "Entry\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005v" + - "alue\030\002 \001(\t:\0028\001\"U\n\023DeleteStateEnvelope\022\013\n" + - "\003key\030\001 \001(\t\022\014\n\004etag\030\002 \001(\t\022#\n\007options\030\003 \001(" + - "\0132\022.dapr.StateOptions\"9\n\021SaveStateEnvelo" + - "pe\022$\n\010requests\030\001 \003(\0132\022.dapr.StateRequest" + - "\"4\n\020GetStateEnvelope\022\013\n\003key\030\001 \001(\t\022\023\n\013con" + - "sistency\030\002 \001(\t\"L\n\030GetStateResponseEnvelo" + - "pe\022\"\n\004data\030\001 \001(\0132\024.google.protobuf.Any\022\014" + - "\n\004etag\030\002 \001(\t\"\267\001\n\025InvokeBindingEnvelope\022\014" + - "\n\004name\030\001 \001(\t\022\"\n\004data\030\002 \001(\0132\024.google.prot" + - "obuf.Any\022;\n\010metadata\030\003 \003(\0132).dapr.Invoke" + - "BindingEnvelope.MetadataEntry\032/\n\rMetadat" + - "aEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"\305" + - "\001\n\025InvokeServiceEnvelope\022\n\n\002id\030\001 \001(\t\022\016\n\006" + - "method\030\002 \001(\t\022\"\n\004data\030\003 \001(\0132\024.google.prot" + - "obuf.Any\022;\n\010metadata\030\004 \003(\0132).dapr.Invoke" + - "ServiceEnvelope.MetadataEntry\032/\n\rMetadat" + - "aEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"I" + - "\n\024PublishEventEnvelope\022\r\n\005topic\030\001 \001(\t\022\"\n" + - "\004data\030\002 \001(\0132\024.google.protobuf.Any\"\312\001\n\005St" + - "ate\022\013\n\003key\030\001 \001(\t\022#\n\005value\030\002 \001(\0132\024.google" + - ".protobuf.Any\022\014\n\004etag\030\003 \001(\t\022+\n\010metadata\030" + - "\004 \003(\0132\031.dapr.State.MetadataEntry\022#\n\007opti" + - "ons\030\005 \001(\0132\022.dapr.StateOptions\032/\n\rMetadat" + - "aEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001\"`" + - "\n\014StateOptions\022\023\n\013concurrency\030\001 \001(\t\022\023\n\013c" + - "onsistency\030\002 \001(\t\022&\n\013retryPolicy\030\003 \001(\0132\021." + - "dapr.RetryPolicy\"^\n\013RetryPolicy\022\021\n\tthres" + - "hold\030\001 \001(\005\022\017\n\007pattern\030\002 \001(\t\022+\n\010interval\030" + - "\003 \001(\0132\031.google.protobuf.Duration\"\337\001\n\014Sta" + - "teRequest\022\013\n\003key\030\001 \001(\t\022#\n\005value\030\002 \001(\0132\024." + - "google.protobuf.Any\022\014\n\004etag\030\003 \001(\t\0222\n\010met" + - "adata\030\004 \003(\0132 .dapr.StateRequest.Metadata" + - "Entry\022*\n\007options\030\005 \001(\0132\031.dapr.StateReque" + - "stOptions\032/\n\rMetadataEntry\022\013\n\003key\030\001 \001(\t\022" + - "\r\n\005value\030\002 \001(\t:\0028\001\"l\n\023StateRequestOption" + - "s\022\023\n\013concurrency\030\001 \001(\t\022\023\n\013consistency\030\002 " + - "\001(\t\022+\n\013retryPolicy\030\003 \001(\0132\026.dapr.StateRet" + - "ryPolicy\"c\n\020StateRetryPolicy\022\021\n\tthreshol" + - "d\030\001 \001(\005\022\017\n\007pattern\030\002 \001(\t\022+\n\010interval\030\003 \001" + - "(\0132\031.google.protobuf.Duration2\263\003\n\004Dapr\022D" + - "\n\014PublishEvent\022\032.dapr.PublishEventEnvelo" + - "pe\032\026.google.protobuf.Empty\"\000\022S\n\rInvokeSe" + - "rvice\022\033.dapr.InvokeServiceEnvelope\032#.dap" + - "r.InvokeServiceResponseEnvelope\"\000\022F\n\rInv" + - "okeBinding\022\033.dapr.InvokeBindingEnvelope\032" + - "\026.google.protobuf.Empty\"\000\022D\n\010GetState\022\026." + - "dapr.GetStateEnvelope\032\036.dapr.GetStateRes" + - "ponseEnvelope\"\000\022>\n\tSaveState\022\027.dapr.Save" + - "StateEnvelope\032\026.google.protobuf.Empty\"\000\022" + - "B\n\013DeleteState\022\031.dapr.DeleteStateEnvelop" + - "e\032\026.google.protobuf.Empty\"\000B(\n\007io.daprB\n" + - "DaprProtos\252\002\020Dapr.Client.Grpcb\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - com.google.protobuf.AnyProto.getDescriptor(), - com.google.protobuf.EmptyProto.getDescriptor(), - com.google.protobuf.DurationProto.getDescriptor(), - }); - internal_static_dapr_InvokeServiceResponseEnvelope_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_dapr_InvokeServiceResponseEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeServiceResponseEnvelope_descriptor, - new java.lang.String[] { "Data", "Metadata", }); - internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_descriptor = - internal_static_dapr_InvokeServiceResponseEnvelope_descriptor.getNestedTypes().get(0); - internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeServiceResponseEnvelope_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_dapr_DeleteStateEnvelope_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_dapr_DeleteStateEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_DeleteStateEnvelope_descriptor, - new java.lang.String[] { "Key", "Etag", "Options", }); - internal_static_dapr_SaveStateEnvelope_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_dapr_SaveStateEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_SaveStateEnvelope_descriptor, - new java.lang.String[] { "Requests", }); - internal_static_dapr_GetStateEnvelope_descriptor = - getDescriptor().getMessageTypes().get(3); - internal_static_dapr_GetStateEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_GetStateEnvelope_descriptor, - new java.lang.String[] { "Key", "Consistency", }); - internal_static_dapr_GetStateResponseEnvelope_descriptor = - getDescriptor().getMessageTypes().get(4); - internal_static_dapr_GetStateResponseEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_GetStateResponseEnvelope_descriptor, - new java.lang.String[] { "Data", "Etag", }); - internal_static_dapr_InvokeBindingEnvelope_descriptor = - getDescriptor().getMessageTypes().get(5); - internal_static_dapr_InvokeBindingEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeBindingEnvelope_descriptor, - new java.lang.String[] { "Name", "Data", "Metadata", }); - internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_descriptor = - internal_static_dapr_InvokeBindingEnvelope_descriptor.getNestedTypes().get(0); - internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeBindingEnvelope_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_dapr_InvokeServiceEnvelope_descriptor = - getDescriptor().getMessageTypes().get(6); - internal_static_dapr_InvokeServiceEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeServiceEnvelope_descriptor, - new java.lang.String[] { "Id", "Method", "Data", "Metadata", }); - internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_descriptor = - internal_static_dapr_InvokeServiceEnvelope_descriptor.getNestedTypes().get(0); - internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_InvokeServiceEnvelope_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_dapr_PublishEventEnvelope_descriptor = - getDescriptor().getMessageTypes().get(7); - internal_static_dapr_PublishEventEnvelope_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_PublishEventEnvelope_descriptor, - new java.lang.String[] { "Topic", "Data", }); - internal_static_dapr_State_descriptor = - getDescriptor().getMessageTypes().get(8); - internal_static_dapr_State_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_State_descriptor, - new java.lang.String[] { "Key", "Value", "Etag", "Metadata", "Options", }); - internal_static_dapr_State_MetadataEntry_descriptor = - internal_static_dapr_State_descriptor.getNestedTypes().get(0); - internal_static_dapr_State_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_State_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_dapr_StateOptions_descriptor = - getDescriptor().getMessageTypes().get(9); - internal_static_dapr_StateOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_StateOptions_descriptor, - new java.lang.String[] { "Concurrency", "Consistency", "RetryPolicy", }); - internal_static_dapr_RetryPolicy_descriptor = - getDescriptor().getMessageTypes().get(10); - internal_static_dapr_RetryPolicy_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_RetryPolicy_descriptor, - new java.lang.String[] { "Threshold", "Pattern", "Interval", }); - internal_static_dapr_StateRequest_descriptor = - getDescriptor().getMessageTypes().get(11); - internal_static_dapr_StateRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_StateRequest_descriptor, - new java.lang.String[] { "Key", "Value", "Etag", "Metadata", "Options", }); - internal_static_dapr_StateRequest_MetadataEntry_descriptor = - internal_static_dapr_StateRequest_descriptor.getNestedTypes().get(0); - internal_static_dapr_StateRequest_MetadataEntry_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_StateRequest_MetadataEntry_descriptor, - new java.lang.String[] { "Key", "Value", }); - internal_static_dapr_StateRequestOptions_descriptor = - getDescriptor().getMessageTypes().get(12); - internal_static_dapr_StateRequestOptions_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_StateRequestOptions_descriptor, - new java.lang.String[] { "Concurrency", "Consistency", "RetryPolicy", }); - internal_static_dapr_StateRetryPolicy_descriptor = - getDescriptor().getMessageTypes().get(13); - internal_static_dapr_StateRetryPolicy_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_dapr_StateRetryPolicy_descriptor, - new java.lang.String[] { "Threshold", "Pattern", "Interval", }); - com.google.protobuf.AnyProto.getDescriptor(); - com.google.protobuf.EmptyProto.getDescriptor(); - com.google.protobuf.DurationProto.getDescriptor(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/sdk/src/main/java/io/dapr/client/DaprClient.java b/sdk/src/main/java/io/dapr/client/DaprClient.java new file mode 100644 index 000000000..6727f3e3e --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprClient.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.client.domain.Verb; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; + +/** + * Generic Client Adapter to be used regardless of the GRPC or the HTTP Client implementation required. + * + * @see io.dapr.client.DaprClientBuilder for information on how to make instance for this interface. + */ +public interface DaprClient { + + /** + * Publish an event. + * + * @param topic the topic where the event will be published. + * @param event the event to be published. + * @param The type of event to be published, use byte[] for skipping serialization. + * @return a Mono plan of type Void. + */ + Mono publishEvent(String topic, T event); + + /** + * Publish an event. + * + * @param topic the topic where the event will be published. + * @param event the event to be published. + * @param metadata The metadata for the published event. + * @param The type of event to be published, use byte[] for skipping serialization. + * @return a Mono plan of type Void. + */ + Mono publishEvent(String topic, T event, Map metadata); + + /** + * Invoke a service with all possible parameters, using serialization. + * + * @param verb The Verb to be used for HTTP will be the HTTP Verb, for GRPC is just a metadata value. + * @param appId The Application ID where the service is. + * @param method The actual Method to be call in the application. + * @param request The request to be sent to invoke the service. + * @param metadata Metadata (in GRPC) or headers (in HTTP) to be send in request. + * @param clazz the Type needed as return for the call. + * @param the Type of the return, use byte[] to skip serialization. + * @param The Type of the request, use byte[] to skip serialization. + * @return A Mono Plan of type clazz. + */ + Mono invokeService(Verb verb, String appId, String method, R request, Map metadata, Class clazz); + + /** + * Invoke a service without input, using serialization for response. + * + * @param verb The Verb to be used for HTTP will be the HTTP Verb, for GRPC is just a metadata value. + * @param appId The Application ID where the service is. + * @param method The actual Method to be call in the application. + * @param metadata Metadata (in GRPC) or headers (in HTTP) to be send in request. + * @param clazz the Type needed as return for the call. + * @param the Type of the return, use byte[] to skip serialization. + * @return A Mono plan of type clazz. + */ + Mono invokeService(Verb verb, String appId, String method, Map metadata, Class clazz); + + /** + * Invoke a service with void response, using serialization. + * + * @param verb The Verb to be used for HTTP will be the HTTP Verb, for GRPC is just a metadata value. + * @param appId The Application ID where the service is. + * @param method The actual Method to be call in the application. + * @param request The request to be sent to invoke the service. + * @param metadata Metadata (in GRPC) or headers (in HTTP) to be send in request. + * @param The Type of the request, use byte[] to skip serialization. + * @return A Mono plan for Void. + */ + Mono invokeService(Verb verb, String appId, String method, R request, Map metadata); + + /** + * Invoke a service without input and void response. + * + * @param verb The Verb to be used for HTTP will be the HTTP Verb, for GRPC is just a metadata value. + * @param appId The Application ID where the service is. + * @param method The actual Method to be call in the application. + * @param metadata Metadata (in GRPC) or headers (in HTTP) to be send in request. + * @return A Mono plan for Void. + */ + Mono invokeService(Verb verb, String appId, String method, Map metadata); + + /** + * Invoke a service without serialization. + * + * @param verb The Verb to be used for HTTP will be the HTTP Verb, for GRPC is just a metadata value. + * @param appId The Application ID where the service is. + * @param method The actual Method to be call in the application. + * @param request The request to be sent to invoke the service + * @param metadata Metadata (in GRPC) or headers (in HTTP) to be send in request. + * @return A Mono plan of byte[]. + */ + Mono invokeService(Verb verb, String appId, String method, byte[] request, Map metadata); + + /** + * Creating a Binding. + * + * @param name The name of the biding to call. + * @param request The request needed for the binding. + * @param The type of the request. + * @return a Mono plan of type Void + */ + Mono invokeBinding(String name, T request); + + /** + * Retrieve a State based on their key. + * + * @param state State to be re-retrieved. + * @param clazz The Type of State needed as return. + * @param The Type of the return. + * @return A Mono Plan for the requested State. + */ + Mono> getState(State state, Class clazz); + + /** + * Retrieve a State based on their key. + * + * @param key The key of the State to be retrieved. + * @param clazz The Type of State needed as return. + * @param The Type of the return. + * @return A Mono Plan for the requested State. + */ + Mono> getState(String key, Class clazz); + + /** + * Retrieve a State based on their key. + * + * @param key The key of the State to be retrieved. + * @param etag Optional etag for conditional get + * @param options Optional settings for retrieve operation. + * @param clazz The Type of State needed as return. + * @param The Type of the return. + * @return A Mono Plan for the requested State. + */ + Mono> getState(String key, String etag, StateOptions options, Class clazz); + + /** + * Save/Update a list of states. + * + * @param states the States to be saved. + * @return a Mono plan of type Void. + */ + Mono saveStates(List> states); + + /** + * Save/Update a state. + * + * @param key the key of the state. + * @param value the value of the state. + * @return a Mono plan of type Void. + */ + Mono saveState(String key, Object value); + + /** + * Save/Update a state. + * + * @param key the key of the state. + * @param etag the etag to be used. + * @param value the value of the state. + * @param options the Options to use for each state. + * @return a Mono plan of type Void. + */ + Mono saveState(String key, String etag, Object value, StateOptions options); + + /** + * Delete a state. + * + * @param key The key of the State to be removed. + * @return a Mono plan of type Void. + */ + Mono deleteState(String key); + + /** + * Delete a state. + * + * @param key The key of the State to be removed. + * @param etag Optional etag for conditional delete. + * @param options Optional settings for state operation. + * @return a Mono plan of type Void. + */ + Mono deleteState(String key, String etag, StateOptions options); +} diff --git a/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java b/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java new file mode 100644 index 000000000..c19cda913 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.DaprGrpc; +import io.dapr.serializer.DaprObjectSerializer; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.utils.Constants; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import okhttp3.OkHttpClient; + +/** + * A builder for the DaprClient, + * Currently only and HTTP Client will be supported. + */ +public class DaprClientBuilder { + + /** + * HTTP port for Dapr after checking environment variable. + */ + private static final int HTTP_PORT = DaprClientBuilder.getEnvHttpPortOrDefault( + Constants.ENV_DAPR_HTTP_PORT, Constants.DEFAULT_HTTP_PORT); + + /** + * GRPC port for Dapr after checking environment variable. + */ + private static final int GRPC_PORT = DaprClientBuilder.getEnvHttpPortOrDefault( + Constants.ENV_DAPR_GRPC_PORT, Constants.DEFAULT_GRPC_PORT); + + /** + * Serializer used for request and response objects in DaprClient. + */ + private final DaprObjectSerializer objectSerializer; + + /** + * Serializer used for state objects in DaprClient. + */ + private final DaprObjectSerializer stateSerializer; + + /** + * Finds the port defined by env variable or sticks to default. + * @param envName Name of env variable with the port. + * @param defaultPort Default port if cannot find a valid port. + * + * @return Port from env variable or default. + */ + private static int getEnvHttpPortOrDefault(String envName, int defaultPort) { + String envPort = System.getenv(envName); + if (envPort == null || envPort.trim().isEmpty()) { + return defaultPort; + } + + try { + return Integer.parseInt(envPort.trim()); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + + return defaultPort; + } + + /** + * Creates a constructor for DaprClient. + * + * See {@link DefaultObjectSerializer} as possible serializer for non-production scenarios. + * + * @param objectSerializer Serializer for objects to be sent and received from Dapr. + * @param stateSerializer Serializer for objects to be persisted. + */ + public DaprClientBuilder(DaprObjectSerializer objectSerializer, DaprObjectSerializer stateSerializer) { + if (objectSerializer == null) { + throw new IllegalArgumentException("Serializer is required"); + } + if (stateSerializer == null) { + throw new IllegalArgumentException("State serializer is required"); + } + + this.objectSerializer = objectSerializer; + this.stateSerializer = stateSerializer; + } + + /** + * Build an instance of the Client based on the provided setup. + * + * @return an instance of the setup Client + * @throws java.lang.IllegalStateException if any required field is missing + */ + public DaprClient build() { + return buildDaprClientHttp(); + } + + /** + * Creates an instance of the GPRC Client. + * + * @return the GRPC Client. + * @throws java.lang.IllegalStateException if either host is missing or if port is missing or a negative number. + */ + private DaprClient buildDaprClientGrpc() { + if (GRPC_PORT <= 0) { + throw new IllegalStateException("Invalid port."); + } + ManagedChannel channel = ManagedChannelBuilder.forAddress(Constants.DEFAULT_HOSTNAME, GRPC_PORT).usePlaintext().build(); + return new DaprClientGrpcAdapter(DaprGrpc.newFutureStub(channel), this.objectSerializer, this.stateSerializer); + } + + /** + * Creates and instance of DaprClient over HTTP. + * + * @return DaprClient over HTTP. + */ + private DaprClient buildDaprClientHttp() { + if (HTTP_PORT <= 0) { + throw new IllegalStateException("Invalid port."); + } + OkHttpClient okHttpClient = new OkHttpClient.Builder().build(); + DaprHttp daprHttp = new DaprHttp(HTTP_PORT, okHttpClient); + return new DaprClientHttpAdapter(daprHttp, this.objectSerializer, this.stateSerializer); + } +} diff --git a/sdk/src/main/java/io/dapr/client/DaprClientGrpcAdapter.java b/sdk/src/main/java/io/dapr/client/DaprClientGrpcAdapter.java new file mode 100644 index 000000000..38f6d3058 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprClientGrpcAdapter.java @@ -0,0 +1,412 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import com.google.common.util.concurrent.ListenableFuture; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import io.dapr.DaprGrpc; +import io.dapr.DaprProtos; +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.client.domain.Verb; +import io.dapr.serializer.DaprObjectSerializer; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * An adapter for the GRPC Client. + * + * @see io.dapr.DaprGrpc + * @see io.dapr.client.DaprClient + */ +class DaprClientGrpcAdapter implements DaprClient { + + /** + * The GRPC client to be used + * + * @see io.dapr.DaprGrpc.DaprFutureStub + */ + private DaprGrpc.DaprFutureStub client; + + /** + * A utitlity class for serialize and deserialize the transient objects. + */ + private DaprObjectSerializer objectSerializer; + + /** + * A utitlity class for serialize and deserialize state objects. + */ + private DaprObjectSerializer stateSerializer; + + /** + * Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder + * + * @param futureClient GRPC client + * @param objectSerializer Serializer for transient request/response objects. + * @param stateSerializer Serializer for state objects. + * @see DaprClientBuilder + */ + DaprClientGrpcAdapter( + DaprGrpc.DaprFutureStub futureClient, + DaprObjectSerializer objectSerializer, + DaprObjectSerializer stateSerializer) { + this.client = futureClient; + this.objectSerializer = objectSerializer; + this.stateSerializer = stateSerializer; + } + + /** + * {@inheritDoc} + */ + @Override + public Mono publishEvent(String topic, T event) { + return this.publishEvent(topic, event, null); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono publishEvent(String topic, T event, Map metadata) { + try { + byte[] byteEvent = objectSerializer.serialize(event); + Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteEvent)).build(); + // TODO: handle metadata. + + DaprProtos.PublishEventEnvelope envelope = DaprProtos.PublishEventEnvelope.newBuilder() + .setTopic(topic).setData(data).build(); + + return Mono.fromCallable(() -> { + ListenableFuture futureEmpty = client.publishEvent(envelope); + futureEmpty.get(); + return null; + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, R request, Map metadata, Class clazz) { + try { + DaprProtos.InvokeServiceEnvelope envelope = buildInvokeServiceEnvelope(verb.toString(), appId, method, request); + return Mono.fromCallable(() -> { + ListenableFuture futureResponse = + client.invokeService(envelope); + return objectSerializer.deserialize(futureResponse.get().getData().getValue().toByteArray(), clazz); + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, Map metadata, Class clazz) { + return this.invokeService(verb, appId, method, null, null, clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, R request, Map metadata) { + return this.invokeService(verb, appId, method, request, metadata, byte[].class).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, Map metadata) { + return this.invokeService(verb, appId, method, null, metadata, Void.class).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, byte[] request, Map metadata) { + return this.invokeService(verb, appId, method, request, metadata, byte[].class); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeBinding(String name, T request) { + try { + byte[] byteRequest = objectSerializer.serialize(request); + Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteRequest)).build(); + DaprProtos.InvokeBindingEnvelope.Builder builder = DaprProtos.InvokeBindingEnvelope.newBuilder() + .setName(name) + .setData(data); + DaprProtos.InvokeBindingEnvelope envelope = builder.build(); + return Mono.fromCallable(() -> { + ListenableFuture futureEmpty = client.invokeBinding(envelope); + futureEmpty.get(); + return null; + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(State state, Class clazz) { + return this.getState(state.getKey(), state.getEtag(), state.getOptions(), clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(String key, Class clazz) { + return this.getState(key, null, null, clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(String key, String etag, StateOptions options, Class clazz) { + try { + DaprProtos.GetStateEnvelope.Builder builder = DaprProtos.GetStateEnvelope.newBuilder() + .setKey(key); + if (options != null && options.getConsistency() != null) { + builder.setConsistency(options.getConsistency().getValue()); + } + + DaprProtos.GetStateEnvelope envelope = builder.build(); + return Mono.fromCallable(() -> { + ListenableFuture futureResponse = client.getState(envelope); + DaprProtos.GetStateResponseEnvelope response = null; + try { + response = futureResponse.get(); + } catch (NullPointerException npe) { + return null; + } + return buildStateKeyValue(response, key, options, clazz); + }); } catch (Exception ex) { + return Mono.error(ex); + } + } + + private State buildStateKeyValue( + DaprProtos.GetStateResponseEnvelope response, + String requestedKey, + StateOptions stateOptions, + Class clazz) throws IOException { + ByteString payload = response.getData().getValue(); + byte[] data = payload == null ? null : payload.toByteArray(); + T value = stateSerializer.deserialize(data, clazz); + String etag = response.getEtag(); + String key = requestedKey; + return new State<>(value, key, etag, stateOptions); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveStates(List> states) { + try { + DaprProtos.SaveStateEnvelope.Builder builder = DaprProtos.SaveStateEnvelope.newBuilder(); + for (State state : states) { + builder.addRequests(buildStateRequest(state).build()); + } + DaprProtos.SaveStateEnvelope envelope = builder.build(); + + ListenableFuture futureEmpty = client.saveState(envelope); + return Mono.just(futureEmpty).flatMap(f -> { + try { + f.get(); + } catch (Exception ex) { + return Mono.error(ex); + } + return Mono.empty(); + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + private DaprProtos.StateRequest.Builder buildStateRequest(State state) throws IOException { + byte[] bytes = stateSerializer.serialize(state.getValue()); + Any data = Any.newBuilder().setValue(ByteString.copyFrom(bytes)).build(); + DaprProtos.StateRequest.Builder stateBuilder = DaprProtos.StateRequest.newBuilder(); + if (state.getEtag() != null) { + stateBuilder.setEtag(state.getEtag()); + } + if (data != null) { + stateBuilder.setValue(data); + } + stateBuilder.setKey(state.getKey()); + DaprProtos.StateRequestOptions.Builder optionBuilder = null; + if (state.getOptions() != null) { + StateOptions options = state.getOptions(); + DaprProtos.StateRetryPolicy.Builder retryPolicyBuilder = null; + if (options.getRetryPolicy() != null) { + retryPolicyBuilder = DaprProtos.StateRetryPolicy.newBuilder(); + StateOptions.RetryPolicy retryPolicy = options.getRetryPolicy(); + if (options.getRetryPolicy().getInterval() != null) { + Duration.Builder durationBuilder = Duration.newBuilder() + .setNanos(retryPolicy.getInterval().getNano()) + .setSeconds(retryPolicy.getInterval().getSeconds()); + retryPolicyBuilder.setInterval(durationBuilder.build()); + } + if (retryPolicy.getThreshold() != null) { + retryPolicyBuilder.setThreshold(retryPolicy.getThreshold()); + } + if (retryPolicy.getPattern() != null) { + retryPolicyBuilder.setPattern(retryPolicy.getPattern().getValue()); + } + } + + optionBuilder = DaprProtos.StateRequestOptions.newBuilder(); + if (options.getConcurrency() != null) { + optionBuilder.setConcurrency(options.getConcurrency().getValue()); + } + if (options.getConsistency() != null) { + optionBuilder.setConsistency(options.getConsistency().getValue()); + } + if (retryPolicyBuilder != null) { + optionBuilder.setRetryPolicy(retryPolicyBuilder.build()); + } + } + if(optionBuilder != null) { + stateBuilder.setOptions(optionBuilder.build()); + } + return stateBuilder; + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveState(String key, Object value) { + return this.saveState(key, null, value, null); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveState(String key, String etag, Object value, StateOptions options) { + State state = new State<>(value, key, etag, options); + return this.saveStates(Arrays.asList(state)); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono deleteState(String key) { + return this.deleteState(key, null, null); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono deleteState(String key, String etag, StateOptions options) { + try { + DaprProtos.StateOptions.Builder optionBuilder = null; + if (options != null) { + optionBuilder = DaprProtos.StateOptions.newBuilder(); + DaprProtos.RetryPolicy.Builder retryPolicyBuilder = null; + if (options.getRetryPolicy() != null) { + retryPolicyBuilder = DaprProtos.RetryPolicy.newBuilder(); + StateOptions.RetryPolicy retryPolicy = options.getRetryPolicy(); + if (options.getRetryPolicy().getInterval() != null) { + Duration.Builder durationBuilder = Duration.newBuilder() + .setNanos(retryPolicy.getInterval().getNano()) + .setSeconds(retryPolicy.getInterval().getSeconds()); + retryPolicyBuilder.setInterval(durationBuilder.build()); + } + if (retryPolicy.getThreshold() != null) { + retryPolicyBuilder.setThreshold(retryPolicy.getThreshold()); + } + if (retryPolicy.getPattern() != null) { + retryPolicyBuilder.setPattern(retryPolicy.getPattern().getValue()); + } + } + + optionBuilder = DaprProtos.StateOptions.newBuilder(); + if (options.getConcurrency() != null) { + optionBuilder.setConcurrency(options.getConcurrency().getValue()); + } + if (options.getConsistency() != null) { + optionBuilder.setConsistency(options.getConsistency().getValue()); + } + if (retryPolicyBuilder != null) { + optionBuilder.setRetryPolicy(retryPolicyBuilder.build()); + } + } + DaprProtos.DeleteStateEnvelope.Builder builder = DaprProtos.DeleteStateEnvelope.newBuilder() + .setKey(key); + if(etag != null) { + builder.setEtag(etag); + } + + if (optionBuilder != null) { + builder.setOptions(optionBuilder.build()); + } + + DaprProtos.DeleteStateEnvelope envelope = builder.build(); + ListenableFuture futureEmpty = client.deleteState(envelope); + return Mono.just(futureEmpty).flatMap(f -> { + try { + f.get(); + } catch (Exception ex) { + return Mono.error(ex); + } + return Mono.empty(); + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * Builds the object io.dapr.{@link DaprProtos.InvokeServiceEnvelope} to be send based on the parameters. + * + * @param verb String that must match HTTP Methods + * @param appId The application id to be invoked + * @param method The application method to be invoked + * @param request The body of the request to be send as part of the invokation + * @param The Type of the Body + * @return The object to be sent as part of the invokation. + * @throws IOException If there's an issue serializing the request. + */ + private DaprProtos.InvokeServiceEnvelope buildInvokeServiceEnvelope( + String verb, String appId, String method, K request) throws IOException { + DaprProtos.InvokeServiceEnvelope.Builder envelopeBuilder = DaprProtos.InvokeServiceEnvelope.newBuilder() + .setId(appId) + .setMethod(verb); + if (request != null) { + byte[] byteRequest = objectSerializer.serialize(request); + Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteRequest)).build(); + envelopeBuilder.setData(data); + } + return envelopeBuilder.build(); + } + +} \ No newline at end of file diff --git a/sdk/src/main/java/io/dapr/client/DaprClientHttpAdapter.java b/sdk/src/main/java/io/dapr/client/DaprClientHttpAdapter.java new file mode 100644 index 000000000..f964ba08d --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprClientHttpAdapter.java @@ -0,0 +1,356 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.client.domain.Verb; +import io.dapr.serializer.DaprObjectSerializer; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.serializer.StringContentType; +import io.dapr.utils.Constants; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.*; + +/** + * An adapter for the HTTP Client. + * + * @see io.dapr.client.DaprHttp + * @see io.dapr.client.DaprClient + */ +public class DaprClientHttpAdapter implements DaprClient { + + /** + * Serializer for internal objects. + */ + private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer(); + + /** + * The HTTP client to be used + * + * @see io.dapr.client.DaprHttp + */ + private final DaprHttp client; + + /** + * A utility class for serialize and deserialize customer's transient objects. + */ + private final DaprObjectSerializer objectSerializer; + + /** + * A utility class for serialize and deserialize customer's state objects. + */ + private final DaprObjectSerializer stateSerializer; + + /** + * Flag determining if serializer's input and output contains a valid String. + */ + private final boolean isStateString; + + /** + * Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder + * + * @param client Dapr's http client. + * @param objectSerializer Dapr's serializer for transient request/response objects. + * @param stateSerializer Dapr's serializer for state objects. + * @see DaprClientBuilder + * @see DefaultObjectSerializer + */ + DaprClientHttpAdapter(DaprHttp client, DaprObjectSerializer objectSerializer, DaprObjectSerializer stateSerializer) { + this.client = client; + this.objectSerializer = objectSerializer; + this.stateSerializer = stateSerializer; + this.isStateString = stateSerializer.getClass().getAnnotation(StringContentType.class) != null; + } + + /** + * Constructor useful for tests. + * + * @param client Dapr's http client. + * @see io.dapr.client.DaprClientBuilder + * @see DefaultObjectSerializer + */ + DaprClientHttpAdapter(DaprHttp client) { + this(client, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono publishEvent(String topic, T event) { + return this.publishEvent(topic, event, null); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono publishEvent(String topic, T event, Map metadata) { + try { + if (topic == null || topic.trim().isEmpty()) { + throw new IllegalArgumentException("Topic name cannot be null or empty."); + } + + byte[] serializedEvent = objectSerializer.serialize(event); + StringBuilder url = new StringBuilder(Constants.PUBLISH_PATH).append("/").append(topic); + return this.client.invokeAPI( + DaprHttp.HttpMethods.POST.name(), url.toString(), null, serializedEvent, metadata).then(); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, R request, Map metadata, Class clazz) { + try { + if (verb == null) { + throw new IllegalArgumentException("Verb cannot be null."); + } + String httMethod = verb.toString(); + if (appId == null || appId.trim().isEmpty()) { + throw new IllegalArgumentException("App Id cannot be null or empty."); + } + if (method == null || method.trim().isEmpty()) { + throw new IllegalArgumentException("Method name cannot be null or empty."); + } + String path = String.format("%s/%s/method/%s", Constants.INVOKE_PATH, appId, method); + byte[] serializedRequestBody = objectSerializer.serialize(request); + Mono response = this.client.invokeAPI(httMethod, path, null, serializedRequestBody, metadata); + return response.flatMap(r -> { + try { + T object = objectSerializer.deserialize(r.getBody(), clazz); + if (object == null) { + return Mono.empty(); + } + + return Mono.just(object); + } catch (Exception ex) { + return Mono.error(ex); + } + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, Map metadata, Class clazz) { + return this.invokeService(verb, appId, method, null, null, clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, R request, Map metadata) { + return this.invokeService(verb, appId, method, request, metadata, byte[].class).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, Map metadata) { + return this.invokeService(verb, appId, method, null, metadata, byte[].class).then(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeService(Verb verb, String appId, String method, byte[] request, Map metadata) { + return this.invokeService(verb, appId, method, request, metadata, byte[].class); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeBinding(String name, T request) { + try { + if (name == null || name.trim().isEmpty()) { + throw new IllegalArgumentException("Name to bind cannot be null or empty."); + } + + Map jsonMap = new HashMap<>(); + jsonMap.put("data", request); + StringBuilder url = new StringBuilder(Constants.BINDING_PATH).append("/").append(name); + + return this.client + .invokeAPI( + DaprHttp.HttpMethods.POST.name(), + url.toString(), + null, + objectSerializer.serialize(jsonMap), + null) + .then(); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(State state, Class clazz) { + return this.getState(state.getKey(), state.getEtag(), state.getOptions(), clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(String key, Class clazz) { + return this.getState(key, null, null, clazz); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> getState(String key, String etag, StateOptions options, Class clazz) { + try { + if (key == null) { + throw new IllegalArgumentException("Name cannot be null or empty."); + } + Map headers = new HashMap<>(); + if (etag != null && !etag.trim().isEmpty()) { + headers.put(Constants.HEADER_HTTP_ETAG_ID, etag); + } + + StringBuilder url = new StringBuilder(Constants.STATE_PATH) + .append("/") + .append(key); + Map urlParameters = Optional.ofNullable(options).map(o -> o.getStateOptionsAsMap() ).orElse(new HashMap<>());; + return this.client + .invokeAPI(DaprHttp.HttpMethods.GET.name(), url.toString(), urlParameters, headers) + .flatMap(s -> { + try { + return Mono.just(buildStateKeyValue(s, key, options, clazz)); + } catch (Exception ex) { + return Mono.error(ex); + } + }); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveStates(List> states) { + try { + if (states == null || states.isEmpty()) { + return Mono.empty(); + } + final Map headers = new HashMap<>(); + final String etag = states.stream().filter(state -> null != state.getEtag() && !state.getEtag().trim().isEmpty()) + .findFirst().orElse(new State<>(null, null, null, null)).getEtag(); + if (etag != null && !etag.trim().isEmpty()) { + headers.put(Constants.HEADER_HTTP_ETAG_ID, etag); + } + final String url = Constants.STATE_PATH; + List> internalStateObjects = new ArrayList<>(states.size()); + for (State state : states) { + if (state == null) { + continue; + } + byte[] data = this.stateSerializer.serialize(state.getValue()); + if (this.isStateString) { + internalStateObjects.add( + new State<>(data == null ? null : new String(data), state.getKey(), state.getEtag(), state.getOptions())); + } else { + internalStateObjects.add(new State<>(data, state.getKey(), state.getEtag(), state.getOptions())); + } + } + byte[] serializedStateBody = INTERNAL_SERIALIZER.serialize(states); + return this.client.invokeAPI( + DaprHttp.HttpMethods.POST.name(), url, null, serializedStateBody, headers).then(); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveState(String key, Object value) { + return this.saveState(key, null, value, null); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono saveState(String key, String etag, Object value, StateOptions options) { + return Mono.fromSupplier(() -> new State<>(value, key, etag, options)) + .flatMap(state -> saveStates(Arrays.asList(state))); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono deleteState(String key) { + return this.deleteState(key); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono deleteState(String key, String etag, StateOptions options) { + try { + if (key == null || key.trim().isEmpty()) { + throw new IllegalArgumentException("Name cannot be null or empty."); + } + Map headers = new HashMap<>(); + if (etag != null && !etag.trim().isEmpty()) { + headers.put(Constants.HEADER_HTTP_ETAG_ID, etag); + } + String url = Constants.STATE_PATH + "/" + key; + Map urlParameters = Optional.ofNullable(options).map(stateOptions -> stateOptions.getStateOptionsAsMap()).orElse( new HashMap<>());; + return this.client.invokeAPI(DaprHttp.HttpMethods.DELETE.name(), url, urlParameters, headers).then(); + } catch (Exception ex) { + return Mono.error(ex); + } + } + + /** + * Builds a State object based on the Response + * + * @param response The response of the HTTP Call + * @param requestedKey The Key Requested. + * @param clazz The Class of the Value of the state + * @param The Type of the Value of the state + * @return A StateKeyValue instance + * @throws IOException If there's a issue deserialzing the response. + */ + private State buildStateKeyValue( + DaprHttp.Response response, String requestedKey, StateOptions stateOptions, Class clazz) throws IOException { + // The state is in the body directly, so we use the state serializer here. + T value = stateSerializer.deserialize(response.getBody(), clazz); + String key = requestedKey; + String etag = null; + if (response.getHeaders() != null && response.getHeaders().containsKey("Etag")) { + etag = response.getHeaders().get("Etag"); + } + return new State<>(value, key, etag, stateOptions); + } + +} diff --git a/sdk/src/main/java/io/dapr/client/DaprHttp.java b/sdk/src/main/java/io/dapr/client/DaprHttp.java new file mode 100644 index 000000000..a45899813 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprHttp.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.exceptions.DaprError; +import io.dapr.exceptions.DaprException; +import io.dapr.utils.Constants; +import okhttp3.*; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class DaprHttp { + + /** + * HTTP Methods supported. + */ + public enum HttpMethods {GET, PUT, POST, DELETE;} + + public static class Response { + private byte[] body; + private Map headers; + private int statusCode; + + public Response(byte[] body, Map headers, int statusCode) { + this.body = body; + this.headers = headers; + this.statusCode = statusCode; + } + + public byte[] getBody() { + return body; + } + + public Map getHeaders() { + return headers; + } + + public int getStatusCode() { + return statusCode; + } + } + + /** + * Defines the standard application/json type for HTTP calls in Dapr. + */ + private static final MediaType MEDIA_TYPE_APPLICATION_JSON = + MediaType.get("application/json; charset=utf-8"); + + /** + * Shared object representing an empty request body in JSON. + */ + private static final RequestBody REQUEST_BODY_EMPTY_JSON = + RequestBody.Companion.create("", MEDIA_TYPE_APPLICATION_JSON); + + /** + * Empty input or output. + */ + private static final byte[] EMPTY_BYTES = new byte[0]; + + /** + * JSON Object Mapper. + */ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * Port used to communicate to Dapr's HTTP endpoint. + */ + private final int port; + + /** + * Http client used for all API calls. + */ + private final OkHttpClient httpClient; + + /** + * Creates a new instance of {@link DaprHttp}. + * + * @param port Port for calling Dapr. (e.g. 3500) + * @param httpClient RestClient used for all API calls in this new instance. + */ + DaprHttp(int port, OkHttpClient httpClient) { + this.port = port; + this.httpClient = httpClient; + } + + /** + * Invokes an API asynchronously without payload that returns a text payload. + * + * @param method HTTP method. + * @param urlString url as String. + * @param urlParameters URL parameters + * @param headers HTTP headers. + * @return Asynchronous text + */ + public Mono invokeAPI(String method, String urlString, Map urlParameters, Map headers) { + return this.invokeAPI(method, urlString, urlParameters, (byte[]) null, headers); + } + + /** + * Invokes an API asynchronously that returns a text payload. + * + * @param method HTTP method. + * @param urlString url as String. + * @param urlParameters Parameters in the URL + * @param content payload to be posted. + * @param headers HTTP headers. + * @return Asynchronous response + */ + public Mono invokeAPI(String method, String urlString, Map urlParameters, String content, Map headers) { + return this.invokeAPI(method, urlString, urlParameters, content == null ? EMPTY_BYTES : content.getBytes(StandardCharsets.UTF_8), headers); + } + + /** + * Invokes an API asynchronously that returns a text payload. + * + * @param method HTTP method. + * @param urlString url as String. + * @param urlParameters Parameters in the URL + * @param content payload to be posted. + * @param headers HTTP headers. + * @return Asynchronous response + */ + public Mono invokeAPI(String method, String urlString, Map urlParameters, byte[] content, Map headers) { + return Mono.fromCallable( + () -> { + try { + String requestId = UUID.randomUUID().toString(); + RequestBody body = REQUEST_BODY_EMPTY_JSON; + + String contentType = headers != null ? headers.get("content-type") : null; + MediaType mediaType = contentType == null ? MEDIA_TYPE_APPLICATION_JSON : MediaType.get(contentType); + if (content == null) { + body = mediaType.equals(MEDIA_TYPE_APPLICATION_JSON) ? + REQUEST_BODY_EMPTY_JSON : RequestBody.Companion.create(new byte[0], mediaType); + } else { + body = RequestBody.Companion.create(content, mediaType); + } + HttpUrl.Builder urlBuilder = new HttpUrl.Builder(); + urlBuilder.scheme("http").host(Constants.DEFAULT_HOSTNAME).port(this.port).addPathSegments(urlString); + Optional.ofNullable(urlParameters).orElse(Collections.emptyMap()).entrySet().stream() + .forEach(urlParameter -> urlBuilder.addQueryParameter(urlParameter.getKey(), urlParameter.getValue())); + + Request.Builder requestBuilder = new Request.Builder() + .url(urlBuilder.build()) + .addHeader(Constants.HEADER_DAPR_REQUEST_ID, requestId); + if (HttpMethods.GET.name().equals(method)) { + requestBuilder.get(); + } else if (HttpMethods.DELETE.name().equals(method)) { + requestBuilder.delete(); + } else { + requestBuilder.method(method, body); + } + if (headers != null) { + Optional.ofNullable(headers.entrySet()).orElse(Collections.emptySet()).stream() + .forEach(header -> { + requestBuilder.addHeader(header.getKey(), header.getValue()); + }); + } + + Request request = requestBuilder.build(); + + try (okhttp3.Response response = this.httpClient.newCall(request).execute()) { + if (!response.isSuccessful()) { + DaprError error = parseDaprError(response.body().bytes()); + if ((error != null) && (error.getErrorCode() != null) && (error.getMessage() != null)) { + throw new RuntimeException(new DaprException(error)); + } + + throw new RuntimeException("Unknown error."); + } + + Map mapHeaders = new HashMap<>(); + byte[] result = response.body().bytes(); + response.headers().forEach(pair -> { + mapHeaders.put(pair.getFirst(), pair.getSecond()); + }); + return new Response(result == null ? EMPTY_BYTES : result, mapHeaders, response.code()); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + /** + * Tries to parse an error from Dapr response body. + * + * @param json Response body from Dapr. + * @return DaprError or null if could not parse. + */ + private static DaprError parseDaprError(byte[] json) throws IOException { + if (json == null) { + return null; + } + return OBJECT_MAPPER.readValue(json, DaprError.class); + } + +} diff --git a/sdk/src/main/java/io/dapr/client/DaprHttpBuilder.java b/sdk/src/main/java/io/dapr/client/DaprHttpBuilder.java new file mode 100644 index 000000000..a00597e61 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/DaprHttpBuilder.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.utils.Constants; +import okhttp3.OkHttpClient; + +import java.time.Duration; + +/** + * A builder for the DaprHttp. + */ +public class DaprHttpBuilder { + + /** + * Default port for Dapr after checking environment variable. + */ + private static final int PORT = DaprHttpBuilder.getEnvPortOrDefault(); + + /** + * Read timeout for http calls. + */ + private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofSeconds(60); + + /** + * Read timeout used to build object. + */ + private Duration readTimeout = DEFAULT_READ_TIMEOUT; + + /** + * Tries to get a valid port from environment variable or returns default. + * + * @return Port defined in env variable or default. + */ + private static int getEnvPortOrDefault() { + String envPort = System.getenv(Constants.ENV_DAPR_HTTP_PORT); + if (envPort == null || envPort.trim().isEmpty()) { + return Constants.DEFAULT_HTTP_PORT; + } + + try { + return Integer.parseInt(envPort.trim()); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + + return Constants.DEFAULT_HTTP_PORT; + } + + /** + * Sets the read timeout duration for the instance to be built. + * + * @param duration Read timeout duration. + * @return Same builder instance. + */ + public DaprHttpBuilder withReadTimeout(Duration duration) { + this.readTimeout = duration; + return this; + } + + /** + * Build an instance of the Http client based on the provided setup. + * + * @return an instance of {@link DaprHttp} + * @throws IllegalStateException if any required field is missing + */ + public DaprHttp build() { + return buildDaprHttp(); + } + + /** + * Creates and instance of the HTTP Client. + * + * @return Instance of {@link DaprHttp} + */ + private DaprHttp buildDaprHttp() { + OkHttpClient.Builder builder = new OkHttpClient.Builder(); + builder.readTimeout(DEFAULT_READ_TIMEOUT); + OkHttpClient okHttpClient = builder.build(); + return new DaprHttp(PORT, okHttpClient); + } +} diff --git a/sdk/src/main/java/io/dapr/client/ObjectSerializer.java b/sdk/src/main/java/io/dapr/client/ObjectSerializer.java new file mode 100644 index 000000000..d95198118 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/ObjectSerializer.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.client.domain.CloudEvent; + +import java.io.IOException; +import java.util.Base64; + +/** + * Serializes and deserializes an internal object. + */ +public class ObjectSerializer { + + /** + * Shared Json serializer/deserializer as per Jackson's documentation. + */ + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setSerializationInclusion(JsonInclude.Include.NON_NULL); + + /** + * Default constructor to avoid class from being instantiated outside package but still inherited. + */ + protected ObjectSerializer() { + } + + /** + * Serializes a given state object into byte array. + * + * @param state State object to be serialized. + * @return Array of bytes[] with the serialized content. + * @throws IOException In case state cannot be serialized. + */ + public byte[] serialize(Object state) throws IOException { + if (state == null) { + return null; + } + + if (state.getClass() == Void.class) { + return null; + } + + // Have this check here to be consistent with deserialization (see deserialize() method below). + if (state instanceof byte[]) { + return (byte[])state; + } + + // This avoids string to be quoted in the state store. + if (state instanceof String) { + return ((String) state).getBytes(); + } + + // Not string, not primitive, so it is a complex type: we use JSON for that. + return OBJECT_MAPPER.writeValueAsBytes(state); + } + + /** + * Deserializes the byte array into the original object. + * + * @param content Content to be parsed. + * @param clazz Type of the object being deserialized. + * @param Generic type of the object being deserialized. + * @return Object of type T. + * @throws IOException In case content cannot be deserialized. + */ + public T deserialize(byte[] content, Class clazz) throws IOException { + if ((clazz == null) || (clazz == Void.class)) { + return null; + } + + if (clazz.isPrimitive()) { + return deserializePrimitives(content, clazz); + } + + if (content == null) { + return (T) null; + } + + if (clazz == String.class) { + return (T) new String(content); + } + + // Deserialization of GRPC response fails without this check since it does not come as base64 encoded byte[]. + if (clazz == byte[].class) { + return (T) content; + } + + if (content.length == 0) { + return (T) null; + } + + if (clazz == CloudEvent.class) { + return (T) CloudEvent.deserialize(content); + } + + return OBJECT_MAPPER.readValue(content, clazz); + } + + /** + * Parses a given String to the corresponding object defined by class. + * + * @param content Value to be parsed. + * @param clazz Class of the expected result type. + * @param Result type. + * @return Result as corresponding type. + * @throws Exception if cannot deserialize primitive time. + */ + private static T deserializePrimitives(byte[] content, Class clazz) throws IOException { + if ((content == null) || (content.length == 0)) { + if (boolean.class == clazz) return (T) Boolean.FALSE; + if (byte.class == clazz) return (T) Byte.valueOf((byte) 0); + if (short.class == clazz) return (T) Short.valueOf((short) 0); + if (int.class == clazz) return (T) Integer.valueOf(0); + if (long.class == clazz) return (T) Long.valueOf(0L); + if (float.class == clazz) return (T) Float.valueOf(0); + if (double.class == clazz) return (T) Double.valueOf(0); + if (char.class == clazz) return (T) Character.valueOf(Character.MIN_VALUE); + + return null; + } + + return OBJECT_MAPPER.readValue(content, clazz); + } +} diff --git a/sdk/src/main/java/io/dapr/client/domain/CloudEvent.java b/sdk/src/main/java/io/dapr/client/domain/CloudEvent.java new file mode 100644 index 000000000..363948e09 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/domain/CloudEvent.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.client.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.util.Objects; + +/** + * A cloud event in Dapr. + */ +public final class CloudEvent { + + /** + * Shared Json serializer/deserializer as per Jackson's documentation. + */ + protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setSerializationInclusion(JsonInclude.Include.NON_NULL); + + /** + * Identifier of the message being processed. + */ + private final String id; + + /** + * Event's source. + */ + private final String source; + + /** + * Envelope type. + */ + private final String type; + + /** + * Version of the specification. + */ + private final String specversion; + + /** + * Type of the data's content. + */ + private final String datacontenttype; + + /** + * Cloud event specs says data can be a JSON object or string. + */ + private final String data; + + /** + * Instantiates a new input request. + * @param id Identifier of the message being processed. + * @param source Source for this event. + * @param type Type of event. + * @param specversion Version of the event spec. + * @param datacontenttype Type of the payload. + * @param data Payload. + */ + public CloudEvent( + String id, + String source, + String type, + String specversion, + String datacontenttype, + String data) { + this.id = id; + this.source = source; + this.type = type; + this.specversion = specversion; + this.datacontenttype = datacontenttype; + this.data = data; + } + + /** + * Gets the identifier of the message being processed. + * @return Identifier of the message being processed. + */ + public String getId() { + return id; + } + + /** + * Gets the source for this event. + * @return Source for this event. + */ + public String getSource() { + return source; + } + + /** + * Gets the type of event. + * @return Type of event. + */ + public String getType() { + return type; + } + + /** + * Gets the version of the event spec. + * @return Version of the event spec. + */ + public String getSpecversion() { + return specversion; + } + + /** + * Gets the type of the payload. + * @return Type of the payload. + */ + public String getDatacontenttype() { + return datacontenttype; + } + + /** + * Gets the payload + * @return Payload + */ + public String getData() { + return data; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CloudEvent that = (CloudEvent) o; + return Objects.equals(id, that.id) && + Objects.equals(source, that.source) && + Objects.equals(type, that.type) && + Objects.equals(specversion, that.specversion) && + Objects.equals(datacontenttype, that.datacontenttype) && + Objects.equals(data, that.data); + } + + @Override + public int hashCode() { + return Objects.hash(id, source, type, specversion, datacontenttype, data); + } + + /** + * Deserialized a message topic from Dapr. + * @param payload Payload sent from Dapr. + * @return Message (can be null if input is null) + * @throws IOException If cannot parse. + */ + public static CloudEvent deserialize(byte[] payload) throws IOException { + if (payload == null) { + return null; + } + + JsonNode node = OBJECT_MAPPER.readTree(payload); + + if (node== null) { + return null; + } + + String id = null; + if (node.has("id") && !node.get("id").isNull()) { + id = node.get("id").asText(); + } + + String source = null; + if (node.has("source") && !node.get("source").isNull()) { + source = node.get("source").asText(); + } + + String type = null; + if (node.has("type") && !node.get("type").isNull()) { + type = node.get("type").asText(); + } + + String specversion = null; + if (node.has("specversion") && !node.get("specversion").isNull()) { + specversion = node.get("specversion").asText(); + } + + String datacontenttype = null; + if (node.has("datacontenttype") && !node.get("datacontenttype").isNull()) { + datacontenttype = node.get("datacontenttype").asText(); + } + + String data = null; + if (node.has("data") && !node.get("data").isNull()) { + JsonNode dataNode = node.get("data"); + if (dataNode.isTextual()) { + data = dataNode.textValue(); + } else { + data = node.get("data").toString(); + } + } + + return new CloudEvent(id, source, type, specversion, datacontenttype, data); + } +} diff --git a/sdk/src/main/java/io/dapr/client/domain/State.java b/sdk/src/main/java/io/dapr/client/domain/State.java new file mode 100644 index 000000000..e37da0af1 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/domain/State.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client.domain; + +/** + * This class reprent what a State is + * @param The type of the value of the sate + */ +public class State { + /** + * The value of the state + */ + private final T value; + /** + * The key of the state + */ + private final String key; + /** + * The ETag to be used + * Keep in mind that for some state stores (like reids) only numbers are supported. + */ + private final String etag; + + /** + * The options used for saving the state + */ + private final StateOptions options; + + /** + * Create an inmutable state + * This Constructor MUST be used anytime you need to retrieve or delete a State. + * @param key - The key of the state + * @param etag - The etag of the state - Keep in mind that for some state stores (like reids) only numbers are supported. + * @param options - REQUIRED when saving a state. + */ + public State(String key, String etag, StateOptions options) { + this.value = null; + this.key = key; + this.etag = etag; + this.options = options; + } + + /** + * Create an inmutable state + * This Constructor MUST be used anytime you want the state to be send for a Save operation. + * @param value - The value of the state + * @param key - The key of the state + * @param etag - The etag of the state - Keep in mind that for some state stores (like reids) only numbers are supported. + * @param options - REQUIRED when saving a state. + */ + public State(T value, String key, String etag, StateOptions options) { + this.value = value; + this.key = key; + this.etag = etag; + this.options = options; + } + + /** + * Retrieves the Value of the state + * @return The value of the state + */ + public T getValue() { + return value; + } + + /** + * Retrieves the Key of the state + * @return The key of the state + */ + public String getKey() { + return key; + } + + /** + * Retrieve the ETag of this state + * @return The etag of the state + */ + public String getEtag() { + return etag; + } + + /** + * Retrieve the Options used for saving the state + * @return The options to save the state + */ + public StateOptions getOptions() { + return options; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof State)) return false; + + State that = (State) o; + + if (getValue() != null ? !getValue().equals(that.getValue()) : that.getValue() != null) return false; + if (getKey() != null ? !getKey().equals(that.getKey()) : that.getKey() != null) return false; + if (getEtag() != null ? !getEtag().equals(that.getEtag()) : that.getEtag() != null) return false; + if (getOptions() != null ? !getOptions().equals(that.getOptions()) : that.getOptions() != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = getValue() != null ? getValue().hashCode() : 0; + result = 31 * result + (getKey() != null ? getKey().hashCode() : 0); + result = 31 * result + (getEtag() != null ? getEtag().hashCode() : 0); + result = 31 * result + (getOptions() != null ? options.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "StateKeyValue{" + + "value=" + value + + ", key='" + key + "'" + + ", etag='" + etag + "'" + + ", options={'" + options.toString() + "}" + + "}"; + } +} diff --git a/sdk/src/main/java/io/dapr/client/domain/StateOptions.java b/sdk/src/main/java/io/dapr/client/domain/StateOptions.java new file mode 100644 index 000000000..cd31cc7d7 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/domain/StateOptions.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client.domain; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.exc.InvalidFormatException; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import io.dapr.utils.DurationUtils; + +import java.io.IOException; +import java.time.Duration; +import java.time.temporal.TemporalUnit; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +public class StateOptions { + private final Consistency consistency; + private final Concurrency concurrency; + private final RetryPolicy retryPolicy; + + public StateOptions(Consistency consistency, Concurrency concurrency, RetryPolicy retryPolicy) { + this.consistency = consistency; + this.concurrency = concurrency; + this.retryPolicy = retryPolicy; + } + + public Concurrency getConcurrency() { + return concurrency; + } + + public Consistency getConsistency() { + return consistency; + } + + public RetryPolicy getRetryPolicy() { + return retryPolicy; + } + + @JsonIgnore + public Map getStateOptionsAsMap() { + Map mapOptions = null; + if (this != null) { + mapOptions = new HashMap<>(); + if (this.getConsistency() != null) { + mapOptions.put("consistency", this.getConsistency().getValue()); + } + if (this.getConcurrency() != null) { + mapOptions.put("concurrency", this.getConcurrency().getValue()); + } + if (this.getRetryPolicy() != null) { + if (this.getRetryPolicy().getInterval() != null) { + mapOptions.put("retryInterval", String.valueOf(this.getRetryPolicy().getInterval().toMillis())); + } + if (this.getRetryPolicy().getThreshold() != null) { + mapOptions.put("retryThreshold", this.getRetryPolicy().getThreshold().toString()); + } + if (this.getRetryPolicy().getPattern() != null) { + mapOptions.put("retryPattern", this.getRetryPolicy().getPattern().getValue()); + } + } + } + return Collections.unmodifiableMap(Optional.ofNullable(mapOptions).orElse(Collections.EMPTY_MAP)); + } + + public enum Consistency { + EVENTUAL("eventual"), + STRONG("strong"); + + private final String value; + + Consistency(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return this.value; + } + + @JsonCreator + public static Consistency fromValue(String value) { + return Consistency.valueOf(value); + } + } + + public enum Concurrency { + FIRST_WRITE("first-write"), + LAST_WRITE ("last-write"); + + private final String value; + + Concurrency(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return this.value; + } + + @JsonCreator + public static Concurrency fromValue(String value) { + return Concurrency.valueOf(value); + } + } + + public static class RetryPolicy { + public enum Pattern { + LINEAR("linear"), + EXPONENTIAL("exponential"); + + private String value; + + Pattern(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return this.value; + } + + @JsonCreator + public static Pattern fromValue(String value) { + return Pattern.valueOf(value); + } + } + + @JsonSerialize(using = StateOptionDurationSerializer.class) + @JsonDeserialize(using = StateOptionDurationDeserializer.class) + private final Duration interval; + private final Integer threshold; + private final Pattern pattern; + + + public RetryPolicy(Duration interval, Integer threshold, Pattern pattern) { + this.interval = interval; + this.threshold = threshold; + this.pattern = pattern; + } + + public Duration getInterval() { + return interval; + } + + public Integer getThreshold() { + return threshold; + } + + public Pattern getPattern() { + return pattern; + } + } + + public static class StateOptionDurationSerializer extends StdSerializer { + + public StateOptionDurationSerializer() { + + super(Duration.class); + } + public StateOptionDurationSerializer(Class t) { + super(t); + } + + @Override + public void serialize(Duration duration, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeNumber(duration.toMillis()); + } + } + + public static class StateOptionDurationDeserializer extends StdDeserializer { + public StateOptionDurationDeserializer(Class vc) { + super(vc); + } + + @Override + public Duration deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + String durationStr = jsonParser.readValueAs(String.class); + Duration duration = null; + if (durationStr != null && !durationStr.trim().isEmpty()) { + try { + duration = DurationUtils.ConvertDurationFromDaprFormat(durationStr); + } catch (Exception ex) { + throw InvalidFormatException.from(jsonParser, "Unable to parse duration.", ex); + } + } + return duration; + } + } +} diff --git a/sdk/src/main/java/io/dapr/client/domain/Verb.java b/sdk/src/main/java/io/dapr/client/domain/Verb.java new file mode 100644 index 000000000..fff696f31 --- /dev/null +++ b/sdk/src/main/java/io/dapr/client/domain/Verb.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client.domain; + +/** + * Verbs used to invoke methods in Dapr. + */ +public enum Verb { + GET, + PUT, + POST, + DELETE +} diff --git a/sdk/src/main/java/io/dapr/exceptions/DaprError.java b/sdk/src/main/java/io/dapr/exceptions/DaprError.java new file mode 100644 index 000000000..24dd4dc66 --- /dev/null +++ b/sdk/src/main/java/io/dapr/exceptions/DaprError.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.exceptions; + +/** + * Represents an error message from Dapr. + */ +public class DaprError { + + /** + * Error code. + */ + private String errorCode; + + /** + * Error Message. + */ + private String message; + + /** + * Gets the error code. + * + * @return Error code. + */ + public String getErrorCode() { + return errorCode; + } + + /** + * Sets the error code. + * + * @param errorCode Error code. + * @return This instance. + */ + public DaprError setErrorCode(String errorCode) { + this.errorCode = errorCode; + return this; + } + + /** + * Gets the error message. + * + * @return Error message. + */ + public String getMessage() { + return message; + } + + /** + * Sets the error message. + * + * @param message Error message. + * @return This instance. + */ + public DaprError setMessage(String message) { + this.message = message; + return this; + } + +} diff --git a/sdk/src/main/java/io/dapr/exceptions/DaprException.java b/sdk/src/main/java/io/dapr/exceptions/DaprException.java new file mode 100644 index 000000000..35325e465 --- /dev/null +++ b/sdk/src/main/java/io/dapr/exceptions/DaprException.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.exceptions; + +/** + * A Dapr's specific exception. + */ +public class DaprException extends RuntimeException { + + /** + * Dapr's error code for this exception. + */ + private String errorCode; + + /** + * New exception from a server-side generated error code and message. + * + * @param daprError Server-side error. + */ + public DaprException(DaprError daprError) { + this(daprError.getErrorCode(), daprError.getMessage()); + } + + /** + * + * @param daprError Client-side error. + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public DaprException(DaprError daprError, Throwable cause) { + this(daprError.getErrorCode(), daprError.getMessage(), cause); + } + + /** + * New Exception from a client-side generated error code and message. + * + * @param errorCode Client-side error code. + * @param message Client-side error message. + */ + public DaprException(String errorCode, String message) { + super(String.format("%s: %s", errorCode, message)); + this.errorCode = errorCode; + } + + /** + * + * @param errorCode Client-side error code. + * @param message Client-side error message. + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public DaprException(String errorCode, String message, Throwable cause) { + super(String.format("%s: %s", errorCode, message), cause); + this.errorCode = errorCode; + } + + /** + * Returns the exception's error code. + * + * @return Error code. + */ + public String getErrorCode() { + return this.errorCode; + } +} diff --git a/sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java b/sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java new file mode 100644 index 000000000..9c11efd17 --- /dev/null +++ b/sdk/src/main/java/io/dapr/serializer/DaprObjectSerializer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.serializer; + +import java.io.IOException; + +/** + * Serializes and deserializes application's objects. + */ +public interface DaprObjectSerializer { + + /** + * Serializes the given object as a String to be saved. + * + * @param o Object to be serialized. + * @return Serialized object. + * @throws IOException If cannot serialize. + */ + byte[] serialize(Object o) throws IOException; + + /** + * Deserializes the given String into a object. + * + * @param data Data to be deserialized. + * @param clazz Class of object to be deserialized. + * @param Type of object to be deserialized. + * @return Deserialized object. + * @throws IOException If cannot deserialize object. + */ + T deserialize(byte[] data, Class clazz) throws IOException; +} diff --git a/sdk/src/main/java/io/dapr/serializer/DefaultObjectSerializer.java b/sdk/src/main/java/io/dapr/serializer/DefaultObjectSerializer.java new file mode 100644 index 000000000..39da7bb42 --- /dev/null +++ b/sdk/src/main/java/io/dapr/serializer/DefaultObjectSerializer.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.serializer; + +import io.dapr.client.ObjectSerializer; + +import java.io.IOException; + +/** + * Default serializer/deserializer for request/response objects and for state objects too. + */ +@StringContentType +public class DefaultObjectSerializer extends ObjectSerializer implements DaprObjectSerializer { + + /** + * {@inheritDoc} + */ + @Override + public byte[] serialize(Object o) throws IOException { + return super.serialize(o); + } + + /** + * {@inheritDoc} + */ + @Override + public T deserialize(byte[] data, Class clazz) throws IOException { + return super.deserialize(data, clazz); + } +} diff --git a/sdk/src/main/java/io/dapr/serializer/StringContentType.java b/sdk/src/main/java/io/dapr/serializer/StringContentType.java new file mode 100644 index 000000000..ef604dd75 --- /dev/null +++ b/sdk/src/main/java/io/dapr/serializer/StringContentType.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.serializer; + +import java.lang.annotation.*; + +/** + * Flags a serializer indicating that byte[] contains String for both input and output. + * + * This information can be used to at the state store, for example, to save serialized data as plain text. + */ +@Documented +@Target({ElementType.TYPE_USE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface StringContentType { +} diff --git a/sdk/src/main/java/io/dapr/utils/Constants.java b/sdk/src/main/java/io/dapr/utils/Constants.java new file mode 100644 index 000000000..58d31939d --- /dev/null +++ b/sdk/src/main/java/io/dapr/utils/Constants.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.utils; + +/** + * Useful constants for the Dapr's Actor SDK. + */ +public final class Constants { + + /** + * Dapr API used in this client. + */ + public static final String API_VERSION = "v1.0"; + + /** + * Dapr's default hostname. + */ + public static final String DEFAULT_HOSTNAME = "localhost"; + + /** + * Dapr's default http base url. + */ + public static final String DEFAULT_BASE_HTTP_URL = "http://" + DEFAULT_HOSTNAME; + + /** + * Dapr's default HTTP port. + */ + public static final int DEFAULT_HTTP_PORT = 3500; + + /** + * Dapr's default GRPC port. + */ + public static final int DEFAULT_GRPC_PORT = 50051; + + /** + * Environment variable used to set Dapr's HTTP port. + */ + public static final String ENV_DAPR_HTTP_PORT = "DAPR_HTTP_PORT"; + + /** + * Environment variable used to set Dapr's GRPC port. + */ + public static final String ENV_DAPR_GRPC_PORT = "DAPR_GRPC_PORT"; + + /** + * Header used for request id in Dapr. + */ + public static final String HEADER_DAPR_REQUEST_ID = "X-DaprRequestId"; + + /** + * Header for the conditional operation. + */ + public static final String HEADER_HTTP_ETAG_ID = "If-Match"; + + /** + * Base URL for Dapr Actor APIs. + */ + private static final String ACTORS_BASE_URL = API_VERSION + "/" + "actors"; + + /** + * String format for Actors state management relative url. + */ + public static final String ACTOR_STATE_KEY_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state/%s"; + + /** + * String format for Actors state management relative url. + */ + public static final String ACTOR_STATE_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state"; + + /** + * String format for Actors method invocation relative url. + */ + public static final String ACTOR_METHOD_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/method/%s"; + + /** + * String format for Actors reminder registration relative url.. + */ + public static final String ACTOR_REMINDER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/reminders/%s"; + + /** + * String format for Actors timer registration relative url.. + */ + public static final String ACTOR_TIMER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/timers/%s"; + + /** + * Base path to invoke methods. + */ + public static final String INVOKE_PATH = API_VERSION + "/invoke"; + + /** + * Invoke Publish Path + */ + public static final String PUBLISH_PATH = API_VERSION + "/publish"; + + /** + * Invoke Binding Path + */ + public static final String BINDING_PATH = API_VERSION + "/bindings"; + + /** + * State Path + */ + public static final String STATE_PATH = API_VERSION + "/state"; +} diff --git a/sdk/src/main/java/io/dapr/utils/DurationUtils.java b/sdk/src/main/java/io/dapr/utils/DurationUtils.java new file mode 100644 index 000000000..1be79fa3a --- /dev/null +++ b/sdk/src/main/java/io/dapr/utils/DurationUtils.java @@ -0,0 +1,142 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +package io.dapr.utils; + +import java.time.Duration; + +public class DurationUtils { + + /** + * Converts time from the String format used by Dapr into a Duration. + * + * @param valueString A String representing time in the Dapr runtime's format (e.g. 4h15m50s60ms). + * @return A Duration + */ + public static Duration ConvertDurationFromDaprFormat(String valueString) { + // Convert the format returned by the Dapr runtime into Duration + // An example of the format is: 4h15m50s60ms. It does not include days. + int hIndex = valueString.indexOf('h'); + int mIndex = valueString.indexOf('m'); + int sIndex = valueString.indexOf('s'); + int msIndex = valueString.indexOf("ms"); + + String hoursSpan = valueString.substring(0, hIndex); + + int hours = Integer.parseInt(hoursSpan); + int days = hours / 24; + hours = hours % 24; + + String minutesSpan = valueString.substring(hIndex + 1, mIndex); + int minutes = Integer.parseInt(minutesSpan); + + String secondsSpan = valueString.substring(mIndex + 1, sIndex); + int seconds = Integer.parseInt(secondsSpan); + + String millisecondsSpan = valueString.substring(sIndex + 1, msIndex); + int milliseconds = Integer.parseInt(millisecondsSpan); + + return Duration.ZERO + .plusDays(days) + .plusHours(hours) + .plusMinutes(minutes) + .plusSeconds(seconds) + .plusMillis(milliseconds); + } + + /** + * Converts a Duration to the format used by the Dapr runtime. + * + * @param value Duration + * @return The Duration formatted as a String in the format the Dapr runtime uses (e.g. 4h15m50s60ms) + */ + public static String ConvertDurationToDaprFormat(Duration value) { + String stringValue = ""; + + // return empty string for anything negative, it'll only happen for reminder "periods", not dueTimes. A + // negative "period" means fire once only. + if (value == Duration.ZERO || + (value.compareTo(Duration.ZERO) == 1)) { + long hours = getDaysPart(value) * 24 + getHoursPart(value); + + StringBuilder sb = new StringBuilder(); + + sb.append(hours); + sb.append("h"); + + sb.append(getMinutesPart((value))); + sb.append("m"); + + sb.append(getSecondsPart((value))); + sb.append("s"); + + sb.append(getMilliSecondsPart((value))); + sb.append("ms"); + + return sb.toString(); + } + + return stringValue; + } + + /** + * Helper to get the "days" part of the Duration. For example if the duration is 26 hours, this returns 1. + * + * @param d Duration + * @return Number of days. + */ + static long getDaysPart(Duration d) { + long t = d.getSeconds() / 60 / 60 / 24; + return t; + } + + /** + * Helper to get the "hours" part of the Duration. For example if the duration is 26 hours, this is 1 day, 2 hours, so this returns 2. + * + * @param d The duration to parse + * @return the hour part of the duration + */ + static long getHoursPart(Duration d) { + long u = (d.getSeconds() / 60 / 60) % 24; + + return u; + } + + /** + * Helper to get the "minutes" part of the Duration. + * + * @param d The duration to parse + * @return the minutes part of the duration + */ + static long getMinutesPart(Duration d) { + long u = (d.getSeconds() / 60) % 60; + + return u; + } + + /** + * Helper to get the "seconds" part of the Duration. + * + * @param d The duration to parse + * @return the seconds part of the duration + */ + static long getSecondsPart(Duration d) { + long u = d.getSeconds() % 60; + + return u; + } + + /** + * Helper to get the "millis" part of the Duration. + * + * @param d The duration to parse + * @return the milliseconds part of the duration + */ + static long getMilliSecondsPart(Duration d) { + long u = d.toMillis() % 1000; + + return u; + } +} diff --git a/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java b/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java new file mode 100644 index 000000000..60dc6ac82 --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java @@ -0,0 +1,27 @@ +package io.dapr.client; + +import io.dapr.serializer.DaprObjectSerializer; +import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; + +public class DaprClientBuilderTest { + + @Test + public void build() { + DaprObjectSerializer objectSerializer = mock(DaprObjectSerializer.class); + DaprObjectSerializer stateSerializer = mock(DaprObjectSerializer.class); + DaprClientBuilder daprClientBuilder = new DaprClientBuilder(objectSerializer, stateSerializer); + DaprClient daprClient = daprClientBuilder.build(); + assertNotNull(daprClient); + } + + @Test(expected = IllegalArgumentException.class) + public void buildException() { + DaprClientBuilder daprClientBuilder = new DaprClientBuilder(null,null); + DaprClient daprClient = daprClientBuilder.build(); + assertNotNull(daprClient); + } + + +} \ No newline at end of file diff --git a/sdk/src/test/java/io/dapr/client/DaprClientGrpcAdapterTest.java b/sdk/src/test/java/io/dapr/client/DaprClientGrpcAdapterTest.java new file mode 100644 index 000000000..46850d087 --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprClientGrpcAdapterTest.java @@ -0,0 +1,1037 @@ +package io.dapr.client; + +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.SettableFuture; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Empty; +import io.dapr.DaprGrpc; +import io.dapr.DaprProtos; +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.client.domain.Verb; +import io.dapr.serializer.DefaultObjectSerializer; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatcher; +import reactor.core.publisher.Mono; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; + +import static com.google.common.util.concurrent.Futures.addCallback; +import static com.google.common.util.concurrent.MoreExecutors.directExecutor; +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +public class DaprClientGrpcAdapterTest { + + private DaprGrpc.DaprFutureStub client; + private DaprClientGrpcAdapter adapter; + private ObjectSerializer serializer; + + @Before + public void setup() { + client = mock(DaprGrpc.DaprFutureStub.class); + adapter = new DaprClientGrpcAdapter(client, new DefaultObjectSerializer(), new DefaultObjectSerializer()); + serializer = new ObjectSerializer(); + } + + @Test(expected = RuntimeException.class) + public void publishEventExceptionThrownTest() { + when(client.publishEvent(any(DaprProtos.PublishEventEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.publishEvent("topic", "object"); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void publishEventCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.publishEvent(any(DaprProtos.PublishEventEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.publishEvent("topic", "object"); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void publishEventTest() { + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.publishEvent(any(DaprProtos.PublishEventEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.publishEvent("topic", "object"); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void publishEventObjectTest() { + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.publishEvent(any(DaprProtos.PublishEventEnvelope.class))) + .thenReturn(settableFuture); + MyObject event = new MyObject(1, "Event"); + Mono result = adapter.publishEvent("topic", event); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test(expected = RuntimeException.class) + public void invokeBindingExceptionThrownTest() { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.invokeBinding("BindingName", "request"); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeBindingCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.setException(ex); + when(client.invokeBinding(any(DaprProtos.InvokeBindingEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeBinding("BindingName", "request"); + result.block(); + } + + @Test + public void invokeBindingTest() { + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeBinding(any(DaprProtos.InvokeBindingEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeBinding("BindingName", "request"); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void invokeBindingObjectTest() { + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeBinding(any(DaprProtos.InvokeBindingEnvelope.class))) + .thenReturn(settableFuture); + MyObject event = new MyObject(1, "Event"); + Mono result = adapter.invokeBinding("BindingName", event); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceVoidExceptionThrownTest() { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceVoidCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.setException(ex); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null); + result.block(); + } + + @Test + public void invokeServiceVoidTest() throws Exception { + SettableFuture settableFuture = SettableFuture.create(); + + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny("Value")).build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny("Value")).build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void invokeServiceVoidObjectTest() throws Exception { + SettableFuture settableFuture = SettableFuture.create(); + + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny("Value")).build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + MyObject request = new MyObject(1, "Event"); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", request, null); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny("Value")).build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceExceptionThrownTest() { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null, String.class); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null, String.class); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void invokeServiceTest() throws Exception { + String expected = "Value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(expected)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(expected)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null, String.class); + String strOutput = result.block(); + assertEquals(expected, strOutput); + } + + @Test + public void invokeServiceObjectTest() throws Exception { + MyObject object = new MyObject(1, "Value"); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(object)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(object)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", "request", null, MyObject.class); + MyObject resultObject = result.block(); + assertEquals(object.id, resultObject.id); + assertEquals(object.value, resultObject.value); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceNoRequestBodyExceptionThrownTest() { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null, String.class); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceNoRequestCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null, String.class); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void invokeServiceNoRequestBodyTest() throws Exception { + String expected = "Value"; + SettableFuture settableFuture = SettableFuture.create(); + + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(expected)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(expected)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null, String.class); + String strOutput = result.block(); + assertEquals(expected, strOutput); + } + + @Test + public void invokeServiceNoRequestBodyObjectTest() throws Exception { + MyObject object = new MyObject(1, "Value"); + SettableFuture settableFuture = SettableFuture.create(); + + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(object)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(object)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null, MyObject.class); + MyObject resultObject = result.block(); + assertEquals(object.id, resultObject.id); + assertEquals(object.value, resultObject.value); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceByteRequestExceptionThrownTest() throws IOException { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + String request = "Request"; + byte[] byteRequest = serializer.serialize(request); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", byteRequest, null); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceByteRequestCallbackExceptionThrownTest() throws IOException { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + String request = "Request"; + byte[] byteRequest = serializer.serialize(request); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", byteRequest, null); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void invokeByteRequestServiceTest() throws Exception { + String expected = "Value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(expected)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(expected)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + String request = "Request"; + byte[] byteRequest = serializer.serialize(request); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", byteRequest, null); + byte[] byteOutput = result.block(); + String strOutput = serializer.deserialize(byteOutput, String.class); + assertEquals(expected, strOutput); + } + + @Test + public void invokeServiceByteRequestObjectTest() throws Exception { + MyObject resultObj = new MyObject(1, "Value"); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(resultObj)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(resultObj)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + String request = "Request"; + byte[] byteRequest = serializer.serialize(request); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", byteRequest, null); + byte[] byteOutput = result.block(); + assertEquals(resultObj, serializer.deserialize(byteOutput, MyObject.class)); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceNoRequestNoClassBodyExceptionThrownTest() { + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenThrow(RuntimeException.class); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void invokeServiceNoRequestNoClassCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void invokeServiceNoRequestNoClassBodyTest() throws Exception { + String expected = "Value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(expected)).build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(expected)).build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void invokeServiceNoRequestNoClassBodyObjectTest() throws Exception { + MyObject resultObj = new MyObject(1, "Value"); + SettableFuture settableFuture = SettableFuture.create(); + + MockCallback callback = + new MockCallback(DaprProtos.InvokeServiceResponseEnvelope.newBuilder() + .setData(getAny(resultObj)).build()); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(DaprProtos.InvokeServiceResponseEnvelope.newBuilder().setData(getAny(resultObj)).build()); + when(client.invokeService(any(DaprProtos.InvokeServiceEnvelope.class))) + .thenReturn(settableFuture); + Mono result = adapter.invokeService(Verb.GET, "appId", "method", null); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test(expected = RuntimeException.class) + public void getStateExceptionThrownTest() { + when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))).thenThrow(RuntimeException.class); + State key = buildStateKey(null, "Key1", "ETag1", null); + Mono> result = adapter.getState(key, String.class); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void getStateCallbackExceptionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback<>(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) + .thenReturn(settableFuture); + State key = buildStateKey(null, "Key1", "ETag1", null); + Mono> result = adapter.getState(key, String.class); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void getStateStringValueNoOptionsTest() throws IOException { + String etag = "ETag1"; + String key = "key1"; + String expectedValue = "Expected state"; + State expectedState = buildStateKey(expectedValue, key, etag, null); + DaprProtos.GetStateResponseEnvelope responseEnvelope = buildGetStateResponseEnvelope(expectedValue, etag); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(responseEnvelope); + addCallback(settableFuture, callback, directExecutor()); + when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) + .thenReturn(settableFuture); + State keyRequest = buildStateKey(null, key, etag, null); + Mono> result = adapter.getState(keyRequest, String.class); + settableFuture.set(responseEnvelope); + assertEquals(expectedState, result.block()); + } + + @Test + public void getStateObjectValueWithOptionsTest() throws IOException { + String etag = "ETag1"; + String key = "key1"; + MyObject expectedValue = new MyObject(1, "The Value"); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + State expectedState = buildStateKey(expectedValue, key, etag, options); + DaprProtos.GetStateResponseEnvelope responseEnvelope = DaprProtos.GetStateResponseEnvelope.newBuilder() + .setData(getAny(expectedValue)) + .setEtag(etag) + .build(); + State keyRequest = buildStateKey(null, key, etag, options); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(responseEnvelope); + addCallback(settableFuture, callback, directExecutor()); + when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) + .thenReturn(settableFuture); + Mono> result = adapter.getState(keyRequest, MyObject.class); + settableFuture.set(responseEnvelope); + assertEquals(expectedState, result.block()); + } + + @Test + public void getStateObjectValueWithOptionsNoConcurrencyTest() throws IOException { + String etag = "ETag1"; + String key = "key1"; + MyObject expectedValue = new MyObject(1, "The Value"); + StateOptions options = new StateOptions(null, StateOptions.Concurrency.FIRST_WRITE, + new StateOptions.RetryPolicy(Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR)); + State expectedState = buildStateKey(expectedValue, key, etag, options); + DaprProtos.GetStateResponseEnvelope responseEnvelope = DaprProtos.GetStateResponseEnvelope.newBuilder() + .setData(getAny(expectedValue)) + .setEtag(etag) + .build(); + State keyRequest = buildStateKey(null, key, etag, options); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(responseEnvelope); + addCallback(settableFuture, callback, directExecutor()); + when(client.getState(any(io.dapr.DaprProtos.GetStateEnvelope.class))) + .thenReturn(settableFuture); + Mono> result = adapter.getState(keyRequest, MyObject.class); + settableFuture.set(responseEnvelope); + assertEquals(expectedState, result.block()); + } + + @Test(expected = RuntimeException.class) + public void deleteStateExceptionThrowTest() { + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))).thenThrow(RuntimeException.class); + State key = buildStateKey(null, "Key1", "ETag1", null); + Mono result = adapter.deleteState(key.getKey(), key.getEtag(), key.getOptions()); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void deleteStateCallbackExcpetionThrownTest() { + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = + new MockCallback(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State key = buildStateKey(null, "Key1", "ETag1", null); + Mono result = adapter.deleteState(key.getKey(), key.getEtag(), key.getOptions()); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void deleteStateNoOptionsTest() { + String etag = "ETag1"; + String key = "key1"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, null); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateNoConsistencyTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(null, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateNoConcurrencyTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateNoRetryPolicyTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + null, null, null); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateRetryPolicyNoDurationTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + null, 1, StateOptions.RetryPolicy.Pattern.LINEAR); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateRetryPolicyNoThresholdTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), null, StateOptions.RetryPolicy.Pattern.LINEAR); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void deleteStateRetryPolicyNoPatternTest() { + String etag = "ETag1"; + String key = "key1"; + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, null); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFuture); + State stateKey = buildStateKey(null, key, etag, options); + Mono result = adapter.deleteState(stateKey.getKey(), stateKey.getEtag(), stateKey.getOptions()); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test(expected = RuntimeException.class) + public void saveStateExceptionThrownTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenThrow(RuntimeException.class); + Mono result = adapter.saveState(key, etag, value, null); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void saveStateCallbackExceptionThrownTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + RuntimeException ex = new RuntimeException("An Exception"); + MockCallback callback = new MockCallback<>(ex); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + Mono result = adapter.saveState(key, etag, value, null); + settableFuture.setException(ex); + result.block(); + } + + @Test + public void saveStateNoOptionsTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + Mono result = adapter.saveState(key, etag, value, null); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateNoConsistencyTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(null, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateNoConcurrencyTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null, + Duration.ofDays(100), 1, StateOptions.RetryPolicy.Pattern.LINEAR); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateNoRetryPolicyTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + null, null, null); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateRetryPolicyNoDurationTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + null, 1, StateOptions.RetryPolicy.Pattern.LINEAR); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateRetryPolicyNoThresholdTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), null, StateOptions.RetryPolicy.Pattern.LINEAR); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + @Test + public void saveStateRetryPolicyNoPatternTest() { + String key = "key1"; + String etag = "ETag1"; + String value = "State value"; + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFuture, callback, directExecutor()); + when(client.saveState(any(io.dapr.DaprProtos.SaveStateEnvelope.class))).thenReturn(settableFuture); + StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, + Duration.ofDays(100), 1, null); + Mono result = adapter.saveState(key, etag, value, options); + settableFuture.set(Empty.newBuilder().build()); + result.block(); + assertTrue(callback.wasCalled); + } + + private State buildStateKey(T value, String key, String etag, StateOptions options) { + return new State(value, key, etag, options); + } + + /** + * The purpose of this test is to show that it doesn't matter when the client is called, the actual coll to DAPR + * will be done when the output Mono response call the Mono.block method. + * Like for instanche if you call getState, withouth blocking for the response, and then call delete for the same state + * you just retrived but block for the delete response, when later you block for the response of the getState, you will + * not found the state. + *

This test will execute the following flow:

+ *
    + *
  1. Exeucte client getState for Key=key1
  2. + *
  3. Block for result to the the state
  4. + *
  5. Assert the Returned State is the expected to key1
  6. + *
  7. Execute client getState for Key=key2
  8. + *
  9. Execute client deleteState for Key=key2
  10. + *
  11. Block for deleteState call.
  12. + *
  13. Block for getState for Key=key2 and Assert they 2 was not found.
  14. + *
+ * @throws Exception + */ + + @Test + public void getStateDeleteStateThenBlockDeleteThenBlockGet() throws Exception { + String etag = "ETag1"; + String key1 = "key1"; + String expectedValue1 = "Expected state 1"; + String key2 = "key2"; + String expectedValue2 = "Expected state 2"; + State expectedState1 = buildStateKey(expectedValue1, key1, etag, null); + Map> futuresMap = new HashMap<>(); + futuresMap.put(key1, buildFutureGetStateEnvelop(expectedValue1, etag)); + futuresMap.put(key2, buildFutureGetStateEnvelop(expectedValue2, etag)); + when(client.getState(argThat(new GetStateEnvelopeKeyMatcher(key1)))).thenReturn(futuresMap.get(key1)); + State keyRequest1 = buildStateKey(null, key1, etag, null); + Mono> resultGet1 = adapter.getState(keyRequest1, String.class); + assertEquals(expectedState1, resultGet1.block()); + State keyRequest2 = buildStateKey(null, key2, etag, null); + Mono> resultGet2 = adapter.getState(keyRequest2, String.class); + + SettableFuture settableFutureDelete = SettableFuture.create(); + MockCallback callbackDelete = new MockCallback<>(Empty.newBuilder().build()); + addCallback(settableFutureDelete, callbackDelete, directExecutor()); + when(client.deleteState(any(io.dapr.DaprProtos.DeleteStateEnvelope.class))) + .thenReturn(settableFutureDelete); + Mono resultDelete = adapter.deleteState(keyRequest2.getKey(), keyRequest2.getEtag(), keyRequest2.getOptions()); + settableFutureDelete.set(Empty.newBuilder().build()); + resultDelete.block(); + assertTrue(callbackDelete.wasCalled); + futuresMap.replace(key2, null); + when(client.getState(argThat(new GetStateEnvelopeKeyMatcher(key2)))).thenReturn(futuresMap.get(key2)); + + State state2 = resultGet2.block(); + assertNull(state2); + } + + private SettableFuture buildFutureGetStateEnvelop(T value, String etag) throws IOException { + DaprProtos.GetStateResponseEnvelope envelope = buildGetStateResponseEnvelope(value, etag); + SettableFuture settableFuture = SettableFuture.create(); + MockCallback callback = new MockCallback<>(envelope); + addCallback(settableFuture, callback, directExecutor()); + settableFuture.set(envelope); + + return settableFuture; + } + + private DaprProtos.GetStateResponseEnvelope buildGetStateResponseEnvelope(T value, String etag) throws IOException { + return DaprProtos.GetStateResponseEnvelope.newBuilder() + .setData(getAny(value)) + .setEtag(etag) + .build(); + } + + private StateOptions buildStateOptions(StateOptions.Consistency consistency, StateOptions.Concurrency concurrency, + Duration interval, Integer threshold, StateOptions.RetryPolicy.Pattern pattern) { + + StateOptions.RetryPolicy retryPolicy = null; + if (interval != null || threshold != null || pattern != null) { + retryPolicy = new StateOptions.RetryPolicy(interval, threshold, pattern); + } + StateOptions options = null; + if (consistency != null || concurrency != null || retryPolicy != null) { + options = new StateOptions(consistency, concurrency, retryPolicy); + } + return options; + } + + private Any getAny(T value) throws IOException { + byte[] byteValue = serializer.serialize(value); + return Any.newBuilder().setValue(ByteString.copyFrom(byteValue)).build(); + } + + private final class MockCallback implements FutureCallback { + @Nullable + private T value = null; + @Nullable + private Throwable failure = null; + private boolean wasCalled = false; + + public MockCallback(T expectedValue) { + this.value = expectedValue; + } + + public MockCallback(Throwable expectedFailure) { + this.failure = expectedFailure; + } + + @Override + public synchronized void onSuccess(@NullableDecl T result) { + assertFalse(wasCalled); + wasCalled = true; + assertEquals(value, result); + } + + @Override + public synchronized void onFailure(Throwable throwable) { + assertFalse(wasCalled); + wasCalled = true; + assertEquals(failure, throwable); + } + } + + public static class MyObject { + private Integer id; + private String value; + + public MyObject() { + } + + public MyObject(Integer id, String value) { + this.id = id; + this.value = value; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MyObject)) return false; + + MyObject myObject = (MyObject) o; + + if (!getId().equals(myObject.getId())) return false; + if (getValue() != null ? !getValue().equals(myObject.getValue()) : myObject.getValue() != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = getId().hashCode(); + result = 31 * result + (getValue() != null ? getValue().hashCode() : 0); + return result; + } + } + + private static class GetStateEnvelopeKeyMatcher implements ArgumentMatcher { + + private final String propValue; + + GetStateEnvelopeKeyMatcher(String propValue) { + this.propValue = propValue; + } + + @Override + public boolean matches(DaprProtos.GetStateEnvelope argument) { + if (argument == null) { + return false; + } + if (propValue == null && argument.getKey() != null) { + return false; + } + if (propValue == null && argument.getKey() == null) { + return true; + } + return propValue.equals(argument.getKey()); + } + + @Override + public String toString() { + return ""; + } + } +} diff --git a/sdk/src/test/java/io/dapr/client/DaprClientHttpAdapterTest.java b/sdk/src/test/java/io/dapr/client/DaprClientHttpAdapterTest.java new file mode 100644 index 000000000..65be1634f --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprClientHttpAdapterTest.java @@ -0,0 +1,376 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.client.domain.Verb; +import okhttp3.OkHttpClient; +import okhttp3.mock.Behavior; +import okhttp3.mock.MockInterceptor; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; + +public class DaprClientHttpAdapterTest { + + private DaprClientHttpAdapter daprClientHttpAdapter; + + private DaprHttp daprHttp; + + private OkHttpClient okHttpClient; + + private MockInterceptor mockInterceptor; + + private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; + + @Before + public void setUp() throws Exception { + mockInterceptor = new MockInterceptor(Behavior.UNORDERED); + okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build(); + } + + @Test + public void publishEventInvokation() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + DaprClientHttpAdapter daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.publishEvent("A", event, null); + assertNull(mono.block()); + } + + @Test + public void publishEvent() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.publishEvent("A", event); + assertNull(mono.block()); + } + + @Test(expected = IllegalArgumentException.class) + public void publishEventIfTopicIsNull() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.publishEvent("", event); + assertNull(mono.block()); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeServiceVerbNull() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(null, "", "", null, null, null); + assertNull(mono.block()); + } + + @Test + public void invokeServiceIllegalArgumentException() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.invokeService(null, "", "", null, null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.invokeService(Verb.POST, null, "", null, null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.invokeService(Verb.POST, "", "", null, null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.invokeService(Verb.POST, "1", null, null, null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.invokeService(Verb.POST, "1", "", null, null, null).block(); + }); + } + + + @Test(expected = IllegalArgumentException.class) + public void invokeServiceMethodNull() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/publish/A") + .respond(EXPECTED_RESULT); + String event = "{ \"message\": \"This is a test\" }"; + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.POST, "1", "", null, null, null); + assertNull(mono.block()); + } + + @Test + public void invokeService() { + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/invoke/41/method/neworder") + .respond("hello world"); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.GET, "41", "neworder", null, null, String.class); + assertEquals("hello world", mono.block()); + } + + @Test + public void simpleInvokeService() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/invoke/41/method/neworder") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.GET, "41", "neworder", null, byte[].class); + assertEquals(new String(mono.block()), EXPECTED_RESULT); + } + + @Test + public void invokeServiceWithMaps() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/invoke/41/method/neworder") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.GET, "41", "neworder", (byte[]) null, map); + String monoString = new String(mono.block()); + assertEquals(monoString, EXPECTED_RESULT); + } + + @Test + public void invokeServiceWithOutRequest() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/invoke/41/method/neworder") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.GET, "41", "neworder", map); + assertNull(mono.block()); + } + + @Test + public void invokeServiceWithRequest() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/invoke/41/method/neworder") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeService(Verb.GET, "41", "neworder", "", map); + assertNull(mono.block()); + } + + @Test + public void invokeBinding() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/bindings/sample-topic") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeBinding("sample-topic", ""); + assertNull(mono.block()); + } + + @Test(expected = IllegalArgumentException.class) + public void invokeBindingNullName() { + Map map = new HashMap<>(); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/bindings/sample-topic") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.invokeBinding(null, ""); + assertNull(mono.block()); + } + + + @Test + public void getStates() { + StateOptions stateOptions = mock(StateOptions.class); + State stateKeyValue = new State("value", "key", "etag", stateOptions); + State stateKeyNull = new State("value", null, "etag", stateOptions); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/state/key") + .respond("\"" + EXPECTED_RESULT + "\""); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.getState(stateKeyNull, String.class).block(); + }); + Mono> mono = daprClientHttpAdapter.getState(stateKeyValue, String.class); + assertEquals(mono.block().getKey(), "key"); + } + + @Test + public void getStatesEmptyEtag() { + State stateEmptyEtag = new State("value", "key", "", null); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/state/key") + .respond("\"" + EXPECTED_RESULT + "\""); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono> monoEmptyEtag = daprClientHttpAdapter.getState(stateEmptyEtag, String.class); + assertEquals(monoEmptyEtag.block().getKey(), "key"); + } + + @Test + public void getStatesNullEtag() { + State stateNullEtag = new State("value", "key", null, null); + mockInterceptor.addRule() + .get("http://localhost:3000/v1.0/state/key") + .respond("\"" + EXPECTED_RESULT + "\""); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono> monoNullEtag = daprClientHttpAdapter.getState(stateNullEtag, String.class); + assertEquals(monoNullEtag.block().getKey(), "key"); + } + + @Test + public void saveStates() { + State stateKeyValue = new State("value", "key", "etag", null); + List> stateKeyValueList = Arrays.asList(stateKeyValue); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/state") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.saveStates(stateKeyValueList); + assertNull(mono.block()); + } + + @Test + public void saveStatesNull() { + State stateKeyValue = new State("value", "key", "", null); + List> stateKeyValueList = new ArrayList(); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/state") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.saveStates(null); + assertNull(mono.block()); + Mono mono1 = daprClientHttpAdapter.saveStates(stateKeyValueList); + assertNull(mono1.block()); + } + + @Test + public void saveStatesEtagNull() { + State stateKeyValue = new State("value", "key", null, null); + List> stateKeyValueList = Arrays.asList(stateKeyValue); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/state") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.saveStates(stateKeyValueList); + assertNull(mono.block()); + } + + @Test + public void saveStatesEtagEmpty() { + State stateKeyValue = new State("value", "key", "", null); + List> stateKeyValueList = Arrays.asList(stateKeyValue); + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/state") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.saveStates(stateKeyValueList); + assertNull(mono.block()); + } + + @Test + public void simpleSaveStates() { + mockInterceptor.addRule() + .post("http://localhost:3000/v1.0/state") + .respond(EXPECTED_RESULT); + StateOptions stateOptions = mock(StateOptions.class); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.saveState("key", "etag", "value", stateOptions); + assertNull(mono.block()); + } + + + @Test + public void deleteState() { + StateOptions stateOptions = mock(StateOptions.class); + State stateKeyValue = new State("value", "key", "etag", stateOptions); + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/state/key") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions); + assertNull(mono.block()); + } + + @Test + public void deleteStateNullEtag() { + State stateKeyValue = new State("value", "key", null, null); + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/state/key") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), null); + assertNull(mono.block()); + } + + @Test + public void deleteStateEmptyEtag() { + State stateKeyValue = new State("value", "key", "", null); + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/state/key") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + Mono mono = daprClientHttpAdapter.deleteState(stateKeyValue.getKey(), stateKeyValue.getEtag(), null); + assertNull(mono.block()); + } + + @Test + public void deleteStateIllegalArgumentException() { + State stateKeyValueNull = new State("value", null, "etag", null); + State stateKeyValueEmpty = new State("value", "", "etag", null); + mockInterceptor.addRule() + .delete("http://localhost:3000/v1.0/state/key") + .respond(EXPECTED_RESULT); + daprHttp = new DaprHttp(3000, okHttpClient); + daprClientHttpAdapter = new DaprClientHttpAdapter(daprHttp); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.deleteState(null, null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.deleteState("", null, null).block(); + }); + assertThrows(IllegalArgumentException.class, () -> { + daprClientHttpAdapter.deleteState(" ", null, null).block(); + }); + } +} \ No newline at end of file diff --git a/sdk/src/test/java/io/dapr/client/DaprClientTestBuilder.java b/sdk/src/test/java/io/dapr/client/DaprClientTestBuilder.java new file mode 100644 index 000000000..802cf1c58 --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprClientTestBuilder.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.client; + +import io.dapr.DaprGrpc; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.utils.Constants; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; + +/** + * Builder for DaprClient used in tests only. + */ +public class DaprClientTestBuilder { + + /** + * Builds a DaprClient. + * @param client DaprHttp used for http calls (can be mocked or stubbed) + * @return New instance of DaprClient. + */ + public static DaprClient buildHttpClient(DaprHttp client) { + return new DaprClientHttpAdapter(client); + } + + /** + * Builds a DaprGrpcClient. + * @return New instance of DaprClient. + */ + public static DaprClient buildGrpcClient(){ + int gprcPort = Integer.parseInt(System.getenv(Constants.ENV_DAPR_GRPC_PORT)); + ManagedChannel channel = ManagedChannelBuilder.forAddress(Constants.DEFAULT_HOSTNAME, gprcPort).usePlaintext().build(); + return new DaprClientGrpcAdapter(DaprGrpc.newFutureStub(channel), + new DefaultObjectSerializer(), + new DefaultObjectSerializer()); + } +} diff --git a/sdk/src/test/java/io/dapr/client/DaprHttpBuilderTest.java b/sdk/src/test/java/io/dapr/client/DaprHttpBuilderTest.java new file mode 100644 index 000000000..9a26db2fc --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprHttpBuilderTest.java @@ -0,0 +1,19 @@ +package io.dapr.client; + +import org.junit.Test; +import java.time.Duration; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; + +public class DaprHttpBuilderTest { + + @Test + public void withReadTimeout() throws Exception { + DaprHttpBuilder daprHttpBuilder = new DaprHttpBuilder(); + Duration duration = mock(Duration.class); + daprHttpBuilder.build(); + DaprHttpBuilder dapr = daprHttpBuilder.withReadTimeout(duration); + assertNotNull(dapr); + } + +} \ No newline at end of file diff --git a/sdk/src/test/java/io/dapr/client/DaprHttpStub.java b/sdk/src/test/java/io/dapr/client/DaprHttpStub.java new file mode 100644 index 000000000..6d920d1d3 --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprHttpStub.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.client; + +import reactor.core.publisher.Mono; + +import java.util.Map; + +/** + * Stub class for DaprHttp. + * Useful to mock as well since it provides a default constructor. + */ +public class DaprHttpStub extends DaprHttp { + + public static class ResponseStub extends DaprHttp.Response { + public ResponseStub(byte[] body, Map headers, int statusCode) { + super(body, headers, statusCode); + } + } + /** + * Instantiates a stub for DaprHttp + */ + public DaprHttpStub() { + super(3000, null); + } + + /** + * {@inheritDoc} + * @return + */ + @Override + public Mono invokeAPI(String method, String urlString, Map urlParameters, Map headers) { + return Mono.empty(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeAPI(String method, String urlString, Map urlParameters, String content, Map headers) { + return Mono.empty(); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono invokeAPI(String method, String urlString, Map urlParameters, byte[] content, Map headers) { + return Mono.empty(); + } +} diff --git a/sdk/src/test/java/io/dapr/client/DaprHttpTest.java b/sdk/src/test/java/io/dapr/client/DaprHttpTest.java new file mode 100644 index 000000000..c0d49ccb2 --- /dev/null +++ b/sdk/src/test/java/io/dapr/client/DaprHttpTest.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ +package io.dapr.client; + +import io.dapr.exceptions.DaprException; +import io.dapr.utils.Constants; +import okhttp3.*; +import okhttp3.mock.Behavior; +import okhttp3.mock.MockInterceptor; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + + +public class DaprHttpTest { + + private OkHttpClient okHttpClient; + + private MockInterceptor mockInterceptor; + + private ObjectSerializer serializer = new ObjectSerializer(); + + private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; + + @Before + public void setUp() throws Exception { + mockInterceptor = new MockInterceptor(Behavior.UNORDERED); + okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build(); + } + + @Test + public void invokeMethod() throws IOException { + Map headers = new HashMap<>(); + headers.put("content-type", "text/html"); + headers.put("header1", "value1"); + mockInterceptor.addRule() + .post("http://localhost:3500/v1.0/state") + .respond(serializer.serialize(EXPECTED_RESULT)); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("POST", "v1.0/state", null, (byte[]) null, headers); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test + public void invokePostMethod() throws IOException { + mockInterceptor.addRule() + .post("http://localhost:3500/v1.0/state") + .respond(serializer.serialize(EXPECTED_RESULT)) + .addHeader("Header", "Value"); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("POST", "v1.0/state", null, "", null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test + public void invokeDeleteMethod() throws IOException { + mockInterceptor.addRule() + .delete("http://localhost:3500/v1.0/state") + .respond(serializer.serialize(EXPECTED_RESULT)); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("DELETE", "v1.0/state", null, (String) null, null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test + public void invokeGetMethod() throws IOException { + mockInterceptor.addRule() + .get("http://localhost:3500/v1.0/get") + .respond(serializer.serialize(EXPECTED_RESULT)); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("GET", "v1.0/get", null, null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test + public void invokeMethodWithHeaders() throws IOException { + Map headers = new HashMap<>(); + headers.put("header", "value"); + headers.put("header1", "value1"); + Map urlParameters = new HashMap<>(); + urlParameters.put("orderId", "41"); + mockInterceptor.addRule() + .get("http://localhost:3500/v1.0/state/order?orderId=41") + .respond(serializer.serialize(EXPECTED_RESULT)); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("GET", "v1.0/state/order", urlParameters, headers); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test(expected = RuntimeException.class) + public void invokePostMethodRuntime() throws IOException { + mockInterceptor.addRule() + .post("http://localhost:3500/v1.0/state") + .respond(500); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("POST", "v1.0/state", null, null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test(expected = RuntimeException.class) + public void invokePostDaprError() throws IOException { + mockInterceptor.addRule() + .post("http://localhost:3500/v1.0/state") + .respond(500, ResponseBody.create(MediaType.parse("text"), + "{\"errorCode\":null,\"message\":null}")); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("POST", "v1.0/state", null, null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + @Test(expected = RuntimeException.class) + public void invokePostMethodUnknownError() throws IOException { + mockInterceptor.addRule() + .post("http://localhost:3500/v1.0/state") + .respond(500, ResponseBody.create(MediaType.parse("application/json"), + "{\"errorCode\":\"null\",\"message\":\"null\"}")); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono mono = daprHttp.invokeAPI("POST", "v1.0/state", null, null); + DaprHttp.Response response = mono.block(); + String body = serializer.deserialize(response.getBody(), String.class); + assertEquals(EXPECTED_RESULT, body); + } + + /** + * The purpose of this test is to show that it doesn't matter when the client is called, the actual coll to DAPR + * will be done when the output Mono response call the Mono.block method. + * Like for instanche if you call getState, withouth blocking for the response, and then call delete for the same state + * you just retrived but block for the delete response, when later you block for the response of the getState, you will + * not found the state. + *

This test will execute the following flow:

+ *
    + *
  1. Exeucte client getState for Key=key1
  2. + *
  3. Block for result to the the state
  4. + *
  5. Assert the Returned State is the expected to key1
  6. + *
  7. Execute client getState for Key=key2
  8. + *
  9. Execute client deleteState for Key=key2
  10. + *
  11. Block for deleteState call.
  12. + *
  13. Block for getState for Key=key2 and Assert they 2 was not found.
  14. + *
+ * + * @throws Exception + */ + @Test() + public void testCallbackCalledAtTheExpectedTimeTest() throws IOException { + String deletedStateKey = "deletedKey"; + String existingState = "existingState"; + String urlDeleteState = Constants.STATE_PATH + "/" + deletedStateKey; + String urlExistingState = Constants.STATE_PATH + "/" + existingState; + mockInterceptor.addRule() + .get("http://localhost:3500/" + urlDeleteState) + .respond(200, ResponseBody.create(MediaType.parse("application/json"), + deletedStateKey)); + mockInterceptor.addRule() + .delete("http://localhost:3500/" + urlDeleteState) + .respond(204); + mockInterceptor.addRule() + .get("http://localhost:3500/" + urlExistingState) + .respond(200, ResponseBody.create(MediaType.parse("application/json"), + serializer.serialize(existingState))); + DaprHttp daprHttp = new DaprHttp(3500, okHttpClient); + Mono response = daprHttp.invokeAPI("GET", urlExistingState, null, null); + assertEquals(existingState, serializer.deserialize(response.block().getBody(), String.class)); + Mono responseDeleted = daprHttp.invokeAPI("GET", urlDeleteState, null, null); + Mono responseDeleteKey = daprHttp.invokeAPI("DELETE", urlDeleteState, null, null); + assertEquals("", serializer.deserialize(responseDeleteKey.block().getBody(), String.class)); + mockInterceptor.reset(); + mockInterceptor.addRule() + .get("http://localhost:3500/" + urlDeleteState) + .respond(404, ResponseBody.create(MediaType.parse("application/json"), + "{\"errorCode\":\"404\",\"message\":\"State Not Fuund\"}")); + try { + responseDeleted.block(); + fail("Expected DaprException"); + } catch (Exception ex) { + assertEquals(DaprException.class, ex.getCause().getCause().getClass()); + } + } + +} diff --git a/sdk/src/test/java/io/dapr/it/BaseIT.java b/sdk/src/test/java/io/dapr/it/BaseIT.java new file mode 100644 index 000000000..2eb7092ce --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/BaseIT.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.contrib.java.lang.system.EnvironmentVariables; + +import java.util.Optional; + +import static io.dapr.it.DaprIntegrationTestingRunner.DAPR_FREEPORTS; + +@Ignore +public class BaseIT { + + protected static DaprIntegrationTestingRunner daprIntegrationTestingRunner; + + + @ClassRule + public static final EnvironmentVariables environmentVariables = new EnvironmentVariables(); + + @BeforeClass + public static void setEnvironmentVariables(){ + environmentVariables.set("DAPR_HTTP_PORT", String.valueOf(DAPR_FREEPORTS.getHttpPort())); + environmentVariables.set("DAPR_GRPC_PORT", String.valueOf(DAPR_FREEPORTS.getGrpcPort())); + } + + public static DaprIntegrationTestingRunner createDaprIntegrationTestingRunner(String successMessage, Class serviceClass, Boolean useAppPort, int sleepTime) { + return new DaprIntegrationTestingRunner(successMessage, serviceClass, useAppPort, sleepTime); + } + + @AfterClass + public static void cleanUp() { + Optional.ofNullable(daprIntegrationTestingRunner).ifPresent(daprRunner -> daprRunner.destroyDapr()); + } + + public static class MyData { + + /// Gets or sets the value for PropertyA. + private String propertyA; + + /// Gets or sets the value for PropertyB. + private String propertyB; + + private MyData myData; + + public String getPropertyB() { + return propertyB; + } + + public void setPropertyB(String propertyB) { + this.propertyB = propertyB; + } + + public String getPropertyA() { + return propertyA; + } + + public void setPropertyA(String propertyA) { + this.propertyA = propertyA; + } + + @Override + public String toString() { + return "MyData{" + + "propertyA='" + propertyA + '\'' + + ", propertyB='" + propertyB + '\'' + + '}'; + } + + public MyData getMyData() { + return myData; + } + + public void setMyData(MyData myData) { + this.myData = myData; + } + } +} diff --git a/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java b/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java new file mode 100644 index 000000000..5abb5dbcb --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/DaprIntegrationTestingRunner.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it; + +import org.junit.Assert; + +import java.io.*; +import java.net.ServerSocket; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.*; + + +public class DaprIntegrationTestingRunner { + + public static DaprIntegrationTestingRunner.DaprFreePorts DAPR_FREEPORTS; + + static { + try { + DAPR_FREEPORTS = new DaprIntegrationTestingRunner.DaprFreePorts().initPorts(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Runtime rt = Runtime.getRuntime(); + private Process proc; + + private String successMessage; + private Class serviceClass; + private Boolean useAppPort; + private int sleepTime; + private String appName; + + DaprIntegrationTestingRunner(String successMessage, Class serviceClass, Boolean useAppPort, int sleepTime) { + this.successMessage = successMessage; + this.serviceClass = serviceClass; + this.useAppPort = useAppPort; + this.sleepTime = sleepTime; + this.generateAppName(); + } + + public DaprFreePorts initializeDapr() throws Exception { + String daprCommand=this.buildDaprCommand(); + System.out.println(daprCommand); + proc= rt.exec(daprCommand); + + final Runnable stuffToDo = new Thread(() -> { + try { + try (InputStream stdin = proc.getInputStream()) { + try(InputStreamReader isr = new InputStreamReader(stdin)) { + try (BufferedReader br = new BufferedReader(isr)){ + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + if (line.contains(successMessage)) { + break; + } + } + } + } + + } + } catch (IOException ex) { + Assert.fail(ex.getMessage()); + } + }); + + final ExecutorService executor = Executors.newSingleThreadExecutor(); + final Future future = executor.submit(stuffToDo); + executor.shutdown(); // This does not cancel the already-scheduled task. + future.get(1, TimeUnit.MINUTES); + Thread.sleep(sleepTime); + return DAPR_FREEPORTS; + } + + private static final String DAPR_RUN = "dapr run --app-id %s "; + + // the arg in -Dexec.args is the app's port + private static final String DAPR_COMMAND = " -- mvn exec:java -Dexec.mainClass=%s -Dexec.classpathScope=test -Dexec.args=\"%d\""; + + private String buildDaprCommand(){ + StringBuilder stringBuilder= new StringBuilder(String.format(DAPR_RUN, this.getAppName())) + .append(this.useAppPort ? "--app-port " + this.DAPR_FREEPORTS.appPort : "") + .append(" --grpc-port ") + .append(this.DAPR_FREEPORTS.grpcPort) + .append(" --port ") + .append(this.DAPR_FREEPORTS.httpPort) + .append(String.format(DAPR_COMMAND, this.serviceClass.getCanonicalName(),this.DAPR_FREEPORTS.appPort)); + return stringBuilder.toString(); + } + + private void generateAppName(){ + + this.appName=UUID.randomUUID().toString(); + } + + private static Integer findRandomOpenPortOnAllLocalInterfaces() throws Exception { + try ( + ServerSocket socket = new ServerSocket(0) + ) { + return socket.getLocalPort(); + + } + } + + public void destroyDapr() { + Optional.ofNullable(rt).ifPresent( runtime -> { + try { + System.out.println("Start dapr Stop"); + runtime.exec("dapr stop --app-id " + this.getAppName()); + System.out.println("End Dapr Stop"); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + Optional.ofNullable(proc).ifPresent(process -> { + System.out.println("Start process Stop"); + process.destroyForcibly(); + System.out.println("End process Stop"); + }); + } + + public String getAppName() { + return appName; + } + + public static class DaprFreePorts + { + public DaprFreePorts initPorts() throws Exception { + this.appPort= findRandomOpenPortOnAllLocalInterfaces(); + this.grpcPort= findRandomOpenPortOnAllLocalInterfaces(); + this.httpPort= findRandomOpenPortOnAllLocalInterfaces(); + return this; + } + + private int grpcPort; + + public int getGrpcPort() { + return grpcPort; + } + + public int getHttpPort() { + return httpPort; + } + + public int getAppPort() { + return appPort; + } + + private int httpPort; + + private int appPort; + } +} diff --git a/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java b/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java new file mode 100644 index 000000000..19d53d376 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/binding/http/OutputBindingExample.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.binding.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.domain.Verb; +import io.dapr.it.BaseIT; +import io.dapr.it.services.InputBindingExample; +import io.dapr.serializer.DefaultObjectSerializer; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.Base64; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Service for output binding example. + */ +public class OutputBindingExample extends BaseIT { + + private static DaprClient client; + + @BeforeClass + public static void init() throws Exception { + daprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "dapr initialized. Status: Running. Init Elapsed", + InputBindingExample.class, + true, + 19000 + ); + daprIntegrationTestingRunner.initializeDapr(); + client = new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + } + + public static class MyClass { + public MyClass(){} + public String message; + } + + @Test + public void BindingTest() { + + + final String BINDING_NAME = "sample123"; + + // This is an example of sending data in a user-defined object. The input binding will receive: + // {"message":"hello"} + MyClass myClass = new MyClass(); + myClass.message = "hello"; + + System.out.println("sending first message"); + client.invokeBinding(BINDING_NAME, myClass).block(); + + // This is an example of sending a plain string. The input binding will receive + // cat + final String m = "cat"; + System.out.println("sending " + m); + client.invokeBinding(BINDING_NAME, m).block(); + + try { + Thread.sleep(8000); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + return; + } + + final List messages = client.invokeService(Verb.GET, daprIntegrationTestingRunner.getAppName(), "messages", null, List.class).block(); + assertEquals(2,messages.size()); + MyClass resultClass = null; + try { + resultClass = new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(0))), MyClass.class); + }catch (Exception ex) + { + ex.printStackTrace(); + fail("Error on decode message 1"); + } + + try { + assertEquals("cat", new ObjectMapper().readValue(new String(Base64.getDecoder().decode(messages.get(1))), String.class)); + }catch (Exception ex){ + ex.printStackTrace(); + fail("Error on decode message 2"); + } + assertEquals("hello",resultClass.message); + } +} diff --git a/sdk/src/test/java/io/dapr/it/deploy/local-test-kafka.yml b/sdk/src/test/java/io/dapr/it/deploy/local-test-kafka.yml new file mode 100644 index 000000000..16f9e4801 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/deploy/local-test-kafka.yml @@ -0,0 +1,14 @@ +version: '2' +services: + zookeeper: + image: wurstmeister/zookeeper:latest + ports: + - "2181:2181" + kafka: + image: wurstmeister/kafka:latest + ports: + - "9092:9092" + environment: + KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1 + KAFKA_CREATE_TOPICS: "sample:1:1" + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 \ No newline at end of file diff --git a/sdk/src/test/java/io/dapr/it/services/EmptyService.java b/sdk/src/test/java/io/dapr/it/services/EmptyService.java new file mode 100644 index 000000000..b5b262220 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/services/EmptyService.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.services; + +/** + * Use this class in order to run DAPR with any needed services, like states. + * + * To run manually, from repo root: + * 1. mvn clean install + * 2. dapr run --grpc-port 41707 --port 32851 -- mvn exec:java -Dexec.mainClass=io.dapr.it.services.EmptyService -Dexec.classpathScope="test" -Dexec.args="-p 44511 -grpcPort 41707 -httpPort 32851" -pl=sdk + */ +public class EmptyService { + public static void main(String[] args) { + System.out.println("Hello from EmptyService"); + } +} diff --git a/sdk/src/test/java/io/dapr/it/services/HelloWorldGrpcStateService.java b/sdk/src/test/java/io/dapr/it/services/HelloWorldGrpcStateService.java new file mode 100644 index 000000000..e203951c2 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/services/HelloWorldGrpcStateService.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.services; + +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import io.dapr.DaprGrpc; +import io.dapr.DaprGrpc.DaprBlockingStub; +import io.dapr.DaprProtos.SaveStateEnvelope; +import io.dapr.DaprProtos.StateRequest; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import org.apache.commons.cli.*; + + +/** + * Simple example. + * To run manually, from repo root: + * 1. mvn clean install + * 2. dapr run --grpc-port 50001 -- mvn exec:java -Dexec.mainClass=io.dapr.it.services.HelloWorldGrpcStateService -Dexec.classpathScope="test" -pl=sdk + */ +public class HelloWorldGrpcStateService { + + public static void main(String[] args) throws ParseException { + String grpcPort = System.getenv("DAPR_GRPC_PORT"); + + // If port string is not valid, it will throw an exception. + int grpcPortInt = Integer.parseInt(grpcPort); + ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", grpcPortInt).usePlaintext().build(); + DaprBlockingStub client = DaprGrpc.newBlockingStub(channel); + + String key = "mykey"; + // First, write key-value pair. + + String value = "Hello World"; + StateRequest req = StateRequest + .newBuilder() + .setKey(key) + .setValue(Any.newBuilder().setValue(ByteString.copyFromUtf8(value)).build()) + .build(); + SaveStateEnvelope state = SaveStateEnvelope.newBuilder() + .addRequests(req) + .build(); + client.saveState(state); + System.out.println("Saved!"); + channel.shutdown(); + } +} diff --git a/sdk/src/test/java/io/dapr/it/services/InputBindingController.java b/sdk/src/test/java/io/dapr/it/services/InputBindingController.java new file mode 100644 index 000000000..803667485 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/services/InputBindingController.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.services; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +import java.util.ArrayList; +import java.util.List; + +/** + * SpringBoot Controller to handle input binding. + */ +@RestController +public class InputBindingController { + + private static final List messagesReceived = new ArrayList(); + + @PostMapping(path = "/sample123") + public Mono handleInputBinding(@RequestBody(required = false) byte[] body) { + + return Mono.fromRunnable(() -> { + messagesReceived.add(body); + System.out.println("Received message through binding: " + (body == null ? "" : new String(body))); + }); + } + + @GetMapping(path = "/messages") + public Mono> getMessages(){ + return Mono.just( messagesReceived); + } + + + +} diff --git a/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java b/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java new file mode 100644 index 000000000..8a84e34fc --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/services/InputBindingExample.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.services; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"io.dapr.it.services"}) +public class InputBindingExample { + + public static void main(String[] args) throws Exception { + // If port string is not valid, it will throw an exception. + int port = Integer.parseInt(args[0]); + // Start Dapr's callback endpoint. + InputBindingExample.start(port); + } + + /** + * Starts Dapr's callback in a given port. + * @param port Port to listen to. + */ + public static void start(int port) { + SpringApplication app = new SpringApplication(InputBindingExample.class); + app.run(String.format("--server.port=%d", port)); + } + +} diff --git a/sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java b/sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java new file mode 100644 index 000000000..2ca6cf612 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/state/GRPCStateClientIT.java @@ -0,0 +1,546 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.state; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientTestBuilder; +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.it.BaseIT; +import io.dapr.it.services.EmptyService; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +import static org.junit.Assert.*; + +/** + * Test State GRPC DAPR capabilities using a DAPR instance with an empty service running + */ +public class GRPCStateClientIT extends BaseIT { + + private static DaprClient daprClient; + + @BeforeClass + public static void init() throws Exception { + daprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "BUILD SUCCESS", + EmptyService.class, + false, + 0 + ); + daprIntegrationTestingRunner.initializeDapr(); + daprClient = DaprClientTestBuilder.buildGrpcClient(); + } + + + @Test + public void saveAndGetState() { + + //The key use to store the state + final String stateKey = "myKey"; + + //create the http client + + + //creation of a dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create of the deferred call to DAPR to store the state + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save action + saveResponse.block(); + + //create of the deferred call to DAPR to get the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + + //retrieve the state + State myDataResponse = response.block(); + + //Assert that the response is the correct one + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveUpdateAndGetState() { + + //The key use to store the state and be updated + final String stateKey = "keyToBeUpdated"; + + //create http DAPR client + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute save action to DAPR + saveResponse.block(); + + //change data properties + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B2"); + //create deferred action to update the sate without any etag or options + saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the update action to DAPR + saveResponse.block(); + + //Create deferred action to retrieve the action + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + State myDataResponse = response.block(); + + //review that the update was success action + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveAndDeleteState() { + //The key use to store the state and be deleted + final String stateKey = "myeKeyToBeDeleted"; + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + State myDataResponse = response.block(); + + //review that the state was saved correctly + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //create deferred action to delete the state + Mono deleteResponse = daprClient.deleteState(stateKey, null, null); + //execute the delete action + deleteResponse.block(); + + //Create deferred action to retrieve the state + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + myDataResponse = response.block(); + + //review that the action does not return any value, because the state was deleted + assertNull(myDataResponse.getValue()); + } + + + @Test + public void saveUpdateAndGetStateWithEtag() { + //The key use to store the state and be updated using etags + final String stateKey = "keyToBeUpdatedWithEtag"; + + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + String firstETag = myDataResponse.getEtag(); + + //change the data in order to update the state + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //Create deferred action to update the data using the correct etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, null); + saveResponse.block(); + + + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //retrive the data wihout any etag + myDataResponse = response.block(); + + //review that state value changes + assertNotNull(myDataResponse.getEtag()); + //review that the etag changes after an update + assertNotEquals(firstETag,myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A2", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + @Ignore("This test case is ignored because DAPR ignore the ETag is wrong when is sent from GRPC protocol, the execution continues and the state is updated.") + @Test(expected = RuntimeException.class) + public void saveUpdateAndGetStateWithWrongEtag() { + final String stateKey = "keyToBeUpdatedWithWrongEtag"; + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + String firstETag = myDataResponse.getEtag(); + + //change the data in order to update the state + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //Create deferred action to update the data using the incorrect etag + saveResponse = daprClient.saveState(stateKey, "99999999999999", data, null); + saveResponse.block(); + + + + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //retrive the data wihout any etag + myDataResponse = response.block(); + + //review that state value changes + assertNotNull(myDataResponse.getEtag()); + //review that the etag changes after an update + assertNotEquals(firstETag,myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A2", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveAndDeleteStateWithEtag() { + final String stateKey = "myeKeyToBeDeletedWithEtag"; + + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to get the state with the etag + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the get state + State myDataResponse = response.block(); + + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to delete an state sending the etag + Mono deleteResponse = daprClient.deleteState(stateKey, myDataResponse.getEtag(), null); + //execute the delete of the state + deleteResponse.block(); + + //Create deferred action to get the sate without an etag + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + myDataResponse = response.block(); + + //Review that the response is null, because the state was deleted + assertNull(myDataResponse.getValue()); + } + + @Ignore("This test case is ignored because DAPR ignore if the ETag is wrong when is sent from GRPC protocol, the execution continues and the state is deleted.") + @Test(expected = RuntimeException.class) + public void saveAndDeleteStateWithWrongEtag() { + final String stateKey = "myeKeyToBeDeletedWithWrongEtag"; + + + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to get the state with the etag + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the get state + State myDataResponse = response.block(); + + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to delete an state sending the incorrect etag + Mono deleteResponse = daprClient.deleteState(stateKey, "99999999999", null); + //execute the delete of the state, this should trhow an exception + deleteResponse.block(); + + //Create deferred action to get the sate without an etag + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + myDataResponse = response.block(); + + //Review that the response is null, because the state was deleted + assertNull(myDataResponse.getValue()); + } + + @Ignore("This test case is ignored because it seems that DAPR using GRPC is ignoring the state options for consistency and concurrency.") + @Test(expected = RuntimeException.class) + public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { + final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; + + //create option with concurrency with first writte and consistency of strong + StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, null); + + + + //create Dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create state using stateOptions + Mono saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); + //execute the save state + saveResponse.block(); + + + //crate deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + //execute the retrieve of the state using options + State myDataResponse = response.block(); + + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //change data to be udpated + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with options + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state + saveResponse.block(); + + + data.setPropertyA("last write"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with the same etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //throws an exception, the state was already udpated + saveResponse.block(); + + response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + State myLastDataResponse = response.block(); + + assertNotNull(myLastDataResponse.getEtag()); + assertNotNull(myLastDataResponse.getKey()); + assertNotNull(myLastDataResponse.getValue()); + assertNotNull(myDataResponse.getEtag(), myLastDataResponse.getEtag()); + assertEquals("data in property A2", myLastDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB()); + } + + @Test() + public void saveUpdateAndGetStateWithEtagAndStateOptionsLastWrite() { + final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; + + //create option with concurrency with first writte and consistency of strong + StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE, null); + + + + //create Dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create state using stateOptions + Mono saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); + //execute the save state + saveResponse.block(); + + + //crate deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + //execute the retrieve of the state using options + State myDataResponse = response.block(); + + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //change data to be udpated + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with options + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state + saveResponse.block(); + + + data.setPropertyA("last write"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with the same etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state without an error + saveResponse.block(); + + response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + State myLastDataResponse = response.block(); + + assertNotNull(myLastDataResponse.getEtag()); + assertNotNull(myLastDataResponse.getKey()); + assertNotNull(myLastDataResponse.getValue()); + assertNotNull(myDataResponse.getEtag(), myLastDataResponse.getEtag()); + assertEquals("last write", myLastDataResponse.getValue().getPropertyA()); + assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB()); + } + + @Test(timeout=13000) + public void saveDeleteWithRetry() { + final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; + StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(3),3, StateOptions.RetryPolicy.Pattern.LINEAR); + StateOptions stateOptions = new StateOptions(null, null, retryPolicy); + + + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + + Mono deleteResponse = daprClient.deleteState(stateKey, "99999999", stateOptions); + + long start = System.currentTimeMillis(); + try { + //delete action + deleteResponse.block(); + }catch(RuntimeException ex){ + assertTrue(ex.getMessage().contains("failed to set value after 3 retries")); + } + long end = System.currentTimeMillis(); + System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds"); + long elapsedTime = end -start; + assertTrue(elapsedTime>9000 && elapsedTime<9200); + + } + + @Ignore("Ignored as an issue on DAPR") + @Test(timeout=13000) + public void saveUpdateWithRetry() { + final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; + StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(4),3, StateOptions.RetryPolicy.Pattern.LINEAR); + StateOptions stateOptions = new StateOptions(null, null, retryPolicy); + + + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + assertNotNull(myDataResponse.getEtag()); + assertNotNull(myDataResponse.getKey()); + assertNotNull(myDataResponse.getValue()); + assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to save the sate + saveResponse = daprClient.saveState(stateKey, "9999999", data, stateOptions); + //execute the save state action + long start = System.currentTimeMillis(); + + + try { + saveResponse.block(); + }catch(RuntimeException ex){ + assertTrue(ex.getMessage().contains("failed to set value after 3 retries")); + } + long end = System.currentTimeMillis(); + System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds"); + long elapsedTime = end -start; + assertTrue(elapsedTime>9000 && elapsedTime<9200); + + } + +} diff --git a/sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java b/sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java new file mode 100644 index 000000000..637e692c4 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/state/HelloWorldClientIT.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.state; + +import io.dapr.DaprGrpc; +import io.dapr.DaprProtos; +import io.dapr.it.BaseIT; +import io.dapr.it.DaprIntegrationTestingRunner; +import io.dapr.it.services.HelloWorldGrpcStateService; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import static io.dapr.it.DaprIntegrationTestingRunner.DAPR_FREEPORTS; + +public class HelloWorldClientIT extends BaseIT { + + private static DaprIntegrationTestingRunner daprIntegrationTestingRunner; + + @BeforeClass + public static void init() throws Exception { + daprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "BUILD SUCCESS", + HelloWorldGrpcStateService.class, + false, + 2000 + ); + daprIntegrationTestingRunner.initializeDapr(); + } + + @Test + public void testHelloWorldState(){ + ManagedChannel channel = + ManagedChannelBuilder.forAddress("localhost", DAPR_FREEPORTS.getGrpcPort()).usePlaintext().build(); + DaprGrpc.DaprBlockingStub client = DaprGrpc.newBlockingStub(channel); + + String key = "mykey"; + { + DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope + .newBuilder() + .setKey(key) + .build(); + DaprProtos.GetStateResponseEnvelope response = client.getState(req); + String value = response.getData().getValue().toStringUtf8(); + System.out.println("Got: " + value); + Assert.assertEquals("Hello World",value); + } + + // Then, delete it. + { + DaprProtos.DeleteStateEnvelope req = DaprProtos.DeleteStateEnvelope + .newBuilder() + .setKey(key) + .build(); + client.deleteState(req); + System.out.println("Deleted!"); + } + + { + DaprProtos.GetStateEnvelope req = DaprProtos.GetStateEnvelope + .newBuilder() + .setKey(key) + .build(); + DaprProtos.GetStateResponseEnvelope response = client.getState(req); + String value = response.getData().getValue().toStringUtf8(); + System.out.println("Got: " + value); + Assert.assertEquals("",value); + } + } +} diff --git a/sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java b/sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java new file mode 100644 index 000000000..3a6022030 --- /dev/null +++ b/sdk/src/test/java/io/dapr/it/state/HttpStateClientIT.java @@ -0,0 +1,549 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.it.state; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.client.domain.State; +import io.dapr.client.domain.StateOptions; +import io.dapr.it.BaseIT; +import io.dapr.it.services.EmptyService; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; + +/** + * Test State HTTP DAPR capabilities using a DAPR instance with an empty service running + */ +public class HttpStateClientIT extends BaseIT { + + @BeforeClass + public static void init() throws Exception { + daprIntegrationTestingRunner = + createDaprIntegrationTestingRunner( + "BUILD SUCCESS", + EmptyService.class, + false, + 0 + ); + daprIntegrationTestingRunner.initializeDapr(); + } + + @Test + public void saveAndGetState() { + + //The key use to store the state + final String stateKey = "myKey"; + + //create the http client + DaprClient daprClient = buildDaprClient(); + + //creation of a dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create of the deferred call to DAPR to store the state + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save action + saveResponse.block(); + + //create of the deferred call to DAPR to get the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + + //retrieve the state + State myDataResponse = response.block(); + + //Assert that the response is the correct one + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveUpdateAndGetState() { + + //The key use to store the state and be updated + final String stateKey = "keyToBeUpdated"; + + //create http DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute save action to DAPR + saveResponse.block(); + + //change data properties + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B2"); + //create deferred action to update the sate without any etag or options + saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the update action to DAPR + saveResponse.block(); + + //Create deferred action to retrieve the action + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + State myDataResponse = response.block(); + + //review that the update was success action + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveAndDeleteState() { + //The key use to store the state and be deleted + final String stateKey = "myeKeyToBeDeleted"; + + //create DAPR client + DaprClient daprClient = buildDaprClient(); + + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + State myDataResponse = response.block(); + + //review that the state was saved correctly + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //create deferred action to delete the state + Mono deleteResponse = daprClient.deleteState(stateKey, null, null); + //execute the delete action + deleteResponse.block(); + + //Create deferred action to retrieve the state + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the retrieve of the state + myDataResponse = response.block(); + + //review that the action does not return any value, because the state was deleted + Assert.assertNull(myDataResponse.getValue()); + } + + + @Test + public void saveUpdateAndGetStateWithEtag() { + //The key use to store the state and be updated using etags + final String stateKey = "keyToBeUpdatedWithEtag"; + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + String firstETag = myDataResponse.getEtag(); + + //change the data in order to update the state + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //Create deferred action to update the data using the correct etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, null); + saveResponse.block(); + + + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //retrive the data wihout any etag + myDataResponse = response.block(); + + //review that state value changes + Assert.assertNotNull(myDataResponse.getEtag()); + //review that the etag changes after an update + Assert.assertNotEquals(firstETag,myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A2", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + + @Test(expected = RuntimeException.class) + public void saveUpdateAndGetStateWithWrongEtag() { + final String stateKey = "keyToBeUpdatedWithWrongEtag"; + + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + String firstETag = myDataResponse.getEtag(); + + //change the data in order to update the state + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //Create deferred action to update the data using the incorrect etag + saveResponse = daprClient.saveState(stateKey, "99999999999999", data, null); + saveResponse.block(); + + + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //retrive the data wihout any etag + myDataResponse = response.block(); + + //review that state value changes + Assert.assertNotNull(myDataResponse.getEtag()); + //review that the etag changes after an update + Assert.assertNotEquals(firstETag,myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A2", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B2", myDataResponse.getValue().getPropertyB()); + } + + @Test + public void saveAndDeleteStateWithEtag() { + final String stateKey = "myeKeyToBeDeletedWithEtag"; + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to get the state with the etag + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the get state + State myDataResponse = response.block(); + + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to delete an state sending the etag + Mono deleteResponse = daprClient.deleteState(stateKey, myDataResponse.getEtag(), null); + //execute the delete of the state + deleteResponse.block(); + + //Create deferred action to get the sate without an etag + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + myDataResponse = response.block(); + + //Review that the response is null, because the state was deleted + Assert.assertNull(myDataResponse.getValue()); + } + + + @Test(expected = RuntimeException.class) + public void saveAndDeleteStateWithWrongEtag() { + final String stateKey = "myeKeyToBeDeletedWithWrongEtag"; + + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to get the state with the etag + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the get state + State myDataResponse = response.block(); + + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to delete an state sending the incorrect etag + Mono deleteResponse = daprClient.deleteState(stateKey, "99999999999", null); + //execute the delete of the state, this should trhow an exception + deleteResponse.block(); + + //Create deferred action to get the sate without an etag + response = daprClient.getState(new State(stateKey, null, null), MyData.class); + myDataResponse = response.block(); + + //Review that the response is null, because the state was deleted + Assert.assertNull(myDataResponse.getValue()); + } + + @Test(expected = RuntimeException.class) + public void saveUpdateAndGetStateWithEtagAndStateOptionsFirstWrite() { + final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; + + //create option with concurrency with first writte and consistency of strong + StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE, null); + + //create dapr client + DaprClient daprClient = buildDaprClient(); + //create Dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create state using stateOptions + Mono saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); + //execute the save state + saveResponse.block(); + + + //crate deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + //execute the retrieve of the state using options + State myDataResponse = response.block(); + + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //change data to be udpated + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with options + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state + saveResponse.block(); + + + data.setPropertyA("last write"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with the same etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //throws an exception, the state was already udpated + saveResponse.block(); + + response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + State myLastDataResponse = response.block(); + + Assert.assertNotNull(myLastDataResponse.getEtag()); + Assert.assertNotNull(myLastDataResponse.getKey()); + Assert.assertNotNull(myLastDataResponse.getValue()); + Assert.assertNotNull(myDataResponse.getEtag(), myLastDataResponse.getEtag()); + Assert.assertEquals("data in property A2", myLastDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB()); + } + + @Test() + public void saveUpdateAndGetStateWithEtagAndStateOptionsLastWrite() { + final String stateKey = "keyToBeUpdatedWithEtagAndOptions"; + + //create option with concurrency with first writte and consistency of strong + StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.LAST_WRITE, null); + + //create dapr client + DaprClient daprClient = buildDaprClient(); + //create Dummy data + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //create state using stateOptions + Mono saveResponse = daprClient.saveState(stateKey, null, data, stateOptions); + //execute the save state + saveResponse.block(); + + + //crate deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + //execute the retrieve of the state using options + State myDataResponse = response.block(); + + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //change data to be udpated + data.setPropertyA("data in property A2"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with options + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state + saveResponse.block(); + + + data.setPropertyA("last write"); + data.setPropertyB("data in property B2"); + //create deferred action to update the action with the same etag + saveResponse = daprClient.saveState(stateKey, myDataResponse.getEtag(), data, stateOptions); + //update the state without an error + saveResponse.block(); + + response = daprClient.getState(new State(stateKey, null, stateOptions), MyData.class); + State myLastDataResponse = response.block(); + + Assert.assertNotNull(myLastDataResponse.getEtag()); + Assert.assertNotNull(myLastDataResponse.getKey()); + Assert.assertNotNull(myLastDataResponse.getValue()); + Assert.assertNotNull(myDataResponse.getEtag(), myLastDataResponse.getEtag()); + Assert.assertEquals("last write", myLastDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B2", myLastDataResponse.getValue().getPropertyB()); + } + + @Test(timeout=13000) + public void saveDeleteWithRetry() { + final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; + StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(3),3, StateOptions.RetryPolicy.Pattern.LINEAR); + StateOptions stateOptions = new StateOptions(null, null, retryPolicy); + + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + + Mono deleteResponse = daprClient.deleteState(stateKey, "99999999", stateOptions); + + long start = System.currentTimeMillis(); + try { + //delete action + deleteResponse.block(); + }catch(RuntimeException ex){ + Assert.assertTrue(ex.getMessage().contains("failed to set value after 3 retries")); + } + long end = System.currentTimeMillis(); + System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds"); + long elapsedTime = end -start; + Assert.assertTrue(elapsedTime>9000 && elapsedTime<9200); + + } + + @Ignore("Ignored as an issue on DAPR") + @Test(timeout=13000) + public void saveUpdateWithRetry() { + final String stateKey = "keyToBeDeleteWithWrongEtagAndRetry"; + StateOptions.RetryPolicy retryPolicy= new StateOptions.RetryPolicy(Duration.ofSeconds(4),3, StateOptions.RetryPolicy.Pattern.EXPONENTIAL); + StateOptions stateOptions = new StateOptions(null, null, retryPolicy); + + //create DAPR client + DaprClient daprClient = buildDaprClient(); + //Create dummy data to be store + MyData data = new MyData(); + data.setPropertyA("data in property A"); + data.setPropertyB("data in property B"); + + //Create deferred action to save the sate + Mono saveResponse = daprClient.saveState(stateKey, null, data, null); + //execute the save state action + saveResponse.block(); + + //Create deferred action to retrieve the state + Mono> response = daprClient.getState(new State(stateKey, null, null), MyData.class); + //execute the action for retrieve the state and the etag + State myDataResponse = response.block(); + + //review that the etag is not empty + Assert.assertNotNull(myDataResponse.getEtag()); + Assert.assertNotNull(myDataResponse.getKey()); + Assert.assertNotNull(myDataResponse.getValue()); + Assert.assertEquals("data in property A", myDataResponse.getValue().getPropertyA()); + Assert.assertEquals("data in property B", myDataResponse.getValue().getPropertyB()); + + //Create deferred action to save the sate + saveResponse = daprClient.saveState(stateKey, "9999999", data, stateOptions); + //execute the save state action + long start = System.currentTimeMillis(); + + + try { + saveResponse.block(); + }catch(RuntimeException ex){ + Assert.assertTrue(ex.getMessage().contains("failed to set value after 3 retries")); + } + long end = System.currentTimeMillis(); + System.out.println("DEBUG: Logic A took " + (end - start) + " MilliSeconds"); + long elapsedTime = end -start; + Assert.assertTrue(elapsedTime>9000 && elapsedTime<9200); + + } + + private static DaprClient buildDaprClient() { + return new DaprClientBuilder(new DefaultObjectSerializer(), new DefaultObjectSerializer()).build(); + } + +} diff --git a/sdk/src/test/java/io/dapr/runtime/Dapr.java b/sdk/src/test/java/io/dapr/runtime/Dapr.java new file mode 100644 index 000000000..bd600a326 --- /dev/null +++ b/sdk/src/test/java/io/dapr/runtime/Dapr.java @@ -0,0 +1,233 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.runtime; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.client.domain.CloudEvent; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Main interface to register and interface with local Dapr instance. + * + * This class DO NOT make I/O operations by itself, only via user-provided listeners. + */ +public final class Dapr implements DaprRuntime { + + /** + * Serializes and deserializes internal objects. + */ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * Singleton instance for this class. + */ + private static volatile DaprRuntime instance; + + /** + * Topics, methods and binding handles. + */ + private final Map>> handlers = Collections.synchronizedMap(new HashMap<>()); + + /** + * Private constructor to keep it singleton. + */ + private Dapr() { + } + + /** + * Returns the only DaprRuntime object. + * + * @return DaprRuntime object. + */ + public static DaprRuntime getInstance() { + if (instance == null) { + synchronized (Dapr.class) { + if (instance == null) { + instance = new Dapr(); + } + } + } + + return instance; + } + + /** + * {@inheritDoc} + */ + @Override + public String serializeSubscribedTopicList() throws IOException { + return OBJECT_MAPPER.writeValueAsString(this.getSubscribedTopics()); + } + + /** + * {@inheritDoc} + */ + @Override + public Collection getSubscribedTopics() { + return this.handlers + .entrySet() + .stream().filter(kv -> kv.getValue() instanceof TopicHandler) + .map(kv -> kv.getKey()) + .collect(Collectors.toCollection(ArrayList::new)); + } + + /** + * {@inheritDoc} + */ + @Override + public void subscribeToTopic(String topic, TopicListener listener) { + this.handlers.putIfAbsent(topic, new TopicHandler(listener)); + } + + /** + * {@inheritDoc} + */ + @Override + public void registerServiceMethod(String name, MethodListener listener) { + this.handlers.putIfAbsent(name, new MethodHandler(listener)); + } + + /** + * {@inheritDoc} + */ + public void registerInputBinding(String name, MethodListener listener) { + this.handlers.putIfAbsent(name, new MethodHandler(listener)); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono handleInvocation(String name, byte[] payload, Map metadata) { + if (name == null) { + return Mono.error(new IllegalArgumentException("Handler's name cannot be null.")); + } + + Function> handler = this.handlers.get(name); + + if (handler == null) { + return Mono.error(new IllegalArgumentException("Did not find handler for : " + (name == null ? "" : name))); + } + + try { + HandleRequest request = new HandleRequest(name, payload, metadata); + Mono response = handler.apply(request); + return response; + } catch (Exception e) { + // Handling exception in user code by propagating up via Mono. + return Mono.error(e); + } + } + + /** + * Class used to pass-through the handler input. + */ + private static final class HandleRequest { + + /** + * Name of topic/method/binding being handled. + */ + private final String name; + + /** + * Payload received. + */ + private final byte[] payload; + + /** + * Metadata received. + */ + private final Map metadata; + + /** + * Instantiates a new handle request. + * @param name Name of topic/method/binding being handled. + * @param payload Payload received. + * @param metadata Metadata received. + */ + private HandleRequest(String name, byte[] payload, Map metadata) { + this.name = name; + this.payload = payload; + this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); + } + } + + /** + * Internal class to handle a method call. + */ + private static final class MethodHandler implements Function> { + + /** + * User-provided listener. + */ + private final MethodListener listener; + + /** + * Instantiates a new method handler. + * @param listener Method to be executed on a given API call. + */ + private MethodHandler(MethodListener listener) { + this.listener = listener; + } + + /** + * Executes the listener's method. + * @param r Internal request object. + * @return Raw output payload or empty. + */ + @Override + public Mono apply(HandleRequest r) { + try { + return listener.process(r.payload, r.metadata); + } catch (Exception e) { + return Mono.error(e); + } + } + } + + /** + * Internal class to handle a topic message delivery. + */ + private static final class TopicHandler implements Function> { + + /** + * User-provided listener. + */ + private final TopicListener listener; + + /** + * Instantiates a new topic handler. + * @param listener Callback to be executed on a given message. + */ + private TopicHandler(TopicListener listener) { + this.listener = listener; + } + + /** + * Executes the listener's method. + * @param r Internal request object. + * @return Always empty response. + */ + @Override + public Mono apply(HandleRequest r) { + try { + CloudEvent message = CloudEvent.deserialize(r.payload); + if (message == null) { + return Mono.empty(); + } + + return listener.process(message, r.metadata).then(Mono.empty()); + } catch (Exception e) { + return Mono.error(e); + } + } + } +} diff --git a/sdk/src/test/java/io/dapr/runtime/DaprRuntime.java b/sdk/src/test/java/io/dapr/runtime/DaprRuntime.java new file mode 100644 index 000000000..bd2ace9a3 --- /dev/null +++ b/sdk/src/test/java/io/dapr/runtime/DaprRuntime.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.runtime; + +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.Collection; +import java.util.Map; + +/** + * Common interface to configure and process callback API. + * + * Used for Integration Tests only, for now. + */ +public interface DaprRuntime { + + /** + * Subscribes to a topic. + * @param topic Topic name to be subscribed to. + * @param listener Callback to be executed on a given message. + */ + void subscribeToTopic(String topic, TopicListener listener); + + /** + * Serializes the list of subscribed topics as a String. + * @return Serialized list of subscribed topics. + * @throws IOException If cannot serialize. + */ + String serializeSubscribedTopicList() throws IOException; + + /** + * Returns the collection of subscribed topics. + * @return Collection of subscribed topics. + */ + Collection getSubscribedTopics(); + + /** + * Registers a service method to be executed on an API call. + * @param name Name of the service API's method. + * @param listener Method to be executed on a given API call. + */ + void registerServiceMethod(String name, MethodListener listener); + + /** + * Registers a method to be executed for an input binding. + * @param name The name of the input binding. + * @param listener The method to run when receiving a message on this binding. + */ + void registerInputBinding(String name, MethodListener listener); + + + /** + * Handles a given topic message or method API call. + * @param name Name of topic or method. + * @param payload Input body. + * @param metadata Headers (or metadata) for the call. + * @return Response payload or empty. + */ + Mono handleInvocation(String name, byte[] payload, Map metadata); + + +} diff --git a/sdk/src/test/java/io/dapr/runtime/DaprRuntimeTest.java b/sdk/src/test/java/io/dapr/runtime/DaprRuntimeTest.java new file mode 100644 index 000000000..bcc23ffd8 --- /dev/null +++ b/sdk/src/test/java/io/dapr/runtime/DaprRuntimeTest.java @@ -0,0 +1,331 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.runtime; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import io.dapr.client.*; +import io.dapr.client.domain.CloudEvent; +import io.dapr.client.domain.Verb; +import io.dapr.serializer.DaprObjectSerializer; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.utils.Constants; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import reactor.core.publisher.Mono; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.Map; +import java.util.UUID; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +public class DaprRuntimeTest { + + protected static final JsonFactory JSON_FACTORY = new JsonFactory(); + + private static final String TYPE_PLAIN_TEXT = "plain/text"; + + private static final String TOPIC_NAME = "mytopic"; + + private static final String APP_ID = "myappid"; + + private static final String METHOD_NAME = "mymethod"; + + private final DaprRuntime daprRuntime = Dapr.getInstance(); + + @Before + public void setup() throws Exception { + // Only for unit tests to simulate a new start of the app. + Field field = this.daprRuntime.getClass().getDeclaredField("instance"); + field.setAccessible(true); + field.set(null, null); + } + + @Test + public void pubSubHappyCase() throws Exception { + Assert.assertNotNull(this.daprRuntime.getSubscribedTopics()); + Assert.assertTrue(this.daprRuntime.getSubscribedTopics().isEmpty()); + + TopicListener listener = mock(TopicListener.class); + when(listener.process(any(), any())).thenReturn(Mono.empty()); + + this.daprRuntime.subscribeToTopic(TOPIC_NAME, listener); + + verify(listener, never()).process(any(), any()); + + Message[] messages = new Message[]{ + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + "", + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + null, + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + null), + new Message( + "", + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + null, + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + "", + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + null, + generatePayload(), + generateSingleMetadata()) + }; + + DaprHttpStub daprHttp = mock(DaprHttpStub.class); + DaprClient client = DaprClientTestBuilder.buildHttpClient(daprHttp); + DaprObjectSerializer serializer = new DefaultObjectSerializer(); + + for (Message message : messages) { + when(daprHttp.invokeAPI( + eq("POST"), + eq(Constants.PUBLISH_PATH + "/" + TOPIC_NAME), + eq(null), + eq(serializer.serialize(message.data)), + eq(null))) + .thenAnswer(invocationOnMock -> this.daprRuntime.handleInvocation( + TOPIC_NAME, + this.serialize(message), + message.metadata).then()); + + client.publishEvent(TOPIC_NAME, message.data).block(); + + CloudEvent envelope = new CloudEvent( + message.id, + null, + null, + null, + message.datacontenttype, + message.data + ); + verify(listener, times(1)).process(eq(envelope), eq(message.metadata)); + } + + verify(listener, times(messages.length)).process(any(), any()); + } + + @Test + public void invokeHappyCase() throws Exception { + MethodListener listener = mock(MethodListener.class); + + this.daprRuntime.registerServiceMethod(METHOD_NAME, listener); + + verify(listener, never()).process(any(), any()); + + Message[] messages = new Message[]{ + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + "", + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + null, + generateSingleMetadata()), + new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + null), + new Message( + "", + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + null, + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + "", + generatePayload(), + generateSingleMetadata()), + new Message( + generateMessageId(), + null, + generatePayload(), + generateSingleMetadata()) + }; + + DaprHttpStub daprHttp = mock(DaprHttpStub.class); + DaprClient client = DaprClientTestBuilder.buildHttpClient(daprHttp); + + DaprObjectSerializer serializer = new DefaultObjectSerializer(); + for (Message message : messages) { + byte[] expectedResponse = serializer.serialize(message.id); + when(listener.process(eq(serializer.serialize(message.data)), eq(message.metadata))) + .then(x -> expectedResponse == null ? Mono.empty() : Mono.just(expectedResponse)); + + when(daprHttp.invokeAPI( + eq("POST"), + eq(Constants.INVOKE_PATH + "/" + APP_ID + "/method/" + METHOD_NAME), + eq(null), + eq(serializer.serialize(message.data)), + any())) + .thenAnswer(x -> + this.daprRuntime.handleInvocation( + METHOD_NAME, + serializer.serialize(message.data), + message.metadata) + .map(r -> new DaprHttpStub.ResponseStub(r, null, 200))); + + Mono response = client.invokeService(Verb.POST, APP_ID, METHOD_NAME, message.data, message.metadata, byte[].class); + Assert.assertEquals(expectedResponse, response.block()); + + verify(listener, times(1)) + .process(eq(serializer.serialize(message.data)), eq(message.metadata)); + } + + verify(listener, times(messages.length)).process(any(), any()); + } + + @Test(expected = RuntimeException.class) + public void subscribeCallbackException() throws Exception { + Assert.assertNotNull(this.daprRuntime.getSubscribedTopics()); + Assert.assertTrue(this.daprRuntime.getSubscribedTopics().isEmpty()); + + TopicListener listener = mock(TopicListener.class); + when(listener.process(any(), any())) + .thenReturn(Mono.error(new RuntimeException())); + + this.daprRuntime.subscribeToTopic(TOPIC_NAME, listener); + + Message message = new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()); + + Mono result = this.daprRuntime + .handleInvocation(TOPIC_NAME, this.serialize(message), message.metadata); + + CloudEvent envelope = new CloudEvent( + message.id, + null, + null, + null, + message.datacontenttype, + message.data + ); + verify(listener, times(1)).process(eq(envelope), eq(message.metadata)); + result.block(); + } + + @Test(expected = RuntimeException.class) + public void subscribeUnknownTopic() throws Exception { + Assert.assertNotNull(this.daprRuntime.getSubscribedTopics()); + Assert.assertTrue(this.daprRuntime.getSubscribedTopics().isEmpty()); + + TopicListener listener = mock(TopicListener.class); + + this.daprRuntime.subscribeToTopic(TOPIC_NAME, listener); + + Message message = new Message( + generateMessageId(), + TYPE_PLAIN_TEXT, + generatePayload(), + generateSingleMetadata()); + + Mono result = this.daprRuntime + .handleInvocation("UNKNOWN", serialize(message), message.metadata); + + verify(listener, never()).process(any(), any()); + + result.block(); + } + + private static final String generateMessageId() { + return UUID.randomUUID().toString(); + } + + private static final String generatePayload() { + return UUID.randomUUID().toString(); + } + + private static final Map generateSingleMetadata() { + return Collections.singletonMap(UUID.randomUUID().toString(), UUID.randomUUID().toString()); + } + + private static final class Message { + + private final String id; + + private final String datacontenttype; + + private final String data; + + private final Map metadata; + + private Message(String id, String datacontenttype, String data, Map metadata) { + this.id = id; + this.datacontenttype = datacontenttype; + this.data = data; + this.metadata = metadata; + } + } + + private byte[] serialize(Message message) throws IOException { + if (message == null) { + return null; + } + + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + JsonGenerator generator = JSON_FACTORY.createGenerator(bos); + generator.writeStartObject(); + if (message.id != null) { + generator.writeStringField("id", message.id); + } + if (message.datacontenttype != null) { + generator.writeStringField("datacontenttype", message.datacontenttype); + } + if (message.data != null) { + generator.writeStringField("data", message.data); + } + generator.writeEndObject(); + generator.close(); + bos.flush(); + return bos.toByteArray(); + } + } +} diff --git a/sdk/src/test/java/io/dapr/runtime/MethodListener.java b/sdk/src/test/java/io/dapr/runtime/MethodListener.java new file mode 100644 index 000000000..314164fea --- /dev/null +++ b/sdk/src/test/java/io/dapr/runtime/MethodListener.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.runtime; + +import com.fasterxml.jackson.core.JsonProcessingException; +import reactor.core.publisher.Mono; + +import java.util.Map; + +/** + * Processes a given API's method call. + */ +public interface MethodListener { + + /** + * Processes a given API's method call. + * @param data Raw input payload. + * @param metadata Header (or metadata). + * @return Raw response or empty. + * @throws Exception Any exception from user code. + */ + Mono process(byte[] data, Map metadata) throws Exception; + +} diff --git a/sdk/src/test/java/io/dapr/runtime/TopicListener.java b/sdk/src/test/java/io/dapr/runtime/TopicListener.java new file mode 100644 index 000000000..eea3a04e2 --- /dev/null +++ b/sdk/src/test/java/io/dapr/runtime/TopicListener.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.runtime; + +import io.dapr.client.domain.CloudEvent; +import reactor.core.publisher.Mono; + +import java.util.Map; + +/** + * Processes a given topic's message delivery. + */ +public interface TopicListener { + + /** + * Processes a given topic's message delivery. + * @param message Message event to be processed. + * @param metadata Headers (or metadata). + * @return Empty response. + * @throws Exception Any exception from user code. + */ + Mono process(CloudEvent message, Map metadata) throws Exception; + +} diff --git a/sdk/src/test/java/io/dapr/serializer/DefaultObjectSerializerTest.java b/sdk/src/test/java/io/dapr/serializer/DefaultObjectSerializerTest.java new file mode 100644 index 000000000..d680a750a --- /dev/null +++ b/sdk/src/test/java/io/dapr/serializer/DefaultObjectSerializerTest.java @@ -0,0 +1,794 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + */ + +package io.dapr.serializer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dapr.serializer.DefaultObjectSerializer; +import io.dapr.client.domain.CloudEvent; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Base64; +import java.util.function.Function; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +public class DefaultObjectSerializerTest { + + private static final DefaultObjectSerializer SERIALIZER = new DefaultObjectSerializer(); + + public static class MyObjectTestToSerialize implements Serializable { + private String stringValue; + private int intValue; + private boolean boolValue; + private char charValue; + private byte byteValue; + private short shortValue; + private long longValue; + private float floatValue; + private double doubleValue; + + public String getStringValue() { + return stringValue; + } + + public void setStringValue(String stringValue) { + this.stringValue = stringValue; + } + + public int getIntValue() { + return intValue; + } + + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + public boolean isBoolValue() { + return boolValue; + } + + public void setBoolValue(boolean boolValue) { + this.boolValue = boolValue; + } + + public char getCharValue() { + return charValue; + } + + public void setCharValue(char charValue) { + this.charValue = charValue; + } + + public byte getByteValue() { + return byteValue; + } + + public void setByteValue(byte byteValue) { + this.byteValue = byteValue; + } + + public short getShortValue() { + return shortValue; + } + + public void setShortValue(short shortValue) { + this.shortValue = shortValue; + } + + public long getLongValue() { + return longValue; + } + + public void setLongValue(long longValue) { + this.longValue = longValue; + } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof MyObjectTestToSerialize)) { + return false; + } + + MyObjectTestToSerialize that = (MyObjectTestToSerialize) o; + + if (getIntValue() != that.getIntValue()) { + return false; + } + if (isBoolValue() != that.isBoolValue()) { + return false; + } + if (getCharValue() != that.getCharValue()) { + return false; + } + if (getByteValue() != that.getByteValue()) { + return false; + } + if (getShortValue() != that.getShortValue()) { + return false; + } + if (getLongValue() != that.getLongValue()) { + return false; + } + if (Float.compare(that.getFloatValue(), getFloatValue()) != 0) { + return false; + } + if (Double.compare(that.getDoubleValue(), getDoubleValue()) != 0) { + return false; + } + if (getStringValue() != null ? !getStringValue().equals(that.getStringValue()) : that.getStringValue() != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result; + long temp; + result = getStringValue() != null ? getStringValue().hashCode() : 0; + result = 31 * result + getIntValue(); + result = 31 * result + (isBoolValue() ? 1 : 0); + result = 31 * result + (int) getCharValue(); + result = 31 * result + (int) getByteValue(); + result = 31 * result + (int) getShortValue(); + result = 31 * result + (int) (getLongValue() ^ (getLongValue() >>> 32)); + result = 31 * result + (getFloatValue() != +0.0f ? Float.floatToIntBits(getFloatValue()) : 0); + temp = Double.doubleToLongBits(getDoubleValue()); + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public String toString() { + return "MyObjectTestToSerialize{" + + "stringValue='" + stringValue + '\'' + + ", intValue=" + intValue + + ", boolValue=" + boolValue + + ", charValue=" + charValue + + ", byteValue=" + byteValue + + ", shortValue=" + shortValue + + ", longValue=" + longValue + + ", floatValue=" + floatValue + + ", doubleValue=" + doubleValue + + '}'; + } + } + + @Test + public void serializeStringObjectTest() { + MyObjectTestToSerialize obj = new MyObjectTestToSerialize(); + obj.setStringValue("A String"); + obj.setIntValue(2147483647); + obj.setBoolValue(true); + obj.setCharValue('a'); + obj.setByteValue((byte) 65); + obj.setShortValue((short) 32767); + obj.setLongValue(9223372036854775807L); + obj.setFloatValue(1.0f); + obj.setDoubleValue(1000.0); + String expectedResult = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + + String serializedValue; + try { + serializedValue = new String(SERIALIZER.serialize(obj)); + assertEquals("FOUND:[[" + serializedValue + "]] \n but was EXPECTING: [[" + expectedResult + "]]", expectedResult, serializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeObjectTest() { + MyObjectTestToSerialize obj = new MyObjectTestToSerialize(); + obj.setStringValue("A String"); + obj.setIntValue(2147483647); + obj.setBoolValue(true); + obj.setCharValue('a'); + obj.setByteValue((byte) 65); + obj.setShortValue((short) 32767); + obj.setLongValue(9223372036854775807L); + obj.setFloatValue(1.0f); + obj.setDoubleValue(1000.0); + //String expectedResult = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + byte[] serializedValue; + try { + serializedValue = SERIALIZER.serialize(obj); + assertNotNull(serializedValue); + MyObjectTestToSerialize deserializedValue = SERIALIZER.deserialize(serializedValue, MyObjectTestToSerialize.class); + assertEquals(obj, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeNullTest() { + + byte[] byteSerializedValue; + try { + byteSerializedValue = SERIALIZER.serialize(null); + assertNull(byteSerializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeStringTest() { + String valueToSerialize = "A String"; + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize)); + assertEquals(valueToSerialize, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + String deserializedValue = SERIALIZER.deserialize(byteValue, String.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeIntTest() { + Integer valueToSerialize = 1; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.intValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Integer deserializedValue = SERIALIZER.deserialize(byteValue, Integer.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeShortTest() { + Short valueToSerialize = 1; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.shortValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Short deserializedValue = SERIALIZER.deserialize(byteValue, Short.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeLongTest() { + Long valueToSerialize = Long.MAX_VALUE; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.longValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Long deserializedValue = SERIALIZER.deserialize(byteValue, Long.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeFloatTest() { + Float valueToSerialize = -1.23456f; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.floatValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Float deserializedValue = SERIALIZER.deserialize(byteValue, Float.class); + assertEquals(valueToSerialize, deserializedValue, 0.00000000001); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeDoubleTest() { + Double valueToSerialize = 1.0; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.doubleValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Double deserializedValue = SERIALIZER.deserialize(byteValue, Double.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void serializeBooleanTest() { + Boolean valueToSerialize = true; + String expectedResult = valueToSerialize.toString(); + + String serializedValue; + byte [] byteValue; + try { + serializedValue = new String(SERIALIZER.serialize(valueToSerialize.booleanValue())); + assertEquals(expectedResult, serializedValue); + byteValue = SERIALIZER.serialize(valueToSerialize); + assertNotNull(byteValue); + Boolean deserializedValue = SERIALIZER.deserialize(byteValue, Boolean.class); + assertEquals(valueToSerialize, deserializedValue); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("The expected value is different than the actual result", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeBytesTest() { + + try { + byte[] result = SERIALIZER.deserialize("String".getBytes(), byte[].class); + assertNotNull(result); + assertEquals("String", new String(result)); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeNullObjectOrPrimitiveTest() { + + try { + MyObjectTestToSerialize expectedObj = null; + MyObjectTestToSerialize objResult = SERIALIZER.deserialize(null, MyObjectTestToSerialize.class); + assertEquals(expectedObj, objResult); + boolean expectedBoolResutl = false; + boolean boolResult = SERIALIZER.deserialize(null, boolean.class); + assertEquals(expectedBoolResutl, boolResult); + byte expectedByteResult = Byte.valueOf((byte) 0); + byte byteResult = SERIALIZER.deserialize(null, byte.class); + assertEquals(expectedByteResult, byteResult); + short expectedShortResult = (short) 0; + short shortResult = SERIALIZER.deserialize(null, short.class); + assertEquals(expectedShortResult, shortResult); + int expectedIntResult = 0; + int intResult = SERIALIZER.deserialize(null, int.class); + assertEquals(expectedIntResult, intResult); + long expectedLongResult = 0L; + long longResult = SERIALIZER.deserialize(null, long.class); + assertEquals(expectedLongResult, longResult); + float expectedFloatResult = 0f; + float floatResult = SERIALIZER.deserialize(null, float.class); + assertEquals(expectedFloatResult, floatResult, 0.0f); + double expectedDoubleResult = (double) 0; + double doubleResult = SERIALIZER.deserialize(null, double.class); + assertEquals(expectedDoubleResult, doubleResult, 0.0); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingStringPropertyTest() { + String jsonToDeserialize = "{\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingIntTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingBooleanTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingCharTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingByteTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingShortTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingLongTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setFloatValue(1.0f); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingFloatTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"doubleValue\":1000.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setDoubleValue(1000.0); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test + public void deserializeObjectMissingDoubleTest() { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0}"; + MyObjectTestToSerialize expectedResult = new MyObjectTestToSerialize(); + expectedResult.setStringValue("A String"); + expectedResult.setIntValue(2147483647); + expectedResult.setBoolValue(true); + expectedResult.setCharValue('a'); + expectedResult.setByteValue((byte) 65); + expectedResult.setShortValue((short) 32767); + expectedResult.setLongValue(9223372036854775807L); + expectedResult.setFloatValue(1.0f); + MyObjectTestToSerialize result; + + try { + result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + assertEquals("FOUND:[[" + result + "]] \n but was EXPECING: [[" + expectedResult + "]]", expectedResult, result); + } catch (IOException exception) { + fail(exception.getMessage()); + } + } + + @Test(expected = IOException.class) + public void deserializeObjectIntExceedMaximunValueTest() throws Exception { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483648,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + } + + @Test(expected = IOException.class) + public void deserializeObjectNotACharTest() throws Exception { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"Not A Char\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + try { + SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + } catch (IOException ioEx) { + throw ioEx; + } catch (Exception ex) { + fail("Wrong exception thrown: [" + ex.getClass() + "] Message:[" + ex.getMessage() + "]"); + } + } + + @Test(expected = IOException.class) + public void deserializeObjectShortExceededMaximunValueTest() throws Exception { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32768,\"longValue\":9223372036854775807,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + } + + @Test(expected = IOException.class) + public void deserializeObjectLongExceededMaximumValueTest() throws Exception { + String jsonToDeserialize = "{\"stringValue\":\"A String\",\"intValue\":2147483647,\"boolValue\":true,\"charValue\":\"a\",\"byteValue\":65,\"shortValue\":32767,\"longValue\":9223372036854775808,\"floatValue\":1.0,\"doubleValue\":1000.0}"; + + MyObjectTestToSerialize result = SERIALIZER.deserialize(jsonToDeserialize.getBytes(), MyObjectTestToSerialize.class); + } + + @Test + public void deserializeNullToPrimitives() throws Exception { + + assertEquals(0, (char)SERIALIZER.deserialize(null, char.class)); + assertEquals(0, (int)SERIALIZER.deserialize(null, int.class)); + assertEquals(0, (long)SERIALIZER.deserialize(null, long.class)); + assertEquals(0, (byte)SERIALIZER.deserialize(null, byte.class)); + assertEquals(0, SERIALIZER.deserialize(null, double.class), 0); + assertEquals(0, SERIALIZER.deserialize(null, float.class), 0); + assertEquals(false, SERIALIZER.deserialize(null, boolean.class)); + + assertNull(SERIALIZER.deserialize(null, Character.class)); + assertNull(SERIALIZER.deserialize(null, Integer.class)); + assertNull(SERIALIZER.deserialize(null, Long.class)); + assertNull(SERIALIZER.deserialize(null, Byte.class)); + assertNull(SERIALIZER.deserialize(null, Double.class)); + assertNull(SERIALIZER.deserialize(null, Float.class)); + assertNull(SERIALIZER.deserialize(null, Boolean.class)); + } + + @Test + public void deserializeEmptyByteArrayToPrimitives() throws Exception { + + assertEquals(0, (char)SERIALIZER.deserialize(new byte[0], char.class)); + assertEquals(0, (int)SERIALIZER.deserialize(new byte[0], int.class)); + assertEquals(0, (long)SERIALIZER.deserialize(new byte[0], long.class)); + assertEquals(0, (byte)SERIALIZER.deserialize(new byte[0], byte.class)); + assertEquals(0, SERIALIZER.deserialize(new byte[0], double.class), 0); + assertEquals(0, SERIALIZER.deserialize(new byte[0], float.class), 0); + assertEquals(false, SERIALIZER.deserialize(new byte[0], boolean.class)); + + assertNull(SERIALIZER.deserialize(new byte[0], Character.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Integer.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Long.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Byte.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Double.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Float.class)); + assertNull(SERIALIZER.deserialize(new byte[0], Boolean.class)); + } + + @Test + public void serializeDeserializeCloudEventEnvelope() throws Exception { + + + Function check = (e -> { + try { + if (e == null) { + return CloudEvent.deserialize(SERIALIZER.serialize(e)) == null; + } + + return e.equals(CloudEvent.deserialize(SERIALIZER.serialize(e))); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + + assertTrue(check.apply(null)); + assertTrue(check.apply( + new CloudEvent( + "1", + "mysource", + "text", + "v2", + "XML", + ""))); + assertTrue(check.apply( + new CloudEvent( + "1234-65432", + "myother", + "image", + "v2", + "byte", + Base64.getEncoder().encodeToString(new byte[] {0, 2, 99})))); + } + + @Test + public void deserializeCloudEventEnvelopeData() throws Exception { + + + Function deserializeData = (jsonData -> { + try { + String payload = String.format("{\"data\": %s}", jsonData); + return CloudEvent.deserialize(payload.getBytes()).getData(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + + assertEquals("123", + deserializeData.apply("123")); + assertEquals("true", + deserializeData.apply("true")); + assertEquals("123.45", + deserializeData.apply("123.45")); + assertEquals("AAEI", + deserializeData.apply(quote(Base64.getEncoder().encodeToString(new byte[] { 0, 1, 8})))); + assertEquals("hello world", + deserializeData.apply(quote("hello world"))); + assertEquals("\"hello world\"", + deserializeData.apply(quote("\\\"hello world\\\""))); + assertEquals("\"hello world\"", + deserializeData.apply(new ObjectMapper().writeValueAsString("\"hello world\""))); + assertEquals("hello world", + deserializeData.apply(new ObjectMapper().writeValueAsString("hello world"))); + assertEquals("{\"id\":\"123:\",\"name\":\"Jon Doe\"}", + deserializeData.apply("{\"id\": \"123:\", \"name\": \"Jon Doe\"}")); + assertEquals("{\"id\": \"123:\", \"name\": \"Jon Doe\"}", + deserializeData.apply(new ObjectMapper().writeValueAsString("{\"id\": \"123:\", \"name\": \"Jon Doe\"}"))); + } + + private static String quote(String content) { + if (content == null) { + return null; + } + + return "\"" + content + "\""; + } +} diff --git a/sdk/src/test/java/io/dapr/utils/DurationUtilsTest.java b/sdk/src/test/java/io/dapr/utils/DurationUtilsTest.java new file mode 100644 index 000000000..2cfc5b83b --- /dev/null +++ b/sdk/src/test/java/io/dapr/utils/DurationUtilsTest.java @@ -0,0 +1,101 @@ +package io.dapr.utils; + +import org.junit.Assert; +import org.junit.Test; + +import java.time.Duration; + +public class DurationUtilsTest { + + @Test + public void convertTimeBothWays() { + String s = "4h15m50s60ms"; + Duration d1 = DurationUtils.ConvertDurationFromDaprFormat(s); + + String t = DurationUtils.ConvertDurationToDaprFormat(d1); + Assert.assertEquals(s, t); + } + + @Test + public void largeHours() { + // hours part is larger than 24 + String s = "31h15m50s60ms"; + Duration d1 = DurationUtils.ConvertDurationFromDaprFormat(s); + + String t = DurationUtils.ConvertDurationToDaprFormat(d1); + Assert.assertEquals(s, t); + } + + @Test + public void negativeDuration() { + Duration d = Duration.ofSeconds(-99); + String t = DurationUtils.ConvertDurationToDaprFormat(d); + Assert.assertEquals("", t); + } + + @Test + public void testGetHoursPart() { + Duration d1 = Duration.ZERO.plusHours(26); + Assert.assertEquals(2, DurationUtils.getHoursPart(d1)); + + Duration d2 = Duration.ZERO.plusHours(23); + Assert.assertEquals(23, DurationUtils.getHoursPart(d2)); + + Duration d3 = Duration.ZERO.plusHours(24); + Assert.assertEquals(0, DurationUtils.getHoursPart(d3)); + } + + @Test + public void testGetMinutesPart() { + Duration d1 = Duration.ZERO.plusMinutes(61); + Assert.assertEquals(1, DurationUtils.getMinutesPart(d1)); + + Duration d2 = Duration.ZERO.plusMinutes(60); + Assert.assertEquals(0, DurationUtils.getMinutesPart(d2)); + + Duration d3 = Duration.ZERO.plusMinutes(59); + Assert.assertEquals(59, DurationUtils.getMinutesPart(d3)); + + Duration d4 = Duration.ZERO.plusMinutes(3600); + Assert.assertEquals(0, DurationUtils.getMinutesPart(d4)); + } + + @Test + public void testGetSecondsPart() { + Duration d1 = Duration.ZERO.plusSeconds(61); + Assert.assertEquals(1, DurationUtils.getSecondsPart(d1)); + + Duration d2 = Duration.ZERO.plusSeconds(60); + Assert.assertEquals(0, DurationUtils.getSecondsPart(d2)); + + Duration d3 = Duration.ZERO.plusSeconds(59); + Assert.assertEquals(59, DurationUtils.getSecondsPart(d3)); + + Duration d4 = Duration.ZERO.plusSeconds(3600); + Assert.assertEquals(0, DurationUtils.getSecondsPart(d4)); + } + + @Test + public void testGetMillisecondsPart() { + Duration d1 = Duration.ZERO.plusMillis(61); + Assert.assertEquals(61, DurationUtils.getMilliSecondsPart(d1)); + + Duration d2 = Duration.ZERO.plusMillis(60); + Assert.assertEquals(60, DurationUtils.getMilliSecondsPart(d2)); + + Duration d3 = Duration.ZERO.plusMillis(59); + Assert.assertEquals(59, DurationUtils.getMilliSecondsPart(d3)); + + Duration d4 = Duration.ZERO.plusMillis(999); + Assert.assertEquals(999, DurationUtils.getMilliSecondsPart(d4)); + + Duration d5 = Duration.ZERO.plusMillis(1001); + Assert.assertEquals(1, DurationUtils.getMilliSecondsPart(d5)); + + Duration d6 = Duration.ZERO.plusMillis(1000); + Assert.assertEquals(0, DurationUtils.getMilliSecondsPart(d6)); + + Duration d7 = Duration.ZERO.plusMillis(10000); + Assert.assertEquals(0, DurationUtils.getMilliSecondsPart(d7)); + } +} diff --git a/sdk/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sdk/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 000000000..ca6ee9cea --- /dev/null +++ b/sdk/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 000000000..cad39afb1 --- /dev/null +++ b/settings.xml @@ -0,0 +1,26 @@ + + + + + + ossrh + ${env.OSSRH_USER_TOKEN} + ${env.OSSRH_PWD_TOKEN} + + + + + + true + + + ${env.GPG_KEY} + ${env.GPG_PWD} + + + + \ No newline at end of file