//$Header$
/////////////////////////////////////////////////////////////////////////////
//PROPRIETARY RIGHTS STATEMENT
//The contents of this file represent confidential information that is the
//proprietary property of Active Endpoints, Inc.  Viewing or use of
//this information is prohibited without the express written consent of
//Active Endpoints, Inc. Removal of this PROPRIETARY RIGHTS STATEMENT
//is strictly forbidden. Copyright (c) 2002-2004 All rights reserved.
/////////////////////////////////////////////////////////////////////////////
package org.apache.sandesha.server;

import org.apache.sandesha.IStorageManager;
import org.apache.sandesha.RMMessageContext;

/**
 *
 */
public class RMInvokeScheduler
{
   
   private static final RMInvokeScheduler INSTANCE = new RMInvokeScheduler();
   
   public static RMInvokeScheduler getInstance()
   {
      return INSTANCE;
   }
   
   public void scheduleInvoke( IStorageManager aStorageManager, RMMessageContext aContext )
   {
      RMInvokerDelegate delegate = new RMInvokerDelegate(aStorageManager, aContext);
      Runnable work = new RMDelegateWrapper( delegate );
      Thread invokerThread = new Thread(work, "RMInvokerDelegate");
      invokerThread.start();
   }
   
   private class RMDelegateWrapper implements Runnable
   {
      private RMInvokerDelegate mDelegate;
      
      public RMDelegateWrapper( RMInvokerDelegate aDelegate)
      {
         mDelegate = aDelegate;
      }
      
      public void run()
      {
         getDelegate().doDelegateInvoke();
      }
      
      protected RMInvokerDelegate getDelegate()
      {
         return mDelegate;
      }
   }
}
