Package org.apache.hedwig.protocol.PubSubProtocol

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


        Map<ByteString, SubscriptionData> states = admin.getTopicSubscriptions(topic);
        if (states.isEmpty()) {
            return RC_NOSUBSCRIBERS;
        }
        for (Map.Entry<ByteString, SubscriptionData> entry : states.entrySet()) {
            SubscriptionData state = entry.getValue();
            long localMsgId = state.getState().getMsgId().getLocalComponent();
            if (localMsgId < leastConsumedSeqId) {
                leastConsumedSeqId = localMsgId;
            }
        }
        if (leastConsumedSeqId == Long.MAX_VALUE) {
View Full Code Here


    }

    private void updateSubscriptionState(final ByteString topic, final ByteString subscriberId,
                                         final InMemorySubscriptionState state,
                                         final Callback<Void> callback, Object ctx) {
        SubscriptionData subData;
        Callback<Version> cb = new Callback<Version>() {
            @Override
            public void operationFinished(Object ctx, Version version) {
                state.setVersion(version);
                callback.operationFinished(ctx, null);
View Full Code Here

    }

    private void updateSubscriptionPreferences(final ByteString topic, final ByteString subscriberId,
                                               final InMemorySubscriptionState state,
                                               final Callback<Void> callback, Object ctx) {
        SubscriptionData subData;
        Callback<Version> cb = new Callback<Version>() {
            @Override
            public void operationFinished(Object ctx, Version version) {
                state.setVersion(version);
                callback.operationFinished(ctx, null);
View Full Code Here

                preferencesBuilder = preferencesBuilder.setMessageBound(subRequest.getMessageBound());
            }

            SubscriptionData.Builder subDataBuilder =
                SubscriptionData.newBuilder().setState(stateBuilder).setPreferences(preferencesBuilder);
            final SubscriptionData subData = subDataBuilder.build();

            createSubscriptionData(topic, subscriberId, subData, new Callback<Version>() {
                @Override
                public void operationFailed(Object ctx, PubSubException exception) {
                    cb.operationFailed(ctx, exception);
View Full Code Here

        public boolean runCmd(String[] args) throws Exception {
            if (args.length < 4) {
                return false;
            }
            long lastConsumedId = 0;
            SubscriptionData subData = admin.getSubscription(ByteString.copyFromUtf8(args[1]),
                                                             ByteString.copyFromUtf8(args[2]));
            if (null == subData) {
                System.err.println("Failed to read subscription for topic: " + args[1]
                                 + " subscriber: " + args[2]);
                return true;
            }
            lastConsumedId = subData.getState().getMsgId().getLocalComponent();
            long numMessagesToConsume = Long.parseLong(args[3]);
            long idToConsumed = lastConsumedId + numMessagesToConsume;
            System.out.println("Try to move subscriber(" + args[2] + ") consume ptr of topic(" + args[1]
                             + ") from " + lastConsumedId + " to " + idToConsumed);
            MessageSeqId consumeId = MessageSeqId.newBuilder().setLocalComponent(idToConsumed).build();
View Full Code Here

        MessageSeqId.Builder builder = MessageSeqId.newBuilder();
        builder.setLocalComponent(seqId);
        MessageSeqId msgId = builder.build();

        SubscriptionState.Builder stateBuilder = SubscriptionState.newBuilder(SubscriptionState.getDefaultInstance()).setMsgId(msgId);
        SubscriptionData data = SubscriptionData.newBuilder().setState(stateBuilder).build();

        // create a subscription state
        subManager.createSubscriptionData(topic, subid, data, callback, null);
        Either<Version, PubSubException> cbResult = callback.queue.take();
        Version v1 = cbResult.left();
        Assert.assertEquals("Should not fail with PubSubException",
                            null, cbResult.right());

        // read subscriptions
        subManager.readSubscriptions(topic, subsCallback, null);
        res = subsCallback.queue.take();
        Assert.assertEquals("Should find just 1 subscriber", 1, res.left().size());
        Assert.assertEquals("Should not fail with PubSubException", null, res.right());
        Versioned<SubscriptionData> versionedSubData = res.left().get(subid);
        Assert.assertEquals(Version.Occurred.CONCURRENTLY, v1.compare(versionedSubData.getVersion()));
        SubscriptionData imss = versionedSubData.getValue();
        Assert.assertEquals("Found inconsistent subscription state",
                            data, imss);
        Assert.assertEquals("Found inconsistent last consumed seq id",
                            seqId, imss.getState().getMsgId().getLocalComponent());

        // move consume seq id
        seqId = 99;
        builder = MessageSeqId.newBuilder();
        builder.setLocalComponent(seqId);
        msgId = builder.build();

        stateBuilder = SubscriptionState.newBuilder(data.getState()).setMsgId(msgId);
        data = SubscriptionData.newBuilder().setState(stateBuilder).build();
       
        // update subscription state
        if (subManager.isPartialUpdateSupported()) {
            subManager.updateSubscriptionData(topic, subid, data, versionedSubData.getVersion(), callback, null);
        } else {
            subManager.replaceSubscriptionData(topic, subid, data, versionedSubData.getVersion(), callback, null);
        }
        cbResult = callback.queue.take();
        Assert.assertEquals("Fail to update a subscription state", null, cbResult.right());
        Version v2 = cbResult.left();
        // read subscription state
        subManager.readSubscriptionData(topic, subid, readCallback, null);
        Assert.assertEquals("Found inconsistent subscription state",
                            data, readCallback.queue.take().left().getValue());
       
        // read subscriptions again
        subManager.readSubscriptions(topic, subsCallback, null);
        res = subsCallback.queue.take();
        Assert.assertEquals("Should find just 1 subscriber", 1, res.left().size());
        Assert.assertEquals("Should not fail with PubSubException", null, res.right());
        versionedSubData = res.left().get(subid);
        Assert.assertEquals(Version.Occurred.CONCURRENTLY, v2.compare(versionedSubData.getVersion()));
        imss = res.left().get(subid).getValue();
        Assert.assertEquals("Found inconsistent subscription state",
                            data, imss);
        Assert.assertEquals("Found inconsistent last consumed seq id",
                            seqId, imss.getState().getMsgId().getLocalComponent());

        // update or replace subscription data with bad version
        if (subManager.isPartialUpdateSupported()) {
            subManager.updateSubscriptionData(topic, subid, data, v1, callback, null);
        } else {
View Full Code Here

TOP

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

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.