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


Java EventType類代碼示例

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


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

示例1: processDataOrChildChange

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
    final String path = event.getPath();

    if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated || event.getType() == EventType.NodeDeleted) {
        Set<IZkChildListener> childListeners = _childListener.get(path);
        if (childListeners != null && !childListeners.isEmpty()) {
            fireChildChangedEvents(path, childListeners);
        }
    }

    if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated) {
        Set<IZkDataListener> listeners = _dataListener.get(path);
        if (listeners != null && !listeners.isEmpty()) {
            fireDataChangedEvents(event.getPath(), listeners);
        }
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:18,代碼來源:ZkClient.java

示例2: setData

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
public Stat setData(String path, byte data[], int version, long zxid,
        long time) throws KeeperException.NoNodeException {
    Stat s = new Stat();
    DataNode n = nodes.get(path);
    if (n == null) {
        throw new KeeperException.NoNodeException();
    }
    byte lastdata[] = null;
    synchronized (n) {
        lastdata = n.data;
        n.data = data;
        n.stat.setMtime(time);
        n.stat.setMzxid(zxid);
        n.stat.setVersion(version);
        n.copyStat(s);
    }
    // now update if the path is in a quota subtree.
    String lastPrefix;
    if((lastPrefix = getMaxPrefixWithQuota(path)) != null) {
      this.updateBytes(lastPrefix, (data == null ? 0 : data.length)
          - (lastdata == null ? 0 : lastdata.length));
    }
    dataWatches.triggerWatch(path, EventType.NodeDataChanged);
    return s;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:26,代碼來源:DataTree.java

示例3: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
@Override
public void process(WatchedEvent event) {
	ZooKeeper zkClient = zookeeperConnManager.getZkClient();
	try {
		/* 重新注冊節點 */
		zkClient.exists(nodePath, this);
		EventType eventType = event.getType();
		switch (eventType) {
		case NodeDeleted:
			election();
			break;
		default:
			break;
		}
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:19,代碼來源:MasterElection.java

示例4: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
@Override
public void process(WatchedEvent event) {
	ZooKeeper zkClient = zookeeperConnManager.getZkClient();
	try {
		/* 重新注冊節點 */
		List<String> childrens = zkClient.getChildren(nodePath, this);
		EventType eventType = event.getType();
		switch (eventType) {
		case NodeChildrenChanged:
			log.info("當前注冊中心內的成功注冊的agent數量-->"
					+ childrens.stream().filter(children -> children.startsWith("agent")).count());
			break;
		default:
			break;
		}
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:20,代碼來源:WatchAgents.java

示例5: testNodeCreated

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
@Test
public void testNodeCreated() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test1-created";

    zk1.exists(path, watcher);
    qu.shutdown(1);
    zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeCreated);

    qu.shutdownAll();
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:22,代碼來源:WatchEventWhenAutoReset.java

示例6: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
public void process(WatchedEvent event) {
    if (event.getState() == KeeperState.SyncConnected) {
        if (latch != null) {
            latch.countDown();
        }
    }

    if (event.getType() == EventType.None) {
        return;
    }
    try {
        events.put(event);
    } catch (InterruptedException e) {
        Assert.assertTrue("interruption unexpected", false);
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:17,代碼來源:WatcherFuncTest.java

示例7: testNodeChildrenChanged

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
@Test
public void testNodeChildrenChanged() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test-children-changed";

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.getChildren(path, watcher);
    qu.shutdown(1);
    zk2.create(path + "/children-1", new byte[2],
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeChildrenChanged);

    qu.shutdownAll();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:24,代碼來源:WatchEventWhenAutoReset.java

示例8: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
public void process(WatchedEvent event) {
    if (!closed) {
        try {
            if (event.getType() != EventType.NodeDeleted) {

                Stat s = zooKeeper.exists(nodePath, this);
                if (s != null) {
                    zookeeper.getChildren(nodePath, this);
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occured re-adding node watcherfor node "
                            + nodePath, e);
        }
        nodeListener.processEvent(event.getPath(), event.getType()
                .name(), null);
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:20,代碼來源:ZooInspectorManagerImpl.java

示例9: processDataOrChildChange

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
    final String path = event.getPath();

    if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated
        || event.getType() == EventType.NodeDeleted) {
        Set<IZkChildListener> childListeners = _childListener.get(path);
        if (childListeners != null && !childListeners.isEmpty()) {
            fireChildChangedEvents(path, childListeners);
        }
    }

    if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
        || event.getType() == EventType.NodeCreated) {
        Set<IZkDataListener> listeners = _dataListener.get(path);
        if (listeners != null && !listeners.isEmpty()) {
            fireDataChangedEvents(event.getPath(), listeners);
        }
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:20,代碼來源:ZkClientx.java

示例10: queueEvent

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
private void queueEvent(WatchedEvent event,
        Set<Watcher> materializedWatchers) {
    if (event.getType() == EventType.None
            && sessionState == event.getState()) {
        return;
    }
    sessionState = event.getState();
    final Set<Watcher> watchers;
    if (materializedWatchers == null) {
        // materialize the watchers based on the event
        watchers = watcher.materialize(event.getState(),
                event.getType(), event.getPath());
    } else {
        watchers = new HashSet<Watcher>();
        watchers.addAll(materializedWatchers);
    }
    WatcherSetEventPair pair = new WatcherSetEventPair(watchers, event);
    // queue the pair (watch set & event) for later processing
    waitingEvents.add(pair);
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:21,代碼來源:ClientCnxn.java

示例11: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
public void process(WatchedEvent event) {
    if (!closed) {
        try {
            if (event.getType() != EventType.NodeDeleted) {

                Stat s = zooKeeper.exists(nodePath, this);
                if (s != null) {
                    zookeeper.getChildren(nodePath, this);
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occurred re-adding node watcherfor node "
                            + nodePath, e);
        }
        nodeListener.processEvent(event.getPath(), event.getType()
                .name(), null);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:20,代碼來源:ZooInspectorManagerImpl.java

示例12: testRemoveNodeChildrenChangedWatches

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
/**
 * Test verifies deletion of NodeChildrenChanged watches
 */
@Test(timeout = 30000)
public void testRemoveNodeChildrenChangedWatches() throws Exception {
    List<EventType> expectedEvents = new ArrayList<Watcher.Event.EventType>();
    expectedEvents.add(EventType.ChildWatchRemoved);
    MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1);

    zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    LOG.info("Adding child changed watcher");
    zk.getChildren("/testnode1", myWatcher);

    String cmdstring = "removewatches /testnode1 -c";
    LOG.info("Remove watchers using shell command : {}", cmdstring);
    zkMain.cl.parseCommand(cmdstring);
    Assert.assertTrue("Removewatches cmd fails to remove child watches",
            zkMain.processZKCmd(zkMain.cl));
    myWatcher.matches();
    Assert.assertEquals(
            "Failed to remove child watches : " + zk.getChildWatches(), 0,
            zk.getChildWatches().size());
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:25,代碼來源:RemoveWatchesCmdTest.java

示例13: processDataOrChildChange

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
	final String path = event.getPath();

	if (event.getType() == EventType.NodeChildrenChanged
			|| event.getType() == EventType.NodeCreated
			|| event.getType() == EventType.NodeDeleted) {
		Set<IZkChildListener> childListeners = _childListener.get(path);
		if (childListeners != null && !childListeners.isEmpty()) {
			fireChildChangedEvents(path, childListeners);
		}
	}

	if (event.getType() == EventType.NodeDataChanged
			|| event.getType() == EventType.NodeDeleted
			|| event.getType() == EventType.NodeCreated) {
		Set<IZkDataListener> listeners = _dataListener.get(path);
		if (listeners != null && !listeners.isEmpty()) {
			fireDataChangedEvents(event.getPath(), listeners);
		}
	}
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:22,代碼來源:ZkClient.java

示例14: setData

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
public Stat setData(String path, byte data[], int version, long zxid,
        long time) throws KeeperException.NoNodeException {
    Stat s = new Stat();
    DataNodeV1 n = nodes.get(path);
    if (n == null) {
        throw new KeeperException.NoNodeException();
    }
    synchronized (n) {
        n.data = data;
        n.stat.setMtime(time);
        n.stat.setMzxid(zxid);
        n.stat.setVersion(version);
        n.copyStat(s);
    }
    dataWatches.triggerWatch(path, EventType.NodeDataChanged);
    return s;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:18,代碼來源:DataTreeV1.java

示例15: process

import org.apache.zookeeper.Watcher.Event.EventType; //導入依賴的package包/類
@Override
public void process(WatchedEvent event) {
    if (event.getType() == EventType.NodeDataChanged) {
        synchronized(this) {
            changed = true;
            notifyAll();
        }
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:10,代碼來源:Zab1_0Test.java


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