org.eclipse.equinox.util_1.0.400.v20120917-192807

 ifnonnull +14 -> 71
    //   60: aload_0
    //   61: new 88	org/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA
    //   64: dup
    //   65: invokespecial 181	org/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA:<init>	()V
    //   68: putfield 158	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:pea	Lorg/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA;
    //   71: aload_0
    //   72: getfield 158	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:pea	Lorg/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA;
    //   75: aload_0
    //   76: getfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   79: putfield 160	org/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA:job	Ljava/lang/Runnable;
    //   82: aload_0
    //   83: getfield 158	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:pea	Lorg/eclipse/equinox/internal/util/impl/tpt/threadpool/PEA;
    //   86: aload_0
    //   87: getfield 157	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:acc	Ljava/security/AccessControlContext;
    //   90: invokestatic 172	java/security/AccessController:doPrivileged	(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    //   93: pop
    //   94: goto +111 -> 205
    //   97: aload_0
    //   98: getfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   101: invokeinterface 185 1 0
    //   106: goto +99 -> 205
    //   109: astore_1
    //   110: new 77	java/lang/Exception
    //   113: dup
    //   114: invokespecial 162	java/lang/Exception:<init>	()V
    //   117: athrow
    //   118: pop
    //   119: getstatic 152	org/eclipse/equinox/internal/util/impl/tpt/ServiceFactoryImpl:log	Lorg/eclipse/equinox/internal/util/ref/Log;
    //   122: ifnull +43 -> 165
    //   125: getstatic 152	org/eclipse/equinox/internal/util/impl/tpt/ServiceFactoryImpl:log	Lorg/eclipse/equinox/internal/util/ref/Log;
    //   128: new 81	java/lang/StringBuffer
    //   131: dup
    //   132: ldc 4
    //   134: invokespecial 166	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   137: aload_0
    //   138: invokevirtual 167	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   141: ldc 2
    //   143: invokevirtual 168	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   146: aload_0
    //   147: getfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   150: invokevirtual 167	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   153: ldc 1
    //   155: invokevirtual 168	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   158: invokevirtual 165	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   161: aload_1
    //   162: invokevirtual 184	org/eclipse/equinox/internal/util/ref/Log:error	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   165: aload_0
    //   166: invokevirtual 177	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   169: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   172: if_acmpeq +50 -> 222
    //   175: aload_0
    //   176: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   179: invokevirtual 178	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   182: goto +40 -> 222
    //   185: astore_2
    //   186: aload_0
    //   187: invokevirtual 177	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   190: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   193: if_acmpeq +10 -> 203
    //   196: aload_0
    //   197: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   200: invokevirtual 178	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   203: aload_2
    //   204: athrow
    //   205: aload_0
    //   206: invokevirtual 177	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:getContextClassLoader	()Ljava/lang/ClassLoader;
    //   209: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   212: if_acmpeq +10 -> 222
    //   215: aload_0
    //   216: getstatic 155	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:defaultTCCL	Ljava/lang/ClassLoader;
    //   219: invokevirtual 178	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:setContextClassLoader	(Ljava/lang/ClassLoader;)V
    //   222: getstatic 148	org/eclipse/equinox/internal/util/UtilActivator:debugLevel	I
    //   225: iconst_2
    //   226: if_icmpne +27 -> 253
    //   229: getstatic 149	org/eclipse/equinox/internal/util/UtilActivator:LOG_DEBUG	Z
    //   232: ifeq +21 -> 253
    //   235: getstatic 150	org/eclipse/equinox/internal/util/UtilActivator:log	Lorg/eclipse/equinox/internal/util/ref/Log;
    //   238: sipush 256
    //   241: sipush 10004
    //   244: aload_0
    //   245: invokevirtual 179	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:getName	()Ljava/lang/String;
    //   248: aconst_null
    //   249: iconst_0
    //   250: invokevirtual 183	org/eclipse/equinox/internal/util/ref/Log:debug	(IILjava/lang/String;Ljava/lang/Throwable;Z)V
    //   253: aload_0
    //   254: aconst_null
    //   255: putfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   258: getstatic 151	org/eclipse/equinox/internal/util/impl/tpt/ServiceFactoryImpl:useNames	Z
    //   261: ifeq +9 -> 270
    //   264: aload_0
    //   265: ldc 5
    //   267: invokevirtual 180	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:setName	(Ljava/lang/String;)V
    //   270: getstatic 161	org/eclipse/equinox/internal/util/impl/tpt/threadpool/ThreadPoolManagerImpl:threadPool	Lorg/eclipse/equinox/internal/util/impl/tpt/threadpool/ThreadPoolManagerImpl;
    //   273: ifnull +13 -> 286
    //   276: getstatic 161	org/eclipse/equinox/internal/util/impl/tpt/threadpool/ThreadPoolManagerImpl:threadPool	Lorg/eclipse/equinox/internal/util/impl/tpt/threadpool/ThreadPoolManagerImpl;
    //   279: aload_0
    //   280: invokevirtual 182	org/eclipse/equinox/internal/util/impl/tpt/threadpool/ThreadPoolManagerImpl:releaseObject	(Ljava/lang/Object;)Z
    //   283: ifne +11 -> 294
    //   286: aload_0
    //   287: iconst_1
    //   288: putfield 154	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:terminated	Z
    //   291: goto +52 -> 343
    //   294: aload_0
    //   295: getfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   298: ifnull +6 -> 304
    //   301: goto +42 -> 343
    //   304: aload_0
    //   305: dup
    //   306: astore_1
    //   307: monitorenter
    //   308: aload_0
    //   309: getfield 156	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:job	Ljava/lang/Runnable;
    //   312: ifnonnull +10 -> 322
    //   315: aload_0
    //   316: getfield 154	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:terminated	Z
    //   319: ifeq +8 -> 327
    //   322: aload_1
    //   323: monitorexit
    //   324: goto +19 -> 343
    //   327: aload_0
    //   328: invokevirtual 164	java/lang/Object:wait	()V
    //   331: goto +4 -> 335
    //   334: pop
    //   335: aload_1
    //   336: monitorexit
    //   337: goto +6 -> 343
    //   340: aload_1
    //   341: monitorexit
    //   342: athrow
    //   343: aload_0
    //   344: getfield 154	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:terminated	Z
    //   347: ifeq -344 -> 3
    //   350: aload_0
    //   351: invokevirtual 174	org/eclipse/equinox/internal/util/impl/tpt/threadpool/Executor:clear	()V
    //   354: return
    // Line number table:
    //   Java source line #57	-> byte code offset #0
    //   Java source line #58	-> byte code offset #3
    //   Java source line #60	-> byte code offset #10
    //   Java source line #61	-> byte code offset #23
    //   Java source line #63	-> byte code offset #41
    //   Java source line #64	-> byte code offset #46
    //   Java source line #65	-> byte code offset #53
    //   Java source line #66	-> byte code offset #60
    //   Java source line #67	-> byte code offset #71
    //   Java source line #68	-> byte code offset #82
    //   Java source line #70	-> byte code offset #97
    //   Java source line #71	-> byte code offset #109
    //   Java source line #73	-> byte code offset #110
    //   Java source line #74	-> byte code offset #118
    //   Java source line #76	-> byte code offset #119
    //   Java source line #77	-> byte code offset #125
    //   Java source line #81	-> byte code offset #165
    //   Java source line #82	-> byte code offset #175
    //   Java source line #80	-> byte code offset #185
    //   Java source line #81	-> byte code offset #186
    //   Java source line #82	-> byte code offset #196
    //   Java source line #84	-> byte code offset #203
    //   Java source line #81	-> byte code offset #205
    //   Java source line #82	-> byte code offset #215
    //   Java source line #85	-> byte code offset #222
    //   Java source line #86	-> byte code offset #235
    //   Java source line #88	-> byte code offset #253
    //   Java source line #89	-> byte code offset #258
    //   Java source line #90	-> byte code offset #264
    //   Java source line #91	-> byte code offset #270
    //   Java source line #92	-> byte code offset #286
    //   Java source line #93	-> byte code offset #291
    //   Java source line #97	-> byte code offset #294
    //   Java source line #98	-> byte code offset #301
    //   Java source line #100	-> byte code offset #304
    //   Java source line #101	-> byte code offset #308
    //   Java source line #102	-> byte code offset #322
    //   Java source line #106	-> byte code offset #327
    //   Java source line #107	-> byte code offset #334
    //   Java source line #100	-> byte code offset #335
    //   Java source line #57	-> byte code offset #343
    //   Java source line #112	-> byte code offset #350
    //   Java source line #113	-> byte code offset #354
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	355	0	this	Executor
    //   109	53	1	t	Throwable
    //   306	35	1	Ljava/lang/Object;	Object
    //   185	19	2	localObject1	Object
    //   118	1	4	localException	Exception
    //   334	1	5	localInterruptedException	InterruptedException
    // Exception table:
    //   from	to	target	type
    //   10	106	109	java/lang/Throwable
    //   110	118	118	java/lang/Exception
    //   10	165	185	finally
    //   327	331	334	java/lang/InterruptedException
    //   308	324	340	finally
    //   327	337	340	finally
    //   340	342	340	finally
  }
  
  void clear()
  {
    job = null;
  }
  
  public synchronized void terminate()
  {
    terminated = true;
    notify();
  }
  
  public Executor()
  {
    super(ServiceFactoryImpl.useNames ? "[ThreadPool Manager] - Idle Thread" : "ThreadPool Manager Thread");
    if (getContextClassLoader() != defaultTCCL) {
      setContextClassLoader(defaultTCCL);
    }
    start();
  }
  
  public Runnable getRunnable()
  {
    return job;
  }
  
  public void setPriorityI(int p)
  {
    if (getPriority() != p) {
      setPriority(p);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.threadpool;

import java.security.AccessControlContext;
import org.eclipse.equinox.internal.util.pool.ObjectCreator;
import org.eclipse.equinox.internal.util.pool.ObjectPool;

class Job
  implements ObjectCreator
{
  public Runnable run;
  public String name;
  public String context;
  public int priority = -1;
  public ThreadPoolFactoryImpl factory;
  AccessControlContext acc;
  
  private void setJob(Runnable run, String name, int priority, ThreadPoolFactoryImpl factory, AccessControlContext acc)
  {
    this.run = run;
    this.name = name;
    this.priority = priority;
    this.factory = factory;
    this.acc = acc;
  }
  
  public Object getInstance()
  {
    return new Job();
  }
  
  public Job root = null;
  public Job last = null;
  private Job next;
  int counter = 0;
  
  public Job addJob(Runnable run, String name, int priority, ThreadPoolFactoryImpl factory, AccessControlContext acc)
  {
    Job tmp = (Job)ThreadPoolManagerImpl.jobPool.getObject();
    counter += 1;
    tmp.setJob(run, name, priority, factory, acc);
    if (root == null)
    {
      root = tmp;
      last = tmp;
      return tmp;
    }
    last.next = tmp;
    last = tmp;
    return tmp;
  }
  
  public void addJob(Job j)
  {
    counter += 1;
    if (root == null)
    {
      root = j;
      last = j;
      return;
    }
    last.next = j;
    last = j;
  }
  
  private void clear()
  {
    next = null;
  }
  
  public void fullClear()
  {
    next = null;
    run = null;
    name = null;
    context = null;
    acc = null;
  }
  
  public Job getJob()
  {
    Job r = null;
    if (root == null) {
      return null;
    }
    counter -= 1;
    r = root;
    root = root.next;
    if (root == null) {
      last = root;
    }
    r.clear();
    return r;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.threadpool.Job
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.threadpool;

import java.security.PrivilegedAction;

class PEA
  implements PrivilegedAction
{
  Runnable job;
  
  public Object run()
  {
    job.run();
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.threadpool.PEA
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.threadpool;

import java.security.AccessControlContext;
import java.security.AccessController;
import org.eclipse.equinox.internal.util.UtilActivator;
import org.eclipse.equinox.internal.util.impl.tpt.ServiceFactoryImpl;
import org.eclipse.equinox.internal.util.ref.Log;
import org.eclipse.equinox.internal.util.threadpool.ThreadPoolFactory;
import org.eclipse.equinox.internal.util.threadpool.ThreadPoolManager;

public class ThreadPoolFactoryImpl
  extends ServiceFactoryImpl
  implements ThreadPoolManager, ThreadPoolFactory
{
  public static ThreadPoolManagerImpl threadPool;
  private int limit;
  private int used = 0;
  private Job queue;
  private static int defaultPercent;
  
  public ThreadPoolFactoryImpl(String bundleName, Log log)
  {
    super(bundleName, log);
    threadPool = ThreadPoolManagerImpl.getThreadPool();
    defaultPercent = UtilActivator.getInteger("equinox.util.threadpool.percent", 30);
    limit = (ThreadPoolManagerImpl.tMaximum * defaultPercent / 100);
    if (limit == 0) {
      limit = 1;
    }
    queue = new Job();
  }
  
  public ThreadPoolFactoryImpl(String bundleName, int size)
  {
    super(bundleName);
    limit = size;
    if (limit == 0) {
      limit = 1;
    }
    queue = new Job();
  }
  
  public ThreadPoolFactoryImpl(String bundleName)
  {
    this(bundleName, ThreadPoolManagerImpl.tMaximum * defaultPercent / 100);
  }
  
  public Object getInstance(String bundleName)
  {
    if (threadPool == null) {
      throw new RuntimeException("ServiceFactory is currently off!");
    }
    return new ThreadPoolFactoryImpl(bundleName);
  }
  
  public static void stopThreadPool()
  {
    ThreadPoolManagerImpl tmp = threadPool;
    threadPool = null;
    tmp.clear();
  }
  
  public ThreadPoolManager getThreadPool(int size, boolean sizeIsInPercents)
  {
    if (threadPool == null) {
      throw new RuntimeException("[ThreadPool] ThreadPool is inaccessible");
    }
    if (sizeIsInPercents) {
      size = ThreadPoolManagerImpl.tMaximum * size / 100;
    }
    if (size <= 0) {
      size = 1;
    }
    return new ThreadPoolFactoryImpl(bundleName, size);
  }
  
  public void execute(Runnable job, String name)
  {
    execute(job, 5, name);
  }
  
  public void execute0(Runnable job, int priority, String name, AccessControlContext acc)
  {
    if ((job == null) || (name == null)) {
      throw new IllegalArgumentException("the job or the name parameter is/are null");
    }
    if (ServiceFactoryImpl.useNames) {
      name = name + bundleName;
    }
    ThreadPoolManagerImpl tmp = threadPool;
    if (tmp != null)
    {
      synchronized (tmp.getSyncMonitor())
      {
        if (used >= limit)
        {
          if (UtilActivator.LOG_DEBUG) {
            UtilActivator.log.debug("In Bundle Queue: " + name + ", bundle queue size: " + queue.counter, null);
          }
          queue.addJob(job, name, priority, this, acc);
          
          return;
        }
        used += 1;
      }
      tmp.execute(job, priority, name, this, acc);
    }
    else
    {
      throw new RuntimeException("[ThreadPool] ThreadPool is inaccessible");
    }
  }
  
  public void execute(Runnable job, int priority, String name, AccessControlContext acc)
  {
    execute0(job, priority, name, acc);
  }
  
  public void execute(Runnable job, int priority, String name)
  {
    execute0(job, priority, name, Log.security() ? AccessController.getContext() : null);
  }
  
  public Executor getExecutor()
  {
    ThreadPoolManagerImpl tmp = threadPool;
    if (tmp != null) {
      synchronized (tmp.getSyncMonitor())
      {
        if (used < limit)
        {
          Executor ex = tmp.getExecutor();
          if (ex != null) {
            used += 1;
          }
          return ex;
        }
      }
    }
    return null;
  }
  
  void finished()
  {
    Job job = queue.getJob();
    if (job != null)
    {
      if (UtilActivator.LOG_DEBUG) {
        UtilActivator.log.debug("To threadpool queue: " + name + ", queue size: " + threadPoolwaiting.counter, null);
      }
      threadPoolwaiting.addJob(job);
    }
    else
    {
      used -= 1;
    }
  }
  
  public void reset()
  {
    if (threadPool != null) {
      threadPool.reset();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.threadpool.ThreadPoolFactoryImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.threadpool;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.eclipse.equinox.internal.util.UtilActivator;
import org.eclipse.equinox.internal.util.impl.tpt.ServiceFactoryImpl;
import org.eclipse.equinox.internal.util.pool.ObjectPool;
import org.eclipse.equinox.internal.util.ref.Log;
import org.eclipse.equinox.internal.util.timer.TimerListener;

public class ThreadPoolManagerImpl
  extends ObjectPool
  implements TimerListener, PrivilegedAction
{
  static ThreadPoolManagerImpl threadPool = null;
  static ObjectPool jobPool;
  private int used = 0;
  static int tMaximum = 0;
  Job waiting = new Job();
  private static String pAutoMaximum = "equinox.util.threadpool.autoMaximum";
  private static String pMin = "equinox.util.threadpool.minThreads";
  private static String pMax = "equinox.util.threadpool.maxThreads";
  private static String pIgnoreMax = "equinox.util.threadpool.ignoreMaximum";
  private static int defMin = 1;
  private static int defMax = 48;
  private static int MAX_WAITING = 20;
  private static float MAX_OVERLOAD = 0.1F;
  private static boolean ignoreMax;
  private static boolean autoMax;
  
  private ThreadPoolManagerImpl(int i, int j, int m)
  {
    super(null, i, j, m);
    tMaximum = i * j;
    ignoreMax = UtilActivator.getBoolean(pIgnoreMax);
    autoMax = UtilActivator.getBoolean(pAutoMaximum);
    jobPool = new ObjectPool(waiting, 5, 8, 4);
  }
  
  public static ThreadPoolManagerImpl getThreadPool()
  {
    if (threadPool == null)
    {
      int intSize = UtilActivator.getInteger(pMin, defMin);
      int minFill = intSize;
      int factor = UtilActivator.getInteger(pMax, defMax);
      intSize = intSize < 2 ? 2 : intSize;
      if (intSize > factor) {
        factor = (int)(intSize * 1.5D + 0.5D);
      }
      threadPool = new ThreadPoolManagerImpl(intSize, factor / intSize, minFill);
    }
    return threadPool;
  }
  
  public void clear()
  {
    shrink(-1);
    threadPool = null;
  }
  
  public Object getInstance()
    throws Exception
  {
    Object result = ServiceFactoryImpl.privileged() ? AccessController.doPrivileged(this) : new Executor();
    
    return result;
  }
  
  public Object run()
  {
    return new Executor();
  }
  
  public Object getObject()
  {
    try
    {
      return super.getObject();
    }
    catch (Throwable tw)
    {
      if (ServiceFactoryImpl.log != null) {
        ServiceFactoryImpl.log.error("Unable to create more threads!\r\nActive Thread Pool tasks: " + used, tw);
      }
    }
    return null;
  }
  
  public Executor getExecutor()
  {
    synchronized (getSyncMonitor())
    {
      if ((used < tMaximum) || (ignoreMax))
      {
        Executor e = (Executor)getObject();
        if (e != null)
        {
          used += 1;
          return e;
        }
      }
    }
    return null;
  }
  
  protected void shrink(int count)
  {
    synchronized (getSyncMonitor())
    {
      dontExtend = true;
      for (; nextFree > count; nextFree -= 1)
      {
        int x = nextFree / factor;
        int y = nextFree % factor;
        Executor e = (Executor)buff[x][y];
        buff[x][y] = null;
        e.terminate();
      }
    }
  }
  
  public void shrink()
  {
    shrink(minimumFill - 1);
    dontExtend = false;
  }
  
  public boolean releaseObject(Object obj)
  {
    Job tmp = null;
    Executor x = (Executor)obj;
    synchronized (getSyncMonitor())
    {
      factory.finished();
      if ((used <= tMaximum) || (ignoreMax)) {
        tmp = waiting.getJob();
      }
    }
    if (tmp == null)
    {
      used -= 1;
      x.clear();
      x.setPriorityI(5);
      return super.releaseObject(obj);
    }
    if (UtilActivator.LOG_DEBUG) {
      UtilActivator.log.debug(256, 10005, name, null, false);
    }
    x.setPriorityI(priority);
    
    x.setRunnable(run, name, factory, acc);
    tmp.fullClear();
    jobPool.releaseObject(tmp);
    return true;
  }
  
  public void timer(int event)
  {
    int count = 0;
    int all = 0;
    synchronized (getSyncMonitor())
    {
      for (int i = 0; i < buff.length; i++) {
        if (buff[i] != null) {
          for (int j = 0; j < buff[i].length; j++)
          {
            Executor e = (Executor)buff[i][j];
            if (e != null)
            {
              all++;
              if (!accessed) {
                count++;
              } else {
                accessed = false;
              }
            }
          }
        }
      }
      if ((count > 0) && (all > minimumFill - 1) && (all > count))
      {
        if (count > minimumFill) {
          shrink(count - 2);
        } else {
          shrink(minimumFill - 2);
        }
        dontExtend = false;
      }
    }
  }
  
  public void execute(Runnable job, int priority, String name, ThreadPoolFactoryImpl factory, AccessControlContext acc)
  {
    Executor ex = null;
    synchronized (getSyncMonitor())
    {
      if ((used < tMaximum) || (ignoreMax)) {
        ex = (Executor)getObject();
      }
      if (ex != null)
      {
        used += 1;
      }
      else
      {
        addInTasksQueue(job, name, priority, factory, acc);
        
        return;
      }
    }
    ex.setPriorityI(priority);
    ex.setRunnable(job, name, factory, acc);
  }
  
  private void addInTasksQueue(Runnable job, String name, int priority, ThreadPoolFactoryImpl factory, AccessControlContext acc)
  {
    waiting.addJob(job, name, priority, factory, acc);
    if (UtilActivator.LOG_DEBUG) {
      UtilActivator.log.debug("In Threadpool Queue: " + name + ", queue size:" + waiting.counter, null);
    }
    if ((autoMax) && (waiting.counter > MAX_WAITING))
    {
      Executor ex = (Executor)getObject();
      if (ex != null)
      {
        tMaximum += MAX_WAITING;
        MAX_WAITING += (int)(MAX_WAITING * MAX_OVERLOAD);
        for (Job j = waiting.getJob(); j != null; j = waiting.getJob())
        {
          if (ex == null) {
            ex = (Executor)getObject();
          }
          if (ex != null)
          {
            used += 1;
            ex.setPriorityI(priority);
            ex.setRunnable(run, name, factory, acc);
            ex = null;
          }
          else
          {
            waiting.addJob(run, name, priority, factory, acc);
            break;
          }
        }
      }
    }
  }
  
  public void reset()
  {
    shrink(-1);
    dontExtend = false;
  }
  
  public Object getSyncMonitor()
  {
    return buff;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.threadpool.ThreadPoolManagerImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.timer;

import org.eclipse.equinox.internal.util.impl.tpt.ServiceFactoryImpl;
import org.eclipse.equinox.internal.util.impl.tpt.threadpool.ThreadPoolFactoryImpl;
import org.eclipse.equinox.internal.util.ref.Log;
import org.eclipse.equinox.internal.util.timer.Timer;
import org.eclipse.equinox.internal.util.timer.TimerListener;

public class TimerFactory
  extends ServiceFactoryImpl
  implements Timer
{
  private static TimerImpl timer;
  
  public TimerFactory(String bundleName, ThreadPoolFactoryImpl factory, Log log)
  {
    super(bundleName, log);
    timer = new TimerImpl(factory);
  }
  
  public TimerFactory(String bundleName)
  {
    super(bundleName);
  }
  
  public Object getInstance(String bundleName)
  {
    if (timer == null) {
      throw new RuntimeException("ServiceFactory is currently off!");
    }
    return new TimerFactory(bundleName);
  }
  
  public void notifyAfterMillis(TimerListener listener, long timePeriod, int event)
    throws IllegalArgumentException
  {
    addNotifyListener(listener, 5, 0, timePeriod, event);
  }
  
  public void notifyAfterMillis(TimerListener listener, int priority, long timePeriod, int event)
    throws IllegalArgumentException
  {
    addNotifyListener(listener, priority, 0, timePeriod, event);
  }
  
  public void notifyAfter(TimerListener listener, int timePeriod, int event)
    throws IllegalArgumentException
  {
    addNotifyListener(listener, 5, 0, timePeriod * 1000, event);
  }
  
  public void notifyAfter(TimerListener listener, int priority, int timePeriod, int event)
    throws IllegalArgumentException
  {
    addNotifyListener(listener, priority, 0, timePeriod * 1000, event);
  }
  
  public void addNotifyListener(TimerListener listener, int priority, int timerType, long periodMilis, int event)
  {
    TimerImpl tmp = timer;
    if (tmp == null) {
      throw new RuntimeException("This is a zombie!");
    }
    tmp.addNotifyListener(listener, priority, timerType, periodMilis, event, bundleName);
  }
  
  public static void stopTimer()
  {
    if (timer != null)
    {
      timer.terminate();
      timer = null;
    }
  }
  
  public void removeListener(TimerListener listener, int event)
  {
    TimerImpl tmp = timer;
    if (tmp == null) {
      throw new RuntimeException("This is a zombie!");
    }
    tmp.removeListener(listener, event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.timer.TimerFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.timer;

import java.security.PrivilegedAction;

class TimerImpl$PrivilegedActionImpl
  implements PrivilegedAction
{
  private Runnable runnable;
  private boolean locked;
  private boolean waiting;
  final TimerImpl this$0;
  
  TimerImpl$PrivilegedActionImpl(TimerImpl paramTimerImpl)
  {
    this$0 = paramTimerImpl;runnable = null;locked = false;waiting = false;
  }
  
  public synchronized void set(Runnable runnable)
  {
    while (locked)
    {
      waiting = true;
      try
      {
        wait();
      }
      catch (Exception localException) {}
      waiting = false;
    }
    locked = true;
    this.runnable = runnable;
  }
  
  public Object run()
  {
    Runnable runnableLocal = null;
    synchronized (this)
    {
      runnableLocal = runnable;
      runnable = null;
      locked = false;
      if (waiting) {
        notifyAll();
      }
    }
    return new Thread(runnableLocal, "[Timer] - Main Queue Handler");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.timer.TimerImpl.PrivilegedActionImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.timer;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Hashtable;
import org.eclipse.equinox.internal.util.UtilActivator;
import org.eclipse.equinox.internal.util.impl.tpt.ServiceFactoryImpl;
import org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor;
import org.eclipse.equinox.internal.util.impl.tpt.threadpool.ThreadPoolFactoryImpl;
import org.eclipse.equinox.internal.util.pool.ObjectPool;
import org.eclipse.equinox.internal.util.ref.Log;
import org.eclipse.equinox.internal.util.timer.TimerListener;
import org.osgi.framework.BundleContext;

public class TimerImpl
  implements Runnable
{
  static Hashtable nodes;
  static ObjectPool nodePool;
  static ThreadPoolFactoryImpl threadPool;
  private TimerQueue queue;
  private boolean terminated = false;
  private Object sync = new Object();
  private Thread th;
  
  public TimerImpl(ThreadPoolFactoryImpl threadPool)
  {
    nodePool = new ObjectPool(new TimerQueueNode(), 2, 4, 2);
    threadPool = threadPool;
    nodes = new Hashtable(10);
    queue = new TimerQueue();
    try
    {
      th = (ServiceFactoryImpl.privileged() ? getOne() : new Thread(this, "[Timer] - Main Queue Handler"));
      try
      {
        String str = UtilActivator.bc.getProperty("equinox.timer.priority");
        if (str != null) {
          th.setPriority(Integer.parseInt(str));
        }
      }
      catch (Throwable localThrowable) {}
      th.start();
    }
    catch (Exception e)
    {
      throw new RuntimeException("Can not start Timer thread!" + e.toString());
    }
  }
  
  public void run()
  {
    TimerQueueNode n = null;
    while (!terminated)
    {
      synchronized (sync)
      {
        if ((n == null) && (queue.isEmpty()))
        {
          try
          {
            sync.wait();
          }
          catch (Exception localException1) {}
          if ((queue.isEmpty()) || (terminated)) {
            continue;
          }
        }
      }
      synchronized (queue)
      {
        n = queue.getMin();
        while ((n != null) && (!enabled))
        {
          queue.removeMin();
          n.returnInPool();
          n = queue.getMin();
        }
        if (n == null) {
          continue;
        }
        long current = System.currentTimeMillis();
        if (runOn <= current)
        {
          switch (type)
          {
          case 0: 
            threadPool.execute0(n, priority, n.getEName(), acc);
            queue.removeMin();
            nodes.remove(n);
            break;
          case 2: 
            Executor e = threadPool.getExecutor();
            if (e != null)
            {
              e.setPriorityI(priority);
              e.setRunnable(n, n.getEName(), threadPool, acc);
            }
            else
            {
              Thread th = new Thread(n, n.getEName());
              th.setPriority(priority);
              th.start();
            }
            queue.removeMin();
            nodes.remove(n);
            break;
          case 1: 
            threadPool.execute0(n, priority, n.getEName(), acc);
            runOn += period;
            if (runOn < current) {
              runOn = (current + period);
            }
            queue.rescheduleMin(runOn);
            break;
          case 3: 
            Executor e = threadPool.getExecutor();
            if (e != null)
            {
              e.setPriorityI(priority);
              e.setRunnable(n, n.getEName(), threadPool, acc);
            }
            else
            {
              Thread th = new Thread(n, n.getEName());
              th.setPriority(priority);
              th.start();
            }
            if (runOn < current) {
              runOn = (current + period);
            }
            queue.rescheduleMin(runOn);
          }
          continue;
        }
      }
      synchronized (sync)
      {
        long tmpWait;
        if ((n != null) && ((tmpWait = runOn - System.currentTimeMillis()) > 0L))
        {
          try
          {
            sync.wait(tmpWait);
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
          TimerQueueNode tmp = null;
          synchronized (queue)
          {
            tmp = queue.getMin();
            if (tmp != n) {
              n = tmp;
            }
          }
        }
      }
    }
    nodePool.clear();
    nodePool = null;
    nodes.clear();
    nodes = null;
    queue = null;
  }
  
  public void terminate()
  {
    terminated = true;
    synchronized (sync)
    {
      sync.notify();
    }
    try
    {
      th.join();
    }
    catch (InterruptedException localInterruptedException) {}
  }
  
  private void put(TimerListener listener, int priority, int timerType, long periodMilis, int event, String name, AccessControlContext acc)
  {
    if ((terminated) || (nodePool == null)) {
      throw new RuntimeException("This Instance is a ZOMBIE!!!" + terminated + " " + nodePool);
    }
    TimerQueueNode n = (TimerQueueNode)nodePool.getObject();
    n.setEvent(listener, priority, timerType, System.currentTimeMillis() + periodMilis, periodMilis, event, name, acc);
    TimerQueueNode tmp = (TimerQueueNode)nodes.remove(n);
    if (tmp != null)
    {
      synchronized (queue)
      {
        queue.removeTimerNode(tmp);
      }
      tmp.returnInPool();
    }
    nodes.put(n, n);
    TimerQueueNode nx;
    synchronized (queue)
    {
      queue.add(n);
      nx = queue.getMin();
    }
    TimerQueueNode nx;
    if (nx == n) {
      synchronized (sync)
      {
        sync.notifyAll();
      }
    }
  }
  
  void addNotifyListener(TimerListener listener, int priority, int timerType, long periodMilis, int event, String name)
  {
    if ((timerType < 0) || (timerType > 3)) {
      throw new IllegalArgumentException("Invalid Timer Type");
    }
    if (listener != null)
    {
      if ((priority >= 1) && (priority <= 10))
      {
        if (periodMilis > 0L)
        {
          AccessControlContext acc = Log.security() ? AccessController.getContext() : null;
          put(listener, priority, timerType, periodMilis, event, name, acc);
        }
        else
        {
          throw new IllegalArgumentException("Time period must be positive!");
        }
      }
      else {
        throw new IllegalArgumentException("Priority must be between Thread.MIN_PRIORITY and Thread.MAX_PRIORITY!");
      }
    }
    else {
      throw new IllegalArgumentException("The timer listener is null");
    }
  }
  
  public void removeListener(TimerListener listener, int event)
  {
    TimerQueueNode rmTmp = (TimerQueueNode)nodePool.getObject();
    rmTmp.setEvent(listener, 0, 0, 0L, 0L, event, null, null);
    TimerQueueNode old = (TimerQueueNode)nodes.remove(rmTmp);
    if (old != null)
    {
      synchronized (queue)
      {
        queue.removeTimerNode(old);
      }
      old.returnInPool();
    }
    rmTmp.returnInPool();
  }
  
  private class PrivilegedActionImpl
    implements PrivilegedAction
  {
    private Runnable runnable = null;
    private boolean locked = false;
    private boolean waiting = false;
    
    PrivilegedActionImpl() {}
    
    public synchronized void set(Runnable runnable)
    {
      while (locked)
      {
        waiting = true;
        try
        {
          wait();
        }
        catch (Exception localException) {}
        waiting = false;
      }
      locked = true;
      this.runnable = runnable;
    }
    
    public Object run()
    {
      Runnable runnableLocal = null;
      synchronized (this)
      {
        runnableLocal = runnable;
        runnable = null;
        locked = false;
        if (waiting) {
          notifyAll();
        }
      }
      return new Thread(runnableLocal, "[Timer] - Main Queue Handler");
    }
  }
  
  public Thread getOne()
    throws Exception
  {
    if (action == null) {
      action = new PrivilegedActionImpl();
    }
    action.set(this);
    return (Thread)AccessController.doPrivileged(action);
  }
  
  PrivilegedActionImpl action = null;
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.timer.TimerImpl
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.timer;

class TimerQueue$QueueElement
{
  QueueElement next;
  TimerQueueNode node;
  final TimerQueue this$0;
  
  public TimerQueue$QueueElement(TimerQueue paramTimerQueue)
  {
    this$0 = paramTimerQueue;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.util.impl.tpt.timer.TimerQueue.QueueElement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.util.impl.tpt.timer;

class TimerQueue
{
  static final int POOL_SIZE = 20;
  QueueElement[] pool = new QueueElement[20];
  int filled = 0;
  QueueElement first;
  QueueElement lastInserted;
  
  void add(TimerQueueNode task)
  {
    QueueElement toAdd = getQueueElement();
    node = task;
    if (first == null) {
      first = toAdd;
    } else {
      insertElement(toAdd);
    }
  }
  
  TimerQueueNode getMin()
  {
    return first != null ? first.node : null;
  }
  
  void removeMin()
  {
    if (first != null)
    {
      if (lastInserted == first) {
        lastInserted = null;
      }
      if (filled < 20)
      {
        QueueElement toFree = first;
        first = first.next;
        freeQueueElement(toFree);
      }
      else
      {
        first = first.next;
      }
    }
  }
  
  void rescheduleMin(long newTime)
  {
    first.node.runOn = newTime;
    if (first.next != null)
    {
      if (lastInserted == first) {
        lastInserted = null;
      }
      QueueElement el = first;
      first = first.next;
      next = null;
      insertElement(el);
    }
  }
  
  boolean isEmpty()
  {
    return first == null;
  }
  
  void clear()
  {
    while (first != null)
    {
      first.node.returnInPool();
      first = first.next;
    }
    lastInserted = null;
  }
  
  void insertElement(QueueElement newElement)
  {
    if (first.node.runOn >= node.runOn)
    {
      next = first;
      first = newElement;
    }
    else if (lastInserted != null)
    {
      if (lastInserted.node.runOn == node.runOn)
      {
        QueueElement tmp = lastInserted.next;
        lastInserted.next = newElement;
        next = tmp;
      }
      else if (lastInserted.node.runOn > node.runOn)
      {
        doInsertElement(first, newElement);
      }
      else
      {
        doInsertElement(lastInserted, newElement);
      }
    }
    else
    {
      doInsertElement(first, 
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd