ClusterForwardProvider 接口 demo 插件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

package com.fr.plugin.cluster.req.demo;
import com.fr.cluster.lock.ClusterLock;
import com.fr.plugin.cluster.req.demo.entity.Task;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.StringUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@FunctionRecorder
public class ReqDemoManager {
/**
* 本机所有处理中的任务
*/
private static final Map<String, Task> PROCESSES = new ConcurrentHashMap<String, Task>();
private ReqDemoManager() {
}
private static ClusterLock getLock() {
return ClusterLockManager.getLock();
}
@ExecuteFunctionRecord
public static void removeTask(String id) throws Exception {
ClusterLock lock = getLock();
try {
lock.lock();
if (id == null) {
return;
}
TaskInfoManager.removeTask(id);
PROCESSES.remove(id);
} finally {
lock.unlock();
}
}
public static Task getTask(String id) throws Exception {
if (id == null) {
return null;
}
ClusterLock lock = getLock();
try {
lock.lock();
return PROCESSES.get(id);
} finally {
lock.unlock();
}
}
public static void addTask(String id, Task task) throws Exception {
if (StringUtils.isBlank(id) || task == null) {
return;
}
ClusterLock lock = getLock();
try {
lock.lock();
TaskInfoManager.addTask(id);
PROCESSES.put(id, task);
} finally {
lock.unlock();
}
}
}