Package org.apache.s4.processor

Examples of org.apache.s4.processor.PEContainer


        CoreTestUtils.watchAndSignalCreation("/value1Set", signalValue1Set, zk);
        final CountDownLatch signalCheckpointed = new CountDownLatch(1);
        CoreTestUtils.watchAndSignalCreation("/checkpointed", signalCheckpointed, zk);

        Injector injector = Guice.createInjector(new MockCommModule(),
                new MockCoreModuleWithFileBaseCheckpointingBackend());
        TestApp app = injector.getInstance(TestApp.class);
        app.init();
        app.start();
View Full Code Here


        cleanupZkBasedTest();
    }

    protected CountDownLatch createTriggerAppAndSendEvent() throws IOException, KeeperException, InterruptedException {
        final ZooKeeper zk = CommTestUtils.createZkClient();
        Injector injector = Guice.createInjector(new MockCommModule(), new MockCoreModule());
        app = injector.getInstance(TriggeredApp.class);
        app.init();
        app.start();
        // app.close();
View Full Code Here

    /*
     * We inject one event and fire one onTime() event, both should be synchronized (not running in parallel)
     */
    @Test
    public void testSynchronization() throws IOException, InterruptedException {
        Injector injector = Guice.createInjector(new MockCommModule(), new MockCoreModule());
        TestApp app = injector.getInstance(TestApp.class);
        app.count = 2; // One for the event, another for the timer
        app.init();
        app.start();

View Full Code Here

    @Test
    public void test() {
        ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
                .getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.DEBUG);
        Injector injector = Guice.createInjector(new MockCommModule(), new MockCoreModule());
        TestTimeWindowedApp app = injector.getInstance(TestTimeWindowedApp.class);
        app.init();
        app.start();

        for (int i = 0; i < NB_EVENTS; i++) {
View Full Code Here

    // public static void main(String[] args) {
    @Test
    public void test() throws Exception {

        Injector injector = Guice.createInjector(new Module());
        FluentApp myApp = injector.getInstance(FluentApp.class);
        Sender sender = injector.getInstance(Sender.class);
        Receiver receiver = injector.getInstance(Receiver.class);
        myApp.setCommLayer(sender, receiver);

        /* Normally. the container will handle this but this is just a test. */
        myApp.init();
        myApp.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        myApp.close();
    }
View Full Code Here

     */
    @Override
    public void configure() {

        /* PE that prints counts to console. */
        PEMaker printPE = addPE(PrintPE.class);

        /* PEs that count events by user, gender, and age. */
        PEMaker userCountPE = addPE(CounterPE.class);
        userCountPE.addTrigger().fireOn(Event.class).ifInterval(100l, TimeUnit.MILLISECONDS);

        PEMaker genderCountPE = addPE(CounterPE.class);
        genderCountPE.addTrigger().fireOn(Event.class).ifInterval(100l, TimeUnit.MILLISECONDS);

        PEMaker ageCountPE = addPE(CounterPE.class);
        ageCountPE.addTrigger().fireOn(Event.class).ifInterval(100l, TimeUnit.MILLISECONDS);

        generateUserEventPE = addPE(GenerateUserEventPE.class).asSingleton();
        generateUserEventPE.addTimer().withDuration(1, TimeUnit.MILLISECONDS);

        ageCountPE.emit(CountEvent.class).onKey(new CountKeyFinder()).to(printPE);
        genderCountPE.emit(CountEvent.class).onKey(new CountKeyFinder()).to(printPE);
        userCountPE.emit(CountEvent.class).onKey(new CountKeyFinder()).to(printPE);

        generateUserEventPE.emit(UserEvent.class).onKey(new AgeKeyFinder()).to(ageCountPE);
        generateUserEventPE.emit(UserEvent.class).onKey("gender").to(genderCountPE);
View Full Code Here

            EventClock s4EventClock = (EventClock)clock;
            s4EventClock.updateTime(seedTime);
            System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
        }
       
        PEContainer peContainer = (PEContainer) context.getBean("peContainer");

        Watcher w = (Watcher) context.getBean("watcher");
        w.setConfigFilename(configPath);

       
        // load extension modules
        String[] configFileNames = getModuleConfigFiles(extsHome, prop);
        if (configFileNames.length > 0) {
            String[] configFileUrls = new String[configFileNames.length];
            for (int i = 0; i < configFileNames.length; i++) {
                configFileUrls[i] = "file:" + configFileNames[i];
            }
            context = new FileSystemXmlApplicationContext(configFileUrls,
                                                          context);
        }

        // load application modules
        configFileNames = getModuleConfigFiles(appsHome, prop);
        if (configFileNames.length > 0) {
            String[] configFileUrls = new String[configFileNames.length];
            for (int i = 0; i < configFileNames.length; i++) {
                configFileUrls[i] = "file:" + configFileNames[i];
            }
            context = new FileSystemXmlApplicationContext(configFileUrls,
                                                          context);
            // attach any beans that implement ProcessingElement to the PE
            // Container
            String[] processingElementBeanNames = context.getBeanNamesForType(AbstractPE.class);
            for (String processingElementBeanName : processingElementBeanNames) {
                AbstractPE bean = (AbstractPE) context.getBean(processingElementBeanName);
                bean.setClock(clock);
                try {
                    bean.setSafeKeeper((SafeKeeper) context.getBean("safeKeeper"));
                } catch (NoSuchBeanDefinitionException ignored) {
                    // no safe keeper = no checkpointing / recovery
                }
                // if the application did not specify an id, use the Spring bean name
                if (bean.getId() == null) {
                    bean.setId(processingElementBeanName);
                }
                System.out.println("Adding processing element with bean name "
                        + processingElementBeanName + ", id "
                        + ((AbstractPE) bean).getId());
                peContainer.addProcessor((AbstractPE) bean);
            }
        } 
    }
View Full Code Here

            s4EventClock.updateTime(seedTime);
            System.out.println("Intializing event clock time with seed time "
                    + s4EventClock.getCurrentTime());
        }

        PEContainer peContainer = (PEContainer) context.getBean("peContainer");

        Watcher w = (Watcher) context.getBean("watcher");
        w.setConfigFilename(configBase + s4CoreConfFileName);

        // load extension modules
        // String[] configFileNames = getModuleConfigFiles(extsHome, prop);
        // if (configFileNames.length > 0) {
        // String[] configFileUrls = new String[configFileNames.length];
        // for (int i = 0; i < configFileNames.length; i++) {
        // configFileUrls[i] = "file:" + configFileNames[i];
        // }
        // context = new FileSystemXmlApplicationContext(configFileUrls,
        // context);
        // }

        // load application modules
        String applicationConfigFileName = configBase + "app_conf.xml";
        String[] configFileUrls = new String[] { "file:"
                + applicationConfigFileName };
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
        // attach any beans that implement ProcessingElement to the PE
        // Container
        String[] processingElementBeanNames = context
                .getBeanNamesForType(AbstractPE.class);
        for (String processingElementBeanName : processingElementBeanNames) {
            Object bean = context.getBean(processingElementBeanName);
            try {
                Method getS4ClockMethod = bean.getClass().getMethod(
                        "getClock");

                if (getS4ClockMethod.getReturnType().equals(Clock.class)) {
                    if (getS4ClockMethod.invoke(bean) == null) {
                        Method setS4ClockMethod = bean.getClass().getMethod(
                                "setClock", Clock.class);
                        setS4ClockMethod.invoke(bean,
                                coreContext.getBean("clock"));
                    }
                }
                ((AbstractPE)bean).setSafeKeeper((SafeKeeper) context.getBean("safeKeeper"));
            } catch (NoSuchMethodException mnfe) {
                // acceptable
            }
            System.out.println("Adding processing element with bean name "
                    + processingElementBeanName + ", id "
                    + ((AbstractPE) bean).getId());
            peContainer.addProcessor((AbstractPE) bean);
        }

        appContext = context;
    }
View Full Code Here

    @Override
    protected void onInit() {

        TriggerablePE prototype = createPE(TriggerablePE.class);
        Stream<StringEvent> stream = createStream("stream", new SentenceKeyFinder(), prototype);
        switch (TriggerTest.triggerType) {
            case COUNT_BASED:
                prototype.setTrigger(Event.class, 1, 0, TimeUnit.SECONDS);
                break;
            case TIME_BASED:
View Full Code Here

        CommTestUtils.watchAndSignalCreation("/onEvent@" + time1, signalEvent1Processed, zk);

        CountDownLatch signalEvent1Triggered = new CountDownLatch(1);
        CommTestUtils.watchAndSignalCreation("/onTrigger[StringEvent]@" + time1, signalEvent1Triggered, zk);

        app.stream.receiveEvent(new EventMessage("-1", "stream", app.getSerDeser().serialize(new StringEvent(time1))));

        // check event processed
        Assert.assertTrue(signalEvent1Processed.await(5, TimeUnit.SECONDS));

        // return latch on trigger signal
View Full Code Here

TOP

Related Classes of org.apache.s4.processor.PEContainer

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.