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


Java WatchedEvent.getType方法代碼示例

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


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

示例1: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) throws Exception {
    String topicParentPath = zkConf.getZKBasePath() + "/topics";
    LOG.info("get zookeeper notification for path={}", topicParentPath);
    if (event.getType() == Watcher.Event.EventType.NodeChildrenChanged) {
        List<String> newTopics = zkClient.getChildren().forPath(topicParentPath);
        List<String> oldTopics = metadata.getAllTopics();
        Collection<String> addedTopics = CollectionUtils.subtract(newTopics, oldTopics);
        Collection<String> deletedTopics = CollectionUtils.subtract(oldTopics, newTopics);
        for (String topic : addedTopics) {
            String topicPath = topicParentPath + "/" + topic;
            zkClient.getChildren()
                    .usingWatcher(new TopicWatcher(topic))
                    .forPath(topicPath);
            Map<Integer, Integer> queueMap = readTopicInfo(topic);
            metadata.updateTopicMap(topic, queueMap);
        }
        metadata.removeTopics(deletedTopics);
    }
    zkClient.getChildren()
            .usingWatcher(new TopicsWather())
            .forPath(topicParentPath);
}
 
開發者ID:wenweihu86,項目名稱:distmq,代碼行數:24,代碼來源:MetadataManager.java

示例2: 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

示例3: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
	switch (event.getType()) {
	case None:   
		switch (event.getState()) {
		case SyncConnected:
			connected = true;
			break;
		case Disconnected:
			connected = false;
			break;
		default:   
			break;
		}
    	break;
	default:
		break;
	}
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:19,代碼來源:LoadFromLogTest.java

示例4: process

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

示例6: 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:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:17,代碼來源:WatcherFuncTest.java

示例7: 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:luoyaogui,項目名稱:otter-G,代碼行數:20,代碼來源:ZkClientx.java

示例8: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
/**
 * It listen to Zookeeper session events. It is called automatically by Zookeeper when a zookeeper session issues an event.
 *
 * @param event issued by zookeeper session
 * @throws IllegalStateException if {@link ZKClusterWatcher#start()} was not called.
 */
@Override
public void process(final WatchedEvent event) {

    if (zkConnection == null || zkNodeWatchers == null) {
        throw new IllegalStateException("Zookeeper monitoring has not been started.");
    }

    try {
        if (event.getType() == Watcher.Event.EventType.None) {
            switch (event.getState()) {
                case SyncConnected:
                    zkClusterStatus.getAndSet(ZKClusterStatusName.QUORUM);
                    zkMonitorListener.onGetQuorum();
                    zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
                    break;

                case Disconnected:
                    zkClusterStatus.getAndSet(ZKClusterStatusName.NO_QUORUM);
                    zkMonitorListener.onLackOfQuorum();
                    zkNodeWatchers.forEach(zkNodeWatcher -> zkNodeWatcher.updateStatus());
                    break;

                case Expired:
                    zkClusterStatus.set(ZKClusterStatusName.NO_QUORUM);
                    restartZKConnection();
                    break;

                default:
                    break;
            }
        }
    } catch (Exception e) {
        throw new ZKMonitorException(e.getMessage(), e, this.getClass());
    }
}
 
開發者ID:mcafee,項目名稱:management-sdk-for-kafka,代碼行數:42,代碼來源:ZKClusterWatcher.java

示例9: process

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

示例10: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() != Event.EventType.None) {
        try {
            events.put(event);
        } catch (InterruptedException e) {
            LOG.warn("ignoring interrupt during event.put");
        }
    }
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:11,代碼來源:FollowerResyncConcurrencyTest.java

示例11: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
@Override
public void process(WatchedEvent event) {
    super.process(event);
    try {
        if (event.getType() != Event.EventType.None) {
            dataEvents.put(event);
        }
    } catch (InterruptedException e) {
        LOG.warn("ignoring interrupt during EventsWatcher process");
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:12,代碼來源:WatchEventWhenAutoReset.java

示例12: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    System.err.println(event);
    synchronized (this) {
        if (event.getType() == EventType.None) {
            connected = (event.getState() == KeeperState.SyncConnected);
            notifyAll();
        }
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:10,代碼來源:GenerateLoad.java

示例13: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    if (event.getType() == Watcher.Event.EventType.None) {
        synchronized (this) {
            connected = event.getState() == Watcher.Event.KeeperState.SyncConnected;
            notifyAll();
        }
    }
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:9,代碼來源:GenerateLoad.java

示例14: processWatchEvent

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
/**
 * interface implementation of Zookeeper watch events (connection and node),
 * proxied by {@link WatcherWithClientRef}.
 */
synchronized void processWatchEvent(ZooKeeper zk, WatchedEvent event) {
  Event.EventType eventType = event.getType();
  if (isStaleClient(zk)) return;
  LOG.debug("Watcher event type: " + eventType + " with state:"
      + event.getState() + " for path:" + event.getPath()
      + " connectionState: " + zkConnectionState
      + " for " + this);

  if (eventType == Event.EventType.None) {
    // the connection state has changed
    switch (event.getState()) {
    case SyncConnected:
      LOG.info("Session connected.");
      // if the listener was asked to move to safe state then it needs to
      // be undone
      ConnectionState prevConnectionState = zkConnectionState;
      zkConnectionState = ConnectionState.CONNECTED;
      if (prevConnectionState == ConnectionState.DISCONNECTED &&
          wantToBeInElection) {
        monitorActiveStatus();
      }
      break;
    case Disconnected:
      LOG.info("Session disconnected. Entering neutral mode...");

      // ask the app to move to safe state because zookeeper connection
      // is not active and we dont know our state
      zkConnectionState = ConnectionState.DISCONNECTED;
      enterNeutralMode();
      break;
    case Expired:
      // the connection got terminated because of session timeout
      // call listener to reconnect
      LOG.info("Session expired. Entering neutral mode and rejoining...");
      enterNeutralMode();
      reJoinElection(0);
      break;
    case SaslAuthenticated:
      LOG.info("Successfully authenticated to ZooKeeper using SASL.");
      break;
    default:
      fatalError("Unexpected Zookeeper watch event state: "
          + event.getState());
      break;
    }

    return;
  }

  // a watch on lock path in zookeeper has fired. so something has changed on
  // the lock. ideally we should check that the path is the same as the lock
  // path but trusting zookeeper for now
  String path = event.getPath();
  if (path != null) {
    switch (eventType) {
    case NodeDeleted:
      if (state == State.ACTIVE) {
        enterNeutralMode();
      }
      joinElectionInternal();
      break;
    case NodeDataChanged:
      monitorActiveStatus();
      break;
    default:
      LOG.debug("Unexpected node event: " + eventType + " for path: " + path);
      monitorActiveStatus();
    }

    return;
  }

  // some unexpected error has occurred
  fatalError("Unexpected watch error from Zookeeper");
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:80,代碼來源:ActiveStandbyElector.java

示例15: process

import org.apache.zookeeper.WatchedEvent; //導入方法依賴的package包/類
public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() == EventType.None) {
        states.add(event);
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:7,代碼來源:SessionTest.java


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