-
Notifications
You must be signed in to change notification settings - Fork 230
Adding MethodContext + StateSerializer. #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sdk/src/main/java/io/dapr/actors/runtime/ActorCallType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * 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 | ||
| } |
78 changes: 78 additions & 0 deletions
78
sdk/src/main/java/io/dapr/actors/runtime/ActorMethodContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| 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} | ||
| * @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); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
sdk/src/main/java/io/dapr/actors/runtime/ActorStateProviderSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| */ | ||
|
|
||
| package io.dapr.actors.runtime; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Serializes and deserializes an object. | ||
| */ | ||
| class ActorStateProviderSerializer { | ||
|
|
||
| /** | ||
| * Shared Json serializer/deserializer as per Jackson's documentation. | ||
| */ | ||
| private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
|
|
||
| /** | ||
| * 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 | ||
| */ | ||
| byte[] serialize(Object state) throws IOException { | ||
| return OBJECT_MAPPER.writeValueAsBytes(state); | ||
| } | ||
|
|
||
| /** | ||
| * Deserializes the byte array into the original object. | ||
| * @param buffer Array of bytes to be parsed. | ||
| * @param clazz Type of the object being deserialized. | ||
| * @param <T> Generic type of the object being deserialized. | ||
| * @return Object of type T. | ||
| * @throws IOException | ||
| */ | ||
| <T> T deserialize(byte[] buffer, Class<T> clazz) throws IOException { | ||
| return OBJECT_MAPPER.readValue(buffer, clazz); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra ;