Deleting Lifecycle extension.

git-svn-id: https://google-guice.googlecode.com/svn/trunk@1226 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/extensions/lifecycle/build.properties b/extensions/lifecycle/build.properties
deleted file mode 100644
index 0b848a2..0000000
--- a/extensions/lifecycle/build.properties
+++ /dev/null
@@ -1,7 +0,0 @@
-lib.dir=../../lib
-src.dir=src
-test.dir=test
-build.dir=build
-test.class=com.google.inject.lifecycle.LifecycleTest
-module=com.google.inject.lifecycle
-fragment=true
diff --git a/extensions/lifecycle/build.xml b/extensions/lifecycle/build.xml
deleted file mode 100644
index eeedef2..0000000
--- a/extensions/lifecycle/build.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0"?>
-
-<project name="guice-lifecycle" basedir="." default="jar">
-
-  <import file="../../common.xml"/>
-  
-  <path id="compile.classpath">
-    <fileset dir="${lib.dir}" includes="*.jar"/>
-    <fileset dir="${lib.dir}/build" includes="*.jar"/>
-    <fileset dir="../../build/dist" includes="*.jar"/>
-  </path>
-
-  <target name="jar" depends="jar.withdeps, manifest" description="Build jar.">
-    <jar destfile="${build.dir}/${ant.project.name}-${version}.jar"
-        manifest="${build.dir}/META-INF/MANIFEST.MF">
-      <zipfileset src="${build.dir}/${ant.project.name}-with-deps.jar"
-          excludes="com/google/inject/internal/**"/>
-    </jar>
-  </target>
-
-</project>
diff --git a/extensions/lifecycle/lifecycle.iml b/extensions/lifecycle/lifecycle.iml
deleted file mode 100644
index 6906ee5..0000000
--- a/extensions/lifecycle/lifecycle.iml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module relativePaths="true" type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="true">
-    <exclude-output />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="module" module-name="guice" />
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="jar://$MODULE_DIR$/../lib/build/junit.jar!/" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
-    <orderEntry type="module-library">
-      <library>
-        <CLASSES>
-          <root url="jar://$MODULE_DIR$/../lib/build/easymock.jar!/" />
-        </CLASSES>
-        <JAVADOC />
-        <SOURCES />
-      </library>
-    </orderEntry>
-  </component>
-</module>
-
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/BroadcastingLifecycle.java b/extensions/lifecycle/src/com/google/inject/lifecycle/BroadcastingLifecycle.java
deleted file mode 100644
index fe4479d..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/BroadcastingLifecycle.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.Binding;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Key;
-import com.google.inject.Scopes;
-import com.google.inject.Singleton;
-import com.google.inject.internal.util.Lists;
-import com.google.inject.internal.util.Maps;
-import com.google.inject.internal.util.Preconditions;
-import com.google.inject.matcher.Matcher;
-import static com.google.inject.matcher.Matchers.any;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import net.sf.cglib.proxy.InvocationHandler;
-import net.sf.cglib.proxy.Proxy;
-
-/**
- * @author dhanji@gmail.com (Dhanji R. Prasanna)
- */
-@Singleton
-class BroadcastingLifecycle implements Lifecycle {
-  private final Injector injector;
-  private final List<Class<?>> callableClasses;
-
-  // @GuardedBy(this)
-  private Map<Class<?>, List<Key<?>>> callableKeys;
-
-  private volatile boolean started = false;
-
-  @Inject
-  public BroadcastingLifecycle(Injector injector, @ListOfMatchers List<Class<?>> callableClasses) {
-    this.injector = injector;
-    this.callableClasses = callableClasses;
-
-    // Self start. Eventually we may want to move this to a hook-in from Guice-core.
-    start();
-  }
-
-  public void start() {
-    if (started) {
-      // throw? log warning?
-      return;
-    }
-
-    // OK to start the startables now.
-    // Guaranteed to return in order of module binding..
-    Map<Key<?>, Binding<?>> allBindings = injector.getBindings();
-
-    List<Binding<Startable>> startables = Lists.newArrayList();
-    Map<Class<?>, List<Key<?>>> callableKeys = Maps.newLinkedHashMap();
-
-    // Do not collapse into loop below (in synchronized block). Time complexity is still linear.
-    for (Binding<?> binding : allBindings.values()) {
-
-      Class<?> bindingType = binding.getKey().getTypeLiteral().getRawType();
-
-      // inner loop N*M complexity
-      for (Class<?> callable : callableClasses) {
-        if (callable.isAssignableFrom(bindingType)) {
-
-          // we don't want to instantiate these right now...
-          List<Key<?>> list = callableKeys.get(callable);
-
-          // Multimap put.
-          if (null == list) {
-            list = Lists.newArrayList();
-            callableKeys.put(callable, list);
-          }
-
-          list.add(binding.getKey());
-        }
-      }
-
-      // check startables now.
-      if (Startable.class.isAssignableFrom(bindingType)) {
-
-        // First make sure this is a singleton.
-        Preconditions.checkState(Scopes.isSingleton(binding),
-            "Egregious error, all Startables must be scopes as singletons!");
-
-        //noinspection unchecked
-        startables.add((Binding<Startable>) binding);
-      }
-    }
-
-    synchronized (this) {
-      for (Binding<Startable> binding : startables) {
-
-        // Go go zilla go! (sequential startup)
-        injector.getInstance(binding.getKey()).start();
-      }
-
-      // Safely publish keymap.
-      this.callableKeys = callableKeys;
-
-      // success!
-      started = true;
-    }
-  }
-
-  public <T> T broadcast(Class<T> clazz) {
-    return broadcast(clazz, any());
-  }
-
-  public <T> T broadcast(Class<T> clazz, Matcher<? super T> matcher) {
-    final List<T> ts = instantiateForBroadcast(clazz, matcher);
-
-    @SuppressWarnings("unchecked") T caster = (T) Proxy
-        .newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, new InvocationHandler() {
-          public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
-
-            // propagate the method call with the same arg list to all instances.
-            for (T t : ts) {
-              method.invoke(t, objects);
-            }
-
-            // We can't return from multiple instances, so just return null.
-            return null;
-          }
-        });
-
-    return caster;
-  }
-
-  private <T> List<T> instantiateForBroadcast(Class<T> clazz, Matcher<? super T> matcher) {
-    final List<T> ts = Lists.newArrayList();
-    for (Key<?> key : callableKeys.get(clazz)) {
-      // Should this get instancing happen during method call?
-      @SuppressWarnings("unchecked") // Guarded by getInstance
-          T t = (T) injector.getInstance(key);
-
-      if (matcher.matches(t)) {
-        ts.add(t);
-      }
-    }
-    return ts;
-  }
-
-  public <T> T broadcast(Class<T> clazz, final ExecutorService executorService) {
-    return broadcast(clazz, executorService, any());
-  }
-
-  public <T> T broadcast(Class<T> clazz, final ExecutorService executorService,
-      Matcher<? super T> matcher) {
-    final List<T> ts = instantiateForBroadcast(clazz, matcher);
-
-    @SuppressWarnings("unchecked") T caster = (T) Proxy
-        .newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, new InvocationHandler() {
-          public Object invoke(Object o, final Method method, final Object[] objects)
-              throws Throwable {
-
-            // propagate the method call with the same arg list to all instances.
-            for (final T t : ts) {
-              // Submit via executor service. TODO See if this can be parallelized by
-              // yet another dimension, i.e. inParallel(N)
-              executorService.submit(new Callable() {
-                public Object call() throws Exception {
-                  return method.invoke(t, objects);
-                }
-              });
-            }
-
-            // We can't return from multiple instances, so just return null.
-            return null;
-          }
-        });
-
-    return caster;
-  }
-}
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/Lifecycle.java b/extensions/lifecycle/src/com/google/inject/lifecycle/Lifecycle.java
deleted file mode 100644
index 7204521..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/Lifecycle.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.ImplementedBy;
-import com.google.inject.matcher.Matcher;
-import java.util.concurrent.ExecutorService;
-
-/**
- *  @author dhanji@gmail.com (Dhanji R. Prasanna)
- */
-@ImplementedBy(BroadcastingLifecycle.class)
-public interface Lifecycle {
-
-  void start();
-
-  <T> T broadcast(Class<T> clazz);
-
-  <T> T broadcast(Class<T> clazz, Matcher<? super T> matcher);
-
-  <T> T broadcast(Class<T> clazz, ExecutorService executorService);
-
-  <T> T broadcast(Class<T> clazz, ExecutorService executorService, Matcher<? super T> matcher);
-}
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/LifecycleModule.java b/extensions/lifecycle/src/com/google/inject/lifecycle/LifecycleModule.java
deleted file mode 100644
index f6b8e98..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/LifecycleModule.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.TypeLiteral;
-import com.google.inject.internal.util.ImmutableList;
-import com.google.inject.internal.util.Lists;
-import java.util.List;
-
-/**
- * Use this module to configure lifecycle and multicasting support
- * for your Guice applications.
- *
- * @author dhanji@gmail.com (Dhanji R. Prasanna)
-// */
-public abstract class LifecycleModule extends AbstractModule {
-
-  private final List<Class<?>> callables = Lists.newArrayList();
-  private boolean autostart = false;
-
-  @Override
-  protected final void configure() {
-
-    // Call down into module.
-    configureLifecycle();
-
-    // The only real purpose of this is to do some error checking.
-    bind(new TypeLiteral<List<Class<?>>>() { })
-        .annotatedWith(ListOfMatchers.class)
-        .toInstance(ImmutableList.copyOf(callables));
-  }
-
-  protected abstract void configureLifecycle();
-  
-  protected void callable(Class<?> type) {
-    callables.add(type);
-  }
-
-  protected void autostart() {
-    this.autostart = true;
-
-    // This is a cool method that will execute after injector creating
-    // completes, and thus much better than the eager singleton hack.
-    throw new UnsupportedOperationException("Asplode!");
-  }
-}
\ No newline at end of file
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/ListOfMatchers.java b/extensions/lifecycle/src/com/google/inject/lifecycle/ListOfMatchers.java
deleted file mode 100644
index 32aedad..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/ListOfMatchers.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.BindingAnnotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
-@Retention(RetentionPolicy.RUNTIME)
-@BindingAnnotation
-@interface ListOfMatchers {
-}
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/Startable.java b/extensions/lifecycle/src/com/google/inject/lifecycle/Startable.java
deleted file mode 100644
index 6ea9ea8..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/Startable.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.google.inject.lifecycle;
-
-/**
- * A convenience lifecycle interface. Any class the exposes
- * this interface will be started if the lifecycle module is
- * installed. The lifecycle module guarantees that the order
- * in which Startables are called will match the order in which
- * modules are installed.
- *
- * All instances that wish to use startable *must* be bound as
- * singletons.
- *
- * @author dhanji@gmail.com (Dhanji R. Prasanna)
- */
-public interface Startable {
-  /**
-   * Called once the injector has been created completely.
-   * In PRODUCTION mode, this means when all singletons
-   * have been instantiated.
-   */
-  void start();
-}
diff --git a/extensions/lifecycle/src/com/google/inject/lifecycle/package-info.java b/extensions/lifecycle/src/com/google/inject/lifecycle/package-info.java
deleted file mode 100644
index afe0e97..0000000
--- a/extensions/lifecycle/src/com/google/inject/lifecycle/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Lifecycle extension; this extension requires {@code guice-lifecycle-2.0.jar}.
- */
-package com.google.inject.lifecycle;
\ No newline at end of file
diff --git a/extensions/lifecycle/test/com/google/inject/lifecycle/ArbitraryBroadcastTest.java b/extensions/lifecycle/test/com/google/inject/lifecycle/ArbitraryBroadcastTest.java
deleted file mode 100644
index f2e930c..0000000
--- a/extensions/lifecycle/test/com/google/inject/lifecycle/ArbitraryBroadcastTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.Guice;
-import com.google.inject.Singleton;
-import junit.framework.TestCase;
-
-/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
-public class ArbitraryBroadcastTest extends TestCase {
-  private static int called;
-
-  public final void testCallable() {
-    called = 0;
-    Lifecycle lifecycle = Guice.createInjector(new LifecycleModule() {
-
-      @Override
-      protected void configureLifecycle() {
-        bind(Runnable.class).to(AClass.class).in(Singleton.class);
-        bind(AClass.class).in(Singleton.class);
-
-        callable(Runnable.class);
-      }
-
-    }).getInstance(Lifecycle.class);
-
-    lifecycle
-      .broadcast(Runnable.class)
-      .run();
-
-    assertEquals(2, called);
-  }
-
-  public static class AClass implements Runnable {
-    public void run() {
-      called++;
-    }
-  }
-}
\ No newline at end of file
diff --git a/extensions/lifecycle/test/com/google/inject/lifecycle/MultipleStartableTest.java b/extensions/lifecycle/test/com/google/inject/lifecycle/MultipleStartableTest.java
deleted file mode 100644
index 6e67ff9..0000000
--- a/extensions/lifecycle/test/com/google/inject/lifecycle/MultipleStartableTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.Guice;
-import com.google.inject.Singleton;
-import junit.framework.TestCase;
-
-/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
-public class MultipleStartableTest extends TestCase {
-  private static int started;
-
-  public final void testMultiStartable() {
-    started = 0;
-    Guice.createInjector(new LifecycleModule() {
-
-      @Override
-      protected void configureLifecycle() {
-        bind(AClass.class).in(Singleton.class);
-        bind(Startable.class)
-            .annotatedWith(ListOfMatchers.class)
-            .to(BClass.class)
-            .in(Singleton.class);
-        bind(Startable.class).to(CClass.class).in(Singleton.class);
-      }
-
-    }).getInstance(Lifecycle.class)
-      .start();
-
-    assertEquals(3, started);
-  }
-
-  public static class AClass implements Startable {
-
-    public void start() {
-      started++;
-    }
-  }
-
-  public static class BClass implements Startable {
-
-    public void start() {
-      started++;
-    }
-  }
-
-  public static class CClass implements Startable {
-
-    public void start() {
-      started++;
-    }
-  }
-}
\ No newline at end of file
diff --git a/extensions/lifecycle/test/com/google/inject/lifecycle/ParallelizedBroadcastTest.java b/extensions/lifecycle/test/com/google/inject/lifecycle/ParallelizedBroadcastTest.java
deleted file mode 100644
index 27e8775..0000000
--- a/extensions/lifecycle/test/com/google/inject/lifecycle/ParallelizedBroadcastTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.Guice;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import junit.framework.TestCase;
-
-/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
-public class ParallelizedBroadcastTest extends TestCase {
-  private static final AtomicInteger called = new AtomicInteger();
-
-  public final void testCallable() throws InterruptedException {
-    called.set(0);
-    Lifecycle lifecycle = Guice.createInjector(new LifecycleModule() {
-
-      @Override
-      protected void configureLifecycle() {
-        bind(Runnable.class).to(AClass.class);
-
-        // Does not get called because the key does not expose the callable.
-        bind(Object.class).to(AClass.class);
-
-        bind(BaseClass.class).to(AClass.class);
-
-        callable(Runnable.class);
-      }
-
-    }).getInstance(Lifecycle.class);
-
-    final ExecutorService executorService = Executors.newFixedThreadPool(3);
-    lifecycle
-      .broadcast(Runnable.class, executorService)
-      .run();
-
-    executorService.shutdown();
-    executorService.awaitTermination(5L, TimeUnit.SECONDS);
-
-    assertEquals(2, called.get());
-  }
-
-  public static class BaseClass implements Runnable {
-
-    public void run() {
-      called.incrementAndGet();
-    }
-  }
-
-  public static class AClass extends BaseClass implements Runnable {
-    public void run() {
-      super.run();
-    }
-  }
-}
diff --git a/extensions/lifecycle/test/com/google/inject/lifecycle/StartableTest.java b/extensions/lifecycle/test/com/google/inject/lifecycle/StartableTest.java
deleted file mode 100644
index 0ec2e37..0000000
--- a/extensions/lifecycle/test/com/google/inject/lifecycle/StartableTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.google.inject.lifecycle;
-
-import com.google.inject.Guice;
-import com.google.inject.Singleton;
-import junit.framework.TestCase;
-
-/** @author dhanji@gmail.com (Dhanji R. Prasanna) */
-public class StartableTest extends TestCase {
-  private static boolean started;
-
-  public final void testStartable() {
-    started = false;
-    Guice.createInjector(new LifecycleModule() {
-
-      @Override
-      protected void configureLifecycle() {
-        bind(AClass.class).in(Singleton.class);
-      }
-
-    }).getInstance(Lifecycle.class)
-      .start();
-
-    assertTrue(started);
-  }
-
-  public static class AClass implements Startable {
-
-    public void start() {
-      started = true;
-    }
-  }
-}