-
Notifications
You must be signed in to change notification settings - Fork 230
ActorService + DaprStateProvider + some more. #53
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
24 changes: 24 additions & 0 deletions
24
sdk/src/main/java/io/dapr/actors/runtime/ActorFactory.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,24 @@ | ||
| /* | ||
| * 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 <T> Actor Type to be created. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface ActorFactory<T extends AbstractActor> { | ||
|
|
||
| /** | ||
| * Creates an Actor. | ||
| * @param actorService Actor Service. | ||
| * @param actorId Actor Id. | ||
| * @return Actor or null it failed. | ||
| */ | ||
| T createActor(ActorService actorService, ActorId actorId); | ||
| } |
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
15 changes: 11 additions & 4 deletions
15
sdk/src/main/java/io/dapr/actors/runtime/ActorService.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 |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| package io.dapr.actors.runtime; | ||
|
|
||
| // stub | ||
| public class ActorService { | ||
| import io.dapr.actors.ActorId; | ||
|
|
||
| public ActorService(ActorTypeInformation actorTypeInformation) { | ||
| /** | ||
| * Interface exposed to Actor's implementations (application layer). | ||
| */ | ||
| public interface ActorService { | ||
|
|
||
| } | ||
| /** | ||
| * Creates an actor. | ||
| * @param actorId Identifier for the Actor to be created. | ||
| * @return New Actor instance. | ||
| */ | ||
| AbstractActor createActor(ActorId actorId); | ||
| } |
67 changes: 67 additions & 0 deletions
67
sdk/src/main/java/io/dapr/actors/runtime/ActorServiceImpl.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,67 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| */ | ||
|
|
||
| package io.dapr.actors.runtime; | ||
|
|
||
| import io.dapr.actors.ActorId; | ||
|
|
||
| /** | ||
| * Implementation of the Actor Service that contains a state provider. | ||
| */ | ||
| class ActorServiceImpl implements ActorService { | ||
|
|
||
| /** | ||
| * Customizable factory for Actors. | ||
| */ | ||
| private final ActorFactory actorFactory; | ||
|
|
||
| /** | ||
| * State provider for Actors. | ||
| */ | ||
| private final DaprStateAsyncProvider stateProvider; | ||
|
|
||
| /** | ||
| * Information on the {@link Actor} type being serviced. | ||
| */ | ||
| private final ActorTypeInformation actorTypeInformation; | ||
|
|
||
| /** | ||
| * Instantiates a stateful service for a given {@link Actor} type. | ||
| * @param actorTypeInformation Information on the {@link Actor} type being serviced. | ||
| * @param stateProvider State provider for Actors. | ||
| * @param actorFactory Customizable factor for Actors. | ||
| */ | ||
| public ActorServiceImpl(ActorTypeInformation actorTypeInformation, DaprStateAsyncProvider stateProvider, ActorFactory actorFactory) { | ||
| this.actorTypeInformation = actorTypeInformation; | ||
| this.actorFactory = actorFactory; | ||
| this.stateProvider = stateProvider; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the state provider for {@link Actor}. | ||
| * @return State provider. | ||
| */ | ||
| DaprStateAsyncProvider getStateProvider() { | ||
| return stateProvider; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the information on the {@link Actor} Type. | ||
| * @return Information on the {@link Actor} Type. | ||
| */ | ||
| ActorTypeInformation getActorTypeInformation() { | ||
| return actorTypeInformation; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an {@link Actor} for this service. | ||
| * @param actorId Identifier for the Actor to be created. | ||
| * @return New {@link Actor} instance. | ||
| */ | ||
| @Override | ||
| public AbstractActor createActor(ActorId actorId) { | ||
| return this.actorFactory.createActor(this, actorId); | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
sdk/src/main/java/io/dapr/actors/runtime/ActorStateChange.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,67 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| */ | ||
|
|
||
| package io.dapr.actors.runtime; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Represents a state change for an actor. | ||
| * @param <T> Type of the value being changed. | ||
| */ | ||
| public final class ActorStateChange<T> { | ||
|
|
||
| /** | ||
| * Name of the state being changed. | ||
| */ | ||
| private final String stateName; | ||
|
|
||
| /** | ||
| * New value for the state being changed. | ||
| */ | ||
| private final T 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, T 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. | ||
| */ | ||
| T getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the kind of change. | ||
| * @return Kind of change. | ||
| */ | ||
| ActorStateChangeKind getChangeKind() { | ||
| return changeKind; | ||
| } | ||
|
|
||
| } |
54 changes: 54 additions & 0 deletions
54
sdk/src/main/java/io/dapr/actors/runtime/ActorStateChangeKind.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,54 @@ | ||
| /* | ||
| * 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; | ||
| } | ||
|
|
||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.