本文整理汇总了Java中org.apache.curator.framework.state.ConnectionState类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState类的具体用法?Java ConnectionState怎么用?Java ConnectionState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionState类属于org.apache.curator.framework.state包,在下文中一共展示了ConnectionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMetricsCacheLocation
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public ListenableFuture<Boolean> setMetricsCacheLocation(
TopologyMaster.MetricsCacheLocation location,
String topologyName) {
client.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework arg0, ConnectionState arg1) {
if (arg1 != ConnectionState.CONNECTED) {
// if not the first time successful connection, fail fast
throw new RuntimeException("Unexpected state change to: " + arg1.name());
}
}
});
return createNode(
StateLocation.METRICSCACHE_LOCATION, topologyName, location.toByteArray(), true);
}
示例2: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.CONNECTED) {
isConnected.set(true);
if (!isFirstConnection.get()) {
for (ConnectionStateListener listener : listenerStateProxy.getListeners()) {
listener.stateChanged(client, ConnectionState.RECONNECTED);
}
}
return;
}
if (newState == ConnectionState.LOST) {
isConnected.set(false);
isFirstConnection.set(false);
retryConnection();
}
}
示例3: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* This implementation is done in parallel because some listeners can hang the thread for a few minutes
* while waiting for the others.
* @param client
* @param newState
*/
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (this.client instanceof RedirectorCuratorFramework) {
if (((RedirectorCuratorFramework) this.client).getConnection().equals(client)) {
currentConnectionState = newState;
}
} else {
if (this.client.equals(client)) {
currentConnectionState = newState;
}
}
Metrics.reportConnectionState(newState.name());
connectionListeners.forEach(listener ->
listenerParallelRunner.submit(
(Runnable) () -> listener.stateChanged(getConnectorState(newState))));
}
示例4: CuratorZookeeperClient
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
public CuratorZookeeperClient(URL url) {
super(url);
try {
Builder builder = CuratorFrameworkFactory.builder()
.connectString(url.getBackupAddress())
.retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
.connectionTimeoutMs(5000);
String authority = url.getAuthority();
if (authority != null && authority.length() > 0) {
builder = builder.authorization("digest", authority.getBytes());
}
client = builder.build();
client.getConnectionStateListenable().addListener((client, state) -> {
if (state == ConnectionState.LOST) {
CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED);
} else if (state == ConnectionState.CONNECTED) {
CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED);
} else if (state == ConnectionState.RECONNECTED) {
CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
}
});
client.start();
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例5: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* some state make effect to the lock, we have to handle it.
*
* @param client curator
* @param newState the state of connection to the io.vertx.spi.cluster.impl.zookeeper.zookeeper.
*/
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
switch (newState) {
case LOST:
//release locks and clean locks
locks.values().stream().forEach(ZKLock::release);
locks.clear();
break;
case SUSPENDED:
//just release locks on this node.
locks.values().stream().forEach(ZKLock::release);
break;
case RECONNECTED:
break;
}
}
示例6: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
switch (newState) {
case LOST:
case SUSPENDED:
Collection<InterProcessMutex> oldLocks = new ArrayList<>(locks.values());
locks.clear();
oldLocks.stream().parallel().forEach(lock -> {
try {
lock.release();
} catch (Exception e) {
logger.trace("Can't release lock on " + newState);
}
});
break;
default:
}
}
示例7: destroy
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void destroy() {
if (connectionState == ConnectionState.CONNECTED) {
for (ServiceDescription service : services.values()) {
String path = pathForProvider(service.getName(), service.getId());
try {
client.delete().forPath(path);
} catch (Exception ignore) {
// ignore
}
}
}
services.clear();
client.getConnectionStateListenable().removeListener(connectionStateListener);
client.close();
}
示例8: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
*/
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
SimpleLogger.log("ZK Connection State Change to [%s]", newState.name());
connected.set(newState.isConnected());
switch(newState) {
case CONNECTED:
registerPending();
dropConnectLatches();
break;
case LOST:
setAllPending();
break;
case READ_ONLY:
break;
case RECONNECTED:
registerPending();
dropConnectLatches();
break;
case SUSPENDED:
break;
default:
break;
}
}
示例9: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
*/
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
log.info("ZK Connection State Change to [{}]", newState.name());
connected.set(newState.isConnected());
switch(newState) {
case CONNECTED:
registerPending();
break;
case LOST:
setAllPending();
break;
case READ_ONLY:
break;
case RECONNECTED:
registerPending();
break;
case SUSPENDED:
break;
default:
break;
}
}
示例10: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
*/
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
log.info("ZK Connection State Change to [{}]", newState.name());
connected.set(newState.isConnected());
switch(newState) {
case CONNECTED:
sendNotification(new Notification(NOTIF_SERVICE_CONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener connected to Zookeeper at [" + zkConnect + "]"));
break;
case LOST:
final int lostEndpoints = registered.size();
registered.clear();
sendNotification(new Notification(NOTIF_SERVICE_DISCONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener lost connection to Zookeeper [" + zkConnect + "]. Lost [" + lostEndpoints + "] endpoints"));
break;
case READ_ONLY:
break;
case RECONNECTED:
sendNotification(new Notification(NOTIF_SERVICE_RECONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener re-connected to Zookeeper at [" + zkConnect + "]"));
break;
case SUSPENDED:
break;
default:
break;
}
}
示例11: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
*/
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
final ConnectionState cs = cfState.getAndSet(newState);
log.info("cfState transition: [{}] --> [{}]", cs, newState);
switch(newState) {
case CONNECTED:
break;
case LOST:
break;
case READ_ONLY:
break;
case RECONNECTED:
break;
case SUSPENDED:
break;
default:
break;
}
}
示例12: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
logger.debug("StateChanged: {}", newState);
switch (newState) {
case SUSPENDED:
resignLeadership();
break;
case RECONNECTED:
try {
takeLeadership();
} catch (InterruptedException e) {
logger.error("While handling RECONNECTED", e);
}
break;
case LOST:
resignLeadership();
break;
}
}
示例13: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework framework, ConnectionState connectionState) {
switch (connectionState) {
case CONNECTED:
metricUpdater.incZKConnected();
break;
case SUSPENDED:
metricUpdater.incZKSuspended();
break;
case RECONNECTED:
metricUpdater.incZKReconnected();
break;
case LOST:
metricUpdater.incZKConnectionLost();
break;
case READ_ONLY:
// NOTE: Should not be relevant for configserver.
break;
}
}
示例14: stateChanged
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@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();
}
}
}
示例15: getAndIncrement
import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public long getAndIncrement() throws Exception {
while (true) {
ConnectionState connState = connStateListener.getLastState();
if (connState != null) {
throw new IllegalStateException("Connection state: " + connState);
}
VersionedValue<Integer> current = sharedCount.getVersionedValue();
int newCount = current.getValue() + 1;
if (newCount < 0) {
// overflow and wrap around
throw new Exception("Checkpoint counter overflow. ZooKeeper checkpoint counter only supports " +
"checkpoints Ids up to " + Integer.MAX_VALUE);
}
if (sharedCount.trySetCount(current, newCount)) {
return current.getValue();
}
}
}