public ChainedDynamicProperty.IntProperty getChainedIntProperty(String overrideKey, String primaryKey, int defaultValue, Runnable listener) { final String mapKey = overrideKey + primaryKey; ChainedDynamicProperty.IntProperty prop = (ChainedDynamicProperty.IntProperty) fastPropMap.get(mapKey); if (prop != null) return prop; final DynamicIntProperty baseProp = new DynamicIntProperty(primaryKey, defaultValue); prop = new ChainedDynamicProperty.IntProperty(overrideKey, baseProp); fastPropMap.put(mapKey, prop); if(listener != null) { baseProp.addCallback(listener); prop.addCallback(listener); } return prop; }
public EVCacheExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, RejectedExecutionHandler handler, String name) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, new LinkedBlockingQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat( "EVCacheExecutor-" + name + "-%d").build()); this.name = name; maxAsyncPoolSize = EVCacheConfig.getInstance().getDynamicIntProperty("EVCacheExecutor." + name + ".max.size", maximumPoolSize); setMaximumPoolSize(maxAsyncPoolSize.get()); coreAsyncPoolSize = EVCacheConfig.getInstance().getDynamicIntProperty("EVCacheExecutor." + name + ".core.size", corePoolSize); setCorePoolSize(coreAsyncPoolSize.get()); setKeepAliveTime(keepAliveTime, unit); maxAsyncPoolSize.addCallback(new Runnable() { public void run() { setMaximumPoolSize(maxAsyncPoolSize.get()); } }); coreAsyncPoolSize.addCallback(new Runnable() { public void run() { setCorePoolSize(coreAsyncPoolSize.get()); prestartAllCoreThreads(); } }); setupMonitoring(name); }
public EVCacheInMemoryCache(String appName, Transcoder<T> tc, EVCacheImpl impl) { this.appName = appName; this.tc = tc; this.impl = impl; final Runnable setupCache = new Runnable() { public void run() { setupCache(); } }; this._cacheDuration = EVCacheConfig.getInstance().getChainedIntProperty(appName + ".inmemory.cache.duration.ms", appName + ".inmemory.expire.after.write.duration.ms", 0, setupCache); this._exireAfterAccessDuration = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".inmemory.expire.after.access.duration.ms", 0); this._exireAfterAccessDuration.addCallback(setupCache); this._refreshDuration = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".inmemory.refresh.after.write.duration.ms", 0); this._refreshDuration.addCallback(setupCache); this._cacheSize = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".inmemory.cache.size", 100); this._cacheSize.addCallback(setupCache); this._poolSize = EVCacheConfig.getInstance().getDynamicIntProperty(appName + ".thread.pool.size", 5); this._poolSize.addCallback(new Runnable() { public void run() { initRefreshPool(); } }); setupCache(); setupMonitoring(appName); }
public EVCacheScheduledExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, RejectedExecutionHandler handler, String name) { super(corePoolSize, handler); this.name = name; maxAsyncPoolSize = EVCacheConfig.getInstance().getDynamicIntProperty("EVCacheScheduledExecutor." + name + ".max.size", maximumPoolSize); setMaximumPoolSize(maxAsyncPoolSize.get()); coreAsyncPoolSize = EVCacheConfig.getInstance().getDynamicIntProperty("EVCacheScheduledExecutor." + name + ".core.size", corePoolSize); setCorePoolSize(coreAsyncPoolSize.get()); setKeepAliveTime(keepAliveTime, unit); final ThreadFactory asyncFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat( "EVCacheScheduledExecutor-" + name + "-%d").build(); setThreadFactory(asyncFactory); maxAsyncPoolSize.addCallback(new Runnable() { public void run() { setMaximumPoolSize(maxAsyncPoolSize.get()); } }); coreAsyncPoolSize.addCallback(new Runnable() { public void run() { setCorePoolSize(coreAsyncPoolSize.get()); prestartAllCoreThreads(); } }); setupMonitoring(name); }
this._poolSize.addCallback(callback); this._readTimeout = new ChainedDynamicProperty.IntProperty(appName + ".EVCacheClientPool.readTimeout", EVCacheClientPoolManager.getDefaultReadTimeout()); this._readTimeout.addCallback(callback); this._opQueueMaxBlockTime.addCallback(callback); this._operationTimeout = config.getDynamicIntProperty(appName + ".operation.timeout", 2500); this._operationTimeout.addCallback(callback); this._maxReadQueueSize = config.getDynamicIntProperty(appName + ".max.read.queue.length", 5); this._retryAcrossAllReplicas = config.getDynamicBooleanProperty(_appName + ".retry.all.copies", Boolean.FALSE);
public static int getConfigVal(String config, int defaultValue) { DynamicIntProperty dynamicIntProperty = DynamicPropertyFactory.getInstance().getIntProperty(config, defaultValue); cfgCallback.computeIfAbsent(config, key -> { dynamicIntProperty.addCallback(() -> { int newValue = dynamicIntProperty.get(); String cfgName = dynamicIntProperty.getName(); //store the value in config center map and check for next requests. FaultInjectionUtil.setConfigCenterValue(cfgName, new AtomicInteger(newValue)); LOGGER.info("{} changed to {}", cfgName, newValue); }); return config; }); return dynamicIntProperty.get(); } }
@Override public int getIntProperty(String propertyName, IntConsumer consumer, int defaultValue) { DynamicIntProperty prop = propertyFactoryInstance().getIntProperty(propertyName, defaultValue); prop.addCallback(() -> consumer.accept(prop.get())); return prop.get(); }
public ScheduledThreadPoolExectuorWithDynamicSize(final DynamicIntProperty corePoolSize, ThreadFactory threadFactory) { super(corePoolSize.get(), threadFactory); corePoolSize.addCallback(new Runnable() { public void run() { setCorePoolSize(corePoolSize.get()); } }); shutdownThread = new Thread(new Runnable() { public void run() { shutdown(); if (shutdownThread != null) { try { Runtime.getRuntime().removeShutdownHook(shutdownThread); } catch (IllegalStateException ise) { // NOPMD } } } }); Runtime.getRuntime().addShutdownHook(shutdownThread); } }
); poolSizeProp.addCallback(new Runnable() { @Override public void run() {
public IntProperty(String name, IntProperty next) { super(next); // setup next pointer sProp = DynamicPropertyFactory.getInstance().getIntProperty(name, Integer.MIN_VALUE); callback = new Runnable() { @Override public void run() { logger.info("Property changed: '" + getName() + " = " + getValue() + "'"); checkAndFlip(); } }; sProp.addCallback(callback); checkAndFlip(); }
public IntProperty(String name, IntProperty next) { super(next); // setup next pointer sProp = DynamicPropertyFactory.getInstance().getIntProperty(name, Integer.MIN_VALUE); callback = new Runnable() { @Override public void run() { logger.info("Property changed: '" + getName() + " = " + getValue() + "'"); checkAndFlip(); } }; sProp.addCallback(callback); checkAndFlip(); }
public static int getConfigVal(String config, int defaultValue) { DynamicIntProperty dynamicIntProperty = DynamicPropertyFactory.getInstance().getIntProperty(config, defaultValue); cfgCallback.computeIfAbsent(config, key -> { dynamicIntProperty.addCallback(() -> { int newValue = dynamicIntProperty.get(); String cfgName = dynamicIntProperty.getName(); //store the value in config center map and check for next requests. FaultInjectionUtil.setConfigCenterValue(cfgName, new AtomicInteger(newValue)); LOGGER.info("{} changed to {}", cfgName, newValue); }); return config; }); return dynamicIntProperty.get(); } }
new ObjectName("java.util.concurrent:type=ThreadPoolExecutor,name=" + name)); corePoolSize.addCallback(new Runnable() { @Override public void run() { maxPoolSize.addCallback(new Runnable() { @Override public void run() { keepAliveTime.addCallback(new Runnable() { @Override public void run() {
@Override public int getIntProperty(String propertyName, IntConsumer consumer, int defaultValue) { DynamicIntProperty prop = propertyFactoryInstance().getIntProperty(propertyName, defaultValue); prop.addCallback(() -> consumer.accept(prop.get())); return prop.get(); }
maxTotalConnectionProperty.addCallback(new Runnable() { @Override public void run() { maxConnectionPerHostProperty = new DynamicIntProperty(this.name + "." + config.getNameSpace() + "." + CommonClientConfigKey.MaxHttpConnectionsPerHost.key(), DefaultClientConfigImpl.DEFAULT_MAX_HTTP_CONNECTIONS_PER_HOST); maxConnectionPerHostProperty.addCallback(new Runnable() { @Override public void run() {