Examples of PubSubResponse


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

            MessageHandler handler = new MessageHandler() {
                @Override
                public void deliver(ByteString topic, ByteString subscriberId, Message msg,
                final Callback<Void> callback, final Object context) {

                    PubSubResponse response = PubSubResponse.newBuilder().setProtocolVersion(
                                                  ProtocolVersion.VERSION_ONE).setStatusCode(StatusCode.SUCCESS).setTxnId(0).setMessage(msg)
                                              .setTopic(topic).setSubscriberId(subscriberId).build();

                    ChannelFuture future = subscribedChannel.write(response);
View Full Code Here

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

    @Test
    public void testHandleRequestOnRedirect() throws Exception {
        tm.setShouldOwnEveryNewTopic(false);
        handler.handleRequest(request, channel);

        PubSubResponse response = getPubSubResponse(channel);
        assertEquals(response.getStatusCode(), StatusCode.NOT_RESPONSIBLE_FOR_TOPIC);
        assertEquals(request.getTxnId(), response.getTxnId());
        assertNull(handler.getRequest());

    }
View Full Code Here

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

    public void testHandleRequestOnError() throws Exception {

        tm.setShouldError(true);
        handler.handleRequest(request, channel);

        PubSubResponse response = getPubSubResponse(channel);
        assertEquals(response.getStatusCode(), StatusCode.SERVICE_DOWN);
        assertEquals(request.getTxnId(), response.getTxnId());
        assertNull(handler.getRequest());

    }
View Full Code Here

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

            /**
             * The method below will invoke our sendingFinished() method when
             * done
             */
            PubSubResponse response = PubSubResponse.newBuilder().setProtocolVersion(ProtocolVersion.VERSION_ONE)
                                      .setStatusCode(StatusCode.SUCCESS).setTxnId(0).setMessage(message).build();

            deliveryEndPoint.send(response, //
                                  // callback =
                                  this);
View Full Code Here

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

        if (!(e.getMessage() instanceof PubSubResponse)) {
            ctx.sendUpstream(e);
        }
        // Retrieve the PubSubResponse from the Message that was sent by the
        // server.
        PubSubResponse response = (PubSubResponse) e.getMessage();
        if (logger.isDebugEnabled())
            logger.debug("Response received from host: " + HedwigClientImpl.getHostFromChannel(ctx.getChannel())
                         + ", response: " + response);

        // Determine if this PubSubResponse is an ack response for a PubSub
        // Request or if it is a message being pushed to the client subscriber.
        if (response.hasMessage()) {
            // Subscribed messages being pushed to the client so handle/consume
            // it and return.
            subHandler.handleSubscribeMessage(response);
            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) {
            logger.error("PubSub Data was not found for PubSubResponse: " + response);
            return;
        }

        // Now that we've retrieved the PubSubData for this specific Txn ID, we
        // can remove it from the Map.
        txn2PubSubData.remove(response.getTxnId());

        // Store the topic2Host mapping if this wasn't a server redirect. We'll
        // assume that if the server was able to have an open Channel connection
        // to the client, and responded with an ack message other than the
        // NOT_RESPONSIBLE_FOR_TOPIC one, it is the correct topic master.
        if (!response.getStatusCode().equals(StatusCode.NOT_RESPONSIBLE_FOR_TOPIC)) {
            client.storeTopic2HostMapping(pubSubData, ctx.getChannel());
        }

        // Depending on the operation type, call the appropriate handler.
        switch (pubSubData.operationType) {
        case PUBLISH:
            pubHandler.handlePublishResponse(response, pubSubData, ctx.getChannel());
            break;
        case SUBSCRIBE:
            subHandler.handleSubscribeResponse(response, pubSubData, ctx.getChannel());
            break;
        case UNSUBSCRIBE:
            unsubHandler.handleUnsubscribeResponse(response, pubSubData, ctx.getChannel());
            break;
        default:
            // The above are the only expected PubSubResponse messages received
            // from the server for the various client side requests made.
            logger.error("Response received from server is for an unhandled operation type, txnId: "
                         + response.getTxnId() + ", operationType: " + pubSubData.operationType);
        }
    }
View Full Code Here

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

    public static void sendErrorResponseToMalformedRequest(Channel channel, long txnId, String msg) {
        if (logger.isDebugEnabled()) {
            logger.debug("Malformed request from " + channel.getRemoteAddress() + " msg, = " + msg);
        }
        MalformedRequestException mre = new MalformedRequestException(msg);
        PubSubResponse response = PubSubResponseUtils.getResponseForException(mre, txnId);
        channel.write(response);
    }
View Full Code Here

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

            if (null != event &&
                (SubscriptionEvent.TOPIC_MOVED == event ||
                 SubscriptionEvent.SUBSCRIPTION_FORCED_CLOSED == event)) {
                // we should not close the channel now after enabling multiplexing
                PubSubResponse response = PubSubResponseUtils.getResponseForSubscriptionEvent(
                    topic, subscriberId, event
                );
                deliveryEndPoint.send(response, new DeliveryCallback() {
                    @Override
                    public void sendingFinished() {
View Full Code Here

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

            /**
             * The method below will invoke our sendingFinished() method when
             * done
             */
            PubSubResponse response = PubSubResponse.newBuilder()
                                      .setProtocolVersion(ProtocolVersion.VERSION_ONE)
                                      .setStatusCode(StatusCode.SUCCESS).setTxnId(0)
                                      .setMessage(message).setTopic(topic)
                                      .setSubscriberId(subscriberId).build();

View Full Code Here

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

        if (!(e.getMessage() instanceof PubSubResponse)) {
            ctx.sendUpstream(e);
        }
        // Retrieve the PubSubResponse from the Message that was sent by the
        // server.
        PubSubResponse response = (PubSubResponse) e.getMessage();
        if (logger.isDebugEnabled())
            logger.debug("Response received from host: " + HedwigClientImpl.getHostFromChannel(ctx.getChannel())
                         + ", response: " + response);

        // Determine if this PubSubResponse is an ack response for a PubSub
        // Request or if it is a message being pushed to the client subscriber.
        if (response.hasMessage()) {
            // Subscribed messages being pushed to the client so handle/consume
            // it and return.
            subHandler.handleSubscribeMessage(response);
            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) {
            logger.error("PubSub Data was not found for PubSubResponse: " + response);
            return;
        }

        // Now that we've retrieved the PubSubData for this specific Txn ID, we
        // can remove it from the Map.
        txn2PubSubData.remove(response.getTxnId());

        // Store the topic2Host mapping if this wasn't a server redirect. We'll
        // assume that if the server was able to have an open Channel connection
        // to the client, and responded with an ack message other than the
        // NOT_RESPONSIBLE_FOR_TOPIC one, it is the correct topic master.
        if (!response.getStatusCode().equals(StatusCode.NOT_RESPONSIBLE_FOR_TOPIC)) {
            client.storeTopic2HostMapping(pubSubData, ctx.getChannel());
        }

        // Depending on the operation type, call the appropriate handler.
        switch (pubSubData.operationType) {
        case PUBLISH:
            pubHandler.handlePublishResponse(response, pubSubData, ctx.getChannel());
            break;
        case SUBSCRIBE:
            subHandler.handleSubscribeResponse(response, pubSubData, ctx.getChannel());
            break;
        case UNSUBSCRIBE:
            unsubHandler.handleUnsubscribeResponse(response, pubSubData, ctx.getChannel());
            break;
        default:
            // The above are the only expected PubSubResponse messages received
            // from the server for the various client side requests made.
            logger.error("Response received from server is for an unhandled operation type, txnId: "
                         + response.getTxnId() + ", operationType: " + pubSubData.operationType);
        }
    }
View Full Code Here

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

            if (null != event &&
                (SubscriptionEvent.TOPIC_MOVED == event ||
                 SubscriptionEvent.SUBSCRIPTION_FORCED_CLOSED == event)) {
                // we should not close the channel now after enabling multiplexing
                PubSubResponse response = PubSubResponseUtils.getResponseForSubscriptionEvent(
                    topic, subscriberId, event
                );
                deliveryEndPoint.send(response, new DeliveryCallback() {
                    @Override
                    public void sendingFinished() {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.