Package org.apache.zookeeper

Examples of org.apache.zookeeper.KeeperException


        }
    }

    private void doWorkLoop() throws Exception
    {
        KeeperException exception = null;
        try
        {
            doWork();
        }
        catch ( KeeperException.ConnectionLossException e )
View Full Code Here


        }, ctx);

    }

    public static KeeperException logErrorAndCreateZKException(String msg, String path, int rc) {
        KeeperException ke = KeeperException.create(Code.get(rc), path);
        logger.error(msg + ",zkPath: " + path, ke);
        return ke;
    }
View Full Code Here

        zk.getChildren(topicSubscribersPath, false, new SafeAsyncZKCallback.ChildrenCallback() {
            @Override
            public void safeProcessResult(int rc, String path, final Object ctx, final List<String> children) {

                if (rc != Code.OK.intValue() && rc != Code.NONODE.intValue()) {
                    KeeperException e = ZkUtils.logErrorAndCreateZKException("Could not read subscribers for topic "
                                        + topic.toStringUtf8(), path, rc);
                    cb.operationFailed(ctx, new PubSubException.ServiceDownException(e));
                    return;
                }

                final Map<ByteString, InMemorySubscriptionState> topicSubs = new ConcurrentHashMap<ByteString, InMemorySubscriptionState>();

                if (rc == Code.NONODE.intValue() || children.size() == 0) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("No subscriptions found while acquiring topic: " + topic.toStringUtf8());
                    }
                    cb.operationFinished(ctx, topicSubs);
                    return;
                }

                final AtomicBoolean failed = new AtomicBoolean();
                final AtomicInteger count = new AtomicInteger();

                for (final String child : children) {

                    final ByteString subscriberId = ByteString.copyFromUtf8(child);
                    final String childPath = path + "/" + child;

                    zk.getData(childPath, false, new SafeAsyncZKCallback.DataCallback() {
                        @Override
                        public void safeProcessResult(int rc, String path, Object ctx, byte[] data, Stat stat) {

                            if (rc != Code.OK.intValue()) {
                                KeeperException e = ZkUtils.logErrorAndCreateZKException(
                                                        "Could not read subscription data for topic: " + topic.toStringUtf8()
                                                        + ", subscriberId: " + subscriberId.toStringUtf8(), path, rc);
                                reportFailure(new PubSubException.ServiceDownException(e));
                                return;
                            }
View Full Code Here

                                     + " subscriberId: " + subscriberId.toStringUtf8() + " state: "
                                     + SubscriptionStateUtils.toString(state));
                    }
                    callback.operationFinished(ctx, null);
                } else {
                    KeeperException ke = ZkUtils.logErrorAndCreateZKException(
                                             "Could not record new subscription for topic: " + topic.toStringUtf8()
                                             + " subscriberId: " + subscriberId.toStringUtf8(), path, rc);
                    callback.operationFailed(ctx, new PubSubException.ServiceDownException(ke));
                }
            }
View Full Code Here

        zk.setData(topicSubscriberPath(topic, subscriberId), state.toByteArray(), -1,
        new SafeAsyncZKCallback.StatCallback() {
            @Override
            public void safeProcessResult(int rc, String path, Object ctx, Stat stat) {
                if (rc != Code.OK.intValue()) {
                    KeeperException e = ZkUtils.logErrorAndCreateZKException("Topic: " + topic.toStringUtf8()
                                        + " subscriberId: " + subscriberId.toStringUtf8()
                                        + " could not set subscription state: " + SubscriptionStateUtils.toString(state),
                                        path, rc);
                    callback.operationFailed(ctx, new PubSubException.ServiceDownException(e));
                } else {
View Full Code Here

                    callback.operationFinished(ctx, null);
                    return;
                }

                KeeperException e = ZkUtils.logErrorAndCreateZKException("Topic: " + topic.toStringUtf8()
                                    + " subscriberId: " + subscriberId.toStringUtf8() + " failed to delete subscription", path, rc);
                callback.operationFailed(ctx, new PubSubException.ServiceDownException(e));
            }
        }, ctx);
    }
View Full Code Here

                        ZkUtils.createFullPathOptimistic(zk, zNodePath, initialData, ZooDefs.Ids.OPEN_ACL_UNSAFE,
                        CreateMode.PERSISTENT, new SafeAsyncZKCallback.StringCallback() {
                            @Override
                            public void safeProcessResult(int rc, String path, Object ctx, String name) {
                                if (rc != Code.OK.intValue()) {
                                    KeeperException ke = ZkUtils.logErrorAndCreateZKException(
                                                             "Could not create ledgers node for topic: " + topic.toStringUtf8(),
                                                             path, rc);
                                    cb.operationFailed(ctx, new PubSubException.ServiceDownException(ke));
                                    return;
                                }
                                // initial version is version 1
                                // (guessing)
                                processTopicLedgersNodeData(initialData, 0);
                            }
                        }, ctx);
                        return;
                    }

                    // otherwise some other error
                    KeeperException ke = ZkUtils.logErrorAndCreateZKException("Could not read ledgers node for topic: "
                                         + topic.toStringUtf8(), path, rc);
                    cb.operationFailed(ctx, new PubSubException.ServiceDownException(ke));

                }
            }, ctx);
View Full Code Here

            zk.setData(zNodePath, data, expectedVersion, new SafeAsyncZKCallback.StatCallback() {
                @Override
                public void safeProcessResult(int rc, String path, Object ctx, Stat stat) {
                    if (rc != KeeperException.Code.OK.intValue()) {
                        KeeperException ke = ZkUtils.logErrorAndCreateZKException(
                                                 "Could not write ledgers node for topic: " + topic.toStringUtf8(), path, rc);
                        cb.operationFailed(ctx, new PubSubException.ServiceDownException(ke));
                        return;
                    }
View Full Code Here

        }
        tryNum++;
      } catch (Exception e1) {
        tryNum++;
        if (e1 instanceof KeeperException) {
          KeeperException e = (KeeperException) e1;
          switch (e.code()) {
          case CONNECTIONLOSS:
          case OPERATIONTIMEOUT:
            LOG.warn("Possibly transient ZooKeeper exception: ", e);
            break;
          default:
View Full Code Here

                if (rc == Code.OK.intValue()) {
                    callback.operationFinished(ctx, null);
                    return;
                }
                if (rc != Code.NODEEXISTS.intValue()) {
                    KeeperException ke = ZkUtils.logErrorAndCreateZKException(
                                             "Could not create ephemeral node to register hub", ephemeralNodePath, rc);
                    callback.operationFailed(ctx, new PubSubException.ServiceDownException(ke));
                    return;
                }

                logger.info("Found stale ephemeral node while registering hub with ZK, deleting it");

                // Node exists, lets try to delete it and retry
                zk.delete(ephemeralNodePath, -1, new SafeAsyncZKCallback.VoidCallback() {
                    @Override
                    public void safeProcessResult(int rc, String path, Object ctx) {
                        if (rc == Code.OK.intValue() || rc == Code.NONODE.intValue()) {
                            registerWithZookeeper(callback, ctx);
                            return;
                        }
                        KeeperException ke = ZkUtils.logErrorAndCreateZKException(
                                                 "Could not delete stale ephemeral node to register hub", ephemeralNodePath, rc);
                        callback.operationFailed(ctx, new PubSubException.ServiceDownException(ke));
                        return;

                    }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.KeeperException

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.