com.github.hengboy.job.schedule.resource.MicroJobScheduleResource Maven / Gradle / Ivy
/*
* Copyright [2019] [恒宇少年 - 于起宇]
*
* 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 com.github.hengboy.job.schedule.resource;
import com.github.hengboy.job.core.http.MicroJobRestTemplate;
import com.github.hengboy.job.core.strategy.model.LoadBalanceNode;
import com.github.hengboy.job.schedule.queue.bean.JobQueueBean;
import com.github.hengboy.job.schedule.store.JobStore;
import lombok.Getter;
import lombok.Setter;
import org.quartz.Scheduler;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
/**
* 任务调度器相关的资源
*
* @author:恒宇少年 - 于起宇
*
* DateTime:2019-01-29 13:02
* Blog:http://blog.yuqiyu.com
* WebSite:http://www.jianshu.com/u/092df3f77bca
* Gitee:https://gitee.com/hengboy
* GitHub:https://github.com/hengyuboy
*/
public class MicroJobScheduleResource {
/**
* 存放当前注册中心的任务消费者的地址列表
*/
private static ConcurrentMap CONSUMER_LB_NODES = new ConcurrentHashMap();
/**
* 任务执行并行队列
*/
public static BlockingQueue JOB_EXECUTE_QUEUE = new LinkedBlockingQueue();
/**
* 任务回收并行队列
*/
public static BlockingQueue JOB_RECOVERY_RETRY_QUEUE = new LinkedBlockingQueue();
/**
* 任务数据源
*/
@Getter
@Setter
private static JobStore jobStore;
/**
* quartz 任务调度器
*/
@Getter
@Setter
private static Scheduler scheduler;
/**
* schedule权重
*/
@Getter
@Setter
private static int scheduleLbWeight;
/**
* restTemplate实例
*/
@Getter
@Setter
private static MicroJobRestTemplate restTemplate;
/**
* 重试次数
*/
@Setter
@Getter
private static int maxRetryTimes;
/**
* 任务注册中心监听端口号
*/
@Getter
@Setter
private static int registryPort;
/**
* 任务注册中心ip地址
*/
@Setter
@Getter
private static String registryIpAddress;
/**
* 调度器端口号
*/
@Getter
@Setter
private static int port;
/**
* 调度器ip地址
*/
@Getter
@Setter
private static String ipAddress;
/**
* 添加消费者负载节点
*
* @param loadBalanceNode 消费者负载节点信息
*/
public static void addConsumerLbNode(LoadBalanceNode loadBalanceNode) {
CONSUMER_LB_NODES.put(loadBalanceNode.getAddress(), loadBalanceNode);
}
/**
* 获取消费者负载节点
*
* @param consumerAddress 消费地址
* @return 消费者负载节点
*/
public static LoadBalanceNode getConsumerLbNode(String consumerAddress) {
return CONSUMER_LB_NODES.get(consumerAddress);
}
/**
* 删除消费者负载节点
*
* @param consumerAddress 消费者地址
*/
public static void removeConsumerLbNode(String consumerAddress) {
CONSUMER_LB_NODES.remove(consumerAddress);
}
/**
* 获取所有的消费者负载均衡节点
*
* @return 所有消费者的负责均衡节点列表
*/
public static ConcurrentMap getAllConsumerLbNode() {
return CONSUMER_LB_NODES;
}
}