Search in sources :

Example 1 with EzyEventType

use of com.tvd12.ezyfoxserver.client.event.EzyEventType in project ezyfox-server by youngmonkeys.

the class EzyEventControllersImplTest method multiThreadTest.

@SuppressWarnings("unchecked")
@Test
public void multiThreadTest() {
    EzyEventControllersImpl sut = new EzyEventControllersImpl();
    ExecutorService executorService = Executors.newFixedThreadPool(12);
    AtomicBoolean active = new AtomicBoolean(true);
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                sut.addController(eventType, mock(EzyEventController.class));
            }
            EzyThreads.sleep(1);
        }
    });
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                for (EzyEventController controller : sut.getControllers(eventType)) {
                    controller.handle(null, null);
                }
            }
            EzyThreads.sleep(1);
        }
    });
    EzyThreads.sleep(1000);
    executorService.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EzyEventType(com.tvd12.ezyfoxserver.constant.EzyEventType) EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) ExecutorService(java.util.concurrent.ExecutorService) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzyEventType

use of com.tvd12.ezyfoxserver.client.event.EzyEventType in project ezyfox-server-android-client by youngmonkeys.

the class EzyEventHandlers method handle.

public void handle(EzyEvent event) {
    EzyEventType eventType = event.getType();
    EzyEventHandler handler = handlers.get(eventType);
    if (handler != null)
        handler.handle(event);
    else
        EzyLogger.warn("has no handler for event type: " + eventType);
}
Also used : EzyEventType(com.tvd12.ezyfoxserver.client.event.EzyEventType)

Aggregations

EzyEventType (com.tvd12.ezyfoxserver.client.event.EzyEventType)1 EzyEventType (com.tvd12.ezyfoxserver.constant.EzyEventType)1 EzyEventController (com.tvd12.ezyfoxserver.controller.EzyEventController)1 EzyEventControllersImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl)1 BaseTest (com.tvd12.test.base.BaseTest)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.testng.annotations.Test)1