当前位置: 首页>>代码示例>>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;未经允许,请勿转载。