use of org.apache.helix.zookeeper.zkclient.ZkConnection in project helix by apache.
the class ZkTestBase method simulateSessionExpiry.
protected void simulateSessionExpiry(HelixZkClient client) throws IOException, InterruptedException, IOException {
ZkClient zkClient = (ZkClient) client;
IZkStateListener listener = new IZkStateListener() {
@Override
public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
LOG.info("In Old connection, state changed:" + state);
}
@Override
public void handleNewSession(final String sessionId) throws Exception {
LOG.info("In Old connection, new session: {}.", sessionId);
}
@Override
public void handleSessionEstablishmentError(Throwable var1) throws Exception {
}
};
zkClient.subscribeStateChanges(listener);
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper oldZookeeper = connection.getZookeeper();
LOG.info("Old sessionId = " + oldZookeeper.getSessionId());
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("In New connection, process event:" + event);
}
};
ZooKeeper newZookeeper = new ZooKeeper(connection.getServers(), oldZookeeper.getSessionTimeout(), watcher, oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
LOG.info("New sessionId = " + newZookeeper.getSessionId());
// Thread.sleep(3000);
newZookeeper.close();
Thread.sleep(10000);
connection = (ZkConnection) zkClient.getConnection();
oldZookeeper = connection.getZookeeper();
LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}
use of org.apache.helix.zookeeper.zkclient.ZkConnection in project helix by apache.
the class ZkTestHelper method asyncExpireSession.
/**
* expire zk session asynchronously
* @param client
* @throws Exception
*/
public static void asyncExpireSession(RealmAwareZkClient client) throws Exception {
final ZkClient zkClient = (ZkClient) client;
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("Process watchEvent: " + event);
}
};
final ZooKeeper dupZookeeper = new ZooKeeper(connection.getServers(), curZookeeper.getSessionTimeout(), watcher, curZookeeper.getSessionId(), curZookeeper.getSessionPasswd());
// wait until connected, then close
while (dupZookeeper.getState() != States.CONNECTED) {
Thread.sleep(10);
}
dupZookeeper.close();
connection = (ZkConnection) zkClient.getConnection();
curZookeeper = connection.getZookeeper();
// System.err.println("zk: " + oldZookeeper);
LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}
use of org.apache.helix.zookeeper.zkclient.ZkConnection in project helix by apache.
the class ZkTestHelper method disconnectSession.
/**
* Expire current zk session and wait for {@link IZkStateListener#handleNewSession(String)} invoked
* @param client
* @throws Exception
*/
public static void disconnectSession(HelixZkClient client) throws Exception {
final ZkClient zkClient = (ZkClient) client;
IZkStateListener listener = new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
// System.err.println("disconnectSession handleStateChanged. state: " + state);
}
@Override
public void handleNewSession(final String sessionId) throws Exception {
// make sure zkclient is connected again
zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
LOG.info("handleNewSession. sessionId: {}.", sessionId);
}
@Override
public void handleSessionEstablishmentError(Throwable var1) throws Exception {
}
};
zkClient.subscribeStateChanges(listener);
ZkConnection connection = (ZkConnection) zkClient.getConnection();
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("Process watchEvent: " + event);
}
};
final ZooKeeper dupZookeeper = new ZooKeeper(connection.getServers(), curZookeeper.getSessionTimeout(), watcher, curZookeeper.getSessionId(), curZookeeper.getSessionPasswd());
// wait until connected, then close
while (dupZookeeper.getState() != States.CONNECTED) {
Thread.sleep(10);
}
dupZookeeper.close();
connection = (ZkConnection) zkClient.getConnection();
curZookeeper = connection.getZookeeper();
zkClient.unsubscribeStateChanges(listener);
// System.err.println("zk: " + oldZookeeper);
LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}
use of org.apache.helix.zookeeper.zkclient.ZkConnection in project helix by apache.
the class ZkTestHelper method asyncExpireSession.
/**
* expire zk session asynchronously
* @param client
* @throws Exception
*/
public static void asyncExpireSession(RealmAwareZkClient client) throws Exception {
final ZkClient zkClient = (ZkClient) client;
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("Process watchEvent: " + event);
}
};
final ZooKeeper dupZookeeper = new ZooKeeper(connection.getServers(), curZookeeper.getSessionTimeout(), watcher, curZookeeper.getSessionId(), curZookeeper.getSessionPasswd());
// wait until connected, then close
while (dupZookeeper.getState() != States.CONNECTED) {
Thread.sleep(10);
}
dupZookeeper.close();
connection = (ZkConnection) zkClient.getConnection();
curZookeeper = connection.getZookeeper();
// System.err.println("zk: " + oldZookeeper);
LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}
use of org.apache.helix.zookeeper.zkclient.ZkConnection in project helix by apache.
the class ZkTestHelper method disconnectSession.
/**
* Expire current zk session and wait for {@link IZkStateListener#handleNewSession(String)} invoked
* @param client
* @throws Exception
*/
public static void disconnectSession(HelixZkClient client) throws Exception {
final ZkClient zkClient = (ZkClient) client;
IZkStateListener listener = new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
// System.err.println("disconnectSession handleStateChanged. state: " + state);
}
@Override
public void handleNewSession(final String sessionId) throws Exception {
// make sure zkclient is connected again
zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
LOG.info("handleNewSession. sessionId: {}.", sessionId);
}
@Override
public void handleSessionEstablishmentError(Throwable var1) throws Exception {
}
};
zkClient.subscribeStateChanges(listener);
ZkConnection connection = (ZkConnection) zkClient.getConnection();
ZooKeeper curZookeeper = connection.getZookeeper();
LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("Process watchEvent: " + event);
}
};
final ZooKeeper dupZookeeper = new ZooKeeper(connection.getServers(), curZookeeper.getSessionTimeout(), watcher, curZookeeper.getSessionId(), curZookeeper.getSessionPasswd());
// wait until connected, then close
while (dupZookeeper.getState() != States.CONNECTED) {
Thread.sleep(10);
}
dupZookeeper.close();
connection = (ZkConnection) zkClient.getConnection();
curZookeeper = connection.getZookeeper();
zkClient.unsubscribeStateChanges(listener);
// System.err.println("zk: " + oldZookeeper);
LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}
Aggregations