Package org.apache.hedwig.exceptions.PubSubException

Examples of org.apache.hedwig.exceptions.PubSubException.ServiceDownException


    protected void asyncUnsubscribe(final ByteString topic, final ByteString subscriberId,
                                    final Callback<Void> callback, final Object context, boolean isHub) {
        // Validate that the format of the subscriberId is valid either as a
        // local or hub subscriber.
        if (!isValidSubscriberId(subscriberId, isHub)) {
            callback.operationFailed(context, new ServiceDownException(new InvalidSubscriberIdException(
                                         "SubscriberId passed is not valid: " + subscriberId.toStringUtf8() + ", isHub: " + isHub)));
            return;
        }
        // Asynchronously close the subscription. On the callback to that
        // operation once it completes, post the async unsubscribe request.
View Full Code Here


            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()) {
                throw new ServiceDownException("Exception while trying to close the subscription for topic: "
                                               + topic.toStringUtf8() + ", subscriberId: " + subscriberId.toStringUtf8());
            }
        }
    }
View Full Code Here

                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (!future.isSuccess()) {
                        logger.error("Failed to close the subscription channel for topic: " + topic.toStringUtf8()
                                     + ", subscriberId: " + subscriberId.toStringUtf8());
                        callback.operationFailed(context, new ServiceDownException(
                                                     "Failed to close the subscription channel for topic: " + topic.toStringUtf8()
                                                     + ", subscriberId: " + subscriberId.toStringUtf8()));
                    } else {
                        callback.operationFinished(context, null);
                    }
View Full Code Here

                                                    + pubSubData.subscriberId.toStringUtf8()));
            break;
        case SERVICE_DOWN:
            // Response was service down failure so just invoke the callback's
            // operationFailed method.
            pubSubData.callback.operationFailed(pubSubData.context, new ServiceDownException(
                                                    "Server responded with a SERVICE_DOWN status"));
            break;
        case NOT_RESPONSIBLE_FOR_TOPIC:
            // Redirect response so we'll need to repost the original Subscribe
            // Request
            responseHandler.handleRedirectResponse(response, pubSubData, channel);
            break;
        default:
            // Consider all other status codes as errors, operation failed
            // cases.
            logger.error("Unexpected error response from server for PubSubResponse: " + response);
            pubSubData.callback.operationFailed(pubSubData.context, new ServiceDownException(
                                                    "Server responded with a status code of: " + response.getStatusCode()));
            break;
        }
    }
View Full Code Here

            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()) {
                // See what the exception was that was thrown when the operation
                // failed.
                PubSubException failureException = pubSubCallback.getFailureException();
                if (failureException == null) {
                    // This should not happen as the operation failed but a null
                    // PubSubException was passed. Log a warning message but
                    // throw a generic ServiceDownException.
                    logger.error("Sync Publish operation failed but no PubSubException was passed!");
                    throw new ServiceDownException("Server ack response to publish request is not successful");
                }
                // For the expected exceptions that could occur, just rethrow
                // them.
                else if (failureException instanceof CouldNotConnectException) {
                    throw (CouldNotConnectException) failureException;
                } else if (failureException instanceof ServiceDownException) {
                    throw (ServiceDownException) failureException;
                } else {
                    // For other types of PubSubExceptions, just throw a generic
                    // ServiceDownException but log a warning message.
                    logger.error("Unexpected exception type when a sync publish operation failed: " + failureException);
                    throw new ServiceDownException("Server ack response to publish request is not successful");
                }
            }
        }
    }
View Full Code Here

            ByteString hostString = (host == null) ? null : ByteString.copyFromUtf8(HedwigSocketAddress.sockAddrStr(host));
            if (pubSubData.writeFailedServers != null && pubSubData.writeFailedServers.contains(hostString)) {
                // We've already tried to write to this server previously and
                // failed, so invoke the operationFailed callback.
                logger.error("Error writing to host more than once so just invoke the operationFailed callback!");
                pubSubData.callback.operationFailed(pubSubData.context, new ServiceDownException(
                                                        "Error while writing message to server: " + hostString));
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("Try to send the PubSubRequest again to the default server host/VIP for pubSubData: "
                                 + pubSubData);
View Full Code Here

        Object ctx = request.getCtx();
        ByteString topic = request.getTopic();
        Message message = request.getMessage();

        if (conn == null) {
            callback.operationFailed(ctx, new ServiceDownException("Not connected to derby"));
            return;
        }

        long seqId;

        try {
            seqId = adjustTopicSeqIdForPublish(topic, message);
        } catch (UnexpectedConditionException e) {
            callback.operationFailed(ctx, e);
            return;
        }
        PreparedStatement stmt;

        boolean triedCreatingTable = false;
        while (true) {
            try {
                message.getBody();
                stmt = conn.prepareStatement("INSERT INTO " + getTableNameForTopic(topic) + " VALUES(?,?)");
                stmt.setLong(1, seqId);
                stmt.setBlob(2, new SerialBlob(message.toByteArray()));

                int rowCount = stmt.executeUpdate();
                stmt.close();
                if (rowCount != 1) {
                    logger.error("Unexpected number of affected rows from derby");
                    callback.operationFailed(ctx, new ServiceDownException("Unexpected response from derby"));
                    return;
                }
                break;
            } catch (SQLException sqle) {
                String theError = (sqle).getSQLState();
                if (theError.equals("42X05") && !triedCreatingTable) {
                    createTable(conn, topic);
                    triedCreatingTable = true;
                    continue;
                }

                logger.error("Error while executing derby insert", sqle);
                callback.operationFailed(ctx, new ServiceDownException(sqle));
                return;
            }
        }
        callback.operationFinished(ctx, MessageIdUtils.mergeLocalSeqId(message, seqId).getMsgId());
    }
View Full Code Here

                                      ScanCallback callback, Object ctx, int scanChunk) {

        Connection conn = threadLocalConnection.get();

        if (conn == null) {
            callback.scanFailed(ctx, new ServiceDownException("Not connected to derby"));
            return;
        }

        long currentSeqId;
        currentSeqId = startSeqId;

        PreparedStatement stmt = null;
        try {
            try {
                stmt = conn.prepareStatement("SELECT * FROM " + getTableNameForTopic(topic) + " WHERE " + ID_FIELD_NAME
                                             + " >= ?  AND " + ID_FIELD_NAME + " <= ?");

            } catch (SQLException sqle) {
                String theError = (sqle).getSQLState();
                if (theError.equals("42X05")) {
                    // No table, scan is over
                    callback.scanFinished(ctx, ReasonForFinish.NO_MORE_MESSAGES);
                    return;
                } else {
                    throw sqle;
                }
            }

            int numMessages = 0;
            long totalSize = 0;

            while (true) {

                stmt.setLong(1, currentSeqId);
                stmt.setLong(2, currentSeqId + scanChunk);

                if (!stmt.execute()) {
                    String errorMsg = "Select query did not return a result set";
                    logger.error(errorMsg);
                    stmt.close();
                    callback.scanFailed(ctx, new ServiceDownException(errorMsg));
                    return;
                }

                ResultSet resultSet = stmt.getResultSet();

                if (!resultSet.next()) {
                    stmt.close();
                    callback.scanFinished(ctx, ReasonForFinish.NO_MORE_MESSAGES);
                    return;
                }

                do {

                    long localSeqId = resultSet.getLong(1);

                    Message.Builder messageBuilder = Message.newBuilder().mergeFrom(resultSet.getBinaryStream(2));

                    // Merge in the local seq-id since that is not stored with
                    // the message
                    Message message = MessageIdUtils.mergeLocalSeqId(messageBuilder, localSeqId);

                    callback.messageScanned(ctx, message);
                    numMessages++;
                    totalSize += message.getBody().size();

                    if (numMessages > messageLimit) {
                        stmt.close();
                        callback.scanFinished(ctx, ReasonForFinish.NUM_MESSAGES_LIMIT_EXCEEDED);
                        return;
                    } else if (totalSize > sizeLimit) {
                        stmt.close();
                        callback.scanFinished(ctx, ReasonForFinish.SIZE_LIMIT_EXCEEDED);
                        return;
                    }

                } while (resultSet.next());

                currentSeqId += SCAN_CHUNK;
            }
        } catch (SQLException e) {
            logger.error("SQL Exception", e);
            callback.scanFailed(ctx, new ServiceDownException(e));
            return;
        } catch (IOException e) {
            logger.error("Message stored in derby is not parseable", e);
            callback.scanFailed(ctx, new ServiceDownException(e));
            return;
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
View Full Code Here

            asyncPublishWithResponseImpl(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()) {
                // See what the exception was that was thrown when the operation
                // failed.
                PubSubException failureException = pubSubCallback.getFailureException();
                if (failureException == null) {
                    // This should not happen as the operation failed but a null
                    // PubSubException was passed. Log a warning message but
                    // throw a generic ServiceDownException.
                    logger.error("Sync Publish operation failed but no PubSubException was passed!");
                    throw new ServiceDownException("Server ack response to publish request is not successful");
                }
                // For the expected exceptions that could occur, just rethrow
                // them.
                else if (failureException instanceof CouldNotConnectException) {
                    throw (CouldNotConnectException) failureException;
                } else if (failureException instanceof ServiceDownException) {
                    throw (ServiceDownException) failureException;
                } else {
                    // For other types of PubSubExceptions, just throw a generic
                    // ServiceDownException but log a warning message.
                    logger.error("Unexpected exception type when a sync publish operation failed: ",
                                 failureException);
                    throw new ServiceDownException("Server ack response to publish request is not successful");
                }
            }

            ResponseBody respBody = pubSubCallback.getResponseBody();
            if (null == respBody) {
View Full Code Here

            ByteString hostString = (host == null) ? null : ByteString.copyFromUtf8(HedwigSocketAddress.sockAddrStr(host));
            if (pubSubData.writeFailedServers != null && pubSubData.writeFailedServers.contains(hostString)) {
                // We've already tried to write to this server previously and
                // failed, so invoke the operationFailed callback.
                logger.error("Error writing to host more than once so just invoke the operationFailed callback!");
                pubSubData.getCallback().operationFailed(pubSubData.context, new ServiceDownException(
                                                        "Error while writing message to server: " + hostString));
            } else {
                logger.debug("Try to send the PubSubRequest again to the default server host/VIP for pubSubData: {}",
                    pubSubData);
                // Keep track of this current server that we failed to write to
View Full Code Here

TOP

Related Classes of org.apache.hedwig.exceptions.PubSubException.ServiceDownException

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.