This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Car
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
###Data
Passenger p;
List<PickupRequest> pickups;
class PickupRequest {Passenger p, Structure s,Structure destination};
Semaphore sem;
###Messages
public void msgCallCar(Passenger p, Structure s,Structure d)
{
pickups.add(new PickupRequest(p,s,d));
}
public void msgDoneBoarding(Passenger p)
{
sem.release();
}
public void msgLeaving(Passenger p)
{
sem.release();
}
//Inherited
public void msgSetDestination(Structure s);
###Scheduler
@Override
protected boolean pickAndExecuteAnAction()
{
if p != null
if destinationReached()
arrival();
else
doGoToDestination();
else if !pickups.isEmpty()
processPickup(pickups.remove(0));
}
###Actions
private void processPickup(PickupRequest request)
{
doGoToDestination(request.s);
p.msgPleaseBoard();
sem.acquire();
p = request.p;
msgSetDestination(request.destination);
}
private void arrival()
{
p.msgArrived();
sem.acquire();
p = null;
//hide car
}