Package org.apache.s4.base

Examples of org.apache.s4.base.Event


    }

    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

    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();
            EventMessage event = (EventMessage) serDeser.deserialize(message);

            int appId = Integer.valueOf(event.getAppName());
            String streamId = event.getStreamName();

            /*
             * 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

                    /*
                     * Sender checked and decided that the target is local so we simply put the event in the queue and
                     * we save the trip over the network.
                     */
                    queue.put(new EventMessage(String.valueOf(event.getAppId()), event.getStreamName(), app
                            .getSerDeser().serialize(event)));
                }

            } else {

                /*
                 * We are broadcasting this event to all PE instance. In a cluster, we need to send the event to every
                 * node. The sender method takes care of the remote partitions an we take care of putting the event into
                 * the queue.
                 */
                sender.sendToRemotePartitions(event);
                queue.put(new EventMessage(String.valueOf(event.getAppId()), event.getStreamName(), app.getSerDeser()
                        .serialize(event)));
            }
        } catch (InterruptedException e) {
            logger.error("Interrupted while waiting to put an event in the queue: {}.", e.getMessage());
            Thread.currentThread().interrupt();
View Full Code Here

    @Override
    public void run() {
        while (true) {
            try {
                /* Get oldest event in queue. */
                EventMessage eventMessage = queue.take();

                @SuppressWarnings("unchecked")
                T event = (T) app.getSerDeser().deserialize(eventMessage.getSerializedEvent());

                /* Send event to each target PE. */
                for (int i = 0; i < targetPEs.length; i++) {

                    if (key == null) {
View Full Code Here

        @Override
        public void run() {
            try {
                for (int i = 0; i < numMessages; i++) {
                    for (int partition = 0; partition < emitter.getPartitionCount(); partition++) {
                        EventMessage message = new EventMessage("app1", "stream1",
                                new String(partitionId + " " + i).getBytes());
                        for (int retries = 0; retries < numRetries; retries++) {
                            if (emitter.send(partition, message)) {
                                sendCounts[partition]++;
                                break;
View Full Code Here

                if (message == null) {
                    logger.error("ReceiveThread {}: received a null message", partitionId);
                    break;
                }

                EventMessage deserialized = (EventMessage) serDeser.deserialize(message);
                // process and store the message
                String msgString = new String(deserialized.getSerializedEvent());
                String[] msgTokens = msgString.split(" ");
                Integer senderPartition = Integer.parseInt(msgTokens[0]);
                Integer receivedMsg = Integer.parseInt(msgTokens[1]);

                if (!receivedMessages.containsKey(senderPartition)) {
View Full Code Here

        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));
        } catch (InterruptedException e) {
View Full Code Here

        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

    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

TOP

Related Classes of org.apache.s4.base.Event

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.