Package org.apache.curator.x.rpc.connections

Examples of org.apache.curator.x.rpc.connections.CuratorEntry


    }

    @ThriftMethod
    public void closeCuratorProjection(CuratorProjection projection)
    {
        CuratorEntry entry = connectionManager.remove(projection.id);
        if ( entry != null )
        {
            entry.close();
        }
    }
View Full Code Here


    @ThriftMethod
    public void sync(CuratorProjection projection, String path, String asyncContext) throws RpcException
    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
            BackgroundCallback backgroundCallback = new RpcBackgroundCallback(this, projection);
            entry.getClient().sync().inBackground(backgroundCallback, asyncContext).forPath(path);
        }
        catch ( Exception e )
        {
            throw new RpcException(e);
        }
View Full Code Here

                closeCuratorProjection(projection);
                return true;
            }
            else
            {
                CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
                return entry.closeThing(id);
            }
        }
        catch ( Exception e )
        {
            throw new RpcException(e);
View Full Code Here

    @ThriftMethod
    public OptionalLockProjection acquireLock(CuratorProjection projection, final String path, int maxWaitMs) throws RpcException
    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
            final InterProcessSemaphoreMutex lock = new InterProcessSemaphoreMutex(entry.getClient(), path);
            if ( !lock.acquire(maxWaitMs, TimeUnit.MILLISECONDS) )
            {
                return new OptionalLockProjection();
            }

            Closer closer = new Closer()
            {
                @Override
                public void close()
                {
                    if ( lock.isAcquiredInThisProcess() )
                    {
                        try
                        {
                            lock.release();
                        }
                        catch ( Exception e )
                        {
                            log.error("Could not release left-over lock for path: " + path, e);
                        }
                    }
                }
            };
            String id = entry.addThing(lock, closer);
            return new OptionalLockProjection(new LockProjection(id));
        }
        catch ( Exception e )
        {
            throw new RpcException(e);
View Full Code Here

    @ThriftMethod
    public LeaderResult startLeaderSelector(final CuratorProjection projection, final String path, final String participantId, int waitForLeadershipMs) throws RpcException
    {
        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()
View Full Code Here

    @ThriftMethod
    public Collection<RpcParticipant> getLeaderParticipants(CuratorProjection projection, LeaderProjection leaderProjection) throws RpcException
    {
        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
            (
View Full Code Here

    @ThriftMethod
    public boolean isLeader(CuratorProjection projection, LeaderProjection leaderProjection) throws RpcException
    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

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

    @ThriftMethod
    public PathChildrenCacheProjection startPathChildrenCache(final CuratorProjection projection, final String path, boolean cacheData, boolean dataIsCompressed, PathChildrenCacheStartMode startMode) throws RpcException
    {
        try
        {
            final CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            final PathChildrenCache cache = new PathChildrenCache(entry.getClient(), path, cacheData, dataIsCompressed, ThreadUtils.newThreadFactory("PathChildrenCacheResource"));
            cache.start(PathChildrenCache.StartMode.valueOf(startMode.name()));

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

            PathChildrenCacheListener listener = new PathChildrenCacheListener()
            {
                @Override
                public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws RpcException
                {
                    entry.addEvent(new RpcCuratorEvent(new RpcPathChildrenCacheEvent(path, event)));
                }
            };
            cache.getListenable().addListener(listener);

            return new PathChildrenCacheProjection(id);
View Full Code Here

    @ThriftMethod
    public List<RpcChildData> getPathChildrenCacheData(CuratorProjection projection, PathChildrenCacheProjection cacheProjection) throws RpcException
    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            PathChildrenCache pathChildrenCache = CuratorEntry.mustGetThing(entry, cacheProjection.id, PathChildrenCache.class);
            return Lists.transform
            (
                pathChildrenCache.getCurrentData(),
View Full Code Here

    @ThriftMethod
    public RpcChildData getPathChildrenCacheDataForPath(CuratorProjection projection, PathChildrenCacheProjection cacheProjection, String path) throws RpcException
    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            PathChildrenCache pathChildrenCache = CuratorEntry.mustGetThing(entry, cacheProjection.id, PathChildrenCache.class);
            return new RpcChildData(pathChildrenCache.getCurrentData(path));
        }
        catch ( Exception e )
View Full Code Here

TOP

Related Classes of org.apache.curator.x.rpc.connections.CuratorEntry

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.