use of org.apache.zookeeper.Watcher.Event.KeeperState in project lucene-solr by apache.
the class ConnectionManager method process.
@Override
public void process(WatchedEvent event) {
if (event.getState() == AuthFailed || event.getState() == Disconnected || event.getState() == Expired) {
log.warn("Watcher {} name: {} got event {} path: {} type: {}", this, name, event, event.getPath(), event.getType());
} else {
log.debug("Watcher {} name: {} got event {} path: {} type: {}", this, name, event, event.getPath(), event.getType());
}
if (isClosed) {
log.debug("Client->ZooKeeper status change trigger but we are already closed");
return;
}
KeeperState state = event.getState();
if (state == KeeperState.SyncConnected) {
connected();
connectionStrategy.connected();
} else if (state == Expired) {
// we don't call disconnected here, because we know we are expired
connected = false;
likelyExpiredState = LikelyExpiredState.EXPIRED;
log.warn("Our previous ZooKeeper session was expired. Attempting to reconnect to recover relationship with ZooKeeper...");
if (beforeReconnect != null) {
try {
beforeReconnect.command();
} catch (Exception e) {
log.warn("Exception running beforeReconnect command", e);
}
}
do {
// try again to create a new connection.
try {
connectionStrategy.reconnect(zkServerAddress, client.getZkClientTimeout(), this, new ZkClientConnectionStrategy.ZkUpdate() {
@Override
public void update(SolrZooKeeper keeper) {
try {
waitForConnected(Long.MAX_VALUE);
} catch (Exception e1) {
closeKeeper(keeper);
throw new RuntimeException(e1);
}
log.info("Connection with ZooKeeper reestablished.");
try {
client.updateKeeper(keeper);
} catch (InterruptedException e) {
closeKeeper(keeper);
Thread.currentThread().interrupt();
// we must have been asked to stop
throw new RuntimeException(e);
} catch (Exception t) {
closeKeeper(keeper);
throw new RuntimeException(t);
}
if (onReconnect != null) {
onReconnect.command();
}
}
});
break;
} catch (Exception e) {
SolrException.log(log, "", e);
log.info("Could not connect due to error, sleeping for 5s and trying agian");
waitSleep(1000);
}
} while (!isClosed);
log.info("Connected:" + connected);
} else if (state == KeeperState.Disconnected) {
log.warn("zkClient has disconnected");
disconnected();
connectionStrategy.disconnected();
} else if (state == KeeperState.AuthFailed) {
log.warn("zkClient received AuthFailed");
}
}
use of org.apache.zookeeper.Watcher.Event.KeeperState in project zookeeper by apache.
the class ClientCnxn method queueEvent.
void queueEvent(String clientPath, int err, Set<Watcher> materializedWatchers, EventType eventType) {
KeeperState sessionState = KeeperState.SyncConnected;
if (KeeperException.Code.SESSIONEXPIRED.intValue() == err || KeeperException.Code.CONNECTIONLOSS.intValue() == err) {
sessionState = Event.KeeperState.Disconnected;
}
WatchedEvent event = new WatchedEvent(eventType, sessionState, clientPath);
eventThread.queueEvent(event, materializedWatchers);
}
use of org.apache.zookeeper.Watcher.Event.KeeperState in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEventFromWrapper.
@Test
public void testCreatingWatchedEventFromWrapper() {
// Make sure we can handle any type of correct wrapper
EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
WatchedEvent we;
WatcherEvent wep;
for (EventType et : allTypes) {
for (KeeperState ks : allStates) {
wep = new WatcherEvent(et.getIntValue(), ks.getIntValue(), "blah");
we = new WatchedEvent(wep);
Assert.assertEquals(et, we.getType());
Assert.assertEquals(ks, we.getState());
Assert.assertEquals("blah", we.getPath());
}
}
}
use of org.apache.zookeeper.Watcher.Event.KeeperState in project canal by alibaba.
the class CanalController method start.
public void start() throws Throwable {
logger.info("## start the canal server[{}:{}]", ip, port);
// 创建整个canal的工作节点
final String path = ZookeeperPathUtils.getCanalClusterNode(ip + ":" + port);
initCid(path);
if (zkclientx != null) {
this.zkclientx.subscribeStateChanges(new IZkStateListener() {
public void handleStateChanged(KeeperState state) throws Exception {
}
public void handleNewSession() throws Exception {
initCid(path);
}
});
}
// 优先启动embeded服务
embededCanalServer.start();
// 尝试启动一下非lazy状态的通道
for (Map.Entry<String, InstanceConfig> entry : instanceConfigs.entrySet()) {
final String destination = entry.getKey();
InstanceConfig config = entry.getValue();
// 创建destination的工作节点
if (!embededCanalServer.isStart(destination)) {
// HA机制启动
ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(destination);
if (!config.getLazy() && !runningMonitor.isStart()) {
runningMonitor.start();
}
}
if (autoScan) {
instanceConfigMonitors.get(config.getMode()).register(destination, defaultAction);
}
}
if (autoScan) {
instanceConfigMonitors.get(globalInstanceConfig.getMode()).start();
for (InstanceConfigMonitor monitor : instanceConfigMonitors.values()) {
if (!monitor.isStart()) {
monitor.start();
}
}
}
// 启动网络接口
canalServer.start();
}
use of org.apache.zookeeper.Watcher.Event.KeeperState in project pinpoint by naver.
the class ZookeeperUtils method isDisconnectedEvent.
public static boolean isDisconnectedEvent(WatchedEvent event) {
KeeperState state = event.getState();
EventType eventType = event.getType();
return isDisconnectedEvent(state, eventType);
}
Aggregations