dapr / dapr/java-sdk

Move All Actor Config to Annotations

Open
#544 1 comment 4 reactions 0 assignees View on GitHub
area/actor/runtime kind/enhancement P2 size/S triaged/unresolved
Dominant language
Java
Stars
300
Forks
230
Avg merge
1d 20h
Merged PRs (30d)
4

Description

## Describe the proposal
Move all actor configuration to an annotation based pattern. Currently, fields like actor timeout are all set via direct calls into the config by the actor themselves while other information like the actor type is handled via an annotation.

### Current Pattern

```java
/**
* Actor Definition.
*/
@ActorType(name = "DemoActor")
public interface DemoActor {
@ActorMethod(name = "echo_message")
String say(String something);
}

/**
* Service that registers actor with runtime.
*/
public class DemoActorService {

/**
* The main method of this app.
* @param args The port the app will listen on.
* @throws Exception An Exception.
*/
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addRequiredOption("p", "port", true, "Port the will listen to.");

CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);

// If port string is not valid, it will throw an exception.
final int port = Integer.parseInt(cmd.getOptionValue("port"));

// Idle timeout until actor instance is deactivated.
ActorRuntime.getInstance().getConfig().setActorIdleTimeout(Duration.ofSeconds(30));
// How often actor instances are scanned for deactivation and balance.
ActorRuntime.getInstance().getConfig().setActorScanInterval(Duration.ofSeconds(10));
// How long to wait until for draining an ongoing API call for an actor instance.
ActorRuntime.getInstance().getConfig().setDrainOngoingCallTimeout(Duration.ofSeconds(10));
// Determines whether to drain API calls for actors instances being balanced.
ActorRuntime.getInstance().getConfig().setDrainBalancedActors(true);

// Register the Actor class.
ActorRuntime.getInstance().registerActor(DemoActorImpl.class);

// Start Dapr's callback endpoint.
DaprApplication.start(port);
}
}
```

### Proposed Pattern
Exact annotation style can change but the general pattern would be as follows.

```java
/**
* Actor Definition.
*/
@ActorType(name = "DemoActor")
@Reentrant(enabled = true)
@Configuration(idleTimeout = 30, scanInterval = 10, ongoingCallTimeout = 10, drainBailancedActors = true)
public interface DemoActor {
@ActorMethod(name = "echo_message")
String say(String something);
}

/**
* The main method of this app.
* @param args The port the app will listen on.
* @throws Exception An Exception.
*/
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addRequiredOption("p", "port", true, "Port the will listen to.");

CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);

// If port string is not valid, it will throw an exception.
final int port = Integer.parseInt(cmd.getOptionValue("port"));

// Register the Actor class.
ActorRuntime.getInstance().registerActor(DemoActorImpl.class);

// Start Dapr's callback endpoint.
DaprApplication.start(port);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.