dapr / dapr/java-sdk

Move All Actor Config to Annotations

Aperta
#544 1 commento 4 reazioni 0 assegnatari Vedi su GitHub
area/actor/runtime kind/enhancement P2 size/S triaged/unresolved
Lingua principale
Java
Stelle
300
Fork
230
Merge medio
5g 1h
PR unite (30g)
5

Descrizione

## 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);
}
}
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia tracciando ActorRuntime.getInstance().getConfig(), le annotazioni @ActorType e @ActorMethod esistenti e registerActor(...), quindi definisci come ogni impostazione di runtime elencata, inclusa la rientranza, sarà rappresentata nella definizione dell’attore. Verifica poi che la registrazione applichi tali impostazioni senza le chiamate dirette di configurazione mostrate nell’issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
distributed-systems
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.