Package org.apache.hedwig.client.data

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


        ClientNotSubscribedException, ServiceDownException {
        if (logger.isDebugEnabled())
            logger.debug("Calling a sync subUnsub request for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8() + ", operationType: " + operationType + ", createOrAttach: "
                         + createOrAttach);
        PubSubData pubSubData = new PubSubData(topic, null, subscriberId, operationType, createOrAttach, null, null);
        synchronized (pubSubData) {
            PubSubCallback pubSubCallback = new PubSubCallback(pubSubData);
            asyncSubUnsub(topic, subscriberId, pubSubCallback, null, operationType, createOrAttach);
            try {
                while (!pubSubData.isDone)
                    pubSubData.wait();
            } catch (InterruptedException e) {
                throw new ServiceDownException("Interrupted Exception while waiting for async subUnsub call");
            }
            // Check from the PubSubCallback if it was successful or not.
            if (!pubSubCallback.getIsCallSuccessful()) {
View Full Code Here


            logger.debug("Calling an async subUnsub request for topic: " + topic.toStringUtf8() + ", subscriberId: "
                         + subscriberId.toStringUtf8() + ", operationType: " + operationType + ", createOrAttach: "
                         + createOrAttach);
        // Check if we know which server host is the master for the topic we are
        // subscribing to.
        PubSubData pubSubData = new PubSubData(topic, null, subscriberId, operationType, createOrAttach, callback,
                                               context);
        if (client.topic2Host.containsKey(topic)) {
            InetSocketAddress host = client.topic2Host.get(topic);
            if (operationType.equals(OperationType.UNSUBSCRIBE) && client.getPublisher().host2Channel.containsKey(host)) {
                // For unsubscribes, we can reuse the channel connections to the
View Full Code Here

        if (!topicSubscriber2Channel.containsKey(topicSubscriber)) {
            throw new ClientNotSubscribedException(
                "Cannot send consume message since client is not subscribed to topic: " + topic.toStringUtf8()
                + ", subscriberId: " + subscriberId.toStringUtf8());
        }
        PubSubData pubSubData = new PubSubData(topic, null, subscriberId, OperationType.CONSUME, null, null, null);
        // Send the consume message to the server using the same subscribe
        // channel that the topic subscription uses.
        doConsume(pubSubData, topicSubscriber2Channel.get(topicSubscriber), messageSeqId);
    }
View Full Code Here

            }
        });
    }

    public void closeSubscription(ByteString topic, ByteString subscriberId) throws ServiceDownException {
        PubSubData pubSubData = new PubSubData(topic, null, subscriberId, null, null, null, null);
        synchronized (pubSubData) {
            PubSubCallback pubSubCallback = new PubSubCallback(pubSubData);
            asyncCloseSubscription(topic, subscriberId, pubSubCallback, null);
            try {
                while (!pubSubData.isDone)
                    pubSubData.wait();
            } catch (InterruptedException e) {
                throw new ServiceDownException("Interrupted Exception while waiting for asyncCloseSubscription call");
            }
            // Check from the PubSubCallback if it was successful or not.
            if (!pubSubCallback.getIsCallSuccessful()) {
View Full Code Here

    }

    public void publish(ByteString topic, Message msg) throws CouldNotConnectException, ServiceDownException {
        if (logger.isDebugEnabled())
            logger.debug("Calling a sync publish for topic: " + topic.toStringUtf8() + ", msg: " + msg);
        PubSubData pubSubData = new PubSubData(topic, msg, null, OperationType.PUBLISH, null, null, null);
        synchronized (pubSubData) {
            PubSubCallback pubSubCallback = new PubSubCallback(pubSubData);
            asyncPublish(topic, msg, pubSubCallback, null);
            try {
                while (!pubSubData.isDone)
                    pubSubData.wait();
            } catch (InterruptedException e) {
                throw new ServiceDownException("Interrupted Exception while waiting for async publish call");
            }
            // Check from the PubSubCallback if it was successful or not.
            if (!pubSubCallback.getIsCallSuccessful()) {
View Full Code Here

    public void asyncPublish(ByteString topic, Message msg, Callback<Void> callback, Object context) {
        if (logger.isDebugEnabled())
            logger.debug("Calling an async publish for topic: " + topic.toStringUtf8() + ", msg: " + msg);
        // Check if we already have a Channel connection set up to the server
        // for the given Topic.
        PubSubData pubSubData = new PubSubData(topic, msg, null, OperationType.PUBLISH, null, callback, context);
        if (client.topic2Host.containsKey(topic)) {
            InetSocketAddress host = client.topic2Host.get(topic);
            if (host2Channel.containsKey(host)) {
                // We already have the Channel connection for the server host so
                // do the publish directly. We will deal with redirect logic
View Full Code Here

            return;
        }

        // Response is an ack to a prior PubSubRequest so first retrieve the
        // PubSub data for this txn.
        PubSubData pubSubData = txn2PubSubData.containsKey(response.getTxnId()) ? txn2PubSubData.get(response
                                .getTxnId()) : null;
        // Validate that the PubSub data for this txn is stored. If not, just
        // log an error message and return since we don't know how to handle
        // this.
        if (pubSubData == null) {
View Full Code Here

        // If this Channel was used for Publish and Unsubscribe flows, just
        // remove it from the HewdigPublisher's host2Channel map. We will
        // re-establish a Channel connection to that server when the next
        // publish/unsubscribe request to a topic that the server owns occurs.
        PubSubData origSubData = subHandler.getOrigSubData();

        // Now determine what type of operation this channel was used for.
        if (origSubData == null) {
            // Only remove the Channel from the mapping if this current
            // disconnected channel is the same as the cached entry.
            // Due to race concurrency situations, it is possible to
            // create multiple channels to the same host for publish
            // and unsubscribe requests.
            if (pub.host2Channel.containsKey(host) && pub.host2Channel.get(host).equals(ctx.getChannel())) {
                if (logger.isDebugEnabled())
                    logger.debug("Disconnected channel for host: " + host
                                 + " was for Publish/Unsubscribe requests so remove all references to it.");
                pub.host2Channel.remove(host);
                client.clearAllTopicsForHost(host);
            }
        } else {
            // Subscribe channel disconnected so first close and clear all
            // cached Channel data set up for this topic subscription.
            sub.closeSubscription(origSubData.topic, origSubData.subscriberId);
            client.clearAllTopicsForHost(host);
            // Since the connection to the server host that was responsible
            // for the topic died, we are not sure about the state of that
            // server. Resend the original subscribe request data to the default
            // server host/VIP. Also clear out all of the servers we've
            // contacted or attempted to from this request as we are starting a
            // "fresh" subscribe request.
            origSubData.clearServersList();
            // Set a new type of VoidCallback for this async call. We need this
            // hook so after the subscribe reconnect has completed, delivery for
            // that topic subscriber should also be restarted (if it was that
            // case before the channel disconnect).
            origSubData.callback = new SubscribeReconnectCallback(origSubData, client, subHandler.getMessageHandler());
View Full Code Here

            return;
        }

        // Response is an ack to a prior PubSubRequest so first retrieve the
        // PubSub data for this txn.
        PubSubData pubSubData = txn2PubSubData.containsKey(response.getTxnId()) ? txn2PubSubData.get(response
                                .getTxnId()) : null;
        // Validate that the PubSub data for this txn is stored. If not, just
        // log an error message and return since we don't know how to handle
        // this.
        if (pubSubData == null) {
View Full Code Here

        // If this Channel was used for Publish and Unsubscribe flows, just
        // remove it from the HewdigPublisher's host2Channel map. We will
        // re-establish a Channel connection to that server when the next
        // publish/unsubscribe request to a topic that the server owns occurs.
        PubSubData origSubData = subHandler.getOrigSubData();

        // Now determine what type of operation this channel was used for.
        if (origSubData == null) {
            // Only remove the Channel from the mapping if this current
            // disconnected channel is the same as the cached entry.
            // Due to race concurrency situations, it is possible to
            // create multiple channels to the same host for publish
            // and unsubscribe requests.
            if (pub.host2Channel.containsKey(host) && pub.host2Channel.get(host).equals(ctx.getChannel())) {
                if (logger.isDebugEnabled())
                    logger.debug("Disconnected channel for host: " + host
                                 + " was for Publish/Unsubscribe requests so remove all references to it.");
                pub.host2Channel.remove(host);
                client.clearAllTopicsForHost(host);
            }
        } else {
            // Subscribe channel disconnected so first close and clear all
            // cached Channel data set up for this topic subscription.
            sub.closeSubscription(origSubData.topic, origSubData.subscriberId);
            client.clearAllTopicsForHost(host);
            // Since the connection to the server host that was responsible
            // for the topic died, we are not sure about the state of that
            // server. Resend the original subscribe request data to the default
            // server host/VIP. Also clear out all of the servers we've
            // contacted or attempted to from this request as we are starting a
            // "fresh" subscribe request.
            origSubData.clearServersList();
            // Set a new type of VoidCallback for this async call. We need this
            // hook so after the subscribe reconnect has completed, delivery for
            // that topic subscriber should also be restarted (if it was that
            // case before the channel disconnect).
            origSubData.callback = new SubscribeReconnectCallback(origSubData, client);
View Full Code Here

TOP

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

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.