public Observable() { this.observers = new CopyOnWriteArrayList<>(); }
@Override public void registerCancelListener( CancelListener listener ) { cancelListeners.add( listener ); } }
public void remove(FilePathFilter f) { for (Entry e : all) { if (e.filter==f) all.remove(e); } }
@VisibleForTesting public void moveTaskGroupToPendingCompletion(int taskGroupId) { final TaskGroup taskGroup = activelyReadingTaskGroups.remove(taskGroupId); if (taskGroup != null) { pendingCompletionTaskGroups.computeIfAbsent(taskGroupId, k -> new CopyOnWriteArrayList<>()).add(taskGroup); } }
public MappedFile getLastMappedFile() { MappedFile mappedFileLast = null; while (!this.mappedFiles.isEmpty()) { try { mappedFileLast = this.mappedFiles.get(this.mappedFiles.size() - 1); break; } catch (IndexOutOfBoundsException e) { //continue; } catch (Exception e) { log.error("getLastMappedFile has exception.", e); break; } } return mappedFileLast; }
@Test public void singleSmartLifecycleShutdown() throws Exception { Assume.group(TestGroup.PERFORMANCE); CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
@Test public void singleSmartLifecycleWithoutAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(false); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertFalse(bean.isRunning()); assertEquals(0, startedBeans.size()); context.start(); assertTrue(bean.isRunning()); assertEquals(1, startedBeans.size()); context.stop(); }
@Restricted(NoExternalUse.class) public Object readResolve() { if (views == null) // this shouldn't happen, but an error in 1.319 meant the last view could be deleted views = new CopyOnWriteArrayList<View>(); if (views.isEmpty()) { // preserve the non-empty invariant views.add(new AllView(AllView.DEFAULT_VIEW_NAME, this)); } if (primaryViewName != null) { // It may happen when the default constructor is invoked primaryViewName = AllView.migrateLegacyPrimaryAllViewLocalizedName(views, primaryViewName); } viewGroupMixIn = new ViewGroupMixIn(this) { protected List<View> views() { return views; } protected String primaryView() { return primaryViewName; } protected void primaryView(String name) { primaryViewName=name; } }; return this; }
@Test public void dependencyStartedFirstAndIsSmartLifecycle() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forStartupTests(-99, startedBeans); TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forStartupTests(99, startedBeans); TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forStartupTests(7, startedBeans); TestLifecycleBean simpleBean = TestLifecycleBean.forStartupTests(startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanNegative", beanNegative); context.getBeanFactory().registerSingleton("bean7", bean7); context.getBeanFactory().registerSingleton("bean99", bean99); context.getBeanFactory().registerSingleton("simpleBean", simpleBean); context.getBeanFactory().registerDependentBean("bean7", "simpleBean"); context.refresh(); context.stop(); startedBeans.clear(); // clean start so that simpleBean is included context.start(); assertTrue(beanNegative.isRunning()); assertTrue(bean99.isRunning()); assertTrue(bean7.isRunning()); assertTrue(simpleBean.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(-99, getPhase(startedBeans.get(0))); assertEquals(7, getPhase(startedBeans.get(1))); assertEquals(0, getPhase(startedBeans.get(2))); assertEquals(99, getPhase(startedBeans.get(3))); context.stop(); }
@Override public void scheduleDrawable(@NonNull final Drawable who, @NonNull final Runnable what, final long when) { for (int i = 0; i < mCallbacks.size(); i++) { final CallbackWeakReference reference = mCallbacks.get(i); final Callback callback = reference.get(); if (callback != null) { callback.scheduleDrawable(who, what, when); } else { // Always remove null references to reduce Set size mCallbacks.remove(reference); } } }
private void addNewExecutorIfNecessary() { if (Jenkins.getInstanceOrNull() == null) { return; } Set<Integer> availableNumbers = new HashSet<Integer>(); for (int i = 0; i < numExecutors; i++) availableNumbers.add(i); for (Executor executor : executors) availableNumbers.remove(executor.getNumber()); for (Integer number : availableNumbers) { /* There may be busy executors with higher index, so only fill up until numExecutors is reached. Extra executors will call removeExecutor(...) and that will create any necessary executors from #0 again. */ if (executors.size() < numExecutors) { Executor e = new Executor(this, number); executors.add(e); } } }
/** * Add a default resource. Resources are loaded in the order of the resources * added. * @param name file name. File should be present in the classpath. */ public static synchronized void addDefaultResource(String name) { if(!defaultResources.contains(name)) { defaultResources.add(name); for(Configuration conf : REGISTRY.keySet()) { if(conf.loadDefaults) { conf.reloadConfiguration(); } } } }
public void removeListener(Listener listener) { if (null == listener) { throw new IllegalArgumentException("listener is null"); } ManagerListenerWrap wrap = new ManagerListenerWrap(listener); if (listeners.remove(wrap)) { log.info(name, "[remove-listener] ok, dataId={}, group={}, cnt={}", dataId, group, listeners.size()); } }
private ManagementRegistration registerServerMXBean(XnioServerMXBean serverMXBean){ serverMetrics.addIfAbsent(serverMXBean); final Closeable handle = NioXnio.register(serverMXBean); return () -> { serverMetrics.remove(serverMXBean); safeClose(handle); }; }
/** * Returns the current size of the executor pool for this computer. * This number may temporarily differ from {@link #getNumExecutors()} if there * are busy tasks when the configured size is decreased. OneOffExecutors are * not included in this count. */ public final int countExecutors() { return executors.size(); }
/** * For only test purpose */ static public void clear() { LISTENER_HUB.clear(); }
@Test public void singleLifecycleShutdown() throws Exception { CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); Lifecycle bean = new TestLifecycleBean(null, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertFalse(bean.isRunning()); bean.start(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
@Test public void singleSmartLifecycleAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(true); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertFalse(bean.isRunning()); assertEquals(1, startedBeans.size()); }