The great Interval revamp.
There is no more SafeInterval, instead Intervals can be constructed with a RunQueue to use for expiring. PresentsDObjectMgr implements RunQueue. Client has a getRunQueue() method to get the client side RunQueue. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3283 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.samskivert.util.IntervalManager;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
@@ -38,7 +38,6 @@ import com.threerings.presents.net.AuthRequest;
|
||||
import com.threerings.presents.net.AuthResponse;
|
||||
import com.threerings.presents.net.Credentials;
|
||||
import com.threerings.presents.server.net.*;
|
||||
import com.threerings.presents.server.util.SafeInterval;
|
||||
|
||||
/**
|
||||
* The client manager is responsible for managing the clients (surprise,
|
||||
@@ -82,11 +81,11 @@ public class ClientManager
|
||||
|
||||
// start up an interval that will check for expired clients and
|
||||
// flush them from the bowels of the server
|
||||
IntervalManager.register(new SafeInterval(PresentsServer.omgr) {
|
||||
public void run () {
|
||||
new Interval(PresentsServer.omgr) {
|
||||
public void expired () {
|
||||
flushClients();
|
||||
}
|
||||
}, CLIENT_FLUSH_INTERVAL, null, true);
|
||||
}.schedule(CLIENT_FLUSH_INTERVAL, true);
|
||||
|
||||
// register as a "state of server" reporter and a shutdowner
|
||||
PresentsServer.registerReporter(this);
|
||||
|
||||
@@ -438,7 +438,7 @@ public class PresentsClient
|
||||
*/
|
||||
protected void safeEndSession ()
|
||||
{
|
||||
PresentsServer.omgr.postUnit(new Runnable() {
|
||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
if (getClientObject() == null) {
|
||||
// refuse to end the session unless the client is
|
||||
@@ -624,7 +624,7 @@ public class PresentsClient
|
||||
// our connection reference. once the connection ref is null, no
|
||||
// more subscriptions will be processed (even those that were
|
||||
// queued up before the connection went away)
|
||||
PresentsServer.omgr.postUnit(new Runnable() {
|
||||
PresentsServer.omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
sessionConnectionClosed();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PresentsDObjectMgr.java,v 1.48 2004/10/28 21:59:00 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -30,8 +30,8 @@ import sun.misc.Perf;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.Histogram;
|
||||
import com.samskivert.util.Invoker;
|
||||
import com.samskivert.util.Queue;
|
||||
import com.samskivert.util.RunQueue;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.util.Throttle;
|
||||
|
||||
@@ -52,8 +52,7 @@ import com.threerings.presents.dobj.*;
|
||||
* requested to shut down.
|
||||
*/
|
||||
public class PresentsDObjectMgr
|
||||
implements RootDObjectManager, Invoker.ResultReceiver,
|
||||
PresentsServer.Reporter
|
||||
implements RootDObjectManager, RunQueue, PresentsServer.Reporter
|
||||
{
|
||||
/**
|
||||
* Creates the dobjmgr and prepares it for operation.
|
||||
@@ -146,8 +145,10 @@ public class PresentsDObjectMgr
|
||||
* opportunity. The code will be queued up with the rest of the events
|
||||
* and invoked in turn. Like event processing code, the code should
|
||||
* not take long to complete and should <em>definitely</em> not block.
|
||||
*
|
||||
* From interface RunQueue
|
||||
*/
|
||||
public void postUnit (Runnable unit)
|
||||
public void postRunnable (Runnable unit)
|
||||
{
|
||||
// just append it to the queue
|
||||
_evqueue.append(unit);
|
||||
@@ -172,8 +173,10 @@ public class PresentsDObjectMgr
|
||||
* that is doing distributed object event dispatch. Code that wishes
|
||||
* to enforce that it is either always or never called on the event
|
||||
* dispatch thread will want to make use of this method.
|
||||
*
|
||||
* From interface RunQueue
|
||||
*/
|
||||
public synchronized boolean isEventDispatchThread ()
|
||||
public synchronized boolean isDispatchThread ()
|
||||
{
|
||||
return Thread.currentThread() == _dobjThread;
|
||||
}
|
||||
@@ -378,7 +381,7 @@ public class PresentsDObjectMgr
|
||||
*/
|
||||
public void harshShutdown ()
|
||||
{
|
||||
postUnit(new Runnable() {
|
||||
postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
_running = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: PresentsInvoker.java,v 1.2 2004/08/27 02:20:23 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -110,7 +110,7 @@ public class PresentsInvoker extends Invoker
|
||||
// if the queue isn't empty, re-post
|
||||
} else if (!_omgr.queueIsEmpty()) {
|
||||
_loopCount++;
|
||||
_omgr.postUnit(this);
|
||||
_omgr.postRunnable(this);
|
||||
|
||||
// if the invoker still has stuff and we're still under the pass
|
||||
// limit, go ahead and pass it back to the invoker
|
||||
|
||||
@@ -23,7 +23,7 @@ package com.threerings.presents.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.IntervalManager;
|
||||
import com.samskivert.util.Interval;
|
||||
import com.samskivert.util.ObserverList;
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.util.SystemInfo;
|
||||
@@ -33,7 +33,6 @@ import com.threerings.util.signal.SignalManager;
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.server.net.ConnectionManager;
|
||||
import com.threerings.presents.server.util.SafeInterval;
|
||||
|
||||
/**
|
||||
* The presents server provides a central point of access to the various
|
||||
@@ -130,11 +129,11 @@ public class PresentsServer
|
||||
TimeBaseProvider.init(invmgr, omgr);
|
||||
|
||||
// queue up an interval which will generate reports
|
||||
IntervalManager.register(new SafeInterval(omgr) {
|
||||
public void run () {
|
||||
new Interval(omgr) {
|
||||
public void expired () {
|
||||
generateReport(System.currentTimeMillis());
|
||||
}
|
||||
}, REPORT_INTERVAL, null, true);
|
||||
}.schedule(REPORT_INTERVAL, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +153,7 @@ public class PresentsServer
|
||||
{
|
||||
// post a unit that will start up the connection manager when
|
||||
// everything else in the dobjmgr queue is processed
|
||||
omgr.postUnit(new Runnable() {
|
||||
omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
// start up the connection manager
|
||||
conmgr.start();
|
||||
@@ -215,12 +214,15 @@ public class PresentsServer
|
||||
}
|
||||
}
|
||||
|
||||
report.append("* samskivert.IntervalManager:\n");
|
||||
/* The following Interval debug methods are no longer supported,
|
||||
* but they could be added back easily if needed.
|
||||
report.append("* samskivert.Interval:\n");
|
||||
report.append("- Registered intervals: ");
|
||||
report.append(IntervalManager.registeredIntervalCount());
|
||||
report.append(Interval.registeredIntervalCount());
|
||||
report.append("\n- Fired since last report: ");
|
||||
report.append(IntervalManager.getAndClearFiredIntervals());
|
||||
report.append(Interval.getAndClearFiredIntervals());
|
||||
report.append("\n");
|
||||
*/
|
||||
|
||||
// strip off the final newline
|
||||
int blen = report.length();
|
||||
@@ -277,7 +279,7 @@ public class PresentsServer
|
||||
*/
|
||||
public void queueShutdown ()
|
||||
{
|
||||
omgr.postUnit(new Runnable() {
|
||||
omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//
|
||||
// $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;
|
||||
}
|
||||
Reference in New Issue
Block a user