package nl.tudelft.simulation.dsol.interpreter.process; import java.io.DataInput; import java.io.IOException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import nl.tudelft.simulation.dsol.interpreter.Frame; import nl.tudelft.simulation.dsol.interpreter.Interpreter; import nl.tudelft.simulation.dsol.interpreter.operations.custom.CUSTOMINVOKESPECIAL; import nl.tudelft.simulation.dsol.interpreter.operations.custom.InterpreterOracleInterface; import nl.tudelft.simulation.language.concurrent.Monitor; /** * PROCESSINVOKESPECIAL. *
* (c) copyright 2002-2014 Delft University of Technology.
* BSD-style license. See DSOL License.
* @author Peter Jacobs
* @author Alexander Verbraeck
*/
public class PROCESSINVOKESPECIAL extends CUSTOMINVOKESPECIAL
{
/**
* constructs a new PROCESSINVOKEVIRTUAL.
* @param interpreterOracle the oracle
* @param dataInput the dataInput
* @throws IOException on IOfailure
*/
public PROCESSINVOKESPECIAL(final InterpreterOracleInterface interpreterOracle, final DataInput dataInput)
throws IOException
{
super(interpreterOracle, dataInput);
}
/**
* executes the operation and returns a new Frame.
* @param frame the original frame
* @param objectRef the object on which to invoke the method
* @param arguments the arguments with which to invoke the method
* @param method the method to invoke
* @throws Exception on invocation exception
* @return a new frame
*/
@Override
public final Frame execute(final Frame frame, final Object objectRef, final Method method, final Object[] arguments)
throws Exception
{
if (!InterpretableProcess.class.isAssignableFrom(method.getDeclaringClass()))
{
return super.execute(frame, objectRef, method, arguments);
}
if (method.getName().equals("suspend"))
{
return super.execute(frame, objectRef, method, arguments);
}
// Let's check for the suspend method
if (method.equals(ProcessFactory.suspendMethod))
{
// we set the state of the process to suspended
InterpretableProcess process = (InterpretableProcess) objectRef;
process.setState(InterpretableProcess.SUSPENDED);
// we pause the frame
frame.setPaused(true);
return frame;
}
if (Modifier.isSynchronized(method.getModifiers()))
{
Monitor.lock(objectRef);
}
return Interpreter.createFrame(objectRef, method, arguments);
}
}