ModernAsyncTask.java 5.09 KB
package android.support.v4.content;

import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Log;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

abstract class ModernAsyncTask<Params, Progress, Result>
{
  private static final ThreadFactory a = new ThreadFactory()
  {
    private final AtomicInteger a = new AtomicInteger(1);
    
    public final Thread newThread(Runnable paramAnonymousRunnable)
    {
      return new Thread(paramAnonymousRunnable, "ModernAsyncTask #" + this.a.getAndIncrement());
    }
  };
  private static final BlockingQueue<Runnable> b = new LinkedBlockingQueue(10);
  private static b c;
  public static final Executor d;
  private static volatile Executor i;
  final c<Params, Result> e = new c()
  {
    public final Result call()
      throws Exception
    {
      ModernAsyncTask.a(ModernAsyncTask.this).set(true);
      Object localObject5 = null;
      Object localObject4 = null;
      Object localObject2 = localObject4;
      Object localObject1 = localObject5;
      try
      {
        Process.setThreadPriority(10);
        localObject2 = localObject4;
        localObject1 = localObject5;
        localObject4 = ModernAsyncTask.this.a();
        localObject2 = localObject4;
        localObject1 = localObject4;
        Binder.flushPendingCommands();
        return (Result)localObject4;
      }
      catch (Throwable localThrowable)
      {
        localObject1 = localObject2;
        ModernAsyncTask.b(ModernAsyncTask.this).set(true);
        localObject1 = localObject2;
        throw localThrowable;
      }
      finally
      {
        ModernAsyncTask.this.d(localObject1);
      }
    }
  };
  final FutureTask<Result> f = new FutureTask(this.e)
  {
    protected final void done()
    {
      try
      {
        Object localObject = get();
        ModernAsyncTask.this.c(localObject);
        return;
      }
      catch (InterruptedException localInterruptedException)
      {
        Log.w("AsyncTask", localInterruptedException);
        return;
      }
      catch (ExecutionException localExecutionException)
      {
        throw new RuntimeException("An error occurred while executing doInBackground()", localExecutionException.getCause());
      }
      catch (CancellationException localCancellationException)
      {
        ModernAsyncTask.this.c(null);
        return;
      }
      catch (Throwable localThrowable)
      {
        throw new RuntimeException("An error occurred while executing doInBackground()", localThrowable);
      }
    }
  };
  volatile Status g = Status.PENDING;
  final AtomicBoolean h = new AtomicBoolean();
  private final AtomicBoolean j = new AtomicBoolean();
  
  static
  {
    ThreadPoolExecutor localThreadPoolExecutor = new ThreadPoolExecutor(5, 128, 1L, TimeUnit.SECONDS, b, a);
    d = localThreadPoolExecutor;
    i = localThreadPoolExecutor;
  }
  
  protected static void b() {}
  
  private static Handler c()
  {
    try
    {
      if (c == null) {
        c = new b();
      }
      b localb = c;
      return localb;
    }
    finally {}
  }
  
  protected abstract Result a();
  
  protected void a(Result paramResult) {}
  
  protected void b(Result paramResult) {}
  
  final void c(Result paramResult)
  {
    if (!this.j.get()) {
      d(paramResult);
    }
  }
  
  final Result d(Result paramResult)
  {
    c().obtainMessage(1, new a(this, new Object[] { paramResult })).sendToTarget();
    return paramResult;
  }
  
  final void e(Result paramResult)
  {
    if (this.h.get()) {
      b(paramResult);
    }
    for (;;)
    {
      this.g = Status.FINISHED;
      return;
      a(paramResult);
    }
  }
  
  public static enum Status
  {
    private Status() {}
  }
  
  static final class a<Data>
  {
    final ModernAsyncTask a;
    final Data[] b;
    
    a(ModernAsyncTask paramModernAsyncTask, Data... paramVarArgs)
    {
      this.a = paramModernAsyncTask;
      this.b = paramVarArgs;
    }
  }
  
  static final class b
    extends Handler
  {
    public b()
    {
      super();
    }
    
    public final void handleMessage(Message paramMessage)
    {
      ModernAsyncTask.a locala = (ModernAsyncTask.a)paramMessage.obj;
      switch (paramMessage.what)
      {
      default: 
        return;
      case 1: 
        locala.a.e(locala.b[0]);
        return;
      }
      ModernAsyncTask.b();
    }
  }
  
  static abstract class c<Params, Result>
    implements Callable<Result>
  {
    Params[] b;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/content/ModernAsyncTask.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */