当前位置: 首页>>代码示例>>Java>>正文


Java Event.EventType方法代码示例

本文整理汇总了Java中org.apache.zookeeper.Watcher.Event.EventType方法的典型用法代码示例。如果您正苦于以下问题:Java Event.EventType方法的具体用法?Java Event.EventType怎么用?Java Event.EventType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.Watcher.Event的用法示例。


在下文中一共展示了Event.EventType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processWatchEvent

import org.apache.zookeeper.Watcher.Event; //导入方法依赖的package包/类
@VisibleForTesting
@Private
@Unstable
public synchronized void processWatchEvent(ZooKeeper zk,
    WatchedEvent event) throws Exception {
  // only process watcher event from current ZooKeeper Client session.
  if (zk != activeZkClient) {
    LOG.info("Ignore watcher event type: " + event.getType() +
        " with state:" + event.getState() + " for path:" +
        event.getPath() + " from old session");
    return;
  }

  Event.EventType eventType = event.getType();
  LOG.info("Watcher event type: " + eventType + " with state:"
      + event.getState() + " for path:" + event.getPath() + " for " + this);

  if (eventType == Event.EventType.None) {

    // the connection state has changed
    switch (event.getState()) {
      case SyncConnected:
        LOG.info("ZKRMStateStore Session connected");
        if (zkClient == null) {
          // the SyncConnected must be from the client that sent Disconnected
          zkClient = activeZkClient;
          ZKRMStateStore.this.notifyAll();
          LOG.info("ZKRMStateStore Session restored");
        }
        break;
      case Disconnected:
        LOG.info("ZKRMStateStore Session disconnected");
        zkClient = null;
        break;
      case Expired:
        // the connection got terminated because of session timeout
        // call listener to reconnect
        LOG.info("ZKRMStateStore Session expired");
        createConnection();
        break;
      default:
        LOG.error("Unexpected Zookeeper" +
            " watch event state: " + event.getState());
        break;
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:48,代码来源:ZKRMStateStore.java

示例2: processWatchEvent

import org.apache.zookeeper.Watcher.Event; //导入方法依赖的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

示例3: processWatchEvent

import org.apache.zookeeper.Watcher.Event; //导入方法依赖的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;
    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:ict-carch,项目名称:hadoop-plus,代码行数:77,代码来源:ActiveStandbyElector.java

示例4: processWatchEvent

import org.apache.zookeeper.Watcher.Event; //导入方法依赖的package包/类
@VisibleForTesting
@Private
@Unstable
public synchronized void processWatchEvent(WatchedEvent event)
    throws Exception {
  Event.EventType eventType = event.getType();
  LOG.info("Watcher event type: " + eventType + " with state:"
      + event.getState() + " for path:" + event.getPath() + " for " + this);

  if (eventType == Event.EventType.None) {

    // the connection state has changed
    switch (event.getState()) {
      case SyncConnected:
        LOG.info("ZKRMStateStore Session connected");
        if (oldZkClient != null) {
          // the SyncConnected must be from the client that sent Disconnected
          zkClient = oldZkClient;
          oldZkClient = null;
          ZKRMStateStore.this.notifyAll();
          LOG.info("ZKRMStateStore Session restored");
        }
        break;
      case Disconnected:
        LOG.info("ZKRMStateStore Session disconnected");
        oldZkClient = zkClient;
        zkClient = null;
        break;
      case Expired:
        // the connection got terminated because of session timeout
        // call listener to reconnect
        LOG.info("Session expired");
        createConnection();
        break;
      default:
        LOG.error("Unexpected Zookeeper" +
            " watch event state: " + event.getState());
        break;
    }
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:42,代码来源:ZKRMStateStore.java


注:本文中的org.apache.zookeeper.Watcher.Event.EventType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。