Instead of forcing PeerManager's view of the architecture (that peer stuff shall be accessed via the Main Invoker) on the developer, let's mark the peer invoker uniquely so that it can be run elsewhere. In order to maintain backwards compatibility, this got a little weird in the organization of PresentsModule doing its default binding. If the new binding went in bindInvokers() where it theoretically belongs, anyone who is already overriding bindInvokers() (and not calling super, cuz this is how things work) would not be binding PeerInvoker at all and would be confused.

If we /didn't/ care at all about backwards compatibility, my preferred approach would have been to have the invoker for PeerManager injected in the constructor instead of as a field such that said constructor could be overridden and the invoker be injected with a different annotation.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6569 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Mike Thomas
2011-03-31 18:07:15 +00:00
parent 5d4ed6636b
commit b42af5855f
3 changed files with 57 additions and 2 deletions
@@ -0,0 +1,44 @@
//
// $Id: MainInvoker.java 6407 2011-01-01 05:02:21Z dhoover $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2011 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/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.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.google.inject.BindingAnnotation;
import com.samskivert.util.Invoker;
/**
* An annotation that identifies the peer {@link Invoker}. Code that requires the ability
* to post units for execution on the peer invoker thread can inject this queue like so:
*
* <code>@Inject @PeerInvoker Invoker _invoker;</code>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@BindingAnnotation
public @interface PeerInvoker
{
}
@@ -59,7 +59,7 @@ import com.threerings.presents.peer.data.DObjectAddress;
import com.threerings.util.Name;
import com.threerings.presents.annotation.MainInvoker;
import com.threerings.presents.annotation.PeerInvoker;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.presents.data.ClientObject;
@@ -1611,7 +1611,7 @@ public abstract class PeerManager
protected Stats _stats = new Stats();
// our service dependencies
@Inject protected @MainInvoker Invoker _invoker;
@Inject protected @PeerInvoker Invoker _invoker;
@Inject protected ClientManager _clmgr;
@Inject protected PresentsConnectionManager _conmgr;
@Inject protected Injector _injector;
@@ -25,6 +25,7 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Singleton;
@@ -36,6 +37,7 @@ import com.samskivert.util.SystemInfo;
import com.threerings.presents.annotation.AuthInvoker;
import com.threerings.presents.annotation.EventQueue;
import com.threerings.presents.annotation.MainInvoker;
import com.threerings.presents.annotation.PeerInvoker;
import com.threerings.presents.client.Client;
import com.threerings.presents.dobj.AccessController;
import com.threerings.presents.dobj.DObject;
@@ -68,6 +70,7 @@ public class PresentsServer
{
@Override protected void configure () {
bindInvokers();
bindPeerInvoker();
bind(ConnectionManager.class).to(PresentsConnectionManager.class);
bind(RunQueue.class).annotatedWith(EventQueue.class).to(PresentsDObjectMgr.class);
bind(DObjectManager.class).to(PresentsDObjectMgr.class);
@@ -82,6 +85,14 @@ public class PresentsServer
bind(Invoker.class).annotatedWith(MainInvoker.class).to(PresentsInvoker.class);
bind(Invoker.class).annotatedWith(AuthInvoker.class).to(PresentsAuthInvoker.class);
}
/**
* Binds just the peer invoker - we separate this from the others for legacy reasons.
*/
protected void bindPeerInvoker () {
bind(Invoker.class).annotatedWith(PeerInvoker.class).to(
Key.get(Invoker.class, MainInvoker.class));
}
}
/**