Package org.apache.curator.framework.recipes.leader

Examples of org.apache.curator.framework.recipes.leader.LeaderLatch


    }
  }

  private LeaderLatch createNewLeaderLatch()
  {
    final LeaderLatch newLeaderLatch = new LeaderLatch(
        curator, ZKPaths.makePath(config.getConnectorPath(), BRIDGE_OWNER_NODE), self.getHost()
    );

    newLeaderLatch.addListener(
        new LeaderLatchListener()
        {
          @Override
          public void isLeader()
          {
View Full Code Here


        leader = true;
      }
      catch (Exception e) {
        log.makeAlert(e, "Exception becoming leader")
           .emit();
        final LeaderLatch oldLatch = createNewLeaderLatch();
        CloseQuietly.close(oldLatch);
        try {
          leaderLatch.get().start();
        }
        catch (Exception e1) {
View Full Code Here

            sDiscovery.close();
            sleep(1000);    // Sleep to allow ZKUtils ServiceCache to update
        }

        private void joinConcurrencyLeaderElection() throws Exception {
            leaderLatch = new LeaderLatch(client, "/services/concurrencyleader", zkId);
            leaderLatch.start();
        }
View Full Code Here

    @Override
    public void init(Services services) throws ServiceException {
        super.init(services);
        try {
            zk = ZKUtils.register(this);
            leaderLatch = new LeaderLatch(zk.getClient(), ZKUtils.ZK_BASE_SERVICES_PATH + "/" + ZK_LEADER_PATH, zk.getZKId());
            leaderLatch.start();
        }
        catch (Exception ex) {
            throw new ServiceException(ErrorCode.E1700, ex.getMessage(), ex);
        }
View Full Code Here

    {
        this.client = client;
        this.queueAllocator = queueAllocator;
        this.queuePath = queuePath;
        this.policies = policies;
        leaderLatch = new LeaderLatch(client, leaderPath);
        service = Executors.newSingleThreadExecutor(policies.getThreadFactory());
    }
View Full Code Here

    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            final LeaderLatch leaderLatch = new LeaderLatch(entry.getClient(), path, participantId);
            leaderLatch.start();

            Closer closer = new Closer()
            {
                @Override
                public void close()
                {
                    try
                    {
                        leaderLatch.close();
                    }
                    catch ( IOException e )
                    {
                        log.error("Could not close left-over leader latch for path: " + path, e);
                    }
                }
            };
            String id = entry.addThing(leaderLatch, closer);

            LeaderLatchListener listener = new LeaderLatchListener()
            {
                @Override
                public void isLeader()
                {
                    addEvent(projection, new RpcCuratorEvent(new LeaderEvent(path, participantId, true)));
                }

                @Override
                public void notLeader()
                {
                    addEvent(projection, new RpcCuratorEvent(new LeaderEvent(path, participantId, false)));
                }
            };
            leaderLatch.addListener(listener);

            if ( waitForLeadershipMs > 0 )
            {
                leaderLatch.await(waitForLeadershipMs, TimeUnit.MILLISECONDS);
            }

            return new LeaderResult(new LeaderProjection(id), leaderLatch.hasLeadership());
        }
        catch ( Exception e )
        {
            throw new RpcException(e);
        }
View Full Code Here

    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            LeaderLatch leaderLatch = CuratorEntry.mustGetThing(entry, leaderProjection.id, LeaderLatch.class);
            Collection<Participant> participants = leaderLatch.getParticipants();
            Collection<RpcParticipant> transformed = Collections2.transform
            (
                participants,
                new Function<Participant, RpcParticipant>()
                {
View Full Code Here

    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            LeaderLatch leaderLatch = CuratorEntry.mustGetThing(entry, leaderProjection.id, LeaderLatch.class);
            return leaderLatch.hasLeadership();
        }
        catch ( Exception e )
        {
            throw new RpcException(e);
        }
View Full Code Here

    {
        this.client = client;
        this.executor = new CloseableScheduledExecutorService(executor);
        this.reapingThresholdMs = reapingThresholdMs / EMPTY_COUNT_THRESHOLD;

        LeaderLatch localLeaderLatch = null;
        if ( leaderPath != null )
        {
            localLeaderLatch = makeLeaderLatch(client, leaderPath);
        }
        leaderLatch = localLeaderLatch;
View Full Code Here

    private LeaderLatch makeLeaderLatch(CuratorFramework client, String leaderPath)
    {
        reapingIsActive.set(false);

        LeaderLatch localLeaderLatch = new LeaderLatch(client, leaderPath);
        LeaderLatchListener listener = new LeaderLatchListener()
        {
            @Override
            public void isLeader()
            {
                reapingIsActive.set(true);
                for ( PathHolder holder : activePaths.values() )
                {
                    schedule(holder, reapingThresholdMs);
                }
            }

            @Override
            public void notLeader()
            {
                reapingIsActive.set(false);
            }
        };
        localLeaderLatch.addListener(listener);
        return localLeaderLatch;
    }
View Full Code Here

TOP

Related Classes of org.apache.curator.framework.recipes.leader.LeaderLatch

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.