當前位置: 首頁>>代碼示例>>Java>>正文


Java KeeperState.Expired方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.Watcher.Event.KeeperState.Expired方法的典型用法代碼示例。如果您正苦於以下問題:Java KeeperState.Expired方法的具體用法?Java KeeperState.Expired怎麽用?Java KeeperState.Expired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.Watcher.Event.KeeperState的用法示例。


在下文中一共展示了KeeperState.Expired方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processStateChanged

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
private void processStateChanged(WatchedEvent event) {
    logger.info("zookeeper state changed (" + event.getState() + ")");
    setCurrentState(event.getState());
    if (getShutdownTrigger()) {
        return;
    }
    try {
        fireStateChangedEvent(event.getState());

        if (event.getState() == KeeperState.Expired) {
            reconnect();
            fireNewSessionEvents();
        }
    } catch (final Exception e) {
        throw new RuntimeException("Exception while restarting zk client", e);
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:18,代碼來源:ZkClient.java

示例2: processStateChanged

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
private void processStateChanged(WatchedEvent event) {
    LOG.info("zookeeper state changed (" + event.getState() + ")");
    setCurrentState(event.getState());
    if (getShutdownTrigger()) {
        return;
    }
    try {
        fireStateChangedEvent(event.getState());

        if (event.getState() == KeeperState.Expired) {
            reconnect();
            fireNewSessionEvents();
        }
    } catch (final Exception e) {
        throw new RuntimeException("Exception while restarting zk client", e);
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:18,代碼來源:ZkClientx.java

示例3: processStateChanged

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
private void processStateChanged(WatchedEvent event) {
	logger.info("zookeeper state changed (" + event.getState() + ")");
	setCurrentState(event.getState());
	if (getShutdownTrigger()) {
           return;
       }
	try {
		fireStateChangedEvent(event.getState());

		if (event.getState() == KeeperState.Expired) {
			reconnect();
			fireNewSessionEvents();
		}
	} catch (final Exception e) {
		throw new RuntimeException("Exception while restarting zk client",
				e);
	}
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:19,代碼來源:ZkClient.java

示例4: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    if (KeeperState.Expired == event.getState()) {
        // It's all over
        LOG.error("Lost session");
        System.exit(4);
    }
    if (event.getPath() != null && event.getPath().equals(assignmentsNode)) {
        // children have changed, so read in the new list
        zk.getChildren(assignmentsNode, true, this, null);
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:12,代碼來源:InstanceContainer.java

示例5: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
@Override
public void process(final WatchedEvent p_event) {
    // #if LOGGER >= ERROR
    if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
        LOGGER.error(getClass().getName(), "ZooKeeper state expired");
    }
    // #endif /* LOGGER >= ERROR */
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:9,代碼來源:ZooKeeperHandler.java

示例6: sessionEvent

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
/**
 * zookeeper 鏈接事件監聽
 *
 * @param connectionLatch 同步鎖
 * @param event           事件
 */
private void sessionEvent(CountDownLatch connectionLatch, WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected) {
        log.info("收到ZK連接成功事件!");
        connectionLatch.countDown();
    } else if (event.getState() == KeeperState.Expired) {
        log.error("會話超時,等待重新建立ZK連接...");
        try {
            reConnection();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    } // Disconnected:Zookeeper會自動處理Disconnected狀態重連
}
 
開發者ID:liuht777,項目名稱:uncode-scheduler,代碼行數:20,代碼來源:ZKManager.java

示例7: testConvertingToEventWrapper

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
@Test
public void testConvertingToEventWrapper() {
    WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
    WatcherEvent wew = we.getWrapper();

    Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
    Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
    Assert.assertEquals("blah", wew.getPath());
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:10,代碼來源:WatchedEventTest.java

示例8: testConvertingToEventWrapper

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
@Test
public void testConvertingToEventWrapper() {
    WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
    WatcherEvent wew = we.getWrapper();
    
    Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
    Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
    Assert.assertEquals("blah", wew.getPath());
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:10,代碼來源:WatchedEventTest.java

示例9: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    logger.debug("Received event: " + event);
    _zookeeperEventThread = Thread.currentThread();

    boolean stateChanged = event.getPath() == null;
    boolean znodeChanged = event.getPath() != null;
    boolean dataChanged = event.getType() == EventType.NodeDataChanged || //
                    event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || //
                    event.getType() == EventType.NodeChildrenChanged;

    getEventLock().lock();
    try {

        // We might have to install child change event listener if a new node was created
        if (getShutdownTrigger()) {
            logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
            return;
        }
        if (stateChanged) {
            processStateChanged(event);
        }
        if (dataChanged) {
            processDataOrChildChange(event);
        }
    } finally {
        if (stateChanged) {
            getEventLock().getStateChangedCondition().signalAll();

            // If the session expired we have to signal all conditions, because watches might have been removed and
            // there is no guarantee that those
            // conditions will be signaled at all after an Expired event
            if (event.getState() == KeeperState.Expired) {
                getEventLock().getZNodeEventCondition().signalAll();
                getEventLock().getDataChangedCondition().signalAll();
                // We also have to notify all listeners that something might have changed
                fireAllEvents();
            }
        }
        if (znodeChanged) {
            getEventLock().getZNodeEventCondition().signalAll();
        }
        if (dataChanged) {
            getEventLock().getDataChangedCondition().signalAll();
        }
        getEventLock().unlock();
        logger.debug("Leaving process event");
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:49,代碼來源:ZkClient.java

示例10: connect

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
public boolean connect(Properties connectionProps) {
    try {
        if (this.zooKeeper == null) {
            String connectString = connectionProps
                    .getProperty(CONNECT_STRING);
            String sessionTimeout = connectionProps
                    .getProperty(SESSION_TIMEOUT);
            String encryptionManager = connectionProps
                    .getProperty(DATA_ENCRYPTION_MANAGER);
            String authScheme = connectionProps
                    .getProperty(AUTH_SCHEME_KEY);
            String authData = connectionProps
                    .getProperty(AUTH_DATA_KEY);

            if (connectString == null || sessionTimeout == null) {
                throw new IllegalArgumentException(
                        "Both connect string and session timeout are required.");
            }
            if (encryptionManager == null) {
                this.encryptionManager = new BasicDataEncryptionManager();
            } else {
                Class<?> clazz = Class.forName(encryptionManager);

                if (Arrays.asList(clazz.getInterfaces()).contains(
                        DataEncryptionManager.class)) {
                    this.encryptionManager = (DataEncryptionManager) Class
                            .forName(encryptionManager).newInstance();
                } else {
                    throw new IllegalArgumentException(
                            "Data encryption manager must implement DataEncryptionManager interface");
                }
            }
            this.connectString = connectString;
            this.sessionTimeout = Integer.valueOf(sessionTimeout);
            this.zooKeeper = new ZooKeeperRetry(connectString, Integer
                    .valueOf(sessionTimeout), new Watcher() {

                public void process(WatchedEvent event) {
                    if (event.getState() == KeeperState.Expired) {
                        connected = false;
                    }
                }
            });
            if (authData != null && authData.length() > 0){
                this.zooKeeper.addAuthInfo(authScheme, authData.getBytes());
            }
            ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10);
            connected = ((ZooKeeperRetry) this.zooKeeper).testConnection();
        }
    } catch (Exception e) {
        connected = false;
        e.printStackTrace();
    }
    if (!connected){
    	disconnect();
    }
    return connected;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:59,代碼來源:ZooInspectorManagerImpl.java

示例11: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
/**
 * Track state - in particular watch for expiration. if it happens for
 * re-creation of the ZK client session
 */
synchronized public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.Expired) {
        close(contextPath);
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:10,代碼來源:ZooKeeperService.java

示例12: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
@Override
public void process(final WatchedEvent p_event) {
    String path;
    String prefix;

    List<String> children;
    short nodeID;
    NodeRole role;
    String node;
    String[] splits;

    if (!m_shutdown) {
        if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
            // #if LOGGER >= ERROR
            LOGGER.error("ZooKeeper state expired");
            // #endif /* LOGGER >= ERROR */
        } else {
            try {
                path = p_event.getPath();
                prefix = m_zookeeper.getPath() + '/';
                while (m_isStarting) {
                    try {
                        Thread.sleep(100);
                    } catch (final InterruptedException ignored) {
                    }
                }
                if (path != null) {
                    if (path.equals(prefix + "nodes/new")) {

                        children = m_zookeeper.getChildren("nodes/new", this);
                        for (String child : children) {
                            nodeID = Short.parseShort(child);
                            node = new String(zookeeperGetData("nodes/new/" + nodeID));
                            splits = node.split(":");

                            role = NodeRole.toNodeRole(splits[2]);

                            m_nodes.addNode(nodeID, new NodeEntry(new IPV4Unit(splits[0], Integer.parseInt(splits[1])), (short) 0, (short) 0, role, false));
                        }
                    }
                }
            } catch (final ZooKeeperException e) {
                // #if LOGGER >= ERROR
                LOGGER.error("Could not access ZooKeeper", e);
                // #endif /* LOGGER >= ERROR */
            }
        }
    }
}
 
開發者ID:hhu-bsinfo,項目名稱:dxram,代碼行數:50,代碼來源:ZookeeperBootComponent.java

示例13: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    LOG.debug("Received event: " + event);
    _zookeeperEventThread = Thread.currentThread();

    boolean stateChanged = event.getPath() == null;
    boolean znodeChanged = event.getPath() != null;
    boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
                          || event.getType() == EventType.NodeCreated
                          || event.getType() == EventType.NodeChildrenChanged;

    getEventLock().lock();
    try {

        // We might have to install child change event listener if a new node was created
        if (getShutdownTrigger()) {
            LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath()
                      + "}' since shutdown triggered");
            return;
        }
        if (stateChanged) {
            processStateChanged(event);
        }
        if (dataChanged) {
            processDataOrChildChange(event);
        }
    } finally {
        if (stateChanged) {
            getEventLock().getStateChangedCondition().signalAll();

            // If the session expired we have to signal all conditions, because watches might have been removed and
            // there is no guarantee that those
            // conditions will be signaled at all after an Expired event
            // TODO PVo write a test for this
            if (event.getState() == KeeperState.Expired) {
                getEventLock().getZNodeEventCondition().signalAll();
                getEventLock().getDataChangedCondition().signalAll();
                // We also have to notify all listeners that something might have changed
                fireAllEvents();
            }
        }
        if (znodeChanged) {
            getEventLock().getZNodeEventCondition().signalAll();
        }
        if (dataChanged) {
            getEventLock().getDataChangedCondition().signalAll();
        }
        getEventLock().unlock();
        LOG.debug("Leaving process event");
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:51,代碼來源:ZkClientx.java

示例14: connect

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
public boolean connect(Properties connectionProps) {
    try {
        if (this.zooKeeper == null) {
            String connectString = connectionProps
                    .getProperty(CONNECT_STRING);
            String sessionTimeout = connectionProps
                    .getProperty(SESSION_TIMEOUT);
            String encryptionManager = connectionProps
                    .getProperty(DATA_ENCRYPTION_MANAGER);
            String authScheme = connectionProps
                    .getProperty(AUTH_SCHEME_KEY);
            String authData = connectionProps
                    .getProperty(AUTH_DATA_KEY);

            if (connectString == null || sessionTimeout == null) {
                throw new IllegalArgumentException(
                        "Both connect string and session timeout are required.");
            }
            if (encryptionManager == null) {
                this.encryptionManager = new BasicDataEncryptionManager();
            } else {
                Class<?> clazz = Class.forName(encryptionManager);

                if (Arrays.asList(clazz.getInterfaces()).contains(
                        DataEncryptionManager.class)) {
                    this.encryptionManager = (DataEncryptionManager) Class
                            .forName(encryptionManager).newInstance();
                } else {
                    throw new IllegalArgumentException(
                            "Data encryption manager must implement DataEncryptionManager interface");
                }
            }
            this.connectString = connectString;
            this.sessionTimeout = Integer.valueOf(sessionTimeout);
            this.zooKeeper = new ZooKeeperRetry(connectString, Integer
                    .valueOf(sessionTimeout), new Watcher() {

                public void process(WatchedEvent event) {
                    if (event.getState() == KeeperState.Expired) {
                        connected = false;
                    }
                }
            });
            if (authData != null && authData.length() > 0){
                this.zooKeeper.addAuthInfo(authScheme, authData.getBytes());
            }
            ((ZooKeeperRetry) this.zooKeeper).setRetryLimit(10);
            connected = ((ZooKeeperRetry) this.zooKeeper).testConnection();
        }
    } catch (Exception e) {
        connected = false;
        e.printStackTrace();
    }
    if (!connected){
    	disconnect();
    } else {
        this.nodesCache = new NodesCache(zooKeeper);
    }
    return connected;
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:61,代碼來源:ZooInspectorManagerImpl.java

示例15: process

import org.apache.zookeeper.Watcher.Event.KeeperState; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
	_zookeeperEventThread = Thread.currentThread();

	boolean stateChanged = event.getPath() == null;
	boolean znodeChanged = event.getPath() != null;
	boolean dataChanged = event.getType() == EventType.NodeDataChanged
			|| event.getType() == EventType.NodeDeleted
			|| event.getType() == EventType.NodeCreated
			|| event.getType() == EventType.NodeChildrenChanged;

	getEventLock().lock();
	try {

		// We might have to install child change event listener if a new
		// node was created
		if (getShutdownTrigger()) {
               logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
               return;
           }
		if (stateChanged) {
			processStateChanged(event);
		}
		if (dataChanged) {
			processDataOrChildChange(event);
		}
	} finally {
		if (stateChanged) {
			getEventLock().getStateChangedCondition().signalAll();

			// If the session expired we have to signal all conditions,
			// because watches might have been removed and
			// there is no guarantee that those
			// conditions will be signaled at all after an Expired event
			// TODO PVo write a test for this
			if (event.getState() == KeeperState.Expired) {
				getEventLock().getZNodeEventCondition().signalAll();
				getEventLock().getDataChangedCondition().signalAll();
				// We also have to notify all listeners that something might
				// have changed
				fireAllEvents();
			}
		}
		if (znodeChanged) {
			getEventLock().getZNodeEventCondition().signalAll();
		}
		if (dataChanged) {
			getEventLock().getDataChangedCondition().signalAll();
		}
		getEventLock().unlock();
		logger.debug("Leaving process event");
	}

}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:55,代碼來源:ZkClient.java


注:本文中的org.apache.zookeeper.Watcher.Event.KeeperState.Expired方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。