Package org.apache.s4.processor

Examples of org.apache.s4.processor.PEContainer


            EventClock s4EventClock = (EventClock)s4Clock;
            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(ProcessingElement.class);
            for (String processingElementBeanName : processingElementBeanNames) {
                Object bean = context.getBean(processingElementBeanName);
                try {
                    Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock");
   
                    if (getS4ClockMethod.getReturnType().equals(Clock.class)) {
                        if (getS4ClockMethod.invoke(bean) == null) {
                            Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class);
                            setS4ClockMethod.invoke(bean, coreContext.getBean("clock"));
                        }
                    }
                }
                catch (NoSuchMethodException mnfe) {
                    // acceptable
                }
                System.out.println("Adding processing element with bean name "
                        + processingElementBeanName + ", id "
                        + ((ProcessingElement) bean).getId());
                peContainer.addProcessor((ProcessingElement) bean);
            }
        } 
    }
View Full Code Here


        String results = new String(zk.getData("/results", false, null));
        Assert.assertEquals("be=2;da=2;doobie=5;not=1;or=1;to=2;", results);
    }

    public void injectSentence(String sentence) throws IOException {
        Event event = new Event();
        event.put("sentence", String.class, sentence);
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));
    }
View Full Code Here

        TestApp app = injector.getInstance(TestApp.class);
        app.count = 2; // One for the event, another for the timer
        app.init();
        app.start();

        app.testStream.receiveEvent(new EventMessage(APP_NAME, STREAM_NAME, app.getSerDeser().serialize(new Event())));

        /*
         * This must raise a timeout, since the onTime() event is blocked waiting for the onEvent() call to finish. If
         * it completes before the timeout, it means onEvent() and onTime() weren't synchronized
         */
 
View Full Code Here

        TestTimeWindowedApp app = injector.getInstance(TestTimeWindowedApp.class);
        app.init();
        app.start();

        for (int i = 0; i < NB_EVENTS; i++) {
            Event e = new Event();
            e.put("value", Integer.class, i);
            app.stream1.receiveEvent(new EventMessage(APP_NAME, STREAM_NAME, app.getSerDeser().serialize(e)));
        }

        try {
            Assert.assertTrue(signalAllEventsProcessed.await(30, TimeUnit.SECONDS));
View Full Code Here

        Injector injector = CoreTestUtils.createInjectorWithNonFailFastZKClients();

        TCPEmitter emitter = injector.getInstance(TCPEmitter.class);

        Event event = new Event();
        event.put("line", String.class, time1);
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));

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

        testCheckpointingConfiguration(S4AppWithCountBasedCheckpointing.class,
                CheckpointingModuleWithUnrespondingFetchingStorageBackend.class, false, "value1= ; value2=message2");
    }

    private void insertCheckpointInstruction(Injector injector, TCPEmitter emitter) {
        Event event;
        event = new Event();
        event.put("command", String.class, "checkpoint");
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));
    }
View Full Code Here

        Injector injector = CoreTestUtils.createInjectorWithNonFailFastZKClients();

        TCPEmitter emitter = injector.getInstance(TCPEmitter.class);

        Event event = new Event();
        event.put("command", String.class, "setValue1");
        event.put("value", String.class, "message1");
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));

        if (manualCheckpointing) {
            insertCheckpointInstruction(injector, emitter);
        }

        Assert.assertTrue(signalCheckpointed.await(10, TimeUnit.SECONDS));

        forkedS4App.destroy();

        zk.delete("/data", -1);

        signalConsumerReady = getConsumerReadySignal("inputStream");
        forkedS4App = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1", "-appClass",
                S4AppWithManualCheckpointing.class.getName(), "-extraModulesClasses", backendModuleClass.getName() });

        Assert.assertTrue(signalConsumerReady.await(20, TimeUnit.SECONDS));
        // // trigger recovery by sending application event to set value 2
        CountDownLatch signalValue2Set = new CountDownLatch(1);
        CoreTestUtils.watchAndSignalCreation("/value2Set", signalValue2Set, zk);

        event = new Event();
        event.put("command", String.class, "setValue2");
        event.put("value", String.class, "message2");
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));

        Assert.assertTrue(signalValue2Set.await(10, TimeUnit.SECONDS));
View Full Code Here

        Assert.assertEquals("be=2;da=2;doobie=5;not=1;or=1;to=2;", results);

    }

    private void injectSentence(Injector injector, TCPEmitter emitter, String sentence) {
        Event event;
        event = new Event();
        event.put("sentence", String.class, sentence);
        emitter.send(0, new EventMessage("-1", "inputStream", injector.getInstance(SerializerDeserializer.class)
                .serialize(event)));
    }
View Full Code Here

                new MockCoreModuleWithFileBaseCheckpointingBackend());
        TestApp app = injector.getInstance(TestApp.class);
        app.init();
        app.start();

        Event event = new Event();
        event.put("command", String.class, "setValue1");
        event.put("value", String.class, "message1");

        app.testStream.receiveEvent(new EventMessage("", "stream1", app.getSerDeser().serialize(event)));

        signalValue1Set.await();

        StatefulTestPE pe = (StatefulTestPE) app.getPE("statefulPE1").getInstanceForKey("X");

        Assert.assertEquals("message1", pe.getValue1());
        Assert.assertEquals("", pe.getValue2());

        // 3. generate a checkpoint event
        event = new Event();
        event.put("command", String.class, "checkpoint");
        app.testStream.receiveEvent(new EventMessage("", "stream1", app.getSerDeser().serialize(event)));
        Assert.assertTrue(signalCheckpointed.await(10, TimeUnit.SECONDS));

        // NOTE: the backend has asynchronous save operations
        Thread.sleep(1000);
View Full Code Here

    public void run() {
        // TODO: this thread never seems to get interrupted. SHould we catch an interrupted exception from listener
        // here?
        while (!Thread.interrupted()) {
            byte[] message = listener.recv();
            Event event = (Event) serDeser.deserialize(message);

            int appId = event.getAppId();
            int streamId = event.getStreamId();

            /*
             * Match appId and streamId in event to the target stream and pass the event to the target stream. TODO:
             * make this more efficient for the case in which we send the same event to multiple PEs.
             */
 
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.