mirror of https://github.com/ZhongFuCheng3y/austin
parent
d3e6265270
commit
e27e420160
@ -1,36 +0,0 @@
|
||||
package com.java3y.austin.handler.config;
|
||||
|
||||
import com.java3y.austin.handler.pending.Task;
|
||||
import com.java3y.austin.handler.receiver.Receiver;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
/**
|
||||
* Handler模块的配置信息
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Configuration
|
||||
public class PrototypeBeanConfig {
|
||||
|
||||
/**
|
||||
* 定义多例的Receiver
|
||||
*/
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public Receiver receiver() {
|
||||
return new Receiver();
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义多例的Task
|
||||
*/
|
||||
@Bean
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public Task task() {
|
||||
return new Task();
|
||||
}
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package com.java3y.austin.support.pending;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
/**
|
||||
* 阻塞队列-消费者和生产者实现
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public abstract class Pending<T> {
|
||||
|
||||
/**
|
||||
* 可使用的线程数
|
||||
*/
|
||||
public static final int DEFAULT_THREAD_NUM = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
/**
|
||||
* 阻塞队列 实现类
|
||||
*/
|
||||
protected BlockingQueue<T> queue;
|
||||
|
||||
/**
|
||||
* 默认消费线程数 = 目前可使用的线程数
|
||||
*/
|
||||
protected Integer threadNum = DEFAULT_THREAD_NUM;
|
||||
|
||||
|
||||
/**
|
||||
* 将元素放入阻塞队列中
|
||||
*
|
||||
* @param t
|
||||
*/
|
||||
public void pending(T t) {
|
||||
try {
|
||||
queue.put(t);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Pending#pending error:{}", Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费阻塞队列元素时的方法
|
||||
*
|
||||
* @param t
|
||||
*/
|
||||
public void handle(List<T> t) {
|
||||
if (t.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
doHandle(t);
|
||||
} catch (Exception e) {
|
||||
log.error("Pending#handle failed:{}", Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化并启动
|
||||
*
|
||||
* @param pendingParam 参数信息
|
||||
*/
|
||||
public abstract void initAndStart(PendingParam pendingParam);
|
||||
|
||||
|
||||
/**
|
||||
* 处理阻塞队列的元素 真正方法
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
public abstract void doHandle(List<T> list);
|
||||
}
|
Loading…
Reference in new issue