本文整理汇总了Java中org.apache.zookeeper.KeeperException.SessionExpiredException方法的典型用法代码示例。如果您正苦于以下问题:Java KeeperException.SessionExpiredException方法的具体用法?Java KeeperException.SessionExpiredException怎么用?Java KeeperException.SessionExpiredException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.KeeperException
的用法示例。
在下文中一共展示了KeeperException.SessionExpiredException方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public synchronized void checkSession(long sessionId, Object owner)
throws KeeperException.SessionExpiredException,
KeeperException.SessionMovedException,
KeeperException.UnknownSessionException {
LOG.debug("Checking session 0x" + Long.toHexString(sessionId));
SessionImpl session = sessionsById.get(sessionId);
if (session == null) {
throw new KeeperException.UnknownSessionException();
}
if (session.isClosing()) {
throw new KeeperException.SessionExpiredException();
}
if (session.owner == null) {
session.owner = owner;
} else if (session.owner != owner) {
throw new KeeperException.SessionMovedException();
}
}
示例2: abort
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Override
public void abort(final String msg, Throwable t) {
if (t instanceof KeeperException.SessionExpiredException
&& keepAliveZookeeper != null) {
synchronized (masterAndZKLock) {
if (keepAliveZookeeper != null) {
LOG.warn("This client just lost it's session with ZooKeeper," +
" closing it." +
" It will be recreated next time someone needs it", t);
closeZooKeeperWatcher();
}
}
} else {
if (t != null) {
LOG.fatal(msg, t);
} else {
LOG.fatal(msg);
}
this.aborted = true;
close();
this.closed = true;
}
}
示例3: checkSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
synchronized public void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException {
SessionImpl session = sessionsById.get(sessionId);
if (session == null || session.isClosing()) {
throw new KeeperException.SessionExpiredException();
}
if (session.owner == null) {
session.owner = owner;
} else if (session.owner != owner) {
throw new KeeperException.SessionMovedException();
}
}
示例4: setOwner
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
synchronized public void setOwner(long id, Object owner) throws SessionExpiredException {
SessionImpl session = sessionsById.get(id);
if (session == null || session.isClosing()) {
throw new KeeperException.SessionExpiredException();
}
session.owner = owner;
}
示例5: testAddSessionAfterSessionExpiry
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
* Verify the create session call in the Leader.FinalRequestProcessor after
* the session expiration.
*/
@Test(timeout = 20000)
public void testAddSessionAfterSessionExpiry() throws Exception {
ZooKeeperServer zks = setupSessionTracker();
latch = new CountDownLatch(1);
zks.sessionTracker.addSession(sessionId, sessionTimeout);
SessionTrackerImpl sessionTrackerImpl = (SessionTrackerImpl) zks.sessionTracker;
SessionImpl sessionImpl = sessionTrackerImpl.sessionsById
.get(sessionId);
Assert.assertNotNull("Sessionid:" + sessionId
+ " doesn't exists in sessiontracker", sessionImpl);
// verify the session existence
Object sessionOwner = new Object();
sessionTrackerImpl.checkSession(sessionId, sessionOwner);
// waiting for the session expiry
latch.await(sessionTimeout * 2, TimeUnit.MILLISECONDS);
// Simulating FinalRequestProcessor logic: create session request has
// delayed and now reaches FinalRequestProcessor. Here the leader zk
// will do sessionTracker.addSession(id, timeout)
sessionTrackerImpl.addSession(sessionId, sessionTimeout);
try {
sessionTrackerImpl.checkSession(sessionId, sessionOwner);
Assert.fail("Should throw session expiry exception "
+ "as the session has expired and closed");
} catch (KeeperException.SessionExpiredException e) {
// expected behaviour
}
Assert.assertTrue("Session didn't expired", sessionImpl.isClosing());
Assert.assertFalse("Session didn't expired", sessionTrackerImpl
.touchSession(sessionId, sessionTimeout));
Assert.assertEquals(
"Duplicate session expiry request has been generated", 1,
firstProcessor.getCountOfCloseSessionReq());
}
示例6: checkGlobalSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public void checkGlobalSession(long sessionId, Object owner)
throws KeeperException.SessionExpiredException,
KeeperException.SessionMovedException {
try {
checkSession(sessionId, owner);
} catch (KeeperException.UnknownSessionException e) {
throw new KeeperException.SessionExpiredException();
}
}
示例7: ephemeralCreateMultiOpTest
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void ephemeralCreateMultiOpTest() throws KeeperException, InterruptedException, IOException {
final ZooKeeper zk = createClient();
String data = "test";
String path = "/ephemeralcreatemultiop";
zk.create(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
QuorumZooKeeperServer server = getConnectedServer(zk.getSessionId());
Assert.assertNotNull("unable to find server interlocutor", server);
UpgradeableSessionTracker sessionTracker = (UpgradeableSessionTracker)server.getSessionTracker();
Assert.assertFalse("session already global", sessionTracker.isGlobalSession(zk.getSessionId()));
List<OpResult> multi = null;
try {
multi = zk.multi(Arrays.asList(
Op.setData(path, data.getBytes(), 0),
Op.create(path + "/e", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL),
Op.create(path + "/p", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create(path + "/q", data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)
));
} catch (KeeperException.SessionExpiredException e) {
// the scenario that inspired this unit test
Assert.fail("received session expired for a session promotion in a multi-op");
}
Assert.assertNotNull(multi);
Assert.assertEquals(4, multi.size());
Assert.assertEquals(data, new String(zk.getData(path + "/e", false, null)));
Assert.assertEquals(data, new String(zk.getData(path + "/p", false, null)));
Assert.assertEquals(data, new String(zk.getData(path + "/q", false, null)));
Assert.assertTrue("session not promoted", sessionTracker.isGlobalSession(zk.getSessionId()));
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:34,代码来源:MultiOpSessionUpgradeTest.java
示例8: removeAllQueues
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Override
public void removeAllQueues() {
try {
ZKUtil.deleteNodeRecursively(this.zookeeper, this.myQueuesZnode);
} catch (KeeperException e) {
// if the znode is already expired, don't bother going further
if (e instanceof KeeperException.SessionExpiredException) {
return;
}
this.abortable.abort("Failed to delete replication queues for region server: "
+ this.myQueuesZnode, e);
}
}
示例9: testSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
* This test verifies that when the session id is reused, and the original
* client is disconnected, but not session closed, that the server
* will remove ephemeral nodes created by the original session.
*/
@Test
public void testSession()
throws IOException, InterruptedException, KeeperException
{
DisconnectableZooKeeper zk = createClient();
zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL);
LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
+ " was destroyed!");
// disconnect the client by killing the socket, not sending the
// session disconnect to the server as usual. This allows the test
// to verify disconnect handling
zk.disconnect();
Stat stat = new Stat();
startSignal = new CountDownLatch(1);
zk = new DisconnectableZooKeeper(HOSTPORT, CONNECTION_TIMEOUT,
new MyWatcher("testSession"), zk.getSessionId(),
zk.getSessionPasswd());
startSignal.await();
LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
+ " was created!");
zk.getData("/e", false, stat);
LOG.info("After get data /e");
zk.close();
zk = createClient();
Assert.assertEquals(null, zk.exists("/e", false));
LOG.info("before close zk with session id 0x"
+ Long.toHexString(zk.getSessionId()) + "!");
zk.close();
try {
zk.getData("/e", false, stat);
Assert.fail("Should have received a SessionExpiredException");
} catch(KeeperException.SessionExpiredException e) {}
AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() {
String status = "not done";
public void processResult(int rc, String p, Object c, byte[] b, Stat s) {
synchronized(this) { status = KeeperException.Code.get(rc).toString(); this.notify(); }
}
public String toString() { return status; }
};
zk.getData("/e", false, cb, null);
synchronized(cb) {
if (cb.toString().equals("not done")) {
cb.wait(1000);
}
}
Assert.assertEquals(KeeperException.Code.SESSIONEXPIRED.toString(), cb.toString());
}
示例10: checkGlobalSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
public void checkGlobalSession(long sessionId, Object owner)
throws KeeperException.SessionExpiredException,
KeeperException.SessionMovedException {
throw new UnsupportedOperationException();
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:6,代码来源:UpgradeableSessionTracker.java
示例11: testUpgradeWithEphemeral
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
private void testUpgradeWithEphemeral(boolean testLeader)
throws Exception {
String nodePrefix = "/testUpgrade-"
+ (testLeader ? "leaderTest-" : "followerTest-");
int leaderIdx = qb.getLeaderIndex();
Assert.assertFalse("No leader in quorum?", leaderIdx == -1);
int followerIdx = (leaderIdx + 1) % 5;
int otherFollowerIdx = (leaderIdx + 2) % 5;
int testPeerIdx = testLeader ? leaderIdx : followerIdx;
String hostPorts[] = qb.hostPort.split(",");
CountdownWatcher watcher = new CountdownWatcher();
DisconnectableZooKeeper zk = new DisconnectableZooKeeper(
hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// Create some ephemeral nodes. This should force the session to
// be propagated to the other servers in the ensemble.
for (int i = 0; i < 5; i++) {
zk.create(nodePrefix + i, new byte[0],
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
}
// We should be able to reconnect with the same session id on a
// different server, since it has been propagated.
long localSessionId = zk.getSessionId();
byte[] localSessionPwd = zk.getSessionPasswd().clone();
zk.disconnect();
watcher.reset();
zk = new DisconnectableZooKeeper(
hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher,
localSessionId, localSessionPwd);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// The created ephemeral nodes are still around.
for (int i = 0; i < 5; i++) {
Assert.assertNotNull(zk.exists(nodePrefix + i, null));
}
// When we explicitly close the session, we should not be able to
// reconnect with the same session id
zk.close();
try {
watcher.reset();
zk = new DisconnectableZooKeeper(
hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher,
localSessionId, localSessionPwd);
zk.exists(nodePrefix + "0", null);
Assert.fail("Reconnecting to a closed session ID should fail.");
} catch (KeeperException.SessionExpiredException e) {
}
watcher.reset();
// And the ephemeral nodes will be gone since the session died.
zk = new DisconnectableZooKeeper(
hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
for (int i = 0; i < 5; i++) {
Assert.assertNull(zk.exists(nodePrefix + i, null));
}
}
示例12: checkSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
* Checks whether the SessionTracker is aware of this session, the session
* is still active, and the owner matches. If the owner wasn't previously
* set, this sets the owner of the session.
*
* UnknownSessionException should never been thrown to the client. It is
* only used internally to deal with possible local session from other
* machine
*
* @param sessionId
* @param owner
*/
public void checkSession(long sessionId, Object owner)
throws KeeperException.SessionExpiredException,
KeeperException.SessionMovedException,
KeeperException.UnknownSessionException;
示例13: checkGlobalSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
* Strictly check that a given session is a global session or not
* @param sessionId
* @param owner
* @throws KeeperException.SessionExpiredException
* @throws KeeperException.SessionMovedException
*/
public void checkGlobalSession(long sessionId, Object owner)
throws KeeperException.SessionExpiredException,
KeeperException.SessionMovedException;
示例14: checkSession
import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, SessionMovedException;