/*****************************************************
 * jr generated file
 ****************************************************/
import edu.ucdavis.jr.*;
import edu.ucdavis.jr.jrx.*;
import java.rmi.*;
import java.io.Serializable;


import edu.ucdavis.jr.JR;

public class RollerCoaster extends java.lang.Object {
    { JRinit(); }
    
    public RollerCoaster() {
        // Begin Expr2
        super();
        JRprocess();
    }
    private static final int NB_PASSENGERS_BASE = 13;
    private static final int PASSENGER_ITER_BASE = 23;
    private static final int NB_WAGONS_BASE = 1;
    private static final int NB_SEATS_BASE = 5;
    private static final int WONDERING_TIME = 11;
    private static final int TRACK_TIME = 110;
    private static final int FOUR_ARGUMENTS = 4;
    private static final int THREE_ARGUMENTS = 3;
    private static final int TWO_ARGUMENTS = 2;
    private static final int ONE_ARGUMENT = 1;
    private static final int NB_OF_ARGUMENTS = 4;
    private static int nb_passengers;
    private static int passenger_iter;
    private static int nb_wagons;
    private static int nb_seats;
    Op_ext.JRProxyOp JRget_op_getInRollerCoaster_intToint()
    {
        return op_getInRollerCoaster_intToint;
    }
    
    public Op_ext.JRProxyOp op_getInRollerCoaster_intToint;
    
    Op_ext.JRProxyOp JRget_op_getOutRollerCoaster_intXintTovoid()
    {
        return op_getOutRollerCoaster_intXintTovoid;
    }
    
    public Op_ext.JRProxyOp op_getOutRollerCoaster_intXintTovoid;
    
    Op_ext.JRProxyOp JRget_op_isOpen_voidToboolean()
    {
        return op_isOpen_voidToboolean;
    }
    
    public Op_ext.JRProxyOp op_isOpen_voidToboolean;
    
    Op_ext.JRProxyOp JRget_op_closeRollerCoaster_voidTovoid()
    {
        return op_closeRollerCoaster_voidTovoid;
    }
    
    public Op_ext.JRProxyOp op_closeRollerCoaster_voidTovoid;
    
    Op_ext.JRProxyOp JRget_op_quitPark_voidTovoid()
    {
        return op_quitPark_voidTovoid;
    }
    
    public Op_ext.JRProxyOp op_quitPark_voidTovoid;
    
    static Op_ext.JRProxyOp JRget_op_closing_voidTovoid()
    {
        return op_closing_voidTovoid;
    }
    
    public static Op_ext.JRProxyOp op_closing_voidTovoid;
    ;
    static    {
        try    {
            op_closing_voidTovoid = new Op_ext_.JRProxyOp(new InOp_ext_impl());
        } catch (Exception e) { throw new jrRuntimeError(e.toString());}
    }
    
    static Op_ext.JRProxyOp JRget_op_nextwagonloading_intTovoid()
    {
        return op_nextwagonloading_intTovoid;
    }
    
    public static Op_ext.JRProxyOp op_nextwagonloading_intTovoid;
    ;
    static    {
        try    {
            op_nextwagonloading_intTovoid = new Op_ext_.JRProxyOp(new InOp_ext_impl());
        } catch (Exception e) { throw new jrRuntimeError(e.toString());}
    }
    
    static Op_ext.JRProxyOp JRget_op_nextwagonunloading_intTovoid()
    {
        return op_nextwagonunloading_intTovoid;
    }
    
    public static Op_ext.JRProxyOp op_nextwagonunloading_intTovoid;
    ;
    static    {
        try    {
            op_nextwagonunloading_intTovoid = new Op_ext_.JRProxyOp(new InOp_ext_impl());
        } catch (Exception e) { throw new jrRuntimeError(e.toString());}
    }
    
    private Op_ext.JRProxyOp JRget_op_passenger_intTovoid()
    {
        return op_passenger_intTovoid;
    }
    
    public Op_ext.JRProxyOp op_passenger_intTovoid;
    class ProcOp_intTovoid_implpassenger extends ProcOp_ext_impl
    {
        RollerCoaster thisarg;
        public ProcOp_intTovoid_implpassenger(RollerCoaster thisIn) throws RemoteException
        {
        thisarg = thisIn;
        }
        public java.lang.Object call(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.ariseAndReceive();  // from caller
            try    {
                jrvm.setTimestamp(JRtimestamp);
                thisarg.passengerintTovoid(null, null, null, JRargs);
return null;
            } finally {
                jrvm.sendAndDie();    // to caller
            }
        }
        class sendThread implements Runnable
        {
            java.lang.Object [] JRargs;
            Op_ext.JRProxyOp retOp;
            Cap_ext fretOp;
            edu.ucdavis.jr.RemoteHandler handler;

            public sendThread(Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.handler = handler;
            }
            public sendThread(Op_ext.JRProxyOp retOp, Cap_ext fretOp,edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.fretOp = fretOp;
                this.handler = handler;
            }
            public void run()
            {
                try    {
                    thisarg.passengerintTovoid(this.retOp, this.fretOp, this.handler, this.JRargs);
                } catch (Exception e) {/* should be safe to ignore this exception */}
                jrvm.threadDeath();
            }
        }
        public void send(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, null, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, null, null, JRargs);
        }
        public void send(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, handler, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, handler, null, JRargs);
        }
        public void send(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, handler, JRargs)).start();
        }
        public Cap_ext cosend(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(null, handler, JRargs)).start();
            Op_ext.JRProxyOp myretOp = new Op_ext_.JRProxyOp(new InOp_ext_impl());
            myretOp.send(jrvm.getTimestamp(), (java.lang.Object []) null);
            return new Cap_ext_(myretOp, "void");
        }
        public Cap_ext cocall(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, null, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Cap_ext cocall(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, Cap_ext fretOp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, fretOp, handler, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Recv_ext recv() throws RemoteException
        {
            /* This is an error */
            throw new jrRuntimeError("Receive invoked on an operation/operation capability associated with a method!");
        }
        public void deliverPendingMessages()
        {
            /* This is an error */
            throw new jrRuntimeError("Message delivery invoked on an operation associated with a method!");
        }
        public int length()
        {
            return 0;
        }
        public InOpIterator elements()
        {
            // This is an error
            throw new jrRuntimeError("Elements invoked on an operation / operation capability associated with a method!");
        }
        public InLock getLock()
        {
            // This is an error
            throw new jrRuntimeError("getLock invoked on an operation / operation capability associated with a method!");
        }
        public long getFirstTime()
        {
            // This is an error
            throw new jrRuntimeError("getFirstTime invoked on an operation / operation capability associated with a method!");
        }
        public boolean isRemote(String site)
        {
            // This is an error
            throw new jrRuntimeError("IsRemote invoked on an operation / operation capability associated with a method!");
        }
    }
    
    private void passengerintTovoid(java.lang.Object [] JRargs) {
        ((Op_ext_.JRProxyOp)op_passenger_intTovoid).call(jrvm.getTimestamp(), JRargs);
    }
    private void passengerintTovoid(Op_ext.JRProxyOp retOp, Cap_ext fretOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
    {
        try    {
            // GetMethod 1
            int passenger = ((Number) JRargs[0]).intValue();
            {
                boolean isOpen = ((Boolean) (new Cap_ext_(op_isOpen_voidToboolean, "boolean")).call(jrvm.getTimestamp(), (java.lang.Object[]) null));
                JRLoop0: for (int i = 0; i < passenger_iter && isOpen; i++) {
                    try {
                        // Begin Expr2
                        Thread.sleep(WONDERING_TIME);
                        int my_wagon;
                        // Begin Expr2
                        my_wagon = ((Integer) (new Cap_ext_(op_getInRollerCoaster_intToint, "int")).call(jrvm.getTimestamp(), new java.lang.Object [] {passenger}));
                        // Begin JRCall
                        // Begin Expr2
                        (new Cap_ext_(op_getOutRollerCoaster_intXintTovoid, "void")).call(jrvm.getTimestamp(), new java.lang.Object [] {my_wagon, passenger});// End JRCall
                        
                        // Begin Expr2
                        isOpen = ((Boolean) (new Cap_ext_(op_isOpen_voidToboolean, "boolean")).call(jrvm.getTimestamp(), (java.lang.Object[]) null));
                    } catch (java.lang.InterruptedException e) {
                        // Begin Expr2
                        e.printStackTrace();
                    }
                }
                op_quitPark_voidTovoid.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, (java.lang.Object[]) null);
                // Return
                { if (retOp != null)
                    retOp.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, null);
                return ; }
                // End Return

            }
        } catch (Exception JRe)    {
            if (retOp != null && fretOp == null)
            {
        	// if it is a forward cocall with handler
        	if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
        	    handler.JRhandler(JRe);
        	else
        	    // give preference to propagation through the call stack
        	    retOp.send(jrvm.getTimestamp(), JRe);
            }
            else if ((retOp != null) && (fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// for COSTMT exception handling in operation
        	if (handler != null)
        	    handler.JRhandler(JRe);
        	fretOp.send(jrvm.getTimestamp(), handler, (java.lang.Object []) null);
            }
            else if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// this should only be for a send/forward
        	handler.JRhandler(JRe);
        	// can rethrow below just to get out of this method
            }
            // rethrow the proper type of exception
            // catch all
            throw new jrRuntimeError("Unhandled exception: " + JRe.toString());
        }
    }
    
    private Op_ext.JRProxyOp JRget_op_wagon_intTovoid()
    {
        return op_wagon_intTovoid;
    }
    
    public Op_ext.JRProxyOp op_wagon_intTovoid;
    class ProcOp_intTovoid_implwagon extends ProcOp_ext_impl
    {
        RollerCoaster thisarg;
        public ProcOp_intTovoid_implwagon(RollerCoaster thisIn) throws RemoteException
        {
        thisarg = thisIn;
        }
        public java.lang.Object call(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.ariseAndReceive();  // from caller
            try    {
                jrvm.setTimestamp(JRtimestamp);
                thisarg.wagonintTovoid(null, null, null, JRargs);
return null;
            } finally {
                jrvm.sendAndDie();    // to caller
            }
        }
        class sendThread implements Runnable
        {
            java.lang.Object [] JRargs;
            Op_ext.JRProxyOp retOp;
            Cap_ext fretOp;
            edu.ucdavis.jr.RemoteHandler handler;

            public sendThread(Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.handler = handler;
            }
            public sendThread(Op_ext.JRProxyOp retOp, Cap_ext fretOp,edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.fretOp = fretOp;
                this.handler = handler;
            }
            public void run()
            {
                try    {
                    thisarg.wagonintTovoid(this.retOp, this.fretOp, this.handler, this.JRargs);
                } catch (Exception e) {/* should be safe to ignore this exception */}
                jrvm.threadDeath();
            }
        }
        public void send(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, null, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, null, null, JRargs);
        }
        public void send(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, handler, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, handler, null, JRargs);
        }
        public void send(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, handler, JRargs)).start();
        }
        public Cap_ext cosend(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(null, handler, JRargs)).start();
            Op_ext.JRProxyOp myretOp = new Op_ext_.JRProxyOp(new InOp_ext_impl());
            myretOp.send(jrvm.getTimestamp(), (java.lang.Object []) null);
            return new Cap_ext_(myretOp, "void");
        }
        public Cap_ext cocall(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, null, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Cap_ext cocall(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, Cap_ext fretOp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, fretOp, handler, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Recv_ext recv() throws RemoteException
        {
            /* This is an error */
            throw new jrRuntimeError("Receive invoked on an operation/operation capability associated with a method!");
        }
        public void deliverPendingMessages()
        {
            /* This is an error */
            throw new jrRuntimeError("Message delivery invoked on an operation associated with a method!");
        }
        public int length()
        {
            return 0;
        }
        public InOpIterator elements()
        {
            // This is an error
            throw new jrRuntimeError("Elements invoked on an operation / operation capability associated with a method!");
        }
        public InLock getLock()
        {
            // This is an error
            throw new jrRuntimeError("getLock invoked on an operation / operation capability associated with a method!");
        }
        public long getFirstTime()
        {
            // This is an error
            throw new jrRuntimeError("getFirstTime invoked on an operation / operation capability associated with a method!");
        }
        public boolean isRemote(String site)
        {
            // This is an error
            throw new jrRuntimeError("IsRemote invoked on an operation / operation capability associated with a method!");
        }
    }
    
    private void wagonintTovoid(java.lang.Object [] JRargs) {
        ((Op_ext_.JRProxyOp)op_wagon_intTovoid).call(jrvm.getTimestamp(), JRargs);
    }
    private void wagonintTovoid(Op_ext.JRProxyOp retOp, Cap_ext fretOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
    {
        try    {
            // GetMethod 1
            int wagon = ((Number) JRargs[0]).intValue();
            {
                InStatObj JRInstmt3 = new InStatObj(1, false);
                InStatObj JRInstmt2 = new InStatObj(1, false);
                InStatObj JRInstmt1 = new InStatObj(2, false);
                InStatObj JRInstmt0 = new InStatObj(1, false);
                int passenger_in_wagon = 0;
                boolean running_wagon = false;
                boolean can_deposit = false;
                JRLoop3: while (true) {
                    try {
                        {
                            // Inni Statement without quantifier
                            JRInstmt0.armArray[0] = new QuantRec(new Cap_ext_(op_nextwagonloading_intTovoid, "void"), 0, 0);
                            JRInstmt0.lock();
                            // Equivalence Class has been created and locked
                            JRInstmt0.serviced = false;
                            _label_JRInstmt0: do
                            {
                                Invocation JRfinalInvoc0 = null;
                                // find THE invocation and service it
                                JRInstmt0.gatherAndSortTimes();
                                for (JRInstmt0.i = 0;
                                    (JRInstmt0.i < JRInstmt0.N) && !JRInstmt0.serviced;
                                     JRInstmt0.i++)
                                {
                                    JRInstmt0.byStrt = true;
                                    JRInstmt0.releaseIter();
                                    // if the op is empty
                                    if (JRInstmt0.timesArray[JRInstmt0.i].time < 0) continue;
                                    switch (JRInstmt0.timesArray[JRInstmt0.i].opNum)
                                    {
                                        case 0:
                                        {
                                            JRInstmt0.j = 0;
                                            // Inni Arm
                                            QuantRec JRquantRec0 = (QuantRec)JRInstmt0.armArray[JRInstmt0.timesArray[JRInstmt0.i].armArrayIndex];
                                            Recv_ext JRrrecv0 = null, JRtmprecv0;
                                            int current_wagon = 0;
                                            for (JRInstmt0.iter = JRInstmt0.armArray[JRInstmt0.timesArray[JRInstmt0.i].armArrayIndex].theCap.elements();
                                                 JRInstmt0.iter.hasNext();)
                                            {
                                                JRtmprecv0 = (Recv_ext)JRInstmt0.iter.next();
                                                JRInstmt0.JRinit.setInvoc(JRInstmt0.j++);
                                                JRtmprecv0.setInvocation(JRInstmt0.JRinit);
                                                // extract values
                                                // GetMethod 2
                                                current_wagon = ((Number) JRtmprecv0.JRargs[0]).intValue();
                                                ;
                                                if (current_wagon == wagon)
                                                    JRrrecv0 = JRtmprecv0;
                                                if (JRrrecv0 != null)
                                                    break;  // get first one
                                            }
                                            // Start of servicing
                                            if (JRrrecv0 != null)
                                            {
                                                JRInstmt0.j = (int)JRrrecv0.getInvoc();
                                                JRInstmt0.serviced = true;
                                                JRInstmt0.iter.remove(JRInstmt0.j);
                                                JRInstmt0.releaseIter();
                                                JRInstmt0.unlock();
                                                {
                                                    try {
                                                        {
                                                            // Begin Expr2
                                                            running_wagon = true;
                                                        }
                                                    } catch (Exception JRe) {
                                                        if (JRrrecv0.retOp != null && JRrrecv0.fretOp == null)
                                                        {
                                                            // forward of cocall
                                                            if ((JRrrecv0.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                                JRrrecv0.handler.JRhandler(JRe);
                                                            else {
                                                                // give preference to propagation through the call stack
                                                                JRrrecv0.retOp.send(jrvm.getTimestamp(), JRe);
                                                                JRrrecv0.retOp = null;
                                                            }
                                                        }
                                                        else if ((JRrrecv0.retOp != null) && (JRrrecv0.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                        {
                                                            // for cocall exception handling in operation invocation
                                                            if (JRrrecv0.handler != null)
                                                                JRrrecv0.handler.JRhandler(JRe);
                                                            JRrrecv0.fretOp.send(jrvm.getTimestamp(), JRrrecv0.handler, (java.lang.Object []) null);
                                                            JRrrecv0.fretOp = null;
                                                        }
                                                        else if ((JRrrecv0.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                        {
                                                            // this should only be a send
                                                            JRrrecv0.handler.JRhandler(JRe);
                                                        }
                                                    }
                                                }
                                                { if (JRrrecv0.retOp != null)
                                                    JRrrecv0.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                            }
                                            else
                                                JRInstmt0.releaseIter();
                                            // End of servicing
                                            // End InniArm
                                            break;
                                        }
                                        
                                    }
                                }
                                if (!JRInstmt0.serviced)
                                {
                                    // must block and loop
                                    JRInstmt0.waitOnLock();
                                }
                            } while (!JRInstmt0.serviced);
                        }
                        // End Inni
                        
                        JRLoop1: while (passenger_in_wagon < nb_seats) {
                            {
                                // Inni Statement without quantifier
                                JRInstmt1.armArray[0] = new QuantRec(new Cap_ext_(op_getInRollerCoaster_intToint, "int"), 0, 0);
                                JRInstmt1.armArray[1] = new QuantRec(new Cap_ext_(op_closing_voidTovoid, "void"), 1, 1);
                                JRInstmt1.lock();
                                // Equivalence Class has been created and locked
                                JRInstmt1.serviced = false;
                                _label_JRInstmt1: do
                                {
                                    Invocation JRfinalInvoc1 = null;
                                    // find THE invocation and service it
                                    JRInstmt1.gatherAndSortTimes();
                                    for (JRInstmt1.i = 0;
                                        (JRInstmt1.i < JRInstmt1.N) && !JRInstmt1.serviced;
                                         JRInstmt1.i++)
                                    {
                                        JRInstmt1.byStrt = true;
                                        JRInstmt1.releaseIter();
                                        // if the op is empty
                                        if (JRInstmt1.timesArray[JRInstmt1.i].time < 0) continue;
                                        switch (JRInstmt1.timesArray[JRInstmt1.i].opNum)
                                        {
                                            case 0:
                                            {
                                                JRInstmt1.j = 0;
                                                // Inni Arm
                                                QuantRec JRquantRec1 = (QuantRec)JRInstmt1.armArray[JRInstmt1.timesArray[JRInstmt1.i].armArrayIndex];
                                                Recv_ext JRrrecv1 = null, JRtmprecv1;
                                                int client = 0;
                                                for (JRInstmt1.iter = JRInstmt1.armArray[JRInstmt1.timesArray[JRInstmt1.i].armArrayIndex].theCap.elements();
                                                     JRInstmt1.iter.hasNext();)
                                                {
                                                    JRtmprecv1 = (Recv_ext)JRInstmt1.iter.next();
                                                    JRInstmt1.JRinit.setInvoc(JRInstmt1.j++);
                                                    JRtmprecv1.setInvocation(JRInstmt1.JRinit);
                                                    // extract values
                                                    // GetMethod 2
                                                    client = ((Number) JRtmprecv1.JRargs[0]).intValue();
                                                    ;
                                                    if (passenger_in_wagon < nb_seats)
                                                        JRrrecv1 = JRtmprecv1;
                                                    if (JRrrecv1 != null)
                                                        break;  // get first one
                                                }
                                                // Start of servicing
                                                if (JRrrecv1 != null)
                                                {
                                                    JRInstmt1.j = (int)JRrrecv1.getInvoc();
                                                    JRInstmt1.serviced = true;
                                                    JRInstmt1.iter.remove(JRInstmt1.j);
                                                    JRInstmt1.releaseIter();
                                                    JRInstmt1.unlock();
                                                    {
                                                        try {
                                                            {
                                                                // Begin Expr2
                                                                passenger_in_wagon++;
                                                                // Begin Expr2
                                                                System.out.println("le client " + client + " entre dans le wagon " + wagon);
                                                                // Return
                                                                { if (retOp != null)
                                                                    retOp.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {(wagon)});
                                                                else {
                                                                    void JRevaltmp = wagon;
                                                                    return JRevaltmp;
                                                                }
                                                                return ; }
                                                                // End Return

                                                            }
                                                        } catch (Exception JRe) {
                                                            if (JRrrecv1.retOp != null && JRrrecv1.fretOp == null)
                                                            {
                                                                // forward of cocall
                                                                if ((JRrrecv1.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                                    JRrrecv1.handler.JRhandler(JRe);
                                                                else {
                                                                    // give preference to propagation through the call stack
                                                                    JRrrecv1.retOp.send(jrvm.getTimestamp(), JRe);
                                                                    JRrrecv1.retOp = null;
                                                                }
                                                            }
                                                            else if ((JRrrecv1.retOp != null) && (JRrrecv1.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // for cocall exception handling in operation invocation
                                                                if (JRrrecv1.handler != null)
                                                                    JRrrecv1.handler.JRhandler(JRe);
                                                                JRrrecv1.fretOp.send(jrvm.getTimestamp(), JRrrecv1.handler, (java.lang.Object []) null);
                                                                JRrrecv1.fretOp = null;
                                                            }
                                                            else if ((JRrrecv1.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // this should only be a send
                                                                JRrrecv1.handler.JRhandler(JRe);
                                                            }
                                                        }
                                                    }
                                                    
                                                }
                                                else
                                                    JRInstmt1.releaseIter();
                                                // End of servicing
                                                // End InniArm
                                                break;
                                            }
                                            case 1:
                                            {
                                                JRInstmt1.j = 0;
                                                // Inni Arm
                                                QuantRec JRquantRec1 = (QuantRec)JRInstmt1.armArray[JRInstmt1.timesArray[JRInstmt1.i].armArrayIndex];
                                                Recv_ext JRrrecv1 = null, JRtmprecv1;
                                                for (JRInstmt1.iter = JRInstmt1.armArray[JRInstmt1.timesArray[JRInstmt1.i].armArrayIndex].theCap.elements();
                                                     JRInstmt1.iter.hasNext();)
                                                {
                                                    JRtmprecv1 = (Recv_ext)JRInstmt1.iter.next();
                                                    JRInstmt1.JRinit.setInvoc(JRInstmt1.j++);
                                                    JRtmprecv1.setInvocation(JRInstmt1.JRinit);
                                                    // extract values
                                                    JRrrecv1 = JRtmprecv1;
                                                    break;  // get first one
                                                }
                                                // Start of servicing
                                                if (JRrrecv1 != null)
                                                {
                                                    JRInstmt1.j = (int)JRrrecv1.getInvoc();
                                                    JRInstmt1.serviced = true;
                                                    JRInstmt1.iter.remove(JRInstmt1.j);
                                                    JRInstmt1.releaseIter();
                                                    JRInstmt1.unlock();
                                                    {
                                                        try {
                                                            {
                                                                if (passenger_in_wagon > 0) {
                                                                    // Begin Expr2
                                                                    nb_seats = passenger_in_wagon;
                                                                    op_closeRollerCoaster_voidTovoid.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, (java.lang.Object[]) null);
                                                                }
                                                            }
                                                        } catch (Exception JRe) {
                                                            if (JRrrecv1.retOp != null && JRrrecv1.fretOp == null)
                                                            {
                                                                // forward of cocall
                                                                if ((JRrrecv1.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                                    JRrrecv1.handler.JRhandler(JRe);
                                                                else {
                                                                    // give preference to propagation through the call stack
                                                                    JRrrecv1.retOp.send(jrvm.getTimestamp(), JRe);
                                                                    JRrrecv1.retOp = null;
                                                                }
                                                            }
                                                            else if ((JRrrecv1.retOp != null) && (JRrrecv1.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // for cocall exception handling in operation invocation
                                                                if (JRrrecv1.handler != null)
                                                                    JRrrecv1.handler.JRhandler(JRe);
                                                                JRrrecv1.fretOp.send(jrvm.getTimestamp(), JRrrecv1.handler, (java.lang.Object []) null);
                                                                JRrrecv1.fretOp = null;
                                                            }
                                                            else if ((JRrrecv1.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // this should only be a send
                                                                JRrrecv1.handler.JRhandler(JRe);
                                                            }
                                                        }
                                                    }
                                                    { if (JRrrecv1.retOp != null)
                                                        JRrrecv1.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                                }
                                                else
                                                    JRInstmt1.releaseIter();
                                                // End of servicing
                                                // End InniArm
                                                break;
                                            }
                                            
                                        }
                                    }
                                    if (!JRInstmt1.serviced)
                                    {
                                        // must block and loop
                                        JRInstmt1.waitOnLock();
                                    }
                                } while (!JRInstmt1.serviced);
                            }
                            // End Inni
                            
                        }
                        if (passenger_in_wagon == nb_seats) {
                            // Begin Expr2
                            running_wagon = false;
                            JRget_op_nextwagonloading_intTovoid().send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {(wagon + 1) % nb_wagons});
                            // Begin Expr2
                            Thread.sleep(TRACK_TIME);
                        }
                        {
                            // Inni Statement without quantifier
                            JRInstmt2.armArray[0] = new QuantRec(new Cap_ext_(op_nextwagonunloading_intTovoid, "void"), 0, 0);
                            JRInstmt2.lock();
                            // Equivalence Class has been created and locked
                            JRInstmt2.serviced = false;
                            _label_JRInstmt2: do
                            {
                                Invocation JRfinalInvoc2 = null;
                                // find THE invocation and service it
                                JRInstmt2.gatherAndSortTimes();
                                for (JRInstmt2.i = 0;
                                    (JRInstmt2.i < JRInstmt2.N) && !JRInstmt2.serviced;
                                     JRInstmt2.i++)
                                {
                                    JRInstmt2.byStrt = true;
                                    JRInstmt2.releaseIter();
                                    // if the op is empty
                                    if (JRInstmt2.timesArray[JRInstmt2.i].time < 0) continue;
                                    switch (JRInstmt2.timesArray[JRInstmt2.i].opNum)
                                    {
                                        case 0:
                                        {
                                            JRInstmt2.j = 0;
                                            // Inni Arm
                                            QuantRec JRquantRec2 = (QuantRec)JRInstmt2.armArray[JRInstmt2.timesArray[JRInstmt2.i].armArrayIndex];
                                            Recv_ext JRrrecv2 = null, JRtmprecv2;
                                            int current_wagon = 0;
                                            for (JRInstmt2.iter = JRInstmt2.armArray[JRInstmt2.timesArray[JRInstmt2.i].armArrayIndex].theCap.elements();
                                                 JRInstmt2.iter.hasNext();)
                                            {
                                                JRtmprecv2 = (Recv_ext)JRInstmt2.iter.next();
                                                JRInstmt2.JRinit.setInvoc(JRInstmt2.j++);
                                                JRtmprecv2.setInvocation(JRInstmt2.JRinit);
                                                // extract values
                                                // GetMethod 2
                                                current_wagon = ((Number) JRtmprecv2.JRargs[0]).intValue();
                                                ;
                                                if (current_wagon == wagon)
                                                    JRrrecv2 = JRtmprecv2;
                                                if (JRrrecv2 != null)
                                                    break;  // get first one
                                            }
                                            // Start of servicing
                                            if (JRrrecv2 != null)
                                            {
                                                JRInstmt2.j = (int)JRrrecv2.getInvoc();
                                                JRInstmt2.serviced = true;
                                                JRInstmt2.iter.remove(JRInstmt2.j);
                                                JRInstmt2.releaseIter();
                                                JRInstmt2.unlock();
                                                {
                                                    try {
                                                        {
                                                            // Begin Expr2
                                                            can_deposit = true;
                                                        }
                                                    } catch (Exception JRe) {
                                                        if (JRrrecv2.retOp != null && JRrrecv2.fretOp == null)
                                                        {
                                                            // forward of cocall
                                                            if ((JRrrecv2.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                                JRrrecv2.handler.JRhandler(JRe);
                                                            else {
                                                                // give preference to propagation through the call stack
                                                                JRrrecv2.retOp.send(jrvm.getTimestamp(), JRe);
                                                                JRrrecv2.retOp = null;
                                                            }
                                                        }
                                                        else if ((JRrrecv2.retOp != null) && (JRrrecv2.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                        {
                                                            // for cocall exception handling in operation invocation
                                                            if (JRrrecv2.handler != null)
                                                                JRrrecv2.handler.JRhandler(JRe);
                                                            JRrrecv2.fretOp.send(jrvm.getTimestamp(), JRrrecv2.handler, (java.lang.Object []) null);
                                                            JRrrecv2.fretOp = null;
                                                        }
                                                        else if ((JRrrecv2.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                        {
                                                            // this should only be a send
                                                            JRrrecv2.handler.JRhandler(JRe);
                                                        }
                                                    }
                                                }
                                                { if (JRrrecv2.retOp != null)
                                                    JRrrecv2.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                            }
                                            else
                                                JRInstmt2.releaseIter();
                                            // End of servicing
                                            // End InniArm
                                            break;
                                        }
                                        
                                    }
                                }
                                if (!JRInstmt2.serviced)
                                {
                                    // must block and loop
                                    JRInstmt2.waitOnLock();
                                }
                            } while (!JRInstmt2.serviced);
                        }
                        // End Inni
                        
                        JRLoop2: while (passenger_in_wagon > 0) {
                            {
                                // Inni Statement without quantifier
                                JRInstmt3.armArray[0] = new QuantRec(new Cap_ext_(op_getOutRollerCoaster_intXintTovoid, "void"), 0, 0);
                                JRInstmt3.lock();
                                // Equivalence Class has been created and locked
                                JRInstmt3.serviced = false;
                                _label_JRInstmt3: do
                                {
                                    Invocation JRfinalInvoc3 = null;
                                    // find THE invocation and service it
                                    JRInstmt3.gatherAndSortTimes();
                                    for (JRInstmt3.i = 0;
                                        (JRInstmt3.i < JRInstmt3.N) && !JRInstmt3.serviced;
                                         JRInstmt3.i++)
                                    {
                                        JRInstmt3.byStrt = true;
                                        JRInstmt3.releaseIter();
                                        // if the op is empty
                                        if (JRInstmt3.timesArray[JRInstmt3.i].time < 0) continue;
                                        switch (JRInstmt3.timesArray[JRInstmt3.i].opNum)
                                        {
                                            case 0:
                                            {
                                                JRInstmt3.j = 0;
                                                // Inni Arm
                                                QuantRec JRquantRec3 = (QuantRec)JRInstmt3.armArray[JRInstmt3.timesArray[JRInstmt3.i].armArrayIndex];
                                                Recv_ext JRrrecv3 = null, JRtmprecv3;
                                                int passenger_wagon = 0;
                                                int client = 0;
                                                for (JRInstmt3.iter = JRInstmt3.armArray[JRInstmt3.timesArray[JRInstmt3.i].armArrayIndex].theCap.elements();
                                                     JRInstmt3.iter.hasNext();)
                                                {
                                                    JRtmprecv3 = (Recv_ext)JRInstmt3.iter.next();
                                                    JRInstmt3.JRinit.setInvoc(JRInstmt3.j++);
                                                    JRtmprecv3.setInvocation(JRInstmt3.JRinit);
                                                    // extract values
                                                    // GetMethod 2
                                                    passenger_wagon = ((Number) JRtmprecv3.JRargs[0]).intValue();
                                                    ;
                                                    // GetMethod 2
                                                    client = ((Number) JRtmprecv3.JRargs[1]).intValue();
                                                    ;
                                                    if ((passenger_wagon == wagon))
                                                        JRrrecv3 = JRtmprecv3;
                                                    if (JRrrecv3 != null)
                                                        break;  // get first one
                                                }
                                                // Start of servicing
                                                if (JRrrecv3 != null)
                                                {
                                                    JRInstmt3.j = (int)JRrrecv3.getInvoc();
                                                    JRInstmt3.serviced = true;
                                                    JRInstmt3.iter.remove(JRInstmt3.j);
                                                    JRInstmt3.releaseIter();
                                                    JRInstmt3.unlock();
                                                    {
                                                        try {
                                                            {
                                                                // Begin Expr2
                                                                System.out.println("le client " + client + " sort du wagon " + wagon);
                                                                // Begin Expr2
                                                                passenger_in_wagon--;
                                                            }
                                                        } catch (Exception JRe) {
                                                            if (JRrrecv3.retOp != null && JRrrecv3.fretOp == null)
                                                            {
                                                                // forward of cocall
                                                                if ((JRrrecv3.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                                    JRrrecv3.handler.JRhandler(JRe);
                                                                else {
                                                                    // give preference to propagation through the call stack
                                                                    JRrrecv3.retOp.send(jrvm.getTimestamp(), JRe);
                                                                    JRrrecv3.retOp = null;
                                                                }
                                                            }
                                                            else if ((JRrrecv3.retOp != null) && (JRrrecv3.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // for cocall exception handling in operation invocation
                                                                if (JRrrecv3.handler != null)
                                                                    JRrrecv3.handler.JRhandler(JRe);
                                                                JRrrecv3.fretOp.send(jrvm.getTimestamp(), JRrrecv3.handler, (java.lang.Object []) null);
                                                                JRrrecv3.fretOp = null;
                                                            }
                                                            else if ((JRrrecv3.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            {
                                                                // this should only be a send
                                                                JRrrecv3.handler.JRhandler(JRe);
                                                            }
                                                        }
                                                    }
                                                    { if (JRrrecv3.retOp != null)
                                                        JRrrecv3.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                                }
                                                else
                                                    JRInstmt3.releaseIter();
                                                // End of servicing
                                                // End InniArm
                                                break;
                                            }
                                            
                                        }
                                    }
                                    if (!JRInstmt3.serviced)
                                    {
                                        // must block and loop
                                        JRInstmt3.waitOnLock();
                                    }
                                } while (!JRInstmt3.serviced);
                            }
                            // End Inni
                            
                        }
                        // Begin Expr2
                        can_deposit = false;
                        JRget_op_nextwagonunloading_intTovoid().send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {(wagon + 1) % nb_wagons});
                    } catch (java.lang.InterruptedException e) {
                        // Begin Expr2
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception JRe)    {
            if (retOp != null && fretOp == null)
            {
        	// if it is a forward cocall with handler
        	if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
        	    handler.JRhandler(JRe);
        	else
        	    // give preference to propagation through the call stack
        	    retOp.send(jrvm.getTimestamp(), JRe);
            }
            else if ((retOp != null) && (fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// for COSTMT exception handling in operation
        	if (handler != null)
        	    handler.JRhandler(JRe);
        	fretOp.send(jrvm.getTimestamp(), handler, (java.lang.Object []) null);
            }
            else if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// this should only be for a send/forward
        	handler.JRhandler(JRe);
        	// can rethrow below just to get out of this method
            }
            // rethrow the proper type of exception
            // catch all
            throw new jrRuntimeError("Unhandled exception: " + JRe.toString());
        }
    }
    
    private Op_ext.JRProxyOp JRget_op_manager_voidTovoid()
    {
        return op_manager_voidTovoid;
    }
    
    public Op_ext.JRProxyOp op_manager_voidTovoid;
    class ProcOp_voidTovoid_implmanager extends ProcOp_ext_impl
    {
        RollerCoaster thisarg;
        public ProcOp_voidTovoid_implmanager(RollerCoaster thisIn) throws RemoteException
        {
        thisarg = thisIn;
        }
        public java.lang.Object call(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.ariseAndReceive();  // from caller
            try    {
                jrvm.setTimestamp(JRtimestamp);
                thisarg.managervoidTovoid(null, null, null, JRargs);
return null;
            } finally {
                jrvm.sendAndDie();    // to caller
            }
        }
        class sendThread implements Runnable
        {
            java.lang.Object [] JRargs;
            Op_ext.JRProxyOp retOp;
            Cap_ext fretOp;
            edu.ucdavis.jr.RemoteHandler handler;

            public sendThread(Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.handler = handler;
            }
            public sendThread(Op_ext.JRProxyOp retOp, Cap_ext fretOp,edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.fretOp = fretOp;
                this.handler = handler;
            }
            public void run()
            {
                try    {
                    thisarg.managervoidTovoid(this.retOp, this.fretOp, this.handler, this.JRargs);
                } catch (Exception e) {/* should be safe to ignore this exception */}
                jrvm.threadDeath();
            }
        }
        public void send(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, null, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, null, null, JRargs);
        }
        public void send(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, handler, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, handler, null, JRargs);
        }
        public void send(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, handler, JRargs)).start();
        }
        public Cap_ext cosend(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(null, handler, JRargs)).start();
            Op_ext.JRProxyOp myretOp = new Op_ext_.JRProxyOp(new InOp_ext_impl());
            myretOp.send(jrvm.getTimestamp(), (java.lang.Object []) null);
            return new Cap_ext_(myretOp, "void");
        }
        public Cap_ext cocall(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, null, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Cap_ext cocall(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, Cap_ext fretOp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, fretOp, handler, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Recv_ext recv() throws RemoteException
        {
            /* This is an error */
            throw new jrRuntimeError("Receive invoked on an operation/operation capability associated with a method!");
        }
        public void deliverPendingMessages()
        {
            /* This is an error */
            throw new jrRuntimeError("Message delivery invoked on an operation associated with a method!");
        }
        public int length()
        {
            return 0;
        }
        public InOpIterator elements()
        {
            // This is an error
            throw new jrRuntimeError("Elements invoked on an operation / operation capability associated with a method!");
        }
        public InLock getLock()
        {
            // This is an error
            throw new jrRuntimeError("getLock invoked on an operation / operation capability associated with a method!");
        }
        public long getFirstTime()
        {
            // This is an error
            throw new jrRuntimeError("getFirstTime invoked on an operation / operation capability associated with a method!");
        }
        public boolean isRemote(String site)
        {
            // This is an error
            throw new jrRuntimeError("IsRemote invoked on an operation / operation capability associated with a method!");
        }
    }
    
    private void managervoidTovoid(java.lang.Object [] JRargs) {
        ((Op_ext_.JRProxyOp)op_manager_voidTovoid).call(jrvm.getTimestamp(), JRargs);
    }
    private void managervoidTovoid(Op_ext.JRProxyOp retOp, Cap_ext fretOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
    {
        try    {
            {
                InStatObj JRInstmt4 = new InStatObj(3, false);
                boolean isOpen = true;
                int clientsDansParc = nb_passengers;
                JRLoop4: while (clientsDansParc > 0) {
                    {
                        // Inni Statement without quantifier
                        JRInstmt4.armArray[0] = new QuantRec(new Cap_ext_(op_isOpen_voidToboolean, "boolean"), 0, 0);
                        JRInstmt4.armArray[1] = new QuantRec(new Cap_ext_(op_closeRollerCoaster_voidTovoid, "void"), 1, 1);
                        JRInstmt4.armArray[2] = new QuantRec(new Cap_ext_(op_quitPark_voidTovoid, "void"), 2, 2);
                        JRInstmt4.lock();
                        // Equivalence Class has been created and locked
                        JRInstmt4.serviced = false;
                        _label_JRInstmt4: do
                        {
                            Invocation JRfinalInvoc4 = null;
                            // find THE invocation and service it
                            JRInstmt4.gatherAndSortTimes();
                            for (JRInstmt4.i = 0;
                                (JRInstmt4.i < JRInstmt4.N) && !JRInstmt4.serviced;
                                 JRInstmt4.i++)
                            {
                                JRInstmt4.byStrt = true;
                                JRInstmt4.releaseIter();
                                // if the op is empty
                                if (JRInstmt4.timesArray[JRInstmt4.i].time < 0) continue;
                                switch (JRInstmt4.timesArray[JRInstmt4.i].opNum)
                                {
                                    case 0:
                                    {
                                        JRInstmt4.j = 0;
                                        // Inni Arm
                                        QuantRec JRquantRec4 = (QuantRec)JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex];
                                        Recv_ext JRrrecv4 = null, JRtmprecv4;
                                        for (JRInstmt4.iter = JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex].theCap.elements();
                                             JRInstmt4.iter.hasNext();)
                                        {
                                            JRtmprecv4 = (Recv_ext)JRInstmt4.iter.next();
                                            JRInstmt4.JRinit.setInvoc(JRInstmt4.j++);
                                            JRtmprecv4.setInvocation(JRInstmt4.JRinit);
                                            // extract values
                                            JRrrecv4 = JRtmprecv4;
                                            break;  // get first one
                                        }
                                        // Start of servicing
                                        if (JRrrecv4 != null)
                                        {
                                            JRInstmt4.j = (int)JRrrecv4.getInvoc();
                                            JRInstmt4.serviced = true;
                                            JRInstmt4.iter.remove(JRInstmt4.j);
                                            JRInstmt4.releaseIter();
                                            JRInstmt4.unlock();
                                            {
                                                try {
                                                    {
                                                        // Return
                                                        { if (retOp != null)
                                                            retOp.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {(isOpen)});
                                                        else {
                                                            void JRevaltmp = isOpen;
                                                            return JRevaltmp;
                                                        }
                                                        return ; }
                                                        // End Return

                                                    }
                                                } catch (Exception JRe) {
                                                    if (JRrrecv4.retOp != null && JRrrecv4.fretOp == null)
                                                    {
                                                        // forward of cocall
                                                        if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        else {
                                                            // give preference to propagation through the call stack
                                                            JRrrecv4.retOp.send(jrvm.getTimestamp(), JRe);
                                                            JRrrecv4.retOp = null;
                                                        }
                                                    }
                                                    else if ((JRrrecv4.retOp != null) && (JRrrecv4.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // for cocall exception handling in operation invocation
                                                        if (JRrrecv4.handler != null)
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        JRrrecv4.fretOp.send(jrvm.getTimestamp(), JRrrecv4.handler, (java.lang.Object []) null);
                                                        JRrrecv4.fretOp = null;
                                                    }
                                                    else if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // this should only be a send
                                                        JRrrecv4.handler.JRhandler(JRe);
                                                    }
                                                }
                                            }
                                            
                                        }
                                        else
                                            JRInstmt4.releaseIter();
                                        // End of servicing
                                        // End InniArm
                                        break;
                                    }
                                    case 1:
                                    {
                                        JRInstmt4.j = 0;
                                        // Inni Arm
                                        QuantRec JRquantRec4 = (QuantRec)JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex];
                                        Recv_ext JRrrecv4 = null, JRtmprecv4;
                                        for (JRInstmt4.iter = JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex].theCap.elements();
                                             JRInstmt4.iter.hasNext();)
                                        {
                                            JRtmprecv4 = (Recv_ext)JRInstmt4.iter.next();
                                            JRInstmt4.JRinit.setInvoc(JRInstmt4.j++);
                                            JRtmprecv4.setInvocation(JRInstmt4.JRinit);
                                            // extract values
                                            JRrrecv4 = JRtmprecv4;
                                            break;  // get first one
                                        }
                                        // Start of servicing
                                        if (JRrrecv4 != null)
                                        {
                                            JRInstmt4.j = (int)JRrrecv4.getInvoc();
                                            JRInstmt4.serviced = true;
                                            JRInstmt4.iter.remove(JRInstmt4.j);
                                            JRInstmt4.releaseIter();
                                            JRInstmt4.unlock();
                                            {
                                                try {
                                                    {
                                                        // Begin Expr2
                                                        isOpen = false;
                                                    }
                                                } catch (Exception JRe) {
                                                    if (JRrrecv4.retOp != null && JRrrecv4.fretOp == null)
                                                    {
                                                        // forward of cocall
                                                        if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        else {
                                                            // give preference to propagation through the call stack
                                                            JRrrecv4.retOp.send(jrvm.getTimestamp(), JRe);
                                                            JRrrecv4.retOp = null;
                                                        }
                                                    }
                                                    else if ((JRrrecv4.retOp != null) && (JRrrecv4.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // for cocall exception handling in operation invocation
                                                        if (JRrrecv4.handler != null)
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        JRrrecv4.fretOp.send(jrvm.getTimestamp(), JRrrecv4.handler, (java.lang.Object []) null);
                                                        JRrrecv4.fretOp = null;
                                                    }
                                                    else if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // this should only be a send
                                                        JRrrecv4.handler.JRhandler(JRe);
                                                    }
                                                }
                                            }
                                            { if (JRrrecv4.retOp != null)
                                                JRrrecv4.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                        }
                                        else
                                            JRInstmt4.releaseIter();
                                        // End of servicing
                                        // End InniArm
                                        break;
                                    }
                                    case 2:
                                    {
                                        JRInstmt4.j = 0;
                                        // Inni Arm
                                        QuantRec JRquantRec4 = (QuantRec)JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex];
                                        Recv_ext JRrrecv4 = null, JRtmprecv4;
                                        for (JRInstmt4.iter = JRInstmt4.armArray[JRInstmt4.timesArray[JRInstmt4.i].armArrayIndex].theCap.elements();
                                             JRInstmt4.iter.hasNext();)
                                        {
                                            JRtmprecv4 = (Recv_ext)JRInstmt4.iter.next();
                                            JRInstmt4.JRinit.setInvoc(JRInstmt4.j++);
                                            JRtmprecv4.setInvocation(JRInstmt4.JRinit);
                                            // extract values
                                            JRrrecv4 = JRtmprecv4;
                                            break;  // get first one
                                        }
                                        // Start of servicing
                                        if (JRrrecv4 != null)
                                        {
                                            JRInstmt4.j = (int)JRrrecv4.getInvoc();
                                            JRInstmt4.serviced = true;
                                            JRInstmt4.iter.remove(JRInstmt4.j);
                                            JRInstmt4.releaseIter();
                                            JRInstmt4.unlock();
                                            {
                                                try {
                                                    {
                                                        // Begin Expr2
                                                        clientsDansParc--;
                                                    }
                                                } catch (Exception JRe) {
                                                    if (JRrrecv4.retOp != null && JRrrecv4.fretOp == null)
                                                    {
                                                        // forward of cocall
                                                        if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        else {
                                                            // give preference to propagation through the call stack
                                                            JRrrecv4.retOp.send(jrvm.getTimestamp(), JRe);
                                                            JRrrecv4.retOp = null;
                                                        }
                                                    }
                                                    else if ((JRrrecv4.retOp != null) && (JRrrecv4.fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // for cocall exception handling in operation invocation
                                                        if (JRrrecv4.handler != null)
                                                            JRrrecv4.handler.JRhandler(JRe);
                                                        JRrrecv4.fretOp.send(jrvm.getTimestamp(), JRrrecv4.handler, (java.lang.Object []) null);
                                                        JRrrecv4.fretOp = null;
                                                    }
                                                    else if ((JRrrecv4.handler != null) && !(JRe instanceof java.rmi.RemoteException))
                                                    {
                                                        // this should only be a send
                                                        JRrrecv4.handler.JRhandler(JRe);
                                                    }
                                                }
                                            }
                                            { if (JRrrecv4.retOp != null)
                                                JRrrecv4.retOp.send(jrvm.getTimestamp(), (java.lang.Object []) null); }
                                        }
                                        else
                                            JRInstmt4.releaseIter();
                                        // End of servicing
                                        // End InniArm
                                        break;
                                    }
                                    
                                }
                            }
                            if (!JRInstmt4.serviced)
                            {
                                // must block and loop
                                JRInstmt4.waitOnLock();
                            }
                        } while (!JRInstmt4.serviced);
                    }
                    // End Inni
                    
                }
            }
        } catch (Exception JRe)    {
            if (retOp != null && fretOp == null)
            {
        	// if it is a forward cocall with handler
        	if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
        	    handler.JRhandler(JRe);
        	else
        	    // give preference to propagation through the call stack
        	    retOp.send(jrvm.getTimestamp(), JRe);
            }
            else if ((retOp != null) && (fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// for COSTMT exception handling in operation
        	if (handler != null)
        	    handler.JRhandler(JRe);
        	fretOp.send(jrvm.getTimestamp(), handler, (java.lang.Object []) null);
            }
            else if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// this should only be for a send/forward
        	handler.JRhandler(JRe);
        	// can rethrow below just to get out of this method
            }
            // rethrow the proper type of exception
            // catch all
            throw new jrRuntimeError("Unhandled exception: " + JRe.toString());
        }
    }
    
    
    public static void main(String[] args) {
        if (args.length > NB_OF_ARGUMENTS) {
            // Begin Expr2
            System.out.println("use of RollerCoaster : \n jr RollerCoaster, NB_PASSENGERS_BASE,PASSENGER_ITER_BASE,NB_SEATS_BASE,NB_WAGONS_BASE");
            // Begin Expr2
            System.exit(0);
        }
        int argc = args.length;
        int var1 = NB_PASSENGERS_BASE;
        int var2 = PASSENGER_ITER_BASE;
        int var3 = NB_SEATS_BASE;
        int var4 = NB_WAGONS_BASE;
        switch (argc) {
        case FOUR_ARGUMENTS: 
            // Begin Expr2
            var4 = Integer.parseInt(args[--argc]);
        
        case THREE_ARGUMENTS: 
            // Begin Expr2
            var3 = Integer.parseInt(args[--argc]);
        
        case TWO_ARGUMENTS: 
            // Begin Expr2
            var2 = Integer.parseInt(args[--argc]);
        
        case ONE_ARGUMENT: 
            // Begin Expr2
            var1 = Integer.parseInt(args[--argc]);
        
        }
        // Begin Expr2
        nb_passengers = var1;
        // Begin Expr2
        passenger_iter = var2;
        // Begin Expr2
        nb_seats = var3;
        // Begin Expr2
        nb_wagons = var4;
        // Begin Expr2
        new RollerCoaster();
        JRget_op_nextwagonloading_intTovoid().send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {0});
        JRget_op_nextwagonunloading_intTovoid().send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, new java.lang.Object [] {0});
        try {
            // Begin Expr2
            JR.registerQuiescenceAction(new Cap_ext_(JRget_op_done_voidTovoid()));
        } catch (edu.ucdavis.jr.QuiescenceRegistrationException e) {
            // Begin Expr2
            e.printStackTrace();
        }
    }
    
    private static void donevoidTovoid(java.lang.Object [] JRargs) {
        ((Op_ext_.JRProxyOp)op_done_voidTovoid).call(jrvm.getTimestamp(), JRargs);
    }
    private static void donevoidTovoid(Op_ext.JRProxyOp retOp, Cap_ext fretOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
    {
        try    {
            {
                // Begin JRCall
                // Begin Expr2
                (new Cap_ext_(JRget_op_closing_voidTovoid(), "void")).call(jrvm.getTimestamp(), (java.lang.Object[]) null);// End JRCall
                
                // Begin Expr2
                System.out.println("--- l\'attraction est termine --- \n il reste le dernier wagon (le non-plein)   d charger");
                // Return
                { if (retOp != null)
                    retOp.send(jrvm.getTimestamp(), (edu.ucdavis.jr.RemoteHandler) null, null);
                return ; }
                // End Return

            }
        } catch (Exception JRe)    {
            if (retOp != null && fretOp == null)
            {
        	// if it is a forward cocall with handler
        	if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
        	    handler.JRhandler(JRe);
        	else
        	    // give preference to propagation through the call stack
        	    retOp.send(jrvm.getTimestamp(), JRe);
            }
            else if ((retOp != null) && (fretOp != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// for COSTMT exception handling in operation
        	if (handler != null)
        	    handler.JRhandler(JRe);
        	fretOp.send(jrvm.getTimestamp(), handler, (java.lang.Object []) null);
            }
            else if ((handler != null) && !(JRe instanceof java.rmi.RemoteException))
            {
        	// this should only be for a send/forward
        	handler.JRhandler(JRe);
        	// can rethrow below just to get out of this method
            }
            // rethrow the proper type of exception
            // catch all
            throw new jrRuntimeError("Unhandled exception: " + JRe.toString());
        }
    }
    private static Op_ext.JRProxyOp JRget_op_done_voidTovoid()
    {
        return op_done_voidTovoid;
    }
    
    public static Op_ext.JRProxyOp op_done_voidTovoid;
    static class ProcOp_voidTovoid_impldone extends ProcOp_ext_impl
    {
        public ProcOp_voidTovoid_impldone(RollerCoaster thisIn) throws RemoteException
        {
        }
        public java.lang.Object call(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.ariseAndReceive();  // from caller
            try    {
                jrvm.setTimestamp(JRtimestamp);
                RollerCoaster.donevoidTovoid(null, null, null, JRargs);
return null;
            } finally {
                jrvm.sendAndDie();    // to caller
            }
        }
        class sendThread implements Runnable
        {
            java.lang.Object [] JRargs;
            Op_ext.JRProxyOp retOp;
            Cap_ext fretOp;
            edu.ucdavis.jr.RemoteHandler handler;

            public sendThread(Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.handler = handler;
            }
            public sendThread(Op_ext.JRProxyOp retOp, Cap_ext fretOp,edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs)
            {
                this.JRargs = JRargs;
                this.retOp = retOp;
                this.fretOp = fretOp;
                this.handler = handler;
            }
            public void run()
            {
                try    {
                    RollerCoaster.donevoidTovoid(this.retOp, this.fretOp, this.handler, this.JRargs);
                } catch (Exception e) {/* should be safe to ignore this exception */}
                jrvm.threadDeath();
            }
        }
        public void send(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, null, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, null, null, JRargs);
        }
        public void send(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            this.send(JRtimestamp, null, handler, null, JRargs);
        }
        public Cap_ext cosend(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, java.lang.Object [] JRargs) throws RemoteException
        {
            return this.cosend(JRtimestamp, null, handler, null, JRargs);
        }
        public void send(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, handler, JRargs)).start();
        }
        public Cap_ext cosend(long JRtimestamp, Op_ext.JRProxyOp retOp, edu.ucdavis.jr.RemoteHandler handler, Exception thrown, java.lang.Object [] JRargs) throws RemoteException
        {
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(null, handler, JRargs)).start();
            Op_ext.JRProxyOp myretOp = new Op_ext_.JRProxyOp(new InOp_ext_impl());
            myretOp.send(jrvm.getTimestamp(), (java.lang.Object []) null);
            return new Cap_ext_(myretOp, "void");
        }
        public Cap_ext cocall(long JRtimestamp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, null, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Cap_ext cocall(long JRtimestamp, edu.ucdavis.jr.RemoteHandler handler, Cap_ext fretOp, java.lang.Object [] JRargs) throws RemoteException
        {
            Op_ext.JRProxyOp retOp = new Op_ext_.JRProxyOp(new InOp_ext_impl(false));
            jrvm.setTimestamp(JRtimestamp);
            jrvm.threadBirth();
            new Thread(new sendThread(retOp, fretOp, handler, JRargs)).start();
            Cap_ext retCap = new Cap_ext_(retOp, "void");
            return retCap;
        }
        public Recv_ext recv() throws RemoteException
        {
            /* This is an error */
            throw new jrRuntimeError("Receive invoked on an operation/operation capability associated with a method!");
        }
        public void deliverPendingMessages()
        {
            /* This is an error */
            throw new jrRuntimeError("Message delivery invoked on an operation associated with a method!");
        }
        public int length()
        {
            return 0;
        }
        public InOpIterator elements()
        {
            // This is an error
            throw new jrRuntimeError("Elements invoked on an operation / operation capability associated with a method!");
        }
        public InLock getLock()
        {
            // This is an error
            throw new jrRuntimeError("getLock invoked on an operation / operation capability associated with a method!");
        }
        public long getFirstTime()
        {
            // This is an error
            throw new jrRuntimeError("getFirstTime invoked on an operation / operation capability associated with a method!");
        }
        public boolean isRemote(String site)
        {
            // This is an error
            throw new jrRuntimeError("IsRemote invoked on an operation / operation capability associated with a method!");
        }
    }
    ;
    static    {
        try    {
            op_done_voidTovoid = new Op_ext_.JRProxyOp(new ProcOp_voidTovoid_impldone(null));
        } catch (Exception e) { throw new jrRuntimeError(e.toString());}
    }
    
    protected boolean JRcalled = false;
    protected JRRollerCoaster jrresref;
    public Object JRgetjrresref()
    { try {return jrresref.clone(); } catch (Exception e) {/* not gonna happen */ return null; } }
    protected void JRinit() {
    	if(this.JRcalled) return;
    	try {
    	op_manager_voidTovoid = new Op_ext_.JRProxyOp(new ProcOp_voidTovoid_implmanager(this));
    	op_wagon_intTovoid = new Op_ext_.JRProxyOp(new ProcOp_intTovoid_implwagon(this));
    	op_passenger_intTovoid = new Op_ext_.JRProxyOp(new ProcOp_intTovoid_implpassenger(this));
    	op_quitPark_voidTovoid = 
    	  new Op_ext_.JRProxyOp(new InOp_ext_impl());
    	op_closeRollerCoaster_voidTovoid = 
    	  new Op_ext_.JRProxyOp(new InOp_ext_impl());
    	op_isOpen_voidToboolean = 
    	  new Op_ext_.JRProxyOp(new InOp_ext_impl());
    	op_getOutRollerCoaster_intXintTovoid = 
    	  new Op_ext_.JRProxyOp(new InOp_ext_impl());
    	op_getInRollerCoaster_intToint = 
    	  new Op_ext_.JRProxyOp(new InOp_ext_impl());
    	} catch (Exception JRe)
    	{ throw new jrRuntimeError(JRe.toString()); }
    	jrresref = new JRRollerCoaster(op_done_voidTovoid, op_manager_voidTovoid, op_wagon_intTovoid, op_passenger_intTovoid, op_nextwagonunloading_intTovoid, op_nextwagonloading_intTovoid, op_closing_voidTovoid, op_quitPark_voidTovoid, op_closeRollerCoaster_voidTovoid, op_isOpen_voidToboolean, op_getOutRollerCoaster_intXintTovoid, op_getInRollerCoaster_intToint);
    	this.JRcalled = true;
    }
    private boolean JRproc = false;
    private void JRprocess() {
    	if (JRproc) return;
    	JRproc = true;
    	try {
    		op_manager_voidTovoid.send(jrvm.getTimestamp(), (java.lang.Object []) null);
    	  for (int wagon = 0; wagon < nb_wagons; wagon++) 
    	  {
    		op_wagon_intTovoid.send(jrvm.getTimestamp(), new java.lang.Object [] {wagon});
    	  }
    	  for (int passenger = 0; passenger < nb_passengers; passenger++) 
    	  {
    		op_passenger_intTovoid.send(jrvm.getTimestamp(), new java.lang.Object [] {passenger});
    	  }
    	} catch (Exception JRe) { throw new jrRuntimeError(JRe.toString()); }
    }
}
