當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。