LISTSERV mailing list manager LISTSERV 16.0

Help for MASON-INTEREST-L Archives


MASON-INTEREST-L Archives

MASON-INTEREST-L Archives


MASON-INTEREST-L@LISTSERV.GMU.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

MASON-INTEREST-L Home

MASON-INTEREST-L Home

MASON-INTEREST-L  February 2008

MASON-INTEREST-L February 2008

Subject:

Re: Using only Display

From:

Siamak Sarmady <[log in to unmask]>

Reply-To:

MASON Multiagent Simulation Toolkit <[log in to unmask]>

Date:

Thu, 14 Feb 2008 11:10:05 +0800

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (92 lines)

Sean,

Thank you very much for your time and kind help. The design of Mason
seems very good to me (for the purpose it has designed). I think I
should be able to handle this with your descriptions.

Thank you again,
Mac


> This is a question with a very complex answer, and it's not easy to
> answer given the hack that you're doing here.  So some background.
> When you press "play" on the Console, here's what it does in short:
>
> 1. Calls start() on the GUIState (which in turn calls start() on the
> underlying SimState)
> 2. Spawns a thread (the "play thread") which:
>         2a. Blocks waiting for all Swing Events to have completed (using
> SwingUtilities.invokeAndWait)
>         2b.  Loops:
>                 2b.i. calls simulation.step() to step the simulation once.  This
> automatically synchronizes on the schedule until the step is completed.
>                 2b.ii. Blocks until all Swing Events have completed
>
> When we try (from the Swing event thread) to repaint the window or
> inspect an object in the window or modify a feature of an object, we
> first synchronize on the underlying Schedule.  This causes us to
> block until the playThread's call of simulation.step() has completed,
> so we don't modify or read bad stuff on the model.
>
> When you call "stop" on the Console we:
>
> 1. Interrupt the play thread (since we were called via a java event
> -- mouse click on stop button -- we know we have control and the
> underlying thread is blocking waiting for our Swing Event to complete.
>
> 2. Kill the play thread
>
> 3. Call finish() on the GUIState
>
>
> [Keep in mind that you should call init() on the GUIState and also
> quit() on it when you first create it and later destroy it at the end
> of your application.]
>
> The important item to note here is that MASON's GUI facilities are
> designed to hand off a baton and forth between an underlying thread
> (called the "play thread") and Swing.  Whoever has the baton is
> allowed to read/write the model and the schedule, otherwise they have
> to wait.  Waiting for and acquiring the baton is easy: just
> synchronize on the Schedule.
>
> It looks like you are deviating from this model in two ways:
>
> 1. You're not handing off the baton.  This could result in race
> conditions you don't want to see.
> 2. Your model thread (the equivalent of the "play thread" above) is
> the underlying main() thread perhaps?  It's not made clear.
> Ordinarily in Java GUI applications, the main thread just sets things
> up and dies.
>
> The easiest way to handle this is to NOT call start(), but rather let
> the console handle it for you.  Just call console.pressPlay() to
> start the simulation, and console.pressStop() to stop the
> simulation.  You really ought to do these from the GUI thread, not
> the main thread.  If you're not in the GUI thread, you can still do
> this by creating a small Runnable, whose sole function in life is to
> call console.pressPlay(), and adding him to SwingUtilities with a
> SwingUtilities.invokeAndWait(...).  Likewise for console.pressStop().
>
> When the Display2D's window is disposed, by default it calls
> Display2D.quit() first.  But note that in Java by default when you
> click on a close box in a window, it doesn't dispose the window.  It
> just hides it.  That's what MASON is relying on -- it's just hiding
> the window.  You can change the behavior of closing the window to
> actually dispose the window (and thus call quit()), look at JFrame's
> documentation.  Basically, let Display2D create its window with
> createFrame(), and then change that frame's close-box behavior.
>
> If you do this, you will also want to hook into JFrame's quit()
> method to quit your program when the window is closed.  The quick and
> dirty, ugly way to do this is to just override the quit() method in
> Display2D to call System.exit(0).  That will kill everything
> immediately and quit your application.  A better approach would be to
> call console.doClose(), which will cleanly shut down and dispose
> everything.
>
> Good luck!  Beware that multithreading coding in Swing is
> nontrivial!  :-)
>
> Sean
>

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

December 2017
November 2017
September 2017
June 2017
May 2017
March 2017
February 2017
January 2017
December 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
February 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
April 2005
March 2005
February 2005
January 2005
December 2004
November 2004
October 2004
September 2004
July 2004
May 2004
April 2004
March 2004

ATOM RSS1 RSS2



LISTSERV.GMU.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager