private void maybeOfferInitializedEvent(Map<String, ChildData> localInitialSet) { if ( !hasUninitialized(localInitialSet) ) { // all initial children have been processed - send initialized message if ( initialSet.getAndSet(null) != null ) // avoid edge case - don't send more than 1 INITIALIZED event { final List<ChildData> children = ImmutableList.copyOf(localInitialSet.values()); PathChildrenCacheEvent event = new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.INITIALIZED, null) { @Override public List<ChildData> getInitialData() { return children; } }; offerOperation(new EventOperation(this, event)); } } }
@VisibleForTesting protected void remove(String fullPath) { ChildData data = currentData.remove(fullPath); if ( data != null ) { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_REMOVED, data))); } Map<String, ChildData> localInitialSet = initialSet.get(); if ( localInitialSet != null ) { localInitialSet.remove(fullPath); maybeOfferInitializedEvent(localInitialSet); } }
private void applyNewData(String fullPath, int resultCode, Stat stat, byte[] bytes) { if ( resultCode == KeeperException.Code.OK.intValue() ) // otherwise - node must have dropped or something - we should be getting another event { ChildData data = new ChildData(fullPath, stat, bytes); ChildData previousData = currentData.put(fullPath, data); if ( previousData == null ) // i.e. new { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_ADDED, data))); } else if ( previousData.getStat().getVersion() != stat.getVersion() ) { offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CHILD_UPDATED, data))); } updateInitialSet(ZKPaths.getNodeFromPath(fullPath), data); } }
offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CONNECTION_SUSPENDED, null))); break; offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CONNECTION_LOST, null))); break; offerOperation(new EventOperation(this, new PathChildrenCacheEvent(PathChildrenCacheEvent.Type.CONNECTION_RECONNECTED, null)));