Package org.apache.hedwig.protocol.PubSubProtocol

Examples of org.apache.hedwig.protocol.PubSubProtocol.Message


        // Lets scan now
        StubScanCallback scanCallback = new StubScanCallback();
        bkpm.scanMessages(new RangeScanRequest(topic, 1, NUM_MESSAGES_TO_TEST, Long.MAX_VALUE, scanCallback, null));
        for (int i = 0; i < messages.size(); i++) {
            Message scannedMessage = ConcurrencyUtils.take(scanCallback.queue).left();
            assertTrue(messages.get(i).getBody().equals(scannedMessage.getBody()));
            assertEquals(i + 1, scannedMessage.getMsgId().getLocalComponent());
        }
        assertTrue(StubScanCallback.END_MESSAGE == ConcurrencyUtils.take(scanCallback.queue).left());

    }
View Full Code Here


                                        ArrayListMessageFactory.instance);
            if (startSeqId + i > messageList.size()) {
                request.getCallback().scanFinished(request.getCtx(), ReasonForFinish.NO_MORE_MESSAGES);
                return;
            }
            Message msg = messageList.get((int) startSeqId + i - 1);
            Message toDeliver = MessageIdUtils.mergeLocalSeqId(msg, startSeqId + i);
            request.getCallback().messageScanned(request.getCtx(), toDeliver);

            totalSize += toDeliver.getBody().size();

            if (totalSize > request.getSizeLimit()) {
                request.getCallback().scanFinished(request.getCtx(), ReasonForFinish.SIZE_LIMIT_EXCEEDED);
                return;
            }
View Full Code Here

        public void messageScanned(Object ctx, Message recvMessage) {
            if (pubMsgs.isEmpty()) {
                throw (failureException = new RuntimeException("Message received when none expected"));
            }

            Message pubMsg = pubMsgs.get(0);
            if (!HelperMethods.areEqual(recvMessage, pubMsg)) {
                throw (failureException = new RuntimeException("Scanned message not equal to expected"));
            }
            pubMsgs.remove(0);
        }
View Full Code Here

        }

        @SuppressWarnings("unchecked")
        public void messageScanned(Object ctx, Message recvMessage) {

            Message pubMsg = pubMsgs.get(0);
            if (!HelperMethods.areEqual(recvMessage, pubMsg)) {
                throw (failureException = new RuntimeException("Scanned message not equal to expected"));
            }
            pubMsgs.remove(0);
View Full Code Here

                                             + topic.toStringUtf8() + ", could not read last entry", bke);
                                cb.operationFailed(ctx, new PubSubException.ServiceDownException(bke));
                                return;
                            }

                            Message lastMessage;
                            try {
                                lastMessage = Message.parseFrom(seq.nextElement().getEntry());
                            } catch (InvalidProtocolBufferException e) {
                                String msg = "While recovering ledger: " + ledgerId + " for topic: "
                                             + topic.toStringUtf8() + ", could not deserialize last message";
                                logger.error(msg, e);
                                cb.operationFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
                                return;
                            }

                            long prevLedgerEnd = topicInfo.ledgerRanges.isEmpty() ? 0 : topicInfo.ledgerRanges
                                                 .lastKey();
                            LedgerRange lr = LedgerRange.newBuilder().setLedgerId(ledgerId)
                                             .setEndSeqIdIncluded(lastMessage.getMsgId()).build();
                            topicInfo.ledgerRanges.put(lr.getEndSeqIdIncluded().getLocalComponent(),
                                                       new InMemoryLedgerRange(lr, prevLedgerEnd + 1, lh));

                            logger.info("Recovered unclosed ledger: " + ledgerId + " for topic: "
                                        + topic.toStringUtf8() + " with " + numEntriesInLastLedger + " entries");
View Full Code Here

            // hear success
            originalRequest.getCallback().operationFinished(originalRequest.getCtx(), resultOfOperation);

            // Original message that was persisted didn't have the local seq-id.
            // Lets add that in
            Message messageWithLocalSeqId = MessageIdUtils.mergeLocalSeqId(originalRequest.getMessage(),
                                            resultOfOperation);

            // Now enqueue a request to add this newly persisted message to our
            // cache
            CacheKey cacheKey = new CacheKey(originalRequest.getTopic(), resultOfOperation);
View Full Code Here

        Connection conn = threadLocalConnection.get();

        Callback<Long> callback = request.getCallback();
        Object ctx = request.getCtx();
        ByteString topic = request.getTopic();
        Message message = request.getMessage();

        if (conn == null) {
            callback.operationFailed(ctx, new ServiceDownException("Not connected to derby"));
            return;
        }

        long seqId;

        try {
            seqId = adjustTopicSeqIdForPublish(topic, message);
        } catch (UnexpectedConditionException e) {
            callback.operationFailed(ctx, e);
            return;
        }
        PreparedStatement stmt;

        boolean triedCreatingTable = false;
        while (true) {
            try {
                message.getBody();
                stmt = conn.prepareStatement("INSERT INTO " + getTableNameForTopic(topic) + " VALUES(?,?)");
                stmt.setLong(1, seqId);
                stmt.setBlob(2, new SerialBlob(message.toByteArray()));

                int rowCount = stmt.executeUpdate();
                stmt.close();
                if (rowCount != 1) {
                    logger.error("Unexpected number of affected rows from derby");
View Full Code Here

                    Message.Builder messageBuilder = Message.newBuilder().mergeFrom(resultSet.getBinaryStream(2));

                    // Merge in the local seq-id since that is not stored with
                    // the message
                    Message message = MessageIdUtils.mergeLocalSeqId(messageBuilder, localSeqId);

                    callback.messageScanned(ctx, message);
                    numMessages++;
                    totalSize += message.getBody().size();

                    if (numMessages > messageLimit) {
                        stmt.close();
                        callback.scanFinished(ctx, ReasonForFinish.NUM_MESSAGES_LIMIT_EXCEEDED);
                        return;
View Full Code Here

                    }

                    LedgerEntry entry = null;
                    while (seq.hasMoreElements()) {
                        entry = seq.nextElement();
                        Message message;
                        try {
                            message = Message.parseFrom(entry.getEntryInputStream());
                        } catch (IOException e) {
                            String msg = "Unreadable message found in ledger: " + imlr.range.getLedgerId()
                                         + " for topic: " + topic.toStringUtf8();
                            logger.error(msg, e);
                            request.callback.scanFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
                            return;
                        }

                        if (logger.isDebugEnabled()) {
                            logger.debug("Read response from ledger: " + lh.getId() + " entry-id: "
                                         + entry.getEntryId());
                        }

                        assert expectedEntryId == entry.getEntryId() : "expectedEntryId (" + expectedEntryId
                        + ") != entry.getEntryId() (" + entry.getEntryId() + ")";
                        assert (message.getMsgId().getLocalComponent() - imlr.startSeqIdIncluded) == expectedEntryId;

                        expectedEntryId++;
                        request.callback.messageScanned(ctx, message);
                        numMessagesRead++;
                        totalSizeRead += message.getBody().size();

                        if (numMessagesRead >= request.messageLimit) {
                            request.callback.scanFinished(ctx, ReasonForFinish.NUM_MESSAGES_LIMIT_EXCEEDED);
                            return;
                        }
View Full Code Here

                builder.addAllRemoteComponents(topicInfo.lastSeqIdPushed.getRemoteComponentsList());
            }
            builder.setLocalComponent(localSeqId);

            topicInfo.lastSeqIdPushed = builder.build();
            Message msgToSerialize = Message.newBuilder(request.message).setMsgId(topicInfo.lastSeqIdPushed).build();

            topicInfo.currentLedgerRange.handle.asyncAddEntry(msgToSerialize.toByteArray(),
            new SafeAsynBKCallback.AddCallback() {
                @Override
                public void safeAddComplete(int rc, LedgerHandle lh, long entryId, Object ctx) {
                    if (rc != BKException.Code.OK) {
                        BKException bke = BKException.create(rc);
View Full Code Here

TOP

Related Classes of org.apache.hedwig.protocol.PubSubProtocol.Message

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.