Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
topframe committed Apr 28, 2024
1 parent 805157e commit ade6c05
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Expand Up @@ -73,6 +73,9 @@ public String getWorkerName() {
}

protected void setWorkerName(String workerName) {
if (isInitialized()) {
throw new IllegalStateException("Already initialized");
}
if (workerName != null && workerName.contains(".")) {
throw new IllegalArgumentException("Worker name cannot contain '.'");
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import com.aspectran.utils.thread.Scheduler;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Implementation of SessionManager.
Expand All @@ -39,6 +40,10 @@ public class DefaultSessionManager extends AbstractSessionHandler

private static final Logger logger = LoggerFactory.getLogger(DefaultSessionManager.class);

private static final String UNNAMED_WORKER_PREFIX = "unnamed";

private static final AtomicInteger uniqueNumberIssuer = new AtomicInteger();

private ApplicationAdapter applicationAdapter;

private SessionManagerConfig sessionManagerConfig;
Expand Down Expand Up @@ -97,6 +102,7 @@ protected void doInitialize() throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Initializing " + getComponentName());
}
setWorkerName(UNNAMED_WORKER_PREFIX + uniqueNumberIssuer.getAndIncrement());
} else {
if (logger.isDebugEnabled()) {
logger.debug("Initializing " + new ToStringBuilder(getComponentName(), sessionManagerConfig));
Expand All @@ -105,7 +111,10 @@ protected void doInitialize() throws Exception {
clusterEnabled = true;
}
if (sessionManagerConfig.hasWorkerName()) {
uniqueNumberIssuer.getAndIncrement();
setWorkerName(sessionManagerConfig.getWorkerName());
} else {
setWorkerName(UNNAMED_WORKER_PREFIX + uniqueNumberIssuer.getAndIncrement());
}
if (sessionManagerConfig.hasMaxIdleSeconds()) {
setDefaultMaxIdleSecs(sessionManagerConfig.getMaxIdleSeconds());
Expand All @@ -120,9 +129,9 @@ protected void doInitialize() throws Exception {
if (getScheduler() == null) {
String schedulerName;
if (getWorkerName() != null) {
schedulerName = "S-Scheduler-" + getWorkerName();
schedulerName = "Scheduler-" + getWorkerName();
} else {
schedulerName = String.format("S-Scheduler-%x", hashCode());
schedulerName = String.format("Scheduler@%x", hashCode());
}
Scheduler scheduler = new ScheduledExecutorScheduler(schedulerName, false);
setScheduler(scheduler);
Expand Down
Expand Up @@ -240,11 +240,7 @@ public String toString(ViewDispatcher viewDispatcher, String targetName) {
@NonNull
public static DispatchRule newInstance(String name, String dispatcherName, String contentType,
String encoding, Boolean defaultResponse) throws IllegalRuleException {
if (name == null) {
throw new IllegalRuleException("name must not be null");
}
DispatchRule dr = new DispatchRule();
dr.setName(name);
DispatchRule dr = newInstance(name);
dr.setDispatcherName(dispatcherName);
dr.setContentType(contentType);
dr.setEncoding(encoding);
Expand Down
Expand Up @@ -52,7 +52,7 @@ public ItemRuleMap(ItemRuleMap itemRuleMap) {
* @param itemRule the item rule
* @return the item rule
*/
public ItemRule putItemRule(ItemRule itemRule) {
public ItemRule putItemRule(@NonNull ItemRule itemRule) {
if (itemRule.isAutoNamed()) {
autoNaming(itemRule);
}
Expand Down
Expand Up @@ -40,10 +40,7 @@
*
* @since 6.3.0
*/
public class ItemRuleUtils {

private ItemRuleUtils() {
}
public abstract class ItemRuleUtils {

/**
* Returns the {@code Class} according to the given item value.
Expand Down

0 comments on commit ade6c05

Please sign in to comment.