Package net.hasor.core

Examples of net.hasor.core.EventContext


public class EventLinkTest {
    @Test
    public void syncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>syncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        final String EventName = "MyEvent";//事件链的终端
        final String SeedEvent = "SeedEvent";//种子事件
        //1.添加事件监听器F
        ec.addListener(EventName, new MyListener());
        ec.addListener(SeedEvent, new EventListener() {
            public void onEvent(String event, Object[] params) throws Throwable {
                AppContext app = (AppContext) params[0];
                EventContext localEC = app.getEnvironment().getEventContext();
                System.out.println("before MyEvent.");
                localEC.fireAsyncEvent(EventName, 1);
                localEC.fireAsyncEvent(EventName, 2);
            }
        });
        //2.引发种子事件
        ec.fireAsyncEvent(SeedEvent, appContext);
        //3.由于是同步事件,因此下面这条日志会在事件处理完毕之后喷出
View Full Code Here


public class AsyncEventTest {
    @Test
    public void asyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>asyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.addListener(EventName, new MyListener());
        //2.引发异步事件
        for (int i = 0; i < 10; i++)
            ec.fireAsyncEvent(EventName, i);
        //3.由于是异步事件,因此下面这条日志会在事件喷出Log之前打印
        System.out.println("before Event do sth...");
        //
        Thread.sleep(5000);
    }
View Full Code Here

public class OnesAsyncEventTest {
    @Test
    public void onesAsyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>onesAsyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.pushListener(EventName, new MyListener());
        //2.引发异步事件,虽然引发了10次事件但只有一次会被执行。
        for (int i = 0; i < 10; i++)
            ec.fireAsyncEvent(EventName, i);
        //3.由于事件引发一次是同步事件,因此下面这条日志会在事件处理完毕之后喷出
        System.out.println("before Event do sth...");
        //
        Thread.sleep(5000);
    }
View Full Code Here

public class SyncEventTest {
    @Test
    public void syncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>syncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.addListener(EventName, new MyListener());
        //2.引发异步事件
        for (int i = 0; i < 10; i++)
            ec.fireSyncEvent(EventName, i);
        //3.由于是同步事件,因此下面这条日志会在事件处理完毕之后喷出
        System.out.println("before Event do sth...");
    }
View Full Code Here

public class OnesSyncEventTest {
    @Test
    public void onesAsyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>onesAsyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.pushListener(EventName, new MyListener());
        //2.引发异步事件,虽然引发了10次事件但只有一次会被执行。
        for (int i = 0; i < 10; i++)
            ec.fireSyncEvent(EventName, i);
        //3.由于事件引发一次是同步事件,因此下面这条日志会在事件处理完毕之后喷出
        System.out.println("after Event do sth...");
    }
View Full Code Here

    public synchronized final void start(Module... modules) throws Throwable {
        if (this.isStart()) {
            return;
        }
        final AbstractAppContext appContext = this;
        EventContext ec = appContext.getEnvironment().getEventContext();
        /*1.Init*/
        Hasor.logInfo("send init sign...");
        appContext.doInitialize();
        /*2.Bind*/
        if (modules != null && modules.length > 0) {
            for (Module module : modules) {
                this.installModule(module);
            }
        }
        ApiBinder apiBinder = appContext.newApiBinder(null);
        appContext.doBind(apiBinder);
        /*3.引发事件*/
        ec.fireSyncEvent(EventContext.ContextEvent_Initialized, apiBinder);
        appContext.doInitializeCompleted();
        Hasor.logInfo("the init is completed!");
        //
        /*3.Start*/
        Hasor.logInfo("send start sign...");
        appContext.doStart();
        /*2.执行Aware通知*/
        List<AppContextAware> awareList = appContext.findBindingBean(AppContextAware.class);
        if (awareList.isEmpty() == false) {
            for (AppContextAware weak : awareList) {
                weak.setAppContext(appContext);
            }
        }
        /*3.发送启动事件*/
        ec.fireSyncEvent(EventContext.ContextEvent_Started, appContext);
        appContext.doStartCompleted();/*用于扩展*/
        /*3.打印状态*/
        this.startState = true;
        Hasor.logInfo("Hasor Started now!");
    }
View Full Code Here

            if (hasMapping == true) {
                apiBinder.bindType(clazz).idWith(newID);
            }
        }
        //3.安装服务
        EventContext ec = apiBinder.getEnvironment().getEventContext();
        RootController root = Hasor.pushStartListener(ec, new RootController());
        apiBinder.bindType(RootController.class).toInstance(root);
    }
View Full Code Here

TOP

Related Classes of net.hasor.core.EventContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.