/** @deprecated No clear purpose, since subclasses may have overridden {@link #getActions}, and does not consider {@link TransientActionFactory}. */ @Deprecated public Action getAction(int index) { if(actions==null) return null; return actions.get(index); }
/** * Notifies all the added {@link AnimationBindingListener}s that has been canceled before start. */ final void notifyCanceledBeforeStart() { for (int index = mListeners.size() - 1; index >= 0; index--) { final AnimationBindingListener listener = mListeners.get(index); listener.onCanceledBeforeStart(this); } }
/** Notifies all the added {@link AnimationBindingListener}s that will start. */ final void notifyWillStart() { for (int index = mListeners.size() - 1; index >= 0; index--) { final AnimationBindingListener listener = mListeners.get(index); listener.onWillStart(this); } }
/** Notifies all the added {@link AnimationBindingListener}s that has finished. */ final void notifyFinished() { for (int index = mListeners.size() - 1; index >= 0; index--) { final AnimationBindingListener listener = mListeners.get(index); listener.onFinish(this); } }
/** * Notifies the added {@link AnimationBindingListener}s that has been scheduled to start later. */ final void notifyScheduledToStartLater() { for (int index = mListeners.size() - 1; index >= 0; index--) { final AnimationBindingListener listener = mListeners.get(index); listener.onScheduledToStartLater(this); } } }
@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); } } }
@Override public void unscheduleDrawable(@NonNull final Drawable who, @NonNull final Runnable what) { for (int i = 0; i < mCallbacks.size(); i++) { final CallbackWeakReference reference = mCallbacks.get(i); final Callback callback = reference.get(); if (callback != null) { callback.unscheduleDrawable(who, what); } else { // Always remove null references to reduce list size mCallbacks.remove(reference); } } }
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; }
public MappedFile getFirstMappedFile() { MappedFile mappedFileFirst = null; if (!this.mappedFiles.isEmpty()) { try { mappedFileFirst = this.mappedFiles.get(0); } catch (IndexOutOfBoundsException e) { //ignore } catch (Exception e) { log.error("getFirstMappedFile has exception.", e); } } return mappedFileFirst; }
public long getMinOffset() { if (!this.mappedFiles.isEmpty()) { try { return this.mappedFiles.get(0).getFileFromOffset(); } catch (IndexOutOfBoundsException e) { //continue; } catch (Exception e) { log.error("getMinOffset has exception.", e); } } return -1; }
@Test public void smartLifecycleGroupShutdown() throws Exception { Assume.group(TestGroup.PERFORMANCE); CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean1 = TestSmartLifecycleBean.forShutdownTests(1, 300, stoppedBeans); TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forShutdownTests(3, 100, stoppedBeans); TestSmartLifecycleBean bean3 = TestSmartLifecycleBean.forShutdownTests(1, 600, stoppedBeans); TestSmartLifecycleBean bean4 = TestSmartLifecycleBean.forShutdownTests(2, 400, stoppedBeans); TestSmartLifecycleBean bean5 = TestSmartLifecycleBean.forShutdownTests(2, 700, stoppedBeans); TestSmartLifecycleBean bean6 = TestSmartLifecycleBean.forShutdownTests(Integer.MAX_VALUE, 200, stoppedBeans); TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forShutdownTests(3, 200, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean1", bean1); context.getBeanFactory().registerSingleton("bean2", bean2); context.getBeanFactory().registerSingleton("bean3", bean3); context.getBeanFactory().registerSingleton("bean4", bean4); context.getBeanFactory().registerSingleton("bean5", bean5); context.getBeanFactory().registerSingleton("bean6", bean6); context.getBeanFactory().registerSingleton("bean7", bean7); context.refresh(); context.stop(); assertEquals(Integer.MAX_VALUE, getPhase(stoppedBeans.get(0))); assertEquals(3, getPhase(stoppedBeans.get(1))); assertEquals(3, getPhase(stoppedBeans.get(2))); assertEquals(2, getPhase(stoppedBeans.get(3))); assertEquals(2, getPhase(stoppedBeans.get(4))); assertEquals(1, getPhase(stoppedBeans.get(5))); assertEquals(1, getPhase(stoppedBeans.get(6))); }
@Test public void dependencyStartedFirstEvenIfItsPhaseIsHigher() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans); TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forStartupTests(2, startedBeans); TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forStartupTests(99, startedBeans); TestSmartLifecycleBean beanMax = TestSmartLifecycleBean.forStartupTests(Integer.MAX_VALUE, startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanMin", beanMin); context.getBeanFactory().registerSingleton("bean2", bean2); context.getBeanFactory().registerSingleton("bean99", bean99); context.getBeanFactory().registerSingleton("beanMax", beanMax); context.getBeanFactory().registerDependentBean("bean99", "bean2"); context.refresh(); assertTrue(beanMin.isRunning()); assertTrue(bean2.isRunning()); assertTrue(bean99.isRunning()); assertTrue(beanMax.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(0))); assertEquals(99, getPhase(startedBeans.get(1))); assertEquals(bean99, startedBeans.get(1)); assertEquals(2, getPhase(startedBeans.get(2))); assertEquals(bean2, startedBeans.get(2)); assertEquals(Integer.MAX_VALUE, getPhase(startedBeans.get(3))); context.stop(); }
@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 dependencyStartedFirstButNotSmartLifecycle() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans); TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forStartupTests(7, startedBeans); TestLifecycleBean simpleBean = TestLifecycleBean.forStartupTests(startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanMin", beanMin); context.getBeanFactory().registerSingleton("bean7", bean7); context.getBeanFactory().registerSingleton("simpleBean", simpleBean); context.getBeanFactory().registerDependentBean("simpleBean", "beanMin"); context.refresh(); assertTrue(beanMin.isRunning()); assertTrue(bean7.isRunning()); assertTrue(simpleBean.isRunning()); assertEquals(3, startedBeans.size()); assertEquals(0, getPhase(startedBeans.get(0))); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(1))); assertEquals(7, getPhase(startedBeans.get(2))); context.stop(); }
@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 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(); }
context.stop(); assertEquals(5, startedBeans.size()); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(0))); assertEquals(1, getPhase(startedBeans.get(1))); assertEquals(2, getPhase(startedBeans.get(2))); assertEquals(3, getPhase(startedBeans.get(3))); assertEquals(Integer.MAX_VALUE, getPhase(startedBeans.get(4)));
assertFalse(simpleBean2.isRunning()); assertEquals(2, startedBeans.size()); assertEquals(-3, getPhase(startedBeans.get(0))); assertEquals(5, getPhase(startedBeans.get(1))); context.start(); assertTrue(smartBean1.isRunning()); assertTrue(simpleBean2.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(0, getPhase(startedBeans.get(2))); assertEquals(0, getPhase(startedBeans.get(3)));
assertFalse(simpleBean.isRunning()); assertEquals(5, stoppedBeans.size()); assertEquals(7, getPhase(stoppedBeans.get(0))); assertEquals(0, getPhase(stoppedBeans.get(1))); assertEquals(2, getPhase(stoppedBeans.get(2))); assertEquals(1, getPhase(stoppedBeans.get(3))); assertEquals(Integer.MIN_VALUE, getPhase(stoppedBeans.get(4)));
assertFalse(simpleBean2.isRunning()); assertEquals(2, startedBeans.size()); assertEquals(-3, getPhase(startedBeans.get(0))); assertEquals(5, getPhase(startedBeans.get(1))); context.stop(); assertFalse(simpleBean1.isRunning()); assertTrue(simpleBean2.isRunning()); assertEquals(6, startedBeans.size()); assertEquals(-3, getPhase(startedBeans.get(2))); assertEquals(0, getPhase(startedBeans.get(3))); assertEquals(0, getPhase(startedBeans.get(4))); assertEquals(5, getPhase(startedBeans.get(5)));