Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md
xsimple: 致力于开发一些简单的java程序组件。遵循:简单即是美!

eventx: 极简的java异步事件处理组件,使用优先级队列线程池。特点:简单、易于使用。
可为事件设置优先级,处理完一个任务即提升等待任务的优先级,在任务优先级与创建时间中取得平衡。

主要组成部分:
发送事件类--EventX
事件分发器--EventDispatcher
事件处理器--EventHandler

使用流程:
1. 引入jar
<dependency>
    <groupId>com.feixc.xsimple</groupId>
    <artifactId>eventx</artifactId>
    <version>1.0.0</version>
</dependency>

2. 编写事件处理代码
package xxx.yyy.zzz;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.feixc.xsimple.eventx.BaseEventHandler;
import com.feixc.xsimple.eventx.Event;
import com.feixc.xsimple.eventx.EventHandler;
import com.feixc.xsimple.eventx.EventPriority;

@EventHandler("/test")
public class TestHandler extends BaseEventHandler {

    @Event("aa")
    public void aa(Map params) {
		String a = getParam(params, "a", String.class, true);
		int b = getParam(params, "b", Integer.class, true);
		Long c = getParam(params, "c", Long.class, false);
		Boolean d = getParam(params, "d", Boolean.class, false);
		
		// do something
	}

	@Event(value = "bb", priority = EventPriority.MIDDLE)
	public void bb(Map params) {
		// do something
	}

	@Event(value = "cc", priority = EventPriority.LOW)
	public void cc(Map params) {
		// do something
	}
}

3. 初始化事件分发器--EventDispatcher
在代码中初始化(只需初始化一次),参数为事件处理器类包名:
EventDispatcher.init("xxx.yyy.zzz")

或在spring配置文件中初始化:
<bean id="eventDispatcher" class="org.opensource.xsimple.eventx.EventDispatcher">
    <constructor name="handlerPackage" value="xxx.yyy.zzz" />
</bean>

4. 在代码中发送事件
Map params = new HashMap();
params.put("a", "aaaaaaaaaa");
params.put("b", 1234);
params.put("c", 0);
params.put("d", true);

EventX.sendEvent("/test/aa", params);

Comments ( 0 )

Sign in for post a comment

About

极简的java异步事件处理组件,使用优先级队列线程池。特点:简单、易于使用。 spread retract
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more