Further wired up the client side of the distributed object system. Removed

the facilities for fetching (without subscribing to) an object. This is
done extremely rarely and the user might as well just subscribe and
immediately unsubscribe because the dichotomy between fetching and
subscribing just served to overly complicate the internals for no good
reason.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@30 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-06-09 23:39:04 +00:00
parent 06f6fa26d5
commit 6a1de87f2a
20 changed files with 574 additions and 189 deletions
@@ -1,5 +1,5 @@
//
// $Id: DObject.java,v 1.8 2001/06/01 20:35:39 mdb Exp $
// $Id: DObject.java,v 1.9 2001/06/09 23:39:04 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -73,20 +73,6 @@ import java.util.ArrayList;
*/
public class DObject
{
/**
* Initializes this distributed object with the supplied object id and
* distributed object manager. This is called by the distributed
* object manager when an object is created and registered with the
* system. Don't call this function yourself.
*
* @see DObjectManager.createObject
*/
public void init (int oid, DObjectManager mgr)
{
_oid = oid;
_mgr = mgr;
}
/**
* Returns the object id of this object. All objects in the system
* have a unique object id.
@@ -97,15 +83,13 @@ public class DObject
}
/**
* Adds the supplied subscriber to the subscriber list for this
* object. This is done automatically when an object is requested for
* subscription by the distributed object manager, thus this function
* should not be called directly except in circumstances where one
* subscriber has already obtained a subscription to an object and
* wishes to include a subordinate subscriber in on the fun.
* Don't call this function! Go through the distributed object manager
* instead to ensure that everything is done on the proper thread.
* This function can only safely be called directly when you know you
* are operating on the omgr thread (you are in the middle of a call
* to <code>objectAvailable</code> or <code>handleEvent</code>).
*
* <p> If the specified subscriber is already subscribed to this
* object, they will not be added to the list a second time.
* @see DObjectManager.subscribeToObject
*/
public void addSubscriber (Subscriber sub)
{
@@ -115,12 +99,13 @@ public class DObject
}
/**
* Removes the specified subscriber from the subscriber list for this
* object. This is done automatically when a subscriber returns false
* from <code>handleEvent</code>, but can also be done directly
* through a call to <code>removeSubscriber</code>. If the specified
* subscriber is not currently on the list of subscribers for this
* object, nothing happens.
* Don't call this function! Go through the distributed object manager
* instead to ensure that everything is done on the proper thread.
* This function can only safely be called directly when you know you
* are operating on the omgr thread (you are in the middle of a call
* to <code>objectAvailable</code> or <code>handleEvent</code>).
*
* @see DObjectManager.unsubscribeFromObject
*/
public void removeSubscriber (Subscriber sub)
{
@@ -129,13 +114,12 @@ public class DObject
/**
* Checks to ensure that the specified subscriber has access to this
* object. This will be called before satisfying any fetch or
* subscription request. By default objects are accessible to all
* subscriber, but certain objects may wish to implement more fine
* grained access control.
* object. This will be called before satisfying a subscription
* request. By default objects are accessible to all subscribers, but
* certain objects may wish to implement more fine grained access
* control.
*
* @param sub the subscriber that will fetch or subscribe to this
* object.
* @param sub the subscriber that will subscribe to this object.
*
* @return true if the subscriber has access to the object, false if
* they do not.
@@ -201,6 +185,30 @@ public class DObject
}
}
/**
* Don't call this function! It initializes this distributed object
* with the supplied distributed object manager. This is called by the
* distributed object manager when an object is created and registered
* with the system.
*
* @see DObjectManager.createObject
*/
public void setManager (DObjectManager mgr)
{
_mgr = mgr;
}
/**
* Don't call this function. It is called by the distributed object
* manager when an object is created and registered with the system.
*
* @see DObjectManager.createObject
*/
public void setOid (int oid)
{
_oid = oid;
}
protected int _oid;
protected DObjectManager _mgr;
protected ArrayList _subscribers = new ArrayList();
@@ -1,5 +1,5 @@
//
// $Id: DObjectManager.java,v 1.4 2001/06/05 22:44:31 mdb Exp $
// $Id: DObjectManager.java,v 1.5 2001/06/09 23:39:04 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -49,25 +49,6 @@ public interface DObjectManager
*/
public void subscribeToObject (int oid, Subscriber target);
/**
* Fetches an up-to-date copy of the specified distributed object and
* makes it available to the subscriber for a one-time access. The
* subscriber will not be added to the object's subscriber list and
* will not be notified of updates to the object and the object
* represents a snapshot in time which, it should be acknowledged,
* could be out of date by the time it reaches the subscriber. If the
* object cannot be fetched for some reason, the subscriber will be
* notified via <code>requestFailed</code>.
*
* @param oid The object id of the distributed object of which a
* snapshot is desired.
* @param target The subscriber that will receive the snapshot.
*
* @see Subscriber.objectAvailable
* @see Subscriber.requestFailed
*/
public void fetchObject (int oid, Subscriber target);
/**
* Requests that the specified subscriber be unsubscribed from the
* object identified by the supplied object id.
@@ -1,5 +1,5 @@
//
// $Id: Subscriber.java,v 1.3 2001/06/02 01:30:37 mdb Exp $
// $Id: Subscriber.java,v 1.4 2001/06/09 23:39:04 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -22,17 +22,15 @@ public interface Subscriber
* should not attempt to modify the object.
*
* @see DObjectManager.subscribeToObject
* @see DObjectManager.fetchObject
*/
public void objectAvailable (DObject object);
/**
* Called when a subscription or fetch request has failed. The nature
* of the failure will be communicated via the supplied
* Called when a subscription request has failed. The nature of the
* failure will be communicated via the supplied
* <code>ObjectAccessException</code>.
*
* @see DObjectManager.subscribeToObject
* @see DObjectManager.fetchObject
*/
public void requestFailed (int oid, ObjectAccessException cause);
@@ -1,5 +1,5 @@
//
// $Id: DObjectFactory.java,v 1.3 2001/05/30 23:58:31 mdb Exp $
// $Id: DObjectFactory.java,v 1.4 2001/06/09 23:39:04 mdb Exp $
package com.threerings.cocktail.cher.dobj.net;
@@ -32,6 +32,8 @@ public class DObjectFactory
Marshaller marsh = getMarshaller(clazz);
// then write the class of the object to the stream
out.writeUTF(clazz.getName());
// write out the oid
out.writeInt(dobj.getOid());
// then use the marshaller to write the object itself
marsh.writeTo(out, dobj);
}
@@ -46,6 +48,7 @@ public class DObjectFactory
// read in the class name and create an instance of that class
Class clazz = Class.forName(in.readUTF());
DObject dobj = (DObject)clazz.newInstance();
dobj.setOid(in.readInt()); // read and set the oid
Log.info("Unmarshalling object: " + dobj);
// look up the marshaller for that class