Package org.apache.hedwig.client.data

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


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

        // make sure the channel was put in the maps
        Set<TopicSubscriber> topicSubs = new HashSet<TopicSubscriber>();
        topicSubs.add(new TopicSubscriber(topic, subscriberId));
        assertEquals(topicSubs,
                     subChannelMgr.channel2sub.get(channel));
        assertEquals(channel,
                     subChannelMgr.sub2Channel.get(new TopicSubscriber(topic, subscriberId)));

        // make sure delivery was started
        StartServingRequest startRequest = (StartServingRequest) dm.lastRequest.poll();
        assertEquals(channel, ((ChannelEndPoint) startRequest.endPoint).getChannel());
        assertEquals(PipelineFilter.class, startRequest.filter.getClass());
        PipelineFilter pfilter = (PipelineFilter)(startRequest.filter);
        assertEquals(1, pfilter.size());
        assertEquals(AllToAllTopologyFilter.class, pfilter.getFirst().getClass());
        assertEquals(1, startRequest.seqIdToStartFrom.getLocalComponent());
        assertEquals(subscriberId, startRequest.subscriberId);
        assertEquals(topic, startRequest.topic);

        // make sure subscription was registered
        StubCallback<SubscriptionData> callback1 = new StubCallback<SubscriptionData>();
        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
        subChannelMgr.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<SubscriptionData> callback2 = new StubCallback<SubscriptionData>();
        sm.serveSubscribeRequest(topic, SubscribeRequest.newBuilder(subRequestPrototype).setCreateOrAttach(
                                     CreateOrAttach.ATTACH).build(), MessageSeqId.newBuilder().setLocalComponent(10).build(), callback2,
View Full Code Here


    @Override
    public void stopServingSubscriber(ByteString topic, ByteString subscriberId,
                                      SubscriptionEvent event,
                                      Callback<Void> cb, Object ctx) {
        lastRequest.add(new TopicSubscriber(topic, subscriberId));
        cb.operationFinished(ctx, null);
    }
View Full Code Here

    public void aboutToUnsubscribe(ByteString topic, ByteString subscriberId) {
        removeSubscriber(topic, subscriberId);
    }

    private synchronized void removeSubscriber(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

                        closesubStats.incrementFailedOps();
                    }
                    @Override
                    public void operationFinished(Object ctx, Void resultOfOperation) {
                        // remove the topic subscription from subscription channels
                        subChannelMgr.remove(new TopicSubscriber(topic, subscriberId),
                                             channel);
                        channel.write(PubSubResponseUtils.getSuccessResponse(request.getTxnId()));
                        closesubStats.updateLatency(System.currentTimeMillis() - requestTime);
                    }
                }, null);
View Full Code Here

                        unsubStats.incrementFailedOps();
                    }
                    @Override
                    public void operationFinished(Object ctx, Void resultOfOperation) {
                        // remove the topic subscription from subscription channels
                        subChannelMgr.remove(new TopicSubscriber(topic, subscriberId),
                                             channel);
                        channel.write(PubSubResponseUtils.getSuccessResponse(request.getTxnId()));
                        unsubStats.updateLatency(System.currentTimeMillis() - requestTime);
                    }
                }, ctx);
View Full Code Here

                    "Missing subscribe request data");
            return;
        }

        SubscribeRequest subRequest = request.getSubscribeRequest();
        final TopicSubscriber topicSubscriber = new TopicSubscriber(request.getTopic(), subRequest.getSubscriberId());

        subscriber.asyncSubscribe(topicSubscriber.getTopic(), subRequest.getSubscriberId(), subRequest
        .getCreateOrAttach(), new Callback<Void>() {
            @Override
            public void operationFailed(Object ctx, PubSubException exception) {
                channel.write(PubSubResponseUtils.getResponseForException(exception, request.getTxnId()));
            }
View Full Code Here

            return true;
    }

    public void consume(ByteString topic, ByteString subscriberId, MessageSeqId messageSeqId)
            throws ClientNotSubscribedException {
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        logger.debug("Calling consume for {}, messageSeqId: {}.",
                     topicSubscriber, messageSeqId);

        SubscribeResponseHandler subscribeResponseHandler =
            channelManager.getSubscribeResponseHandler(topicSubscriber);
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.
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        SubscribeResponseHandler subscribeResponseHandler =
            channelManager.getSubscribeResponseHandler(topicSubscriber);
        return !(null == subscribeResponseHandler ||
                 !subscribeResponseHandler.hasSubscription(topicSubscriber));
    }
View Full Code Here

    }

    public void startDelivery(final ByteString topic, final ByteString subscriberId,
                              MessageHandler messageHandler)
            throws ClientNotSubscribedException, AlreadyStartDeliveryException {
        TopicSubscriber topicSubscriber = new TopicSubscriber(topic, subscriberId);
        logger.debug("Starting delivery for {}.", topicSubscriber);
        channelManager.startDelivery(topicSubscriber, messageHandler);
    }
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.