Package org.apache.s4.collector

Examples of org.apache.s4.collector.EventWrapper


        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));

        Assert.assertEquals(expectedFinalResult, new String(zk.getData("/data", false, null)));
View Full Code Here


    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

        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

    @Inject
    RemoteEmitterFactory emitterFactory;

    public RemoteEmitter getEmitter(Cluster topology) {
        RemoteEmitter emitter = emitters.get(topology);
        if (emitter == null) {
            emitter = emitterFactory.createRemoteEmitter(topology);
            emitters.put(topology, emitter);
        }
        return emitter;
View Full Code Here

        // TODO handle application upgrade
        logger.info("Loading application [{}] from file [{}]", appName, s4r.getAbsolutePath());

        S4RLoaderFactory loaderFactory = injector.getInstance(S4RLoaderFactory.class);
        S4RLoader cl = loaderFactory.createS4RLoader(s4r.getAbsolutePath());
        try {
            JarFile s4rFile = new JarFile(s4r);
            if (s4rFile.getManifest() == null) {
                logger.warn("Cannot load s4r archive [{}] : missing manifest file");
                return null;
            }
            if (!s4rFile.getManifest().getMainAttributes().containsKey(new Name(MANIFEST_S4_APP_CLASS))) {
                logger.warn("Cannot load s4r archive [{}] : missing attribute [{}] in manifest", s4r.getAbsolutePath(),
                        MANIFEST_S4_APP_CLASS);
                return null;
            }
            String appClassName = s4rFile.getManifest().getMainAttributes().getValue(MANIFEST_S4_APP_CLASS);
            logger.info("App class name is: " + appClassName);
            App app = null;

            try {
                Object o = (cl.loadClass(appClassName)).newInstance();
                app = (App) o;
                injector.injectMembers(app);
            } catch (Exception e) {
                logger.error("Could not load s4 application form s4r file [{" + s4r.getAbsolutePath() + "}]", e);
                return null;
View Full Code Here

    public App loadApp(File s4r, String appName) {

        // TODO handle application upgrade
        logger.info("Loading application [{}] from file [{}]", appName, s4r.getAbsolutePath());

        S4RLoaderFactory loaderFactory = injector.getInstance(S4RLoaderFactory.class);
        S4RLoader cl = loaderFactory.createS4RLoader(s4r.getAbsolutePath());
        try {
            JarFile s4rFile = new JarFile(s4r);
            if (s4rFile.getManifest() == null) {
                logger.warn("Cannot load s4r archive [{}] : missing manifest file");
                return null;
View Full Code Here

                        continue;
                    }

                    Status status = getStatus(jsonObject);

                    EventWrapper ew = new EventWrapper(streamName, status, null);
                    for (org.apache.s4.listener.EventHandler handler : handlers) {
                        try {
                            handler.processEvent(ew);
                        } catch (Exception e) {
                            Logger.getLogger("s4")
View Full Code Here

                inputReader = new FileReader(inputFilename);
            }
            br = new BufferedReader(inputReader);
            String inputLine = null;
            boolean firstLine = true;
            EventWrapper eventWrapper = null;
            for (startTime = System.nanoTime(); (inputLine = br.readLine()) != null; startTime = System.nanoTime()) {
                if (firstLine) {
                    JSONObject jsonRecord = new JSONObject(inputLine);
                    createEventTypeInfo(jsonRecord);
                    System.out.println(eventTypeInfoMap);
                    if (eventTypeInfoMap.size() == 0) {
                        return;
                    }
                    firstLine = false;
                    continue;
                }

                try {
                    JSONObject jsonRecord = new JSONObject(inputLine);
                    int classIndex = jsonRecord.getInt("_index");
                    EventTypeInfo eventTypeInfo = eventTypeInfoMap.get(classIndex);
                    if (eventTypeInfo == null) {
                        System.err.printf("Invalid _index value %d\n",
                                          classIndex);
                        return;
                    }

                    Object event = makeRecord(jsonRecord,
                                              eventTypeInfo.getSchema());
                    eventWrapper = new EventWrapper(eventTypeInfo.getStreamName(),
                                                    event,
                                                    new ArrayList<CompoundKeyInfo>());
                    // System.out.println(eventWrapper.getStreamName() + ": " +
                    // eventWrapper.getEvent());
                } catch (Exception e) {
View Full Code Here

    }

    public void run() {
        long startTime, endTime;
        while (true) {
            EventWrapper eventWrapper = null;
            try {
                eventWrapper = workQueue.take();
                if (clock instanceof EventClock) {
                    EventClock eventClock = (EventClock) clock;
                    eventClock.update(eventWrapper);
                    // To what time to update the clock
                }
                if (trackByKey) {
                    boolean foundOne = false;
                    for (CompoundKeyInfo compoundKeyInfo : eventWrapper.getCompoundKeys()) {
                        foundOne = true;
                        updateCount(eventWrapper.getStreamName() + " "
                                + compoundKeyInfo.getCompoundKey());
                    }

                    if (!foundOne) {
                        updateCount(eventWrapper.getStreamName() + " *");
                    }
                }

                startTime = System.currentTimeMillis();
                if (logger.isDebugEnabled()) {
                    logger.debug("STEP 5 (PEContainer): workQueue.take - "
                            + eventWrapper.toString());
                }
                // Logger.getLogger("s4").debug(
                // "Incoming: " + event.getEventName());
                if (monitor != null) {
                    monitor.increment(pecontainer_ev_dq_ct.toString(),
                                      1,
                                      S4_CORE_METRICS.toString());
                }
                // printPlainPartitionInfoList(event.getCompoundKeyList());

                if (eventWrapper.getStreamName().endsWith("_checkpointing")
                        || eventWrapper.getStreamName().endsWith("_recovery")) {
                    // in that case, we don't need to iterate over all prototypes and advises:
                    // the target PE is specified in the event
                    handleCheckpointingOrRecovery(eventWrapper);
                } else {

                    boolean ctrlEvent = testControlEvent(eventWrapper);

                    // execute the PEs interested in this event
                    for (int i = 0; i < prototypeWrappers.size(); i++) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("STEP 6 (PEContainer): prototypeWrappers("
                                    + i
                                    + ") - "
                                    + prototypeWrappers.get(i).toString()
                                    + " - " + eventWrapper.getStreamName());
                        }

                        // first check if this is a control message and handle
                        // it if
                        // so.
                        if (ctrlEvent) {
                            if (controlEventProcessor != null) {
                                controlEventProcessor.process(eventWrapper,
                                        prototypeWrappers.get(i));
                            }

                            continue;
                        }

                        // otherwise, continue processing event.
                        List<EventAdvice> adviceList = adviceLists.get(i);
                        for (EventAdvice eventAdvice : adviceList) {
                            if (eventAdvice.getEventName().equals("*")
                                    || eventAdvice.getEventName().equals(
                                            eventWrapper.getStreamName())) {
                                // event name matches
                            } else {
                                continue;
                            }

                            if (eventAdvice.getKey().equals("*")) {
                                invokePE(prototypeWrappers.get(i).getPE("*"),
                                        eventWrapper, null);
                                continue;
                            }
                           
                            for (CompoundKeyInfo compoundKeyInfo : eventWrapper
                                    .getCompoundKeys()) {
                                if (eventAdvice.getKey().equals(
                                        compoundKeyInfo.getCompoundKey())) {
                                    invokePE(
                                            prototypeWrappers
View Full Code Here

        stub.init();

        while (true) {
            Thread.sleep(10000);
            TestReturnType r = new TestReturnType(100, 200);
            adapter.eventReader.queueWork(new EventWrapper("TESTSTREAM",
                                                           r,
                                                           null));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.s4.collector.EventWrapper

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.