From: Dirk S. <di...@tb...> - 2004-10-18 09:35:50
|
Herman, Peter and others, Thanks; i'm on my way but not quite there yet. I changed my model a bit; now the stack fires events to which the crane listens (if the stack fires an event, let's say, STACK_EMPTY_EVENT, the crane responds by scheduling the next container delivery. My questions are in the comments of the (pseudo) code here-below. ==================================== public class Stack extends EventProducer { public static final EventType STACK_EMPTY_EVENT = new EventType( "STACK_EMPTY_EVENT"); ... public void emptyStack() { this.fireEvent(STACK_EMPTY_EVENT, "what's the second parameter used for?"); // 2nd parameter?? } } ==================================== public class Crane implements EventListenerInterface { ... public Crane(Stack stack) { stack.addListener(this, Stack.STACK_EMPTY_EVENT); } ... public void notify(EventInterface arg0) throws RemoteException { // what argument should be used? System.out.println("I want this to be on my console!"); } } ==================================== public static void Main(String args[]) { Stack myStack = new Stack(); Crane myCrane = new Crane(myStack) myStack.emptyStack(); // I expect some output; will this happen?? } -----Original Message----- From: Herman van Hovell [mailto:h_v...@ho...] Sent: woensdag 13 oktober 2004 19:46 To: di...@tb...; dso...@li... Subject: RE: [Dsol-java] how to listen to fireEvent? Hi, I think I can provide you with the answer. the vehicle has to subscribe to the event. This is done with the addListener(ListenerInterface listener, EvenType event) method which is in the EventProducer class and thuss in your crane class. Assuming it is in you r constructor it should look like this: public class Vehicle implements EventListenerInterface { public Vehicle(Crane crane) { /** Call super class constructor*/ super(); /** Do all other stuff*/ /** Add our listener*/ try { Crane.addListener(this, CONTAINER_RELEASED_EVENT); } catch (Exception e) { e.printStackTrace(); } } /** Methods*/ } Hope this helps, regards, Herman van Hovell >From: "Dirk Samson" <di...@tb...> >To: <dso...@li...> >Subject: [Dsol-java] how to listen to fireEvent? >Date: Wed, 13 Oct 2004 15:10:48 +0200 > >Dear all, > >I've made a "crane" that delivers "containers" every 1..5 timeunits. These >containers should be picked up by several "someVehicles". I would like to >have my crane fire an event, CONTAINER_RELEASED_EVENT. The code for this I >found in the tutorial, section 4.2: > >... >public class QuayCrane extends EventProducer { > public static final EventType CONTAINER_RELEASED_EVENT = new EventType( > "CONTAINER_RELEASED_EVENT"); >... > >private void releaseContainer () { >... >this.fireEvent(CONTAINER_RELEASED_EVENT, >this.simulator.getSimulatorTime()); >... } >} // end class > >My question: > >How do I get an instance of my someVehicle to listen to this event? The >events in the tutorial are (so it seems) only used by the Tallies. For this >moment I;m not interested in the prioritization of my someVehicles; I just >want them to respond. > >Is this the proper mechanism to create interaction between objects in the >simulation?? > >Dirk Samson >(PS My very-first-test-project can be found on the CVS Server: "SPM9322 - >port") > > > > >------------------------------------------------------- >This SF.net email is sponsored by: IT Product Guide on ITManagersJournal >Use IT products in your business? Tell us what you think of them. Give us >Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more >http://productguide.itmanagersjournal.com/guidepromo.tmpl >_______________________________________________ >Dsol-java mailing list >Dso...@li... >https://lists.sourceforge.net/lists/listinfo/dsol-java _________________________________________________________________ MSN Search, for accurate results! http://search.msn.nl |