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


Java WatchedEvent类代码示例

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


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

示例1: processStateChanged

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
private void processStateChanged(WatchedEvent event) {
    logger.info("zookeeper state changed (" + event.getState() + ")");
    setCurrentState(event.getState());
    if (getShutdownTrigger()) {
        return;
    }
    try {
        fireStateChangedEvent(event.getState());

        if (event.getState() == KeeperState.Expired) {
            reconnect();
            fireNewSessionEvents();
        }
    } catch (final Exception e) {
        throw new RuntimeException("Exception while restarting zk client", e);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:18,代码来源:ZkClient.java

示例2: watchNode

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
private void watchNode(final ZooKeeper zk) {
    try {
        List<String> nodeList = zk.getChildren(Constant.ZK_REGISTRY_PATH, new Watcher() {

            public void process(WatchedEvent event) {
                if (event.getType() == Event.EventType.NodeChildrenChanged) {
                    watchNode(zk);
                }
            }
        });
        List<String> dataList = new ArrayList<>();
        for (String node : nodeList) {
            byte[] bytes = zk.getData(Constant.ZK_REGISTRY_PATH + "/" + node, false, null);
            dataList.add(new String(bytes));
        }
        LOGGER.debug("node data: {}", dataList);
        this.dataList = dataList;

        LOGGER.debug("Service discovery triggered updating connected server node.");
        updateConnectedServer();
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
 
开发者ID:islittlechen,项目名称:lionrpc,代码行数:25,代码来源:ServiceDiscovery.java

示例3: process

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:NettyServerCnxn.java

示例4: connectZooKeeper

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
private static ZooKeeper connectZooKeeper(String ensemble)
    throws IOException, KeeperException, InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);

  ZooKeeper zkc = new ZooKeeper(HOSTPORT, ZK_SESSION_TIMEOUT, new Watcher() {
    public void process(WatchedEvent event) {
      if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
        latch.countDown();
      }
    }
  });
  if (!latch.await(ZK_SESSION_TIMEOUT, TimeUnit.MILLISECONDS)) {
    throw new IOException("Zookeeper took too long to connect");
  }
  return zkc;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestBookKeeperConfiguration.java

示例5: getZooKeeperConnection

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
/**
 * 获取Zookeeper连接
 * @return
 */
public static ZooKeeper getZooKeeperConnection() {
    try {
        // Zookeeper连接闭锁cdl
        final CountDownLatch cdl = new CountDownLatch(1);
        final ZooKeeper zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                if (watchedEvent.getState() == Event.KeeperState.SyncConnected) {
                    // 当连接成功时放开cdl
                    cdl.countDown();
                }
            }
        });
        // cdl阻塞
        cdl.await();
        return zooKeeper;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:jthinking,项目名称:linux-memory-monitor,代码行数:26,代码来源:ServerMonitor.java

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

示例7: process

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
@Override
public void process(WatchedEvent event) {
	try {
		/* 重新注册节点 */
		zkClient.exists(nodePath, this);
		EventType eventType = event.getType();
		switch (eventType) {
		case NodeDeleted:
			createNode();
			break;
		default:
			break;
		}
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:18,代码来源:MasterElection.java

示例8: process

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
@Override
public void process(WatchedEvent event) {
	ZooKeeper zkClient = zookeeperConnManager.getZkClient();
	try {
		/* 重新注册节点 */
		zkClient.exists(nodePath, this);
		EventType eventType = event.getType();
		switch (eventType) {
		case NodeDeleted:
			election();
			break;
		default:
			break;
		}
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:19,代码来源:MasterElection.java

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

示例10: processWatchEvent

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
@Override
public synchronized void processWatchEvent(ZooKeeper zk,
    WatchedEvent event) throws Exception {

  if (forExpire) {
    // a hack... couldn't find a way to trigger expired event.
    WatchedEvent expriredEvent = new WatchedEvent(
        Watcher.Event.EventType.None,
        Watcher.Event.KeeperState.Expired, null);
    super.processWatchEvent(zk, expriredEvent);
    forExpire = false;
    syncBarrier.await();
  } else {
    super.processWatchEvent(zk, event);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestZKRMStateStoreZKClientConnections.java

示例11: process

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
public void process(WatchedEvent event) {
    if (!closed) {
        try {
            if (event.getType() != EventType.NodeDeleted) {

                Stat s = zooKeeper.exists(nodePath, this);
                if (s != null) {
                    zookeeper.getChildren(nodePath, this);
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occured re-adding node watcherfor node "
                            + nodePath, e);
        }
        nodeListener.processEvent(event.getPath(), event.getType()
                .name(), null);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:ZooInspectorManagerImpl.java

示例12: testRootWatchTriggered

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
@Test(timeout = 60000)
public void testRootWatchTriggered() throws Exception {
    class MyWatcher implements Watcher{
        boolean fired=false;
        public void process(WatchedEvent event) {
            if(event.getPath().equals("/"))
                fired=true;
        }
    }
    MyWatcher watcher=new MyWatcher();
    // set a watch on the root node
    dt.getChildren("/", new Stat(), watcher);
    // add a new node, should trigger a watch
    dt.createNode("/xyz", new byte[0], null, 0, dt.getNode("/").stat.getCversion()+1, 1, 1);
    Assert.assertFalse("Root node watch not triggered",!watcher.fired);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:17,代码来源:DataTreeTest.java

示例13: processStateChanged

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
private void processStateChanged(WatchedEvent event) {
    LOG.info("zookeeper state changed (" + event.getState() + ")");
    setCurrentState(event.getState());
    if (getShutdownTrigger()) {
        return;
    }
    try {
        fireStateChangedEvent(event.getState());

        if (event.getState() == KeeperState.Expired) {
            reconnect();
            fireNewSessionEvents();
        }
    } catch (final Exception e) {
        throw new RuntimeException("Exception while restarting zk client", e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:18,代码来源:ZkClientx.java

示例14: process

import org.apache.zookeeper.WatchedEvent; //导入依赖的package包/类
public void process(WatchedEvent event) {
    if (!closed) {
        try {
            if (event.getType() != EventType.NodeDeleted) {

                Stat s = zooKeeper.exists(nodePath, this);
                if (s != null) {
                    zookeeper.getChildren(nodePath, this);
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger().error(
                    "Error occurred re-adding node watcherfor node "
                            + nodePath, e);
        }
        nodeListener.processEvent(event.getPath(), event.getType()
                .name(), null);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:20,代码来源:ZooInspectorManagerImpl.java

示例15: 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:l294265421,项目名称:ZooKeeper,代码行数:17,代码来源:WatcherFuncTest.java


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