Package nexj.core.runtime

Source Code of nexj.core.runtime.FunctionExecutor

// Copyright 2010 NexJ Systems Inc. This software is licensed under the terms of the Eclipse Public License 1.0
package nexj.core.runtime;

import java.io.Serializable;
import java.util.List;

import nexj.core.rpc.GenericServer;
import nexj.core.rpc.TransferObject;
import nexj.core.rpc.jms.JMS;
import nexj.core.rpc.jms.JMSSender;
import nexj.core.scripting.Function;
import nexj.core.util.Logger;
import nexj.core.util.ObjUtil;

/**
* A command that executes a Scheme function
*/
public class FunctionExecutor extends TrustedExecutable implements Serializable
{
   /**
    * Serialization UID.
    */
   private static final long serialVersionUID = -6540349061564467099L;

   /**
    * The class logger.
    */
   private final static Logger s_logger = Logger.getLogger(GenericServer.class);

   private final Function m_function;
   private final List m_arguments;
  
   public FunctionExecutor(Function function, List arguments)
   {
      m_function = function;
      m_arguments = arguments;
   }

   /**
    * @see nexj.core.runtime.TrustedExecutable#executeTrusted()
    */
   protected void executeTrusted()
   {
      try
      {
         m_context.getMachine().invoke(m_function, m_arguments);
         m_context.complete(true);
      }
      catch (Throwable e)
      {
         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Error executing command", e);
         }

         m_context.complete(false);
         throw ObjUtil.rethrow(e);
      }
   }


   public static void submit(Function function, List arguments, InvocationContext context)
   {
      TransferObject properties = new TransferObject(1);
     
      if (context.getPrincipal() != InvocationContext.ANONYMOUS_PRINCIPAL)
      {
         properties.setValue(JMSSender.USER, context.getPrincipal().getName());
      }
     
      properties.setValue(JMS.MAX_ERROR_COUNT, new Integer(0)); // Do not retry

      context.getUnitOfWork().addMessage(UnitOfWork.SYSTEM_QUEUE, new FunctionExecutor(function, arguments), properties, 2, 0, false);
   }
}
TOP

Related Classes of nexj.core.runtime.FunctionExecutor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.