public abstract class BasicObject extends Object implements DefaultDispatchTarget, DispatchTarget, Encodable, MessageRetargeter, Referenceable
All such objects share many characteristics in common, hence this base
class. They are all Encodable
since representations of them can be
sent to the client, DispatchTarget
s since the client can address
messages to them, MessageRetargeter
s since they can have Mod
s attached and so need to be able to retarget arriving messages to those
mods, and Referenceable
since they can be referred to in messages.
Modifier and Type | Field and Description |
---|---|
static int |
VIS_CONTAINER
Visible according to the visibility of its container.
|
static int |
VIS_NONE
Not visible to anyone.
|
static int |
VIS_PERSONAL
Visible to user holding object but nobody else.
|
static int |
VIS_PUBLIC
Visible to everyone in the enclosing context.
|
Modifier and Type | Method and Description |
---|---|
String |
baseRef()
Obtain an object clone's base reference.
|
void |
checkpoint()
Checkpoint this object, its contents, and any registered codependent
objects (that is, objects whose state must be kept consistent with this
object and vice versa).
|
void |
checkpoint(ArgRunnable handler)
Checkpoint this object, with completion handler.
|
BasicObject |
container()
Get this objects's container.
|
Iterable<Item> |
contents()
Obtain an iterable for this object's contents.
|
abstract Context |
context()
Obtain the context in which this object is located, regardless of how
deeply nested in containers it might be.
|
Contextor |
contextor()
Obtain the contextor that created this object.
|
Item |
createItem(String name,
boolean isPossibleContainer,
boolean isDeletable)
Create a
Item directly (i.e., create it at runtime rather than
loading it from the database). |
DispatchTarget |
findActualTarget(Class type)
Find the object to handle a message for some class (either the object
itself or one of its mods).
|
Mod |
getMod(Class type)
Obtain one of this object's
Mod s. |
void |
handleMessage(Deliverer from,
JSONObject msg)
Handle an otherwise unhandled message.
|
BasicObject |
holder()
Obtain the user or context holding this object, regardless of how deeply
nested in containers it might be.
|
boolean |
isClone()
Test if this object is a clone.
|
boolean |
isContainer()
Test if this object is allowed to be used as a container.
|
boolean |
isEphemeral()
Test if this object is ephemeral.
|
void |
markAsChanged()
Mark this object as needing to be written to persistent storage.
|
void |
markAsDeleted()
Mark this object as having been deleted.
|
void |
markAsEphemeral()
Mark this object as being ephemeral.
|
String |
name()
Obtain this object's name, if it has one.
|
void |
noteCodependent(BasicObject obj)
Note another object that needs to be checkpointed when this object is
checkpointed (in order to maintain data consistency).
|
void |
objectIsComplete()
Inform this object that its construction is now complete.
|
Position |
position()
Obtain this object's position with respect to its container.
|
String |
ref()
Obtain this object's reference string.
|
abstract void |
sendObjectDescription(Deliverer to,
Referenceable maker)
Transmit a description of this object as a series of 'make' messages,
such that the receiver will be able to construct a local presence of it.
|
void |
sendToClones(JSONLiteral message)
Send a JSON message to all other clones of this object.
|
void |
setName(String name)
Set this object's name.
|
void |
setPosition(Position pos)
Set this object's position.
|
void |
setVisibility(int visibility)
Set this object's visibility without taking any other action.
|
abstract User |
user()
Obtain the user within which this object is contained, regardless of how
deeply nested in containers it might be.
|
boolean |
visibleTo(Deliverer receiver)
Test if this object is visible to a given receiver.
|
public static final int VIS_PUBLIC
public static final int VIS_PERSONAL
public static final int VIS_NONE
public static final int VIS_CONTAINER
public String baseRef()
public void checkpoint()
public void checkpoint(ArgRunnable handler)
handler
- Optional completion handler.public BasicObject container()
public Iterable<Item> contents()
hasNext()
method will return false right
away) but null will never be returned.public abstract Context context()
public Contextor contextor()
public Item createItem(String name, boolean isPossibleContainer, boolean isDeletable)
Item
directly (i.e., create it at runtime rather than
loading it from the database). The new item will be contained by this
object and have neither any contents nor any mods.name
- The name for the new item, or null if the name doesn't
matter.isPossibleContainer
- true if the new item may itself be used as a
container, false if not.isDeletable
- true if users may delete the new item at will, false
if not.Item
object as described by the parameters.public Mod getMod(Class type)
Mod
s.type
- The type of the mod desired.public BasicObject holder()
public boolean isClone()
public boolean isContainer()
public boolean isEphemeral()
markAsEphemeral()
method.public void markAsChanged()
public void markAsDeleted()
markAsChanged()
, there is no corresponding method to unmark deletion;
this is a one-way trip.public void markAsEphemeral()
public String name()
public void noteCodependent(BasicObject obj)
obj
- The other, codependent object.public void objectIsComplete()
Mod
s that have expressed an interest in this
event so that they can do any post-creation cleanup or initialization.
Application code should not normally need to call this method, since
it is called automatically when an object is loaded from persistent
storage. However, certain specialized applications that synthesize
objects directly will need to call this after they finish attaching any
synthesized Mod
s.
public Position position()
public abstract void sendObjectDescription(Deliverer to, Referenceable maker)
to
- Where to send the description.maker
- Maker object to address the message(s) to.public void sendToClones(JSONLiteral message)
message
- The message to send.public void setName(String name)
name
- The new name for the object to have.public void setPosition(Position pos)
pos
- New position for the object.public void setVisibility(int visibility)
VIS_PUBLIC
indicates that the object is visible to anyone in
the context, i.e., its description will always be transmitted.
VIS_PERSONAL
indicates that the object's description will only
be sent to the user who is holding it and not to anyone else.
VIS_NONE
indicates that the object's description will never be
sent to anyone.
VIS_CONTAINER
indicates that the object inherits its visiblity
from its container, i.e., its description will be transmitted to anyone
to whom its container's description is transmitted.
If the visibility is not set by calling this method, a default
visibility rule will be applied, which is equivalent in every way to
VIS_PUBLIC
except that it may be modified by calling this
method. Note also that users and contexts are always implicitly set to
VIS_PUBLIC
regardless.visibility
- The visibility setting. This should be one of the
constants VIS_PUBLIC
, VIS_PERSONAL
, VIS_NONE
, or VIS_CONTAINER
.public abstract User user()
public boolean visibleTo(Deliverer receiver)
User
, then this will test the visibility of the object to that
particular user. If the receiver is a Context
, then it will
test the visibility of the object to any user in that context.receiver
- User or context whose sightlines are at issue.public void handleMessage(Deliverer from, JSONObject msg) throws MessageHandlerException
handleMessage
in interface DefaultDispatchTarget
from
- Who sent the message.msg
- The message itself.MessageHandlerException
- if there was a problem handling the
message.public DispatchTarget findActualTarget(Class type)
findActualTarget
in interface MessageRetargeter
type
- The class associated with the message verb.public String ref()
ref
in interface Referenceable
Copyright © 2017. All rights reserved.