Package org.apache.hedwig.client.data

Examples of org.apache.hedwig.client.data.TopicSubscriber


    public void consume(ByteString topic, ByteString subscriberId, MessageSeqId messageSeqId)
            throws ClientNotSubscribedException {
        if (logger.isDebugEnabled())
            logger.debug("Calling consume for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8() + ", messageSeqId: " + messageSeqId);
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        // Check that this topic subscription on the client side exists.
        if (!topicSubscriber2Channel.containsKey(topicSubscriber)) {
            throw new ClientNotSubscribedException(
                "Cannot send consume message since client is not subscribed to topic: " + topic.toStringUtf8()
                + ", subscriberId: " + subscriberId.toStringUtf8());
View Full Code Here


        // Commenting out these type of API's related to that here for now until
        // this data is available on the server. Will figure out what the
        // correct way to contact the server to get this info is then.
        // The client side just has soft memory state for client subscription
        // information.
        return topicSubscriber2Channel.containsKey(new TopicSubscriber(topic, subscriberId));
    }
View Full Code Here

    public void startDelivery(final ByteString topic, final ByteString subscriberId, MessageHandler messageHandler)
            throws ClientNotSubscribedException {
        if (logger.isDebugEnabled())
            logger.debug("Starting delivery for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8());
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        // Make sure we know about this topic subscription on the client side
        // exists. The assumption is that the client should have in memory the
        // Channel created for the TopicSubscriber once the server has sent
        // an ack response to the initial subscribe request.
        if (!topicSubscriber2Channel.containsKey(topicSubscriber)) {
View Full Code Here

    public void stopDelivery(final ByteString topic, final ByteString subscriberId) throws ClientNotSubscribedException {
        if (logger.isDebugEnabled())
            logger.debug("Stopping delivery for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8());
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        // Make sure we know that this topic subscription on the client side
        // exists. The assumption is that the client should have in memory the
        // Channel created for the TopicSubscriber once the server has sent
        // an ack response to the initial subscribe request.
        if (!topicSubscriber2Channel.containsKey(topicSubscriber)) {
View Full Code Here

    public void asyncCloseSubscription(final ByteString topic, final ByteString subscriberId,
                                       final Callback<Void> callback, final Object context) {
        if (logger.isDebugEnabled())
            logger.debug("Closing subscription asynchronously for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8());
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        if (topicSubscriber2Channel.containsKey(topicSubscriber)) {
            // Remove all cached references for the TopicSubscriber
            Channel channel = topicSubscriber2Channel.get(topicSubscriber);
            topicSubscriber2Channel.remove(topicSubscriber);
            // Close the subscribe channel asynchronously.
View Full Code Here

    }

    @Override
    public void stopServingSubscriber(ByteString topic, ByteString subscriberId) {
        lastRequest.add(new TopicSubscriber(topic, subscriberId));
    }
View Full Code Here

        sh.handleRequestAtOwner(pubSubRequestPrototype, channel);
        assertEquals(StatusCode.SUCCESS, ((PubSubResponse) channel.getMessagesWritten().get(0)).getStatusCode());

        // make sure the channel was put in the maps
        assertEquals(new TopicSubscriber(topic, subscriberId), sh.channel2sub.get(channel));
        assertEquals(channel, sh.sub2Channel.get(new TopicSubscriber(topic, subscriberId)));

        // make sure delivery was started
        StartServingRequest startRequest = (StartServingRequest) dm.lastRequest.poll();
        assertEquals(channel, ((ChannelEndPoint) startRequest.endPoint).getChannel());
        assertEquals(false, startRequest.isHubSubscriber);
        assertEquals(TrueFilter.class, startRequest.filter.getClass());
        assertEquals(1, startRequest.seqIdToStartFrom.getLocalComponent());
        assertEquals(subscriberId, startRequest.subscriberId);
        assertEquals(topic, startRequest.topic);

        // make sure subscription was registered
        StubCallback<MessageSeqId> callback1 = new StubCallback<MessageSeqId>();
        sm.serveSubscribeRequest(topic, SubscribeRequest.newBuilder(subRequestPrototype).setCreateOrAttach(
                                     CreateOrAttach.CREATE).build(), MessageSeqId.newBuilder().setLocalComponent(10).build(), callback1,
                                 null);

        assertEquals(PubSubException.ClientAlreadySubscribedException.class, ConcurrencyUtils.take(callback1.queue)
                     .right().getClass());

        // trying to subscribe again should throw an error
        WriteRecordingChannel dupChannel = new WriteRecordingChannel();
        sh.handleRequestAtOwner(pubSubRequestPrototype, dupChannel);
        assertEquals(StatusCode.TOPIC_BUSY, ((PubSubResponse) dupChannel.getMessagesWritten().get(0)).getStatusCode());

        // after disconnecting the channel, subscribe should work again
        sh.channelDisconnected(channel);

        dupChannel = new WriteRecordingChannel();
        sh.handleRequestAtOwner(pubSubRequestPrototype, dupChannel);
        assertEquals(StatusCode.SUCCESS, ((PubSubResponse) dupChannel.getMessagesWritten().get(0)).getStatusCode());

        // test unsubscribe
        channel = new WriteRecordingChannel();
        ush.handleRequestAtOwner(pubSubRequestPrototype, channel);
        assertEquals(StatusCode.MALFORMED_REQUEST, ((PubSubResponse) channel.getMessagesWritten().get(0))
                     .getStatusCode());

        PubSubRequest unsubRequest = PubSubRequest.newBuilder(pubSubRequestPrototype).setUnsubscribeRequest(
                                         UnsubscribeRequest.newBuilder().setSubscriberId(subscriberId)).build();
        channel = new WriteRecordingChannel();
        dm.lastRequest.clear();

        ush.handleRequestAtOwner(unsubRequest, channel);
        assertEquals(StatusCode.SUCCESS, ((PubSubResponse) channel.getMessagesWritten().get(0)).getStatusCode());

        // make sure delivery has been stopped
        assertEquals(new TopicSubscriber(topic, subscriberId), dm.lastRequest.poll());

        // make sure the info is gone from the sm
        StubCallback<MessageSeqId> callback2 = new StubCallback<MessageSeqId>();
        sm.serveSubscribeRequest(topic, SubscribeRequest.newBuilder(subRequestPrototype).setCreateOrAttach(
                                     CreateOrAttach.ATTACH).build(), MessageSeqId.newBuilder().setLocalComponent(10).build(), callback2,
View Full Code Here

        topicSubs.add(topicSubscriber);

    }

    public synchronized void aboutToUnsubscribe(ByteString topic, ByteString subscriberId) {
        TopicSubscriber topicSub = new TopicSubscriber(topic, subscriberId);

        Channel channel = topicSub2Channel.remove(topicSub);

        if (channel != null) {
            List<TopicSubscriber> topicSubs = channel2TopicSubs.get(channel);
View Full Code Here

        }

    }

    public synchronized Channel getChannel(ByteString topic, ByteString subscriberId) {
        return topicSub2Channel.get(new TopicSubscriber(topic, subscriberId));
    }
View Full Code Here

        enqueueWithoutFailure(subscriber);
    }

    public void stopServingSubscriber(ByteString topic, ByteString subscriberId) {
        ActiveSubscriberState subState = subscriberStates.get(new TopicSubscriber(topic, subscriberId));

        if (subState != null) {
            stopServingSubscriber(subState);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.hedwig.client.data.TopicSubscriber

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.