Revamped toString() to be more derived class friendly. Added a

ReleaseLockEvent which will be used by the distributed object locking
facilities.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@169 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-08-04 00:32:11 +00:00
parent 31d1aa1edb
commit a831089362
7 changed files with 152 additions and 18 deletions
@@ -1,5 +1,5 @@
//
// $Id: AttributeChangedEvent.java,v 1.7 2001/08/02 04:49:08 mdb Exp $
// $Id: AttributeChangedEvent.java,v 1.8 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -142,10 +142,12 @@ public class AttributeChangedEvent extends TypedEvent
_value = ValueMarshaller.readFrom(in);
}
public String toString ()
protected void toString (StringBuffer buf)
{
return "[CHANGE:targetOid=" + _toid + ", name=" + _name +
", value=" + _value + "]";
buf.append("CHANGE:");
super.toString(buf);
buf.append(", name=").append(_name);
buf.append(", value=").append(_value);
}
protected String _name;
@@ -1,5 +1,5 @@
//
// $Id: AttributesChangedEvent.java,v 1.6 2001/08/02 04:49:08 mdb Exp $
// $Id: AttributesChangedEvent.java,v 1.7 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -7,6 +7,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.samskivert.util.StringUtil;
import com.threerings.cocktail.cher.dobj.io.ValueMarshaller;
/**
@@ -198,6 +199,14 @@ public class AttributesChangedEvent extends TypedEvent
}
}
protected void toString (StringBuffer buf)
{
buf.append("CHANGES:");
super.toString(buf);
buf.append(", names=").append(StringUtil.toString(_names));
buf.append(", values=").append(StringUtil.toString(_values));
}
protected int _count;
protected String[] _names;
protected Object[] _values;
@@ -1,5 +1,5 @@
//
// $Id: DEvent.java,v 1.4 2001/07/19 18:08:20 mdb Exp $
// $Id: DEvent.java,v 1.5 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -63,6 +63,29 @@ public abstract class DEvent
_toid = targetOid;
}
/**
* Constructs and returns a string representation of this event.
*/
public String toString ()
{
StringBuffer buf = new StringBuffer();
buf.append("[");
toString(buf);
buf.append("]");
return buf.toString();
}
/**
* This should be overridden by derived classes (which should be sure
* to call <code>super.toString()</code>) to append the derived class
* specific event information to the string buffer.
*/
protected void toString (StringBuffer buf)
{
buf.append("targetOid=").append(_toid);
buf.append(", sourceOid=").append(_soid);
}
/** The oid of the object that is the target of this event. */
protected int _toid;
@@ -1,5 +1,5 @@
//
// $Id: MessageEvent.java,v 1.3 2001/08/02 04:49:08 mdb Exp $
// $Id: MessageEvent.java,v 1.4 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -110,10 +110,12 @@ public class MessageEvent extends TypedEvent
}
}
public String toString ()
protected void toString (StringBuffer buf)
{
return "[MSG:targetOid=" + _toid + ", name=" + _name +
", args=" + StringUtil.toString(_args) + "]";
buf.append("MSG:");
super.toString(buf);
buf.append(", name=").append(_name);
buf.append(", args=").append(StringUtil.toString(_args));
}
protected String _name;
@@ -1,5 +1,5 @@
//
// $Id: ObjectAddedEvent.java,v 1.3 2001/08/02 04:49:08 mdb Exp $
// $Id: ObjectAddedEvent.java,v 1.4 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -94,10 +94,12 @@ public class ObjectAddedEvent extends TypedEvent
_oid = in.readInt();
}
public String toString ()
protected void toString (StringBuffer buf)
{
return "[OBJADD:targetOid=" + _toid + ", name=" + _name +
", oid=" + _oid + "]";
buf.append("OBJADD:");
super.toString(buf);
buf.append(", name=").append(_name);
buf.append(", oid=").append(_oid);
}
protected String _name;
@@ -1,5 +1,5 @@
//
// $Id: ObjectRemovedEvent.java,v 1.3 2001/08/02 04:49:08 mdb Exp $
// $Id: ObjectRemovedEvent.java,v 1.4 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
@@ -95,10 +95,12 @@ public class ObjectRemovedEvent extends TypedEvent
_oid = in.readInt();
}
public String toString ()
protected void toString (StringBuffer buf)
{
return "[OBJREM:targetOid=" + _toid + ", name=" + _name +
", oid=" + _oid + "]";
buf.append("OBJREM:");
super.toString(buf);
buf.append(", name=").append(_name);
buf.append(", oid=").append(_oid);
}
protected String _name;
@@ -0,0 +1,94 @@
//
// $Id: ReleaseLockEvent.java,v 1.1 2001/08/04 00:32:11 mdb Exp $
package com.threerings.cocktail.cher.dobj;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import com.threerings.cocktail.cher.dobj.io.ValueMarshaller;
/**
* A release lock event is dispatched at the end of a chain of attribute
* change events to release a lock that is intended to prevent some
* application defined activity from happening on the distributed object
* until those events have been processed.
*
* @see DObjectManager#postEvent
*/
public class ReleaseLockEvent extends TypedEvent
{
/** The typed object code for this event. */
public static final short TYPE = TYPE_BASE + 6;
/**
* Constructs a new release lock event for the specified target object
* with the supplied lock name.
*
* @param targetOid the object id of the object in question.
* @param name the name of the lock to release.
*/
public ReleaseLockEvent (int targetOid, String name)
{
super(targetOid);
_name = name;
}
/**
* Constructs a blank instance of this event in preparation for
* unserialization from the network.
*/
public ReleaseLockEvent ()
{
}
/**
* Returns the name of the lock to release.
*/
public String getName ()
{
return _name;
}
/**
* Applies this attribute change to the object.
*/
public boolean applyToObject (DObject target)
throws ObjectAccessException
{
// pass the new value on to the object
target.setAttribute(_name, _value);
return true;
}
public short getType ()
{
return TYPE;
}
public void writeTo (DataOutputStream out)
throws IOException
{
super.writeTo(out);
out.writeUTF(_name);
}
public void readFrom (DataInputStream in)
throws IOException
{
super.readFrom(in);
_name = in.readUTF();
}
protected void toString (StringBuffer buf)
{
buf.append("UNLOCK:");
super.toString(buf);
buf.append(", name=").append(_name);
}
protected String _name;
protected Object _value;
}