Skip to content
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

Add Support for Per Actor Type Configuration #892

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,51 @@ private byte[] serialize(ActorRuntimeConfig config) throws IOException {
if (config.getRemindersStoragePartitions() != null) {
generator.writeNumberField("remindersStoragePartitions", config.getRemindersStoragePartitions());
}
if (config.getActorReentrancyConfig() != null) {
generator.writeObjectFieldStart("actorReentrancyConfig");
generator.writeBooleanField("enabled", config.getActorReentrancyConfig().getEnabled());
generator.writeNumberField("maxStackDepth", config.getActorReentrancyConfig().getMaxStackDepth());
generator.writeEndObject();
}
if (!config.getActorTypeConfigs().isEmpty()) {

generator.writeArrayFieldStart("entitiesConfig");
for (ActorTypeConfig actorTypeConfig : config.getActorTypeConfigs()) {
generator.writeStartObject();
if (actorTypeConfig.getActorTypeName() != null) {
generator.writeArrayFieldStart("entities");
generator.writeString(actorTypeConfig.getActorTypeName());
generator.writeEndArray();
}
if (actorTypeConfig.getActorIdleTimeout() != null) {
generator.writeStringField("actorIdleTimeout",
DurationUtils.convertDurationToDaprFormat(actorTypeConfig.getActorIdleTimeout()));
}
if (actorTypeConfig.getActorScanInterval() != null) {
generator.writeStringField("actorScanInterval",
DurationUtils.convertDurationToDaprFormat(actorTypeConfig.getActorScanInterval()));
}
if (actorTypeConfig.getDrainOngoingCallTimeout() != null) {
generator.writeStringField("drainOngoingCallTimeout",
DurationUtils.convertDurationToDaprFormat(actorTypeConfig.getDrainOngoingCallTimeout()));
}
if (actorTypeConfig.getDrainBalancedActors() != null) {
generator.writeBooleanField("drainBalancedActors", actorTypeConfig.getDrainBalancedActors());
}
if (actorTypeConfig.getRemindersStoragePartitions() != null) {
generator.writeNumberField("remindersStoragePartitions", actorTypeConfig.getRemindersStoragePartitions());
}
if (actorTypeConfig.getActorReentrancyConfig() != null) {
generator.writeObjectFieldStart("actorReentrancyConfig");
generator.writeBooleanField("enabled", actorTypeConfig.getActorReentrancyConfig().getEnabled());
generator.writeNumberField("maxStackDepth", actorTypeConfig.getActorReentrancyConfig().getMaxStackDepth());
generator.writeEndObject();
}

generator.writeEndObject();
}
generator.writeEndArray();
}
generator.writeEndObject();
generator.close();
writer.flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2021 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.actors.runtime;

/**
* Represents the configuration for the Actor Type.
*/
public class ActorReentrancyConfig {

private volatile Boolean enabled;

private volatile Integer maxStackDepth;

/**
* Instantiates a new config for the Actor Reentrancy.
*/
ActorReentrancyConfig() {
}

/**
* Gets whether reentrancy is enabled.
*
* @return Whether reentrancy is enabled.
*/
public Boolean getEnabled() {
return enabled;
}

/**
* Sets whether reentrancy should be enabled.
*
* @param enabled Whether reentrancy should be enabled.
* @return This instance.
*/
public ActorReentrancyConfig setEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}

/**
* Gets the number of max stack depth.
*
* @return The number of max stack depth.
*/
public Integer getMaxStackDepth() {
return maxStackDepth;
}

/**
* Sets the number of max stack depth.
*
* @param maxStackDepth The number of max stack depth.
* @return This instance.
*/
public ActorReentrancyConfig setMaxStackDepth(Integer maxStackDepth) {
this.maxStackDepth = maxStackDepth;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class ActorRuntimeConfig {

private volatile Integer remindersStoragePartitions;

private volatile ActorReentrancyConfig actorReentrancyConfig;

private volatile List<ActorTypeConfig> actorTypeConfigs = new CopyOnWriteArrayList<>();

/**
* Instantiates a new config for the Actor Runtime.
*/
Expand Down Expand Up @@ -166,4 +170,48 @@ public ActorRuntimeConfig setRemindersStoragePartitions(Integer remindersStorage
return this;
}

/**
* Adds a actor type config to the list of actors type configs.
*
* @param actorTypeName Actor type that was registered.
* @return This instance.
*/
ActorRuntimeConfig addActorTypeConfig(ActorTypeConfig config) {
if (config == null) {
throw new IllegalArgumentException("Add actor type config failed.");
}

this.actorTypeConfigs.add(config);
return this;
}

/**
* Gets the list of registered actor types.
*
* @return List of registered actor types.
*/
Collection<ActorTypeConfig> getActorTypeConfigs() {
return Collections.unmodifiableCollection(actorTypeConfigs);
}

/**
* Sets actors reentrancy config.
*
* @param actorReentrancyConfig Actor reentrancy type .
* @return This instance.
*/
ActorRuntimeConfig setActorReentrancyConfig(ActorReentrancyConfig actorReentrancyConfig) {
this.actorReentrancyConfig = actorReentrancyConfig;
return this;
}

/**
* Gets actors reentrancy config.
*
* @return Actors reentrancy config.
*/
ActorReentrancyConfig getActorReentrancyConfig() {
return actorReentrancyConfig;
}

}
187 changes: 187 additions & 0 deletions sdk-actors/src/main/java/io/dapr/actors/runtime/ActorTypeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright 2021 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.actors.runtime;

import java.time.Duration;

/**
* Represents the configuration for the Actor Type.
*/
public class ActorTypeConfig {

private String actorTypeName;

private volatile Duration actorIdleTimeout;

private volatile Duration actorScanInterval;

private volatile Duration drainOngoingCallTimeout;

private volatile Boolean drainBalancedActors;

private volatile Integer remindersStoragePartitions;

private volatile ActorReentrancyConfig actorReentrancyConfig;

/**
* Instantiates a new config for the Actor Runtime.
*/
ActorTypeConfig() {
}

/**
* Sets registered actors name.
*
* @param actorTypeName Actor type that was registered.
* @return This instance.
*/
ActorTypeConfig setActorTypeName(String actorTypeName) {
if (actorTypeName == null) {
throw new IllegalArgumentException("Registered actor must have a type name.");
}

this.actorTypeName = actorTypeName;
return this;
}

/**
* Gets registered actor types name.
*
* @return Registered actor types name.
*/
String getActorTypeName() {
return this.actorTypeName;
}

/**
* Gets the duration for Actors' timeout.
*
* @return Duration for Actors' timeout.
*/
public Duration getActorIdleTimeout() {
return this.actorIdleTimeout;
}

/**
* Sets the duration for Actors' timeout.
*
* @param actorIdleTimeout Duration for Actors' timeout.
* @return This instance.
*/
public ActorTypeConfig setActorIdleTimeout(Duration actorIdleTimeout) {
this.actorIdleTimeout = actorIdleTimeout;
return this;
}

/**
* Gets the duration to scan for Actors.
*
* @return The duration to scan for Actors.
*/
public Duration getActorScanInterval() {
return this.actorScanInterval;
}

/**
* Sets the duration to scan for Actors.
*
* @param actorScanInterval The duration to scan for Actors.
* @return This instance.
*/
public ActorTypeConfig setActorScanInterval(Duration actorScanInterval) {
this.actorScanInterval = actorScanInterval;
return this;
}

/**
* Gets the timeout to drain ongoing calls.
*
* @return The timeout to drain ongoing calls.
*/
public Duration getDrainOngoingCallTimeout() {
return this.drainOngoingCallTimeout;
}

/**
* Sets the timeout to drain ongoing calls.
*
* @param drainOngoingCallTimeout The timeout to drain ongoing calls.
* @return This instance.
*/
public ActorTypeConfig setDrainOngoingCallTimeout(Duration drainOngoingCallTimeout) {
this.drainOngoingCallTimeout = drainOngoingCallTimeout;
return this;
}

/**
* Gets whether balanced actors should be drained.
*
* @return Whether balanced actors should be drained.
*/
public Boolean getDrainBalancedActors() {
return this.drainBalancedActors;
}

/**
* Sets whether balanced actors should be drained.
*
* @param drainBalancedActors Whether balanced actors should be drained.
* @return This instance.
*/
public ActorTypeConfig setDrainBalancedActors(Boolean drainBalancedActors) {
this.drainBalancedActors = drainBalancedActors;
return this;
}

/**
* Gets the number of storage partitions for Actor reminders.
*
* @return The number of Actor reminder storage partitions.
*/
public Integer getRemindersStoragePartitions() {
return this.remindersStoragePartitions;
}

/**
* Sets the number of storage partitions for Actor reminders.
*
* @param remindersStoragePartitions The number of storage partitions for Actor reminders.
* @return This instance.
*/
public ActorTypeConfig setRemindersStoragePartitions(Integer remindersStoragePartitions) {
this.remindersStoragePartitions = remindersStoragePartitions;
return this;
}

/**
* Sets actors reentrancy config.
*
* @param actorReentrancyConfig Actor reentrancy type .
* @return This instance.
*/
ActorTypeConfig setActorReentrancyConfig(ActorReentrancyConfig actorReentrancyConfig) {
this.actorReentrancyConfig = actorReentrancyConfig;
return this;
}

/**
* Gets actors reentrancy config.
*
* @return Actors reentrancy config.
*/
ActorReentrancyConfig getActorReentrancyConfig() {
return actorReentrancyConfig;
}

}
Loading