View Javadoc
1   package psl;
2   
3   import ensure.Ensure;
4   
5   /**
6    * Runnable that is added to the thread pool executor for execution of
7    * asynchronous tasks. This runnable will run another runnable, which is
8    * usually a {@link AsyncDispatchRunnable}. To keep track of executions,
9    * the inner runnable is run using the
10   * {@link DispatcherThread#dispatch(Runnable)} method.
11   */
12  class ExecutorRunnable implements Runnable {
13  	/**
14  	 * The runnable that will be run. Never <code>null</code>.
15  	 */
16  	private Runnable m_inner;
17  	
18  	/**
19  	 * Creates a new executor runnable.
20  	 * @param r the inner runnable, cannot be <code>null</code>
21  	 */
22  	public ExecutorRunnable(Runnable r) {
23  		Ensure.not_null(r, "r == null");
24  		
25  		m_inner = r;
26  	}
27  	
28  	@Override
29  	public void run() {
30  		Ensure.is_instance(Thread.currentThread(), DispatcherThread.class,
31  				"!(Thread.currentThread() instanceof DispatcherThread)");
32  		((DispatcherThread) Thread.currentThread()).dispatch(m_inner);
33  	}
34  }