Beginnings of event stuff.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@18 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-06-01 07:12:13 +00:00
parent b6d12bc06d
commit 825b36c0ff
4 changed files with 281 additions and 2 deletions
@@ -0,0 +1,97 @@
//
// $Id: AttributeChangedEvent.java,v 1.1 2001/06/01 07:12:13 mdb Exp $
package com.threerings.cocktail.cher.dobj;
/**
* An attribute changed event is dispatched when a single attribute of a
* distributed object has changed. It can also be constructed to request
* an attribute change on an object and posted to the dobjmgr.
*
* @see DObjectManager.postEvent
*/
public class AttributeChangedEvent extends DEvent
{
/**
* Constructs a new attribute changed event on the specified target
* object with the supplied attribute name and value.
*
* @param targetOid the object id of the object whose attribute has
* changed.
* @param name the name of the attribute (data member) that has
* changed.
* @param value the new value of the attribute (in the case of
* primitive types, the reflection-defined object-alternative is
* used).
*/
public AttributeChangedEvent (int targetOid, String name, Object value)
{
super(targetOid);
_name = name;
_value = value;
}
/**
* Returns the name of the attribute that has changed.
*/
public String getName ()
{
return _name;
}
/**
* Returns the new value of the attribute.
*/
public Object getValue ()
{
return _value;
}
/**
* Returns the new value of the attribute as a short. This will fail
* if the attribute in question is not a short.
*/
public short getShortValue ()
{
return ((Short)_value).shortValue();
}
/**
* Returns the new value of the attribute as an int. This will fail if
* the attribute in question is not an int.
*/
public int getIntValue ()
{
return ((Integer)_value).intValue();
}
/**
* Returns the new value of the attribute as a long. This will fail if
* the attribute in question is not a long.
*/
public long getLongValue ()
{
return ((Long)_value).longValue();
}
/**
* Returns the new value of the attribute as a float. This will fail
* if the attribute in question is not a float.
*/
public float getFloatValue ()
{
return ((Float)_value).floatValue();
}
/**
* Returns the new value of the attribute as a double. This will fail
* if the attribute in question is not a double.
*/
public double getDoubleValue ()
{
return ((Double)_value).doubleValue();
}
protected String _name;
protected Object _value;
}
@@ -0,0 +1,145 @@
//
// $Id: AttributesChangedEvent.java,v 1.1 2001/06/01 07:12:13 mdb Exp $
package com.threerings.cocktail.cher.dobj;
/**
* An attribute<em>s</em> changed event is dispatched when multiple
* attributes of a distributed object have been changed in a single
* transaction.
*
* @see DObjectManager.postEvent
*/
public class AttributesChangedEvent extends DEvent
{
/**
* Constructs a new attribute changed event on the specified target
* object with the supplied attribute name and value.
*
* @param targetOid the object id of the object whose attribute has
* changed.
* @param count the number of attributes that have changed (the length
* of the <code>names</code> and <code>values</code> arrays need not
* be exactly equal to the number of attributes changed, there can be
* extra space at the end).
* @param names the names of the attributes (data members) that have
* changed.
* @param values the new values of the attributes (in the case of
* primitive types, the reflection-defined object-alternative is
* used).
*/
public AttributesChangedEvent (int targetOid, int count,
String[] names, Object[] values)
{
super(targetOid);
_count = count;
_names = names;
_values = values;
}
/**
* Returns the number of attributes that have changed.
*/
public int getCount ()
{
return _count;
}
/**
* Returns the name of the index<em>th</em> attribute that has
* changed. This value is not range checked, so be sure it is between
* <code>0</code> and <code>getCount()-1</code>. You may not receive
* an <code>ArrayIndexOutOfBounds</code> exception if you exceed
* <code>getCount()</code> but rather get a null name.
*/
public String getName (int index)
{
return _names[index];
}
/**
* Returns the new value of the index<em>th</em> attribute. This value
* is not range checked, so be sure it is between <code>0</code> and
* <code>getCount()-1</code>. You may not receive an
* <code>ArrayIndexOutOfBounds</code> exception if you exceed
* <code>getCount()</code> but rather get a null value.
*/
public Object getValue (int index)
{
return _values[index];
}
/**
* Returns the new value of the index<em>th</em> attribute as a
* short. This will fail if the attribute in question is not a short.
* The <code>index</code> parameter is not range checked, so be sure
* it is between <code>0</code> and <code>getCount()-1</code>. You may
* not receive an <code>ArrayIndexOutOfBounds</code> exception if you
* exceed <code>getCount()</code> but rather get a
* <code>NullPointerException</code>.
*/
public short getShortValue (int index)
{
return ((Short)_values[index]).shortValue();
}
/**
* Returns the new value of the index<em>th</em> attribute as an
* int. This will fail if the attribute in question is not an int.
* The <code>index</code> parameter is not range checked, so be sure
* it is between <code>0</code> and <code>getCount()-1</code>. You may
* not receive an <code>ArrayIndexOutOfBounds</code> exception if you
* exceed <code>getCount()</code> but rather get a
* <code>NullPointerException</code>.
*/
public int getIntValue (int index)
{
return ((Integer)_values[index]).intValue();
}
/**
* Returns the new value of the index<em>th</em> attribute as a
* long. This will fail if the attribute in question is not a long.
* The <code>index</code> parameter is not range checked, so be sure
* it is between <code>0</code> and <code>getCount()-1</code>. You may
* not receive an <code>ArrayIndexOutOfBounds</code> exception if you
* exceed <code>getCount()</code> but rather get a
* <code>NullPointerException</code>.
*/
public long getLongValue (int index)
{
return ((Long)_values[index]).longValue();
}
/**
* Returns the new value of the index<em>th</em> attribute as a
* float. This will fail if the attribute in question is not a float.
* The <code>index</code> parameter is not range checked, so be sure
* it is between <code>0</code> and <code>getCount()-1</code>. You may
* not receive an <code>ArrayIndexOutOfBounds</code> exception if you
* exceed <code>getCount()</code> but rather get a
* <code>NullPointerException</code>.
*/
public float getFloatValue (int index)
{
return ((Float)_values[index]).floatValue();
}
/**
* Returns the new value of the index<em>th</em> attribute as a
* double. This will fail if the attribute in question is not a
* double. The <code>index</code> parameter is not range checked, so
* be sure it is between <code>0</code> and <code>getCount()-1</code>.
* You may not receive an <code>ArrayIndexOutOfBounds</code> exception
* if you exceed <code>getCount()</code> but rather get a
* <code>NullPointerException</code>.
*/
public double getDoubleValue (int index)
{
return ((Double)_values[index]).doubleValue();
}
protected int _count;
protected String[] _names;
protected Object[] _values;
}
@@ -1,5 +1,5 @@
//
// $Id: DEvent.java,v 1.1 2001/06/01 05:01:52 mdb Exp $
// $Id: DEvent.java,v 1.2 2001/06/01 07:12:13 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -11,4 +11,23 @@ package com.threerings.cocktail.cher.dobj;
*/
public class DEvent
{
/**
* Returns the oid of the object that is the target of this event.
*/
public int getTargetOid ()
{
return _toid;
}
/**
* Constructs a new distributed object event that pertains to the
* specified distributed object.
*/
protected DEvent (int targetOid)
{
_toid = targetOid;
}
/** The oid of the object that is the target of this event. */
protected int _toid;
}
@@ -1,5 +1,5 @@
//
// $Id: DObjectManager.java,v 1.2 2001/06/01 05:17:16 mdb Exp $
// $Id: DObjectManager.java,v 1.3 2001/06/01 07:12:13 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -67,4 +67,22 @@ public interface DObjectManager
* @see Subscriber.requestFailed
*/
public void fetchObject (int oid, Subscriber target);
/**
* Posts a distributed object event into the system. Instead of
* requesting the modification of a distributed object attribute by
* calling the setter for that attribute on the object itself, an
* <code>AttributeChangedEvent</code> can be constructed and posted
* directly. This is true for all event types and is useful for
* situations where one doesn't have access to the object in question,
* but needs to affect some event.
*
* <p> This event will be forwarded to the ultimate manager of the
* object (on the client, this means it will be forwarded to the
* server) where it will be checked for validity and then applied to
* the object and dispatched to all its subscribers.
*
* @param event The event to be dispatched.
*/
public void postEvent (DEvent event);
}