Files
narya/src/java/com/threerings/presents/server/util/SafeInterval.java
T
Andrzej Kapolka f5fc8f9d2a Added stored interval id to server SafeInterval, to match client.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3223 542714f4-19e9-0310-aa3c-eee0fc999fb1
2004-11-19 00:32:18 +00:00

77 lines
2.6 KiB
Java

//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.presents.server.util;
import com.samskivert.util.Interval;
import com.threerings.presents.server.PresentsDObjectMgr;
/**
* Used in conjunction with the {@link PresentsDObjectMgr}, this class
* provides a means by which code can be run on the dobjmgr thread at some
* point in the future, either as a recurring interval or as a one shot
* deal. The code is built on top of the {@link IntervalManager} services.
*
* <p> A {@link SafeInterval} instance should be created and then
* scheduled to run using the {@link IntervalManager}. For example:
*
* <pre>
* IntervalManager.register(new SafeInterval(_omgr) {
* public void run () {
* System.out.println("Foo!");
* }
* }, 25L * 1000L, null, false);
* </pre>
*/
public abstract class SafeInterval
implements Runnable, Interval
{
/**
* Creates a safe interval instance that will queue itself up for
* execution on the supplied dobjmgr when it expires.
*/
public SafeInterval (PresentsDObjectMgr omgr)
{
_omgr = omgr;
}
/**
* Called (on the dobjmgr thread) when the interval period has
* expired. If this is a recurring interval, this method will be
* called each time the interval expires.
*/
public abstract void run ();
/** Handles the proper scheduling and queueing. */
public void intervalExpired (int id, Object arg)
{
_iid = id;
_omgr.postUnit(this);
}
/** The dobjmgr on which we queue ourselves when we expire. */
protected PresentsDObjectMgr _omgr;
/** Configured with our current interval id when we are triggered. */
protected int _iid;
}