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


Java WatchedEvent類代碼示例

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


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

示例1: processStateChanged

import org.apache.zookeeper.WatchedEvent; //導入依賴的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: watchNode

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
private void watchNode(final ZooKeeper zk) {
    try {
        List<String> nodeList = zk.getChildren(Constant.ZK_REGISTRY_PATH, new Watcher() {

            public void process(WatchedEvent event) {
                if (event.getType() == Event.EventType.NodeChildrenChanged) {
                    watchNode(zk);
                }
            }
        });
        List<String> dataList = new ArrayList<>();
        for (String node : nodeList) {
            byte[] bytes = zk.getData(Constant.ZK_REGISTRY_PATH + "/" + node, false, null);
            dataList.add(new String(bytes));
        }
        LOGGER.debug("node data: {}", dataList);
        this.dataList = dataList;

        LOGGER.debug("Service discovery triggered updating connected server node.");
        updateConnectedServer();
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
 
開發者ID:islittlechen,項目名稱:lionrpc,代碼行數:25,代碼來源:ServiceDiscovery.java

示例3: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:23,代碼來源:NettyServerCnxn.java

示例4: connectZooKeeper

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
private static ZooKeeper connectZooKeeper(String ensemble)
    throws IOException, KeeperException, InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);

  ZooKeeper zkc = new ZooKeeper(HOSTPORT, ZK_SESSION_TIMEOUT, new Watcher() {
    public void process(WatchedEvent event) {
      if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
        latch.countDown();
      }
    }
  });
  if (!latch.await(ZK_SESSION_TIMEOUT, TimeUnit.MILLISECONDS)) {
    throw new IOException("Zookeeper took too long to connect");
  }
  return zkc;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestBookKeeperConfiguration.java

示例5: getZooKeeperConnection

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
/**
 * 獲取Zookeeper連接
 * @return
 */
public static ZooKeeper getZooKeeperConnection() {
    try {
        // Zookeeper連接閉鎖cdl
        final CountDownLatch cdl = new CountDownLatch(1);
        final ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
                    // 當連接成功時放開cdl
                    cdl.countDown();
                }
            }
        });
        // cdl阻塞
        cdl.await();
        return zooKeeper;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:jthinking,項目名稱:linux-memory-monitor,代碼行數:26,代碼來源:ServerMonitor.java

示例6: processDataOrChildChange

import org.apache.zookeeper.WatchedEvent; //導入依賴的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

示例7: process

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

示例8: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的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

示例9: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
@Override
public void process(WatchedEvent event) {

    if (isDestroyed()) {
        return;
    }
    
    if (!getZooKeeperConnection().isConnected()) {
        return;
    }

    String eventPath = event.getPath();
    EventType eventType = event.getType();

    Znode znode = getData();
    String path = znode.getPath();

    if (path.equals(eventPath) && eventType.equals(EventType.NodeDeleted)) {
        destroy();
        return;
    }

    processUpdate(event);

    fireDataModelDataChanged();
}
 
開發者ID:baloise,項目名稱:eZooKeeper,代碼行數:27,代碼來源:ZnodeModel.java

示例10: processWatchEvent

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
@Override
public synchronized void processWatchEvent(ZooKeeper zk,
    WatchedEvent event) throws Exception {

  if (forExpire) {
    // a hack... couldn't find a way to trigger expired event.
    WatchedEvent expriredEvent = new WatchedEvent(
        Watcher.Event.EventType.None,
        Watcher.Event.KeeperState.Expired, null);
    super.processWatchEvent(zk, expriredEvent);
    forExpire = false;
    syncBarrier.await();
  } else {
    super.processWatchEvent(zk, event);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestZKRMStateStoreZKClientConnections.java

示例11: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的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

示例12: testRootWatchTriggered

import org.apache.zookeeper.WatchedEvent; //導入依賴的package包/類
@Test(timeout = 60000)
public void testRootWatchTriggered() throws Exception {
    class MyWatcher implements Watcher{
        boolean fired=false;
        public void process(WatchedEvent event) {
            if(event.getPath().equals("/"))
                fired=true;
        }
    }
    MyWatcher watcher=new MyWatcher();
    // set a watch on the root node
    dt.getChildren("/", new Stat(), watcher);
    // add a new node, should trigger a watch
    dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1);
    Assert.assertFalse("Root node watch not triggered",!watcher.fired);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:17,代碼來源:DataTreeTest.java

示例13: processStateChanged

import org.apache.zookeeper.WatchedEvent; //導入依賴的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

示例14: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的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

示例15: process

import org.apache.zookeeper.WatchedEvent; //導入依賴的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:l294265421,項目名稱:ZooKeeper,代碼行數:17,代碼來源:WatcherFuncTest.java


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