本文整理了Java中org.I0Itec.zkclient.ZkEventThread
类的一些代码示例,展示了ZkEventThread
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkEventThread
类的具体详情如下:
包路径:org.I0Itec.zkclient.ZkEventThread
类名称:ZkEventThread
暂无
代码示例来源:origin: com.101tec/zkclient
ZkEventThread(String name) {
setDaemon(true);
setName("ZkClient-EventThread-" + getId() + "-" + name);
}
代码示例来源:origin: com.101tec/zkclient
public void send(ZkEvent event) {
if (!isInterrupted()) {
LOG.debug("New event: " + event);
_events.add(event);
}
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
private void fireStateChangedEvent(final KeeperState state) {
for (final IZkStateListener stateListener : _stateListener) {
_eventThread.send(new ZkEvent("State changed to " + state + " sent to " + stateListener) {
@Override
public void run() throws Exception {
stateListener.handleStateChanged(state);
}
});
}
}
代码示例来源:origin: com.101tec/zkclient
@Override
public void run() {
LOG.info("Starting ZkClient event thread.");
try {
while (!isInterrupted()) {
ZkEvent zkEvent = _events.take();
int eventId = _eventId.incrementAndGet();
LOG.debug("Delivering event #" + eventId + " " + zkEvent);
try {
zkEvent.run();
} catch (InterruptedException e) {
interrupt();
} catch (ZkInterruptedException e) {
interrupt();
} catch (Throwable e) {
LOG.error("Error handling event " + zkEvent, e);
}
LOG.debug("Delivering event #" + eventId + " done");
}
} catch (InterruptedException e) {
LOG.info("Terminate ZkClient event thread.");
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
/**
* Close the client.
*
* @throws ZkInterruptedException
*/
public void close() throws ZkInterruptedException {
if (_connection == null) {
return;
}
LOG.debug("Closing ZkClient...");
getEventLock().lock();
try {
setShutdownTrigger(true);
_eventThread.interrupt();
_eventThread.join(2000);
_connection.close();
_connection = null;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
LOG.debug("Closing ZkClient...done");
}
代码示例来源:origin: com.101tec/zkclient
try {
setShutdownTrigger(false);
_eventThread = new ZkEventThread(_connection.getServers());
_eventThread.start();
_connection.connect(watcher);
代码示例来源:origin: com.github.sgroschupf/zkclient
@Override
public void run() {
LOG.info("Starting ZkClient event thread.");
try {
while (!isInterrupted()) {
ZkEvent zkEvent = _events.take();
int eventId = _eventId.incrementAndGet();
LOG.debug("Delivering event #" + eventId + " " + zkEvent);
try {
zkEvent.run();
} catch (InterruptedException e) {
interrupt();
} catch (ZkInterruptedException e) {
interrupt();
} catch (Throwable e) {
LOG.error("Error handling event " + zkEvent, e);
}
LOG.debug("Delivering event #" + eventId + " done");
}
} catch (InterruptedException e) {
LOG.info("Terminate ZkClient event thread.");
}
}
代码示例来源:origin: com.101tec/zkclient
/**
* Close the client.
*
* @throws ZkInterruptedException
*/
public void close() throws ZkInterruptedException {
if (_closed) {
return;
}
LOG.debug("Closing ZkClient...");
getEventLock().lock();
try {
setShutdownTrigger(true);
_eventThread.interrupt();
_eventThread.join(2000);
_connection.close();
_closed = true;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
LOG.debug("Closing ZkClient...done");
}
代码示例来源:origin: com.github.sgroschupf/zkclient
getEventLock().lockInterruptibly();
setShutdownTrigger(false);
_eventThread = new ZkEventThread(_connection.getServers());
_eventThread.start();
_connection.connect(watcher);
代码示例来源:origin: com.github.sgroschupf/zkclient
ZkEventThread(String name) {
setDaemon(true);
setName("ZkClient-EventThread-" + getId() + "-" + name);
}
代码示例来源:origin: com.101tec/zkclient
private void fireStateChangedEvent(final KeeperState state) {
for (final IZkStateListener stateListener : _stateListener) {
_eventThread.send(new ZkEvent("State changed to " + state + " sent to " + stateListener) {
@Override
public void run() throws Exception {
stateListener.handleStateChanged(state);
}
});
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
public void send(ZkEvent event) {
if (!isInterrupted()) {
LOG.debug("New event: " + event);
_events.add(event);
}
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
private void fireNewSessionEvents() {
for (final IZkStateListener stateListener : _stateListener) {
_eventThread.send(new ZkEvent("New session event sent to " + stateListener) {
@Override
public void run() throws Exception {
stateListener.handleNewSession();
}
});
}
}
代码示例来源:origin: com.101tec/zkclient
private void fireNewSessionEvents() {
for (final IZkStateListener stateListener : _stateListener) {
_eventThread.send(new ZkEvent("New session event sent to " + stateListener) {
@Override
public void run() throws Exception {
stateListener.handleNewSession();
}
});
}
}
代码示例来源:origin: com.101tec/zkclient
private void fireSessionEstablishmentError(final Throwable error) {
for (final IZkStateListener stateListener : _stateListener) {
_eventThread.send(new ZkEvent("Session establishment error(" + error + ") sent to " + stateListener) {
@Override
public void run() throws Exception {
stateListener.handleSessionEstablishmentError(error);
}
});
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
for (final IZkDataListener listener : listeners) {
_eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {
@Override
public void run() throws Exception {
// reinstall watch
exists(path, true);
try {
Object data = readData(path, null, true);
listener.handleDataChange(path, data);
} catch (ZkNoNodeException e) {
listener.handleDataDeleted(path);
}
}
});
}
}
代码示例来源:origin: com.101tec/zkclient
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
for (final IZkDataListener listener : listeners) {
_eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {
@Override
public void run() throws Exception {
// reinstall watch
exists(path, true);
try {
Object data = readData(path, null, true);
listener.handleDataChange(path, data);
} catch (ZkNoNodeException e) {
listener.handleDataDeleted(path);
}
}
});
}
}
代码示例来源:origin: com.github.sgroschupf/zkclient
private void fireChildChangedEvents(final String path, Set<IZkChildListener> childListeners) {
try {
// reinstall the watch
for (final IZkChildListener listener : childListeners) {
_eventThread.send(new ZkEvent("Children of " + path + " changed sent to " + listener) {
@Override
public void run() throws Exception {
try {
// if the node doesn't exist we should listen for the root node to reappear
exists(path);
List<String> children = getChildren(path);
listener.handleChildChange(path, children);
} catch (ZkNoNodeException e) {
listener.handleChildChange(path, null);
}
}
});
}
} catch (Exception e) {
LOG.error("Failed to fire child changed event. Unable to getChildren. ", e);
}
}
代码示例来源:origin: com.101tec/zkclient
private void fireChildChangedEvents(final String path, Set<IZkChildListener> childListeners) {
try {
// reinstall the watch
for (final IZkChildListener listener : childListeners) {
_eventThread.send(new ZkEvent("Children of " + path + " changed sent to " + listener) {
@Override
public void run() throws Exception {
try {
// if the node doesn't exist we should listen for the root node to reappear
exists(path);
List<String> children = getChildren(path);
listener.handleChildChange(path, children);
} catch (ZkNoNodeException e) {
listener.handleChildChange(path, null);
}
}
});
}
} catch (Exception e) {
LOG.error("Failed to fire child changed event. Unable to getChildren. ", e);
}
}
内容来源于网络,如有侵权,请联系作者删除!