BackgroundInitializer.java 6.26 KB
package org.apache.commons.lang3.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

public abstract class BackgroundInitializer<T>
  implements ConcurrentInitializer<T>
{
  private ExecutorService a;
  private ExecutorService b;
  private Future<T> c;
  
  protected BackgroundInitializer()
  {
    this(null);
  }
  
  protected BackgroundInitializer(ExecutorService paramExecutorService)
  {
    setExternalExecutor(paramExecutorService);
  }
  
  public T get()
    throws ConcurrentException
  {
    try
    {
      Object localObject = getFuture().get();
      return (T)localObject;
    }
    catch (ExecutionException localExecutionException)
    {
      ConcurrentUtils.handleCause(localExecutionException);
      return null;
    }
    catch (InterruptedException localInterruptedException)
    {
      Thread.currentThread().interrupt();
      throw new ConcurrentException(localInterruptedException);
    }
  }
  
  protected final ExecutorService getActiveExecutor()
  {
    try
    {
      ExecutorService localExecutorService = this.b;
      return localExecutorService;
    }
    finally
    {
      localObject = finally;
      throw ((Throwable)localObject);
    }
  }
  
  public final ExecutorService getExternalExecutor()
  {
    try
    {
      ExecutorService localExecutorService = this.a;
      return localExecutorService;
    }
    finally
    {
      localObject = finally;
      throw ((Throwable)localObject);
    }
  }
  
  public Future<T> getFuture()
  {
    try
    {
      if (this.c == null) {
        throw new IllegalStateException("start() must be called first!");
      }
    }
    finally {}
    Future localFuture = this.c;
    return localFuture;
  }
  
  protected int getTaskCount()
  {
    return 1;
  }
  
  protected abstract T initialize()
    throws Exception;
  
  /* Error */
  public boolean isStarted()
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: aload_0
    //   3: getfield 72	org/apache/commons/lang3/concurrent/BackgroundInitializer:c	Ljava/util/concurrent/Future;
    //   6: astore_2
    //   7: aload_2
    //   8: ifnull +9 -> 17
    //   11: iconst_1
    //   12: istore_1
    //   13: aload_0
    //   14: monitorexit
    //   15: iload_1
    //   16: ireturn
    //   17: iconst_0
    //   18: istore_1
    //   19: goto -6 -> 13
    //   22: astore_2
    //   23: aload_0
    //   24: monitorexit
    //   25: aload_2
    //   26: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	27	0	this	BackgroundInitializer
    //   12	7	1	bool	boolean
    //   6	2	2	localFuture	Future
    //   22	4	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   2	7	22	finally
  }
  
  public final void setExternalExecutor(ExecutorService paramExecutorService)
  {
    try
    {
      if (isStarted()) {
        throw new IllegalStateException("Cannot set ExecutorService after start()!");
      }
    }
    finally {}
    this.a = paramExecutorService;
  }
  
  /* Error */
  public boolean start()
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: aload_0
    //   3: invokevirtual 89	org/apache/commons/lang3/concurrent/BackgroundInitializer:isStarted	()Z
    //   6: ifne +64 -> 70
    //   9: aload_0
    //   10: aload_0
    //   11: invokevirtual 94	org/apache/commons/lang3/concurrent/BackgroundInitializer:getExternalExecutor	()Ljava/util/concurrent/ExecutorService;
    //   14: putfield 67	org/apache/commons/lang3/concurrent/BackgroundInitializer:b	Ljava/util/concurrent/ExecutorService;
    //   17: aload_0
    //   18: getfield 67	org/apache/commons/lang3/concurrent/BackgroundInitializer:b	Ljava/util/concurrent/ExecutorService;
    //   21: ifnonnull +44 -> 65
    //   24: aload_0
    //   25: invokevirtual 96	org/apache/commons/lang3/concurrent/BackgroundInitializer:getTaskCount	()I
    //   28: invokestatic 102	java/util/concurrent/Executors:newFixedThreadPool	(I)Ljava/util/concurrent/ExecutorService;
    //   31: astore_2
    //   32: aload_0
    //   33: aload_2
    //   34: putfield 67	org/apache/commons/lang3/concurrent/BackgroundInitializer:b	Ljava/util/concurrent/ExecutorService;
    //   37: aload_0
    //   38: aload_0
    //   39: getfield 67	org/apache/commons/lang3/concurrent/BackgroundInitializer:b	Ljava/util/concurrent/ExecutorService;
    //   42: new 9	org/apache/commons/lang3/concurrent/BackgroundInitializer$a
    //   45: dup
    //   46: aload_0
    //   47: aload_2
    //   48: invokespecial 105	org/apache/commons/lang3/concurrent/BackgroundInitializer$a:<init>	(Lorg/apache/commons/lang3/concurrent/BackgroundInitializer;Ljava/util/concurrent/ExecutorService;)V
    //   51: invokeinterface 111 2 0
    //   56: putfield 72	org/apache/commons/lang3/concurrent/BackgroundInitializer:c	Ljava/util/concurrent/Future;
    //   59: iconst_1
    //   60: istore_1
    //   61: aload_0
    //   62: monitorexit
    //   63: iload_1
    //   64: ireturn
    //   65: aconst_null
    //   66: astore_2
    //   67: goto -30 -> 37
    //   70: iconst_0
    //   71: istore_1
    //   72: goto -11 -> 61
    //   75: astore_2
    //   76: aload_0
    //   77: monitorexit
    //   78: aload_2
    //   79: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	80	0	this	BackgroundInitializer
    //   60	12	1	bool	boolean
    //   31	36	2	localExecutorService	ExecutorService
    //   75	4	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   2	37	75	finally
    //   37	59	75	finally
  }
  
  final class a
    implements Callable<T>
  {
    private final ExecutorService b;
    
    public a(ExecutorService paramExecutorService)
    {
      this.b = paramExecutorService;
    }
    
    public final T call()
      throws Exception
    {
      try
      {
        Object localObject1 = BackgroundInitializer.this.initialize();
        return (T)localObject1;
      }
      finally
      {
        if (this.b != null) {
          this.b.shutdown();
        }
      }
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/concurrent/BackgroundInitializer.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */