java event-loop

a pure lightweight event-loop.

Лицензия

Лицензия

Группа

Группа

com.zmannotes
Идентификатор

Идентификатор

event-loop
Последняя версия

Последняя версия

1.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

java event-loop
a pure lightweight event-loop.
Ссылка на сайт

Ссылка на сайт

https://github.com/zman2013/event-loop
Система контроля версий

Система контроля версий

https://github.com/zman2013/event-loop

Скачать event-loop

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.zmannotes/event-loop/ -->
<dependency>
    <groupId>com.zmannotes</groupId>
    <artifactId>event-loop</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.zmannotes/event-loop/
implementation 'com.zmannotes:event-loop:1.0.2'
// https://jarcasting.com/artifacts/com.zmannotes/event-loop/
implementation ("com.zmannotes:event-loop:1.0.2")
'com.zmannotes:event-loop:jar:1.0.2'
<dependency org="com.zmannotes" name="event-loop" rev="1.0.2">
  <artifact name="event-loop" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.zmannotes', module='event-loop', version='1.0.2')
)
libraryDependencies += "com.zmannotes" % "event-loop" % "1.0.2"
[com.zmannotes/event-loop "1.0.2"]

Зависимости

test (3)

Идентификатор библиотеки Тип Версия
ch.qos.logback : logback-classic jar 1.2.3
junit : junit jar 4.12
org.mockito : mockito-core jar 3.1.0

Модули Проекта

Данный проект не имеет модулей.

Travis Build Coverage Status

event-loop

a pure lightweight event-loop based on a single thread

Dependency

<dependency>
    <groupId>com.zmannotes</groupId>
    <artifactId>event-loop</artifactId>
    <version>1.0.2</version>
</dependency>

Interface

/**
 * eventloop一旦创建就会开始运行loop,无需start,直接可以submit任务
 */
public interface EventLoop {

    /**
     * 提交任务
     * @param taskType 事件类型,用于区分不同类型的任务,用于做任务调度
     * @param task     任务
     * @param <T>      返回值的泛型
     * @return  future
     */
    <T> Future<T> submit(String taskType, Callable<T> task);

    /**
     * 提交任务
     * @param taskType  事件类型,用于区分不同类型的任务,用于做任务调度
     * @param task      任务
     * @param timeout   时间
     * @param timeUnit  单位
     * @param <T>       返回值的泛型
     * @return  future
     */
    <T> Future<T> submit(String taskType, Callable<T> task, long timeout, TimeUnit timeUnit);

    /**
     * 停止event loop
     * @return future
     */
    Future<?> shutdown();
}

Example

EventLoop eventLoop = new DefaultEventLoop("event-loop");
Future<Long> future = eventLoop.submit(TaskType.COMPUTE.name(), ()-> 1+1L);
Assert.assertEquals(2L, future.get().longValue());

Future<Long> future2 = eventLoop.submit(TaskType.COMPUTE.name(), ()-> 1+1L, 10, TimeUnit.MILLISECONDS);
Assert.assertEquals(2L, future2.get(100, TimeUnit.MILLISECONDS).longValue());

AtomicInteger c = new AtomicInteger(0);
eventLoop.submit(()->c.incrementAndGet());
eventLoop.submit(()->c.incrementAndGet(),1,TimeUnit.NANOSECONDS);

Версии библиотеки

Версия
1.0.2
1.0.1
0.0.2
0.0.1