Java Code Examples for org.apache.curator.framework.recipes.cache.TreeCacheEvent#getType()
The following examples show how to use
org.apache.curator.framework.recipes.cache.TreeCacheEvent#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogSearchConfigZKHelper.java From ambari-logsearch with Apache License 2.0 | 6 votes |
/** * Create listener for znode of log level filters - can be used for Log Feeder as it can be useful if it's monitoring the log level changes * @param clusterName name of the cluster * @param gson object to be used for json serialization * @param logLevelFilterMonitor log level filter monitor object that can be used to do something during znode chagne * @return listener response */ public static TreeCacheListener createTreeCacheListener(String clusterName, Gson gson, LogLevelFilterMonitor logLevelFilterMonitor) { return new TreeCacheListener() { private final Set<TreeCacheEvent.Type> nodeEvents = ImmutableSet.of(TreeCacheEvent.Type.NODE_ADDED, TreeCacheEvent.Type.NODE_UPDATED, TreeCacheEvent.Type.NODE_REMOVED); public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { if (!nodeEvents.contains(event.getType())) { return; } String nodeName = ZKPaths.getNodeFromPath(event.getData().getPath()); String nodeData = new String(event.getData().getData()); TreeCacheEvent.Type eventType = event.getType(); String configPathStab = String.format("/%s/", clusterName); if (event.getData().getPath().startsWith(configPathStab + "loglevelfilter/")) { handleLogLevelFilterChange(eventType, nodeName, nodeData, gson, logLevelFilterMonitor); } } }; }
Example 2
Source File: ZKCacheListener.java From mpush with Apache License 2.0 | 6 votes |
@Override public void childEvent(CuratorFramework curator, TreeCacheEvent event) throws Exception { ChildData data = event.getData(); if (data == null) return; String dataPath = data.getPath(); if (Strings.isNullOrEmpty(dataPath)) return; if (dataPath.startsWith(watchPath)) { switch (event.getType()) { case NODE_ADDED: listener.onServiceAdded(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class)); break; case NODE_REMOVED: listener.onServiceRemoved(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class)); break; case NODE_UPDATED: listener.onServiceUpdated(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class)); break; } Logs.RSD.info("ZK node data change={}, nodePath={}, watchPath={}, ns={}"); } }
Example 3
Source File: TopicListener.java From kafka-monitor with Apache License 2.0 | 5 votes |
@Override public void childEvent(CuratorFramework curator, TreeCacheEvent event) throws Exception { ChildData data = event.getData(); if (data != null) { if (event.getType() == NODE_ADDED) { } String path = data.getPath(); //判断是否为topics节点 if (path.contains(String.format("%s/",ZkUtils.BrokerTopicsPath())) && (!path.contains("partitions"))) { Topic topic = JSONObject.parseObject(data.getData(), Topic.class); String name = path.substring(path.lastIndexOf("/") + 1, path.length()); topic.setName(name); int[] tPartiyions = topic.getPartitions().keySet().stream().mapToInt((t) -> Integer.valueOf(t)).sorted().toArray(); for (Object key : tPartiyions ) { String partitionPath = String.format("%s/partitions/%s/state", path, key); String state = new String(curator.getData().forPath(partitionPath)); Partition partition = JSONObject.parseObject(state, Partition.class); JSONArray replicas = topic.getPartitions().getJSONArray(String.valueOf(key)); int[] replicasArray = new int[replicas.size()]; for (int i = 0; i < replicas.size(); i++) { replicasArray[i] = replicas.getInteger(i); } partition.setReplicasArray(replicasArray); topic.getPartitionMap().put((Integer) key, partition); } topicList.add(topic); } } }
Example 4
Source File: CuratorZookeeperCenterRepository.java From shardingsphere with Apache License 2.0 | 5 votes |
private DataChangedEvent.ChangedType getChangedType(final TreeCacheEvent event) { switch (event.getType()) { case NODE_ADDED: return DataChangedEvent.ChangedType.ADDED; case NODE_UPDATED: return DataChangedEvent.ChangedType.UPDATED; case NODE_REMOVED: return DataChangedEvent.ChangedType.DELETED; default: return DataChangedEvent.ChangedType.IGNORED; } }
Example 5
Source File: TenantDebugger.java From vespa with Apache License 2.0 | 5 votes |
@Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { switch (event.getType()) { case NODE_ADDED: case NODE_REMOVED: case NODE_UPDATED: log.log(Level.INFO, event.toString()); break; } }
Example 6
Source File: ZookeeperTreeCacheListener.java From Thunder with Apache License 2.0 | 5 votes |
@Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { TreeCacheEvent.Type type = event.getType(); switch (type) { case INITIALIZED: initialized(event); break; case NODE_ADDED: nodeAdded(event); break; case NODE_UPDATED: nodeUpdated(event); break; case NODE_REMOVED: nodeRemoved(event); break; case CONNECTION_SUSPENDED: connectionSuspended(event); break; case CONNECTION_RECONNECTED: connectionReconnected(event); break; case CONNECTION_LOST: connectionLost(event); break; } }
Example 7
Source File: ConfigWatcher.java From spring-cloud-zookeeper with Apache License 2.0 | 5 votes |
@Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { TreeCacheEvent.Type eventType = event.getType(); if (eventType == NODE_ADDED || eventType == NODE_REMOVED || eventType == NODE_UPDATED) { this.publisher .publishEvent(new RefreshEvent(this, event, getEventDesc(event))); } }
Example 8
Source File: TreeCacheExample.java From ZKRecipesByExample with Apache License 2.0 | 5 votes |
private static void addListener(final TreeCache cache) { TreeCacheListener listener = new TreeCacheListener() { @Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { switch (event.getType()) { case NODE_ADDED: { System.out.println("TreeNode added: " + ZKPaths.getNodeFromPath(event.getData().getPath()) + ", value: " + new String(event.getData().getData())); break; } case NODE_UPDATED: { System.out.println("TreeNode changed: " + ZKPaths.getNodeFromPath(event.getData().getPath()) + ", value: " + new String(event.getData().getData())); break; } case NODE_REMOVED: { System.out.println("TreeNode removed: " + ZKPaths.getNodeFromPath(event.getData().getPath())); break; } default: System.out.println("Other event: " + event.getType().name()); } } }; cache.getListenable().addListener(listener); }
Example 9
Source File: CuratorZookeeperClient.java From FATE-Serving with Apache License 2.0 | 4 votes |
@Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { if (dataListener != null) { if (logger.isDebugEnabled()) { logger.debug("listen the zookeeper changed. The changed data:" + event.getData()); } TreeCacheEvent.Type type = event.getType(); EventType eventType = null; String content = null; String path = null; switch (type) { case NODE_ADDED: eventType = EventType.NodeCreated; path = event.getData().getPath(); content = event.getData().getData() == null ? "" : new String(event.getData().getData(), CHARSET); break; case NODE_UPDATED: eventType = EventType.NodeDataChanged; path = event.getData().getPath(); content = event.getData().getData() == null ? "" : new String(event.getData().getData(), CHARSET); break; case NODE_REMOVED: path = event.getData().getPath(); eventType = EventType.NodeDeleted; break; case INITIALIZED: eventType = EventType.INITIALIZED; break; case CONNECTION_LOST: eventType = EventType.CONNECTION_LOST; break; case CONNECTION_RECONNECTED: eventType = EventType.CONNECTION_RECONNECTED; break; case CONNECTION_SUSPENDED: eventType = EventType.CONNECTION_SUSPENDED; break; default: break; } dataListener.dataChanged(path, content, eventType); } }
Example 10
Source File: CloudJobConfigurationListener.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 4 votes |
private boolean isJobConfigNode(final TreeCacheEvent event, final String path, final Type type) { return type == event.getType() && path.startsWith(CloudJobConfigurationNode.ROOT) && path.length() > CloudJobConfigurationNode.ROOT.length(); }
Example 11
Source File: DubboServiceDiscoveryAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 3 votes |
/** * The {@link TreeCacheEvent#getType() event type} is supported or not. * @param event {@link TreeCacheEvent} * @return the rule is same as * {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)} * method */ private boolean supportsEventType(TreeCacheEvent event) { TreeCacheEvent.Type eventType = event.getType(); return eventType.equals(TreeCacheEvent.Type.NODE_ADDED) || eventType.equals(TreeCacheEvent.Type.NODE_REMOVED) || eventType.equals(TreeCacheEvent.Type.NODE_UPDATED); }