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


Java WatchedEvent.getPath方法代码示例

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


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

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

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

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

示例4: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
    if (KeeperState.Expired == event.getState()) {
        // It's all over
        LOG.error("Lost session");
        System.exit(4);
    }
    if (event.getPath() != null && event.getPath().equals(assignmentsNode)) {
        // children have changed, so read in the new list
        zk.getChildren(assignmentsNode, true, this, null);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:12,代码来源:InstanceContainer.java

示例5: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
/**
 * Watcher callback
 */
public void process(WatchedEvent event) {
  String path = event.getPath();
  if (event.getType() == Event.EventType.None) {
    // We are are being told that the state of the
    // connection has changed
    switch (event.getState()) {
      case SyncConnected:
        // In this particular example we don't need to do anything
        // here - watches are automatically re-registered with
        // server and any watches triggered while the client was
        // disconnected will be delivered (in order of course)
        onZooKeeperReconnected();
        break;
      case Expired:
        // It's all over
        onZooKeeperSessionClosed();
        break;

      // It's all over
      case Disconnected:
        onZooKeeperDisconnected();
        break;
    }
  } else {
    if (path != null && path.equals(getZNodePath())) {
      // Something has changed on the node, let's find out
      checkZNodeExistsAsync();
    }
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:34,代码来源:ZkDataMonitor.java

示例6: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
    logger.debug("Received event: " + event);
    _zookeeperEventThread = Thread.currentThread();

    boolean stateChanged = event.getPath() == null;
    boolean znodeChanged = event.getPath() != null;
    boolean dataChanged = event.getType() == EventType.NodeDataChanged || //
                    event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || //
                    event.getType() == EventType.NodeChildrenChanged;

    getEventLock().lock();
    try {

        // We might have to install child change event listener if a new node was created
        if (getShutdownTrigger()) {
            logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
            return;
        }
        if (stateChanged) {
            processStateChanged(event);
        }
        if (dataChanged) {
            processDataOrChildChange(event);
        }
    } finally {
        if (stateChanged) {
            getEventLock().getStateChangedCondition().signalAll();

            // If the session expired we have to signal all conditions, because watches might have been removed and
            // there is no guarantee that those
            // conditions will be signaled at all after an Expired event
            if (event.getState() == KeeperState.Expired) {
                getEventLock().getZNodeEventCondition().signalAll();
                getEventLock().getDataChangedCondition().signalAll();
                // We also have to notify all listeners that something might have changed
                fireAllEvents();
            }
        }
        if (znodeChanged) {
            getEventLock().getZNodeEventCondition().signalAll();
        }
        if (dataChanged) {
            getEventLock().getDataChangedCondition().signalAll();
        }
        getEventLock().unlock();
        logger.debug("Leaving process event");
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:49,代码来源:ZkClient.java

示例7: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
    if (event.getPath() != null && event.getPath().equals("/simpleCase")) {
        zk.getData("/simpleCase", true, this, null);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:SimpleClient.java

示例8: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
    System.out.println("latch:" + path + " " + event.getPath());
    this.eventPath = event.getPath();
    latch.countDown();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:6,代码来源:ChrootTest.java

示例9: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public void process(final WatchedEvent p_event) {
    String path;
    String prefix;

    List<String> children;
    short nodeID;
    NodeRole role;
    String node;
    String[] splits;

    if (!m_shutdown) {
        if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
            // #if LOGGER >= ERROR
            LOGGER.error("ZooKeeper state expired");
            // #endif /* LOGGER >= ERROR */
        } else {
            try {
                path = p_event.getPath();
                prefix = m_zookeeper.getPath() + '/';
                while (m_isStarting) {
                    try {
                        Thread.sleep(100);
                    } catch (final InterruptedException ignored) {
                    }
                }
                if (path != null) {
                    if (path.equals(prefix + "nodes/new")) {

                        children = m_zookeeper.getChildren("nodes/new", this);
                        for (String child : children) {
                            nodeID = Short.parseShort(child);
                            node = new String(zookeeperGetData("nodes/new/" + nodeID));
                            splits = node.split(":");

                            role = NodeRole.toNodeRole(splits[2]);

                            m_nodes.addNode(nodeID, new NodeEntry(new IPV4Unit(splits[0], Integer.parseInt(splits[1])), (short) 0, (short) 0, role, false));
                        }
                    }
                }
            } catch (final ZooKeeperException e) {
                // #if LOGGER >= ERROR
                LOGGER.error("Could not access ZooKeeper", e);
                // #endif /* LOGGER >= ERROR */
            }
        }
    }
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:50,代码来源:ZookeeperBootComponent.java

示例10: process

import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
    LOG.debug("Received event: " + event);
    _zookeeperEventThread = Thread.currentThread();

    boolean stateChanged = event.getPath() == null;
    boolean znodeChanged = event.getPath() != null;
    boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
                          || event.getType() == EventType.NodeCreated
                          || event.getType() == EventType.NodeChildrenChanged;

    getEventLock().lock();
    try {

        // We might have to install child change event listener if a new node was created
        if (getShutdownTrigger()) {
            LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath()
                      + "}' since shutdown triggered");
            return;
        }
        if (stateChanged) {
            processStateChanged(event);
        }
        if (dataChanged) {
            processDataOrChildChange(event);
        }
    } finally {
        if (stateChanged) {
            getEventLock().getStateChangedCondition().signalAll();

            // If the session expired we have to signal all conditions, because watches might have been removed and
            // there is no guarantee that those
            // conditions will be signaled at all after an Expired event
            // TODO PVo write a test for this
            if (event.getState() == KeeperState.Expired) {
                getEventLock().getZNodeEventCondition().signalAll();
                getEventLock().getDataChangedCondition().signalAll();
                // We also have to notify all listeners that something might have changed
                fireAllEvents();
            }
        }
        if (znodeChanged) {
            getEventLock().getZNodeEventCondition().signalAll();
        }
        if (dataChanged) {
            getEventLock().getDataChangedCondition().signalAll();
        }
        getEventLock().unlock();
        LOG.debug("Leaving process event");
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:51,代码来源:ZkClientx.java

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


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