AbstractIdleService.java 3.57 KB
package com.google.common.util.concurrent;

import com.google.common.annotations.Beta;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

@Beta
public abstract class AbstractIdleService
  implements Service
{
  private final Supplier<String> a = new Supplier() {};
  private final Service b = new AbstractService()
  {
    protected final void doStart()
    {
      MoreExecutors.a(AbstractIdleService.this.executor(), AbstractIdleService.a(AbstractIdleService.this)).execute(new Runnable()
      {
        public final void run()
        {
          try
          {
            AbstractIdleService.this.startUp();
            AbstractIdleService.2.this.notifyStarted();
            return;
          }
          catch (Throwable localThrowable)
          {
            AbstractIdleService.2.this.notifyFailed(localThrowable);
            throw Throwables.propagate(localThrowable);
          }
        }
      });
    }
    
    protected final void doStop()
    {
      MoreExecutors.a(AbstractIdleService.this.executor(), AbstractIdleService.a(AbstractIdleService.this)).execute(new Runnable()
      {
        public final void run()
        {
          try
          {
            AbstractIdleService.this.shutDown();
            AbstractIdleService.2.this.notifyStopped();
            return;
          }
          catch (Throwable localThrowable)
          {
            AbstractIdleService.2.this.notifyFailed(localThrowable);
            throw Throwables.propagate(localThrowable);
          }
        }
      });
    }
  };
  
  public final void addListener(Service.Listener paramListener, Executor paramExecutor)
  {
    this.b.addListener(paramListener, paramExecutor);
  }
  
  public final void awaitRunning()
  {
    this.b.awaitRunning();
  }
  
  public final void awaitRunning(long paramLong, TimeUnit paramTimeUnit)
    throws TimeoutException
  {
    this.b.awaitRunning(paramLong, paramTimeUnit);
  }
  
  public final void awaitTerminated()
  {
    this.b.awaitTerminated();
  }
  
  public final void awaitTerminated(long paramLong, TimeUnit paramTimeUnit)
    throws TimeoutException
  {
    this.b.awaitTerminated(paramLong, paramTimeUnit);
  }
  
  protected Executor executor()
  {
    new Executor()
    {
      public final void execute(Runnable paramAnonymousRunnable)
      {
        MoreExecutors.a((String)AbstractIdleService.a(AbstractIdleService.this).get(), paramAnonymousRunnable).start();
      }
    };
  }
  
  public final Throwable failureCause()
  {
    return this.b.failureCause();
  }
  
  public final boolean isRunning()
  {
    return this.b.isRunning();
  }
  
  protected String serviceName()
  {
    return getClass().getSimpleName();
  }
  
  protected abstract void shutDown()
    throws Exception;
  
  public final Service startAsync()
  {
    this.b.startAsync();
    return this;
  }
  
  protected abstract void startUp()
    throws Exception;
  
  public final Service.State state()
  {
    return this.b.state();
  }
  
  public final Service stopAsync()
  {
    this.b.stopAsync();
    return this;
  }
  
  public String toString()
  {
    String str1 = String.valueOf(String.valueOf(serviceName()));
    String str2 = String.valueOf(String.valueOf(state()));
    return str1.length() + 3 + str2.length() + str1 + " [" + str2 + "]";
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/util/concurrent/AbstractIdleService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */