View Javadoc

1   /*
2    * @(#) PROCESSINVOKEVIRTUAL.java Jan 8, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.formalisms.process;
11  
12  import java.io.DataInput;
13  import java.io.IOException;
14  import java.lang.reflect.Method;
15  import java.lang.reflect.Modifier;
16  
17  import nl.tudelft.simulation.dsol.interpreter.Frame;
18  import nl.tudelft.simulation.dsol.interpreter.Interpreter;
19  import nl.tudelft.simulation.dsol.interpreter.operations.reflection.INVOKEVIRTUAL;
20  import nl.tudelft.simulation.language.concurrent.Monitor;
21  
22  /***
23   * PROCESSINVOKEVIRTUAL <br>
24   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
25   * University of Technology </a>, the Netherlands. <br>
26   * See for project information <a
27   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
28   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
29   * License (GPL) </a>, no warranty <br>
30   * 
31   * @version 1.0 Jan 8, 2004 <br>
32   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33   *         Jacobs </a> <br>
34   *         <a
35   *         href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
36   *         Verbraeck </a>
37   */
38  public class PROCESSINVOKEVIRTUAL extends INVOKEVIRTUAL
39  {
40  	/***
41  	 * constructs a new PROCESSINVOKEVIRTUAL
42  	 * 
43  	 * @param dataInput the dataInput
44  	 * @throws IOException on IOfailure
45  	 */
46  	public PROCESSINVOKEVIRTUAL(final DataInput dataInput) throws IOException
47  	{
48  		super(dataInput);
49  	}
50  
51  	/***
52  	 * executes the operation and returns a new Frame
53  	 * 
54  	 * @param frame the original frame
55  	 * @param objectRef the object on which to invoke the method
56  	 * @param arguments the arguments with which to invoke the method
57  	 * @param method the method to invoke
58  	 * @throws Exception on invocation exception
59  	 * @return a new frame
60  	 */
61  	public Frame execute(final Frame frame, final Object objectRef,
62  			final Method method, final Object[] arguments) throws Exception
63  	{
64  		if (Modifier.isNative(method.getModifiers())
65  				|| !Process.class.isAssignableFrom(objectRef.getClass()))
66  		{
67  			return super.execute(frame, objectRef, method, arguments);
68  		}
69  
70  		//Let's check for the suspend method
71  		if (method.getName().equals("suspend")
72  				&& method.getParameterTypes().length == 0)
73  		{
74  			//we pause the frame
75  			frame.setPaused(true);
76  			return frame;
77  		}
78  		if (Modifier.isSynchronized(method.getModifiers()))
79  		{
80  			Monitor.lock(objectRef);
81  		}
82  		return Interpreter.createFrame(objectRef, method, arguments);
83  	}
84  }