Example usage for com.google.common.util.concurrent ExecutionList add

List of usage examples for com.google.common.util.concurrent ExecutionList add

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ExecutionList add.

Prototype

public void add(Runnable runnable, Executor executor) 

Source Link

Document

Adds the Runnable and accompanying Executor to the list of listeners to execute.

Usage

From source file:org.jclouds.lifecycle.config.LifeCycleModule.java

protected void bindPostInjectionInvoke(final Closer closer, final ExecutionList list) {
    bindListener(any(), new TypeListener() {
        public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) {
            Collection<? extends Invokable<? super I, Object>> methods = methods(injectableType.getRawType());
            for (final Invokable<? super I, Object> method : filter(methods, isPostConstruct)) {
                encounter.register(new InjectionListener<I>() {
                    public void afterInjection(final I injectee) {
                        list.add(new Runnable() {
                            public void run() {
                                invokeOnInjectee(method, injectee);
                            }/*from ww  w .j  a v a  2  s.  c  o m*/

                        }, sameThreadExecutor());
                    }
                });
            }
            for (final Invokable<? super I, Object> method : filter(methods, isPreDestroy)) {
                encounter.register(new InjectionListener<I>() {
                    public void afterInjection(final I injectee) {
                        closer.addToClose(new Closeable() {
                            public void close() throws IOException {
                                invokeOnInjectee(method, injectee);
                            }
                        });
                    }
                });
            }
        }

    });
}