/** * Start the cache. The cache is not started automatically. You must call this method. * * @throws Exception errors */ public void start() throws Exception { start(false); }
/** * NOTE: this is a BLOCKING method. Completely rebuild the internal cache by querying * for all needed data WITHOUT generating any events to send to listeners. * * @throws Exception errors */ public void rebuild() throws Exception { Preconditions.checkState(state.get() == State.STARTED, "Not started"); internalRebuild(); reset(); }
/** * When {@link FabricService} becomes available, we can initialize this {@link PlaceholderResolver} * @param fabricService */ public void initialize(FabricService fabricService) { this.fabricService = fabricService; encryptor = getEncryptor(fabricService); if (bundleContext != null) { seRegistration = bundleContext.registerService(PBEStringEncryptor.class, encryptor, null); BundleContext context = FrameworkUtil.getBundle(PersistenceManager.class).getBundleContext(); encryptingPersistenceManager = new EncryptingPersistenceManager( context, context.getProperty(ConfigurationManager.CM_CONFIG_DIR), encryptor); originalPersistenceManager = inject(configAdmin, encryptingPersistenceManager); passwordNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_PASSWORD.getPath()); passwordNodeCache.getListenable().addListener(this); alogrithmNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_ALGORITHM.getPath()); alogrithmNodeCache.getListenable().addListener(this); try { passwordNodeCache.start(); alogrithmNodeCache.start(); } catch (Exception e) { throw new FabricException(e); } } }
@Deactivate void deactivate() throws Exception { if (registeredListener && mBeanServer != null) { mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener); } // lets remove all the previously generated paths List<String> paths = new ArrayList<String>(registeredZkPaths); for (String path : paths) { removeZkPath(path); } deactivateComponent(); versionNodeMonitor.getListenable().removeListener(this); Closeables.closeQuietly(versionNodeMonitor); versionNodeMonitor = null; }
@Deactivate void deactivate() { deactivateComponent(); if (originalPersistenceManager != null) { inject(configAdmin, originalPersistenceManager); } if (seRegistration != null) { seRegistration.unregister(); } encryptor = null; try { alogrithmNodeCache.close(); passwordNodeCache.close(); } catch (IOException e) { LOG.warn("Exception while closing node caches."); if(LOG.isTraceEnabled()){ LOG.trace("", e); } } }
@Override public void nodeChanged(ChildData previousData, ChildData newData) throws Exception { ChildData currentData = versionNodeMonitor.getCurrentData(); byte[] data = currentData.getData(); LOGGER.info("Container Version has been updated to version {}, republishing of APIs endpoints", new String(data)); String oldVersion = ((previousData != null) ? new String(previousData.getData()):""); // registered paths have this structure: // /fabric/registry/clusters/apis/rest/CustomerService/crm/1.0/root for(String path : registeredZkPaths){ if(path.endsWith(getCurrentContainer().getId())){ String[] split = path.split("/"); if(split.length >= 2){ String version = split[split.length -2]; if(oldVersion.equals(version)){ removeZkPath(path); } } } } replay(); } }
setNewData(childData); setNewData(null);
@Activate void activate() throws Exception { activateComponent(); if (mBeanServer == null) { mBeanServer = ManagementFactory.getPlatformMBeanServer(); } if (mBeanServer != null) { Object handback = null; mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, handback); this.registeredListener = true; } String id = getCurrentContainer().getId(); String zkPath = ZkPath.CONFIG_CONTAINER.getPath(id); versionNodeMonitor = new NodeCacheExtended(curator.get(), zkPath); versionNodeMonitor.getListenable().addListener(this); versionNodeMonitor.start(); replay(); }
/** * Same as {@link #start()} but gives the option of doing an initial build * * @param buildInitial if true, {@link #rebuild()} will be called before this method * returns in order to get an initial view of the node * @throws Exception errors */ public void start(boolean buildInitial) throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once"); ensurePath.ensure(client.getZookeeperClient()); client.getConnectionStateListenable().addListener(connectionStateListener); if ( buildInitial ) { internalRebuild(); } reset(); }