当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionState.RECONNECTED属性代码示例

本文整理汇总了Java中org.apache.curator.framework.state.ConnectionState.RECONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState.RECONNECTED属性的具体用法?Java ConnectionState.RECONNECTED怎么用?Java ConnectionState.RECONNECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.curator.framework.state.ConnectionState的用法示例。


在下文中一共展示了ConnectionState.RECONNECTED属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stateChanged

@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    JobScheduleController jobScheduleController = JobRegistry.getInstance().getJobScheduleController(jobName);
    if (ConnectionState.LOST == newState) {
        jobScheduleController.pauseJob();
    } else if (ConnectionState.RECONNECTED == newState) {
        if (!leaderElectionService.hasLeader()) {
            leaderElectionService.leaderElection();
        }
        serverService.persistServerOnline();
        executionService.clearRunningInfo(shardingService.getLocalHostShardingItems());
        if (!serverService.isJobPausedManually()) {
            jobScheduleController.resumeJob();
        }
    }
}
 
开发者ID:artoderk,项目名称:elastic-jobx,代码行数:16,代码来源:JobOperationListenerManager.java

示例2: stateChanged

@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
    if ( (newState == ConnectionState.RECONNECTED) || (newState == ConnectionState.CONNECTED) )
    {
        try
        {
            log.debug("Re-registering due to reconnection");
            reRegisterServices();
        }
        catch (InterruptedException ex)
        {
            Thread.currentThread().interrupt();
        }
        catch ( Exception e )
        {
            log.error("Could not re-register instances after reconnection", e);
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:20,代码来源:ServiceDiscoveryImpl.java

示例3: isConnected

@Override
public boolean isConnected() {
    return client != null && client.isStarted() &&
            currentConnectionState != null &&
            (currentConnectionState == ConnectionState.CONNECTED ||
            currentConnectionState == ConnectionState.RECONNECTED);
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:7,代码来源:ZookeeperConnector.java

示例4: checkConnection

private void checkConnection() throws KeeperException.ConnectionLossException {
    if (client != null &&
            currentConnectionState != null &&
            currentConnectionState != ConnectionState.CONNECTED &&
            currentConnectionState != ConnectionState.RECONNECTED) {

        KeeperException.ConnectionLossException exception = new KeeperException.ConnectionLossException();
        Metrics.reportZookeeperConnectionIssue(exception);
        throw exception;
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:11,代码来源:ZookeeperConnector.java

示例5: KafkaConsumerCache

/**
 * Creates a KafkaConsumerCache object. Before it is used, you must call
 * startCache()
 * 
 * @param apiId
 * @param s
 * @param metrics
 */
public KafkaConsumerCache(String apiId,  MetricsSet metrics) {

	if (apiId == null) {
		throw new IllegalArgumentException("API Node ID must be specified.");
	}

	fApiId = apiId;
//	fSettings = s;
	fMetrics = metrics;
	String strkSetting_ZkBasePath= AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,kSetting_ZkBasePath);
	if(null==strkSetting_ZkBasePath)strkSetting_ZkBasePath = kDefault_ZkBasePath;
	fBaseZkPath = strkSetting_ZkBasePath;

	fConsumers = new ConcurrentHashMap<String, KafkaConsumer>();
	fSweepScheduler = Executors.newScheduledThreadPool(1);

	curatorConsumerCache = null;

	status = Status.NOT_STARTED;

	listener = new ConnectionStateListener() {
		public void stateChanged(CuratorFramework client, ConnectionState newState) {
			if (newState == ConnectionState.LOST) {
				log.info("ZooKeeper connection expired");
				handleConnectionLoss();
			} else if (newState == ConnectionState.READ_ONLY) {
				log.warn("ZooKeeper connection set to read only mode.");
			} else if (newState == ConnectionState.RECONNECTED) {
				log.info("ZooKeeper connection re-established");
				handleReconnection();
			} else if (newState == ConnectionState.SUSPENDED) {
				log.warn("ZooKeeper connection has been suspended.");
				handleConnectionSuspended();
			}
		}
	};
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:45,代码来源:KafkaConsumerCache.java

示例6: stateChanged

@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    if (ConnectionState.LOST == newState) {
        log.info("Connection lost from zookeeper :server=" + serverLists + ", namespace=" + namespace);
    }

    if (ConnectionState.RECONNECTED == newState) {
        log.info("Reconnection from zookeeper :server=" + serverLists + ", namespace=" + namespace);
    }
}
 
开发者ID:artoderk,项目名称:elastic-jobx,代码行数:10,代码来源:ConsoleRegistryCenter.java

示例7: stateChanged

@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    log.info("zookeeper connection state changed.new state:{}", newState);
    if (ConnectionState.RECONNECTED == newState) {
        zookeeperConfigGroup.loadNode();
    }
}
 
开发者ID:ErinDavid,项目名称:elastic-config,代码行数:7,代码来源:ZookeeperListenerManager.java

示例8: stateChanged

@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
    if ( newState == ConnectionState.RECONNECTED )
    {
        reconnected.countDown();
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:8,代码来源:TestLeaderSelectorEdges.java

示例9: stateChanged

/**
 * TODO - figure out how to register this listener
 */
@Override
public void stateChanged(final CuratorFramework client,
        final ConnectionState newState) {
    if (newState == ConnectionState.RECONNECTED) {
        registerAvailability();
    }
}
 
开发者ID:GeneralElectric,项目名称:snowizard-discovery,代码行数:10,代码来源:CuratorAdvertiser.java

示例10: stateChanged

public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
    log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
    connected = connectionState == ConnectionState.CONNECTED || connectionState == ConnectionState.RECONNECTED;
    if (connectionState == ConnectionState.LOST) {
        log.error("Connection to Zookeeper toggled to state " + connectionState.toString());
        this.handleZookeeperConnectionFailed();
    } else if (connectionState == ConnectionState.RECONNECTED) {
        log.info("Reconnected to zookeeper, forcing lock scavenge");
        forceLockScavenge();
    } else {
        log.info("Connection to Zookeeper toggled to state " + connectionState.toString());
    }
}
 
开发者ID:rackerlabs,项目名称:blueflood,代码行数:13,代码来源:ZKShardLockManager.java

示例11: start

@Override
public void start()
{
    log.info("Starting");
    if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) )
    {
        throw new IllegalStateException("Cannot be started more than once");
    }

    try
    {
        connectionStateManager.start(); // ordering dependency - must be called before client.start()

        final ConnectionStateListener listener = new ConnectionStateListener()
        {
            @Override
            public void stateChanged(CuratorFramework client, ConnectionState newState)
            {
                if ( ConnectionState.CONNECTED == newState || ConnectionState.RECONNECTED == newState )
                {
                    logAsErrorConnectionErrors.set(true);
                }
            }
        };

        this.getConnectionStateListenable().addListener(listener);

        client.start();

        executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
        executorService.submit(new Callable<Object>()
        {
            @Override
            public Object call() throws Exception
            {
                backgroundOperationsLoop();
                return null;
            }
        });

        if ( ensembleTracker != null )
        {
            ensembleTracker.start();
        }

        log.info(schemaSet.toDocumentation());
    }
    catch ( Exception e )
    {
        ThreadUtils.checkInterrupted(e);
        handleBackgroundOperationException(null, e);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:53,代码来源:CuratorFrameworkImpl.java

示例12: testDisconnectReconnectWithMultipleClients

@Test
public void testDisconnectReconnectWithMultipleClients() throws Exception
{
    Timing timing = new Timing();
    CuratorFramework curatorFramework1 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(10, 500));
    CuratorFramework curatorFramework2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(10, 500));

    curatorFramework1.start();
    curatorFramework1.checkExists().forPath("/");   // clear initial connect events
    curatorFramework2.start();
    curatorFramework2.checkExists().forPath("/");   // clear initial connect events

    final String sharedCountPath = "/count";
    final int initialCount = 10;
    SharedCount sharedCount1 = new SharedCount(curatorFramework1, sharedCountPath, initialCount);
    SharedCount sharedCountWithFaultyWatcher = createSharedCountWithFaultyWatcher(curatorFramework2, sharedCountPath, initialCount);

    class MySharedCountListener implements SharedCountListener
    {
        final public Phaser gotSuspendEvent = new Phaser(1);
        final public Phaser gotChangeEvent = new Phaser(1);
        final public Phaser getReconnectEvent = new Phaser(1);
        final public AtomicInteger numChangeEvents = new AtomicInteger(0);

        @Override
        public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception
        {
            numChangeEvents.incrementAndGet();
            gotChangeEvent.arrive();
        }

        @Override
        public void stateChanged(CuratorFramework client, ConnectionState newState)
        {
            if (newState == ConnectionState.SUSPENDED) {
                gotSuspendEvent.arrive();
            } else if (newState == ConnectionState.RECONNECTED) {
                getReconnectEvent.arrive();
            }
        }
    }

    MySharedCountListener listener1 = new MySharedCountListener();
    sharedCount1.addListener(listener1);
    sharedCount1.start();
    MySharedCountListener listener2 = new MySharedCountListener();
    sharedCountWithFaultyWatcher.addListener(listener2);

    try
    {
        sharedCount1.setCount(12);
        Assert.assertEquals(listener1.gotChangeEvent.awaitAdvanceInterruptibly(0, timing.seconds(), TimeUnit.SECONDS), 1);
        Assert.assertEquals(sharedCount1.getCount(), 12);

        Assert.assertEquals(sharedCountWithFaultyWatcher.getCount(), 10);
        // new counter with faultyWatcher start
        sharedCountWithFaultyWatcher.start();

        for (int i = 0; i < 10; i++) {
            sharedCount1.setCount(13 + i);
            Assert.assertEquals(sharedCount1.getCount(), 13 + i);

            server.restart();

            Assert.assertEquals(listener2.getReconnectEvent.awaitAdvanceInterruptibly(i, timing.forWaiting().seconds(), TimeUnit.SECONDS), i + 1);
            // CURATOR-311 introduces to Curator's client reading server's shared count value
            // when client's state gets ConnectionState.RECONNECTED. Following tests ensures that.
            Assert.assertEquals(listener2.gotChangeEvent.awaitAdvanceInterruptibly(i, timing.forWaiting().seconds(), TimeUnit.SECONDS), i + 1);
            Assert.assertEquals(sharedCountWithFaultyWatcher.getCount(), 13 + i);
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(sharedCount1);
        CloseableUtils.closeQuietly(curatorFramework1);
        CloseableUtils.closeQuietly(sharedCountWithFaultyWatcher);
        CloseableUtils.closeQuietly(curatorFramework2);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:79,代码来源:TestSharedCount.java

示例13: start

public void start(String nodeName, int port, boolean addShutdownHook, byte[] payload) throws Exception {
    Preconditions.checkArgument(framework.getState() == CuratorFrameworkState.STARTED);
    this.nodeName = nodeName;
    this.port = port;
    this.payload = payload;

    // Register ephemeral node as representation of this service's nodename and port
    // such as /services/myservice/nodes/192.168.1.1:8000
    this.node = baseNode + "/" + nodeName + ":" + port;
    this.listener = new ConnectionStateListener() {
        @Override
        public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
            if (connectionState == ConnectionState.RECONNECTED) {
                log.info("Re-registering with ZK as node {}", node);
                deleteAndCreateNode();
            }
        }
    };

    // Ensure the parent paths exist persistently
    while (framework.checkExists().forPath(baseNode) == null) {
        log.info("Creating base node {}", baseNode);
        framework.create()
                .creatingParentsIfNeeded()
                .withMode(CreateMode.PERSISTENT)
                .forPath(baseNode);
    }

    log.info("Registering with ZK as node {}", node);
    deleteAndCreateNode();

    framework.getConnectionStateListenable().addListener(listener);
    if (addShutdownHook) {
        log.info("Adding shutdown hook for disco service");
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                log.info("Shutting down disco service");
                try {
                    DiscoService.this.stop();
                } catch (Exception e) {
                    log.error("Couldn't stop disco service", e);
                }
            }
        });
    }
}
 
开发者ID:librato,项目名称:disco-java,代码行数:47,代码来源:DiscoService.java

示例14: reconnectedTrigger

public static ConnectionTrigger reconnectedTrigger() {
    return new ConnectionTrigger(ConnectionState.RECONNECTED);
}
 
开发者ID:bazaarvoice,项目名称:curator-extensions,代码行数:3,代码来源:ZooKeeperTest.java


注:本文中的org.apache.curator.framework.state.ConnectionState.RECONNECTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。