git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5025 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Jamie Doornbos
2008-04-25 20:22:21 +00:00
parent 5d02ac7306
commit e7374452cd
14 changed files with 797 additions and 0 deletions
@@ -0,0 +1,29 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2008 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.bureau.client;
/**
* Represents an agent running within a bureau client.
*/
public class Agent
{
}
@@ -0,0 +1,21 @@
package com.threerings.bureau.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.net.Credentials;
import com.samskivert.util.RunQueue;
/**
* Represents a client embedded in a bureau.
*/
public class BureauClient extends Client
{
/**
* Creates a new client.
* @param creds the credentials supplied during connection
* @param runQueue the place to post tasks required by clients
*/
public BureauClient (Credentials creds, RunQueue runQueue)
{
super(creds, runQueue);
}
}
@@ -0,0 +1,80 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2008 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.bureau.client;
import com.threerings.bureau.client.BureauReceiver;
import com.threerings.presents.client.InvocationDecoder;
import com.threerings.presents.data.ClientObject;
/**
* Dispatches calls to a {@link BureauReceiver} instance.
*/
public class BureauDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static final String RECEIVER_CODE = "3e98f7a30deb5a8e25e05c71c6081bf4";
/** The method id used to dispatch {@link BureauReceiver#createAgent}
* notifications. */
public static final int CREATE_AGENT = 1;
/** The method id used to dispatch {@link BureauReceiver#destroyAgent}
* notifications. */
public static final int DESTROY_AGENT = 2;
/**
* Creates a decoder that may be registered to dispatch invocation
* service notifications to the specified receiver.
*/
public BureauDecoder (BureauReceiver receiver)
{
this.receiver = receiver;
}
@Override // documentation inherited
public String getReceiverCode ()
{
return RECEIVER_CODE;
}
@Override // documentation inherited
public void dispatchNotification (int methodId, Object[] args)
{
switch (methodId) {
case CREATE_AGENT:
((BureauReceiver)receiver).createAgent(
(ClientObject)args[0], ((Integer)args[1]).intValue()
);
return;
case DESTROY_AGENT:
((BureauReceiver)receiver).destroyAgent(
(ClientObject)args[0], ((Integer)args[1]).intValue()
);
return;
default:
super.dispatchNotification(methodId, args);
return;
}
}
}
@@ -0,0 +1,33 @@
package com.threerings.bureau.client;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.util.PresentsContext;
/**
* Allows the server to create and destroy agents on a client.
* @see BureauRegistry
*/
public class BureauDirector extends BasicDirector
implements BureauReceiver
{
protected BureauDirector (PresentsContext ctx)
{
super(ctx);
// Set up our decoder so we can receive method calls
// from the server
_ctx.getClient().getInvocationDirector().
registerReceiver(new BureauDecoder(this));
}
@Override // inherited documentation
public void createAgent (ClientObject client, int agentId)
{
}
@Override // inherited documentation
public void destroyAgent (ClientObject client, int agentId)
{
}
}
@@ -0,0 +1,50 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2008 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.bureau.client;
import com.threerings.presents.client.InvocationReceiver;
import com.threerings.presents.data.ClientObject;
/**
* Hooks for controlling a previously launched bureau client.
*/
public interface BureauReceiver extends InvocationReceiver
{
/**
* Creates a new agent. Implementors should create a new {@link Agent} and give it access to
* the {@link AgentObject} referred to by the <code>agentId</code> parameter and must notify
* the service that the agent has been created using {@link BureauService#agentCreated}.
* @param client the client receiving the request
* @param agentId the id of the <code>AgentObject</code> that needs an <code>Agent</code>
*/
void createAgent (ClientObject client, int agentId);
/**
* Destroys a previously created agent. Implementors should destroy the agent that was created
* by the call to <code>createAgent</code> with the same agent id and must notify
* the service that the agent has been created using {@link BureauService#agentDestroyed}.
* @param client the client receiving the request
* @param agentId the id of the <code>AgentObject</code> whose <code>Agent</code>
* should be destroyed
*/
void destroyAgent (ClientObject client, int agentId);
}
@@ -0,0 +1,52 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2008 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.bureau.client;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
/**
* Interface for the bureau to communicate with the server.
*/
public interface BureauService extends InvocationService
{
/**
* Notifies the server that the bureau is up and running and ready to receive
* requests via the <code>BureauReceiver</code>.
* @see BureauReceiver
*/
void bureauInitialized (Client client, String bureauId);
/**
* Notify the server that a previosuly requested agent is not created and ready to use.
* @see BureauReceiver#createAgent
*/
void agentCreated (Client client, int agentId);
/**
* Notify the server that an agent is no longer running. Normally called in response
* to a call to <code>destroyAgent</code>
* @see BureauReceiver#destroyAgent
*/
void agentDestroyed (Client client, int agentId);
}