T - The type of model receiving the ModelListener's updates.E - a type of ModelListenerpublic abstract class Model<T extends Model<T,E>,E extends ModelListener<T>> extends Listenable<E,JsonObject>
| Modifier and Type | Field and Description |
|---|---|
private boolean |
isConnected
Whether or not the model has connected with the Pathfinder server.
|
private static org.slf4j.Logger |
logger
Logs actions performed by the class.
|
private Queue<JsonObject> |
messageBacklog
Messages saved to be sent later, after the model's path is fully defined.
|
private Path |
path
The path of the model.
|
private PathfinderServices |
services
A pathfinder services object to have access to the model registry
and the web socket.
|
| Constructor and Description |
|---|
Model(String path,
ModelType type,
PathfinderServices services)
Creates a basic object that all pathfinder models should use.
|
| Modifier and Type | Method and Description |
|---|---|
protected Path |
getChildPath(String name,
ModelType type)
Returns the path of a child of this model.
|
ModelType |
getModelType()
Returns the type of the model
|
String |
getName()
Returns the name of the model.
|
Cluster |
getParentCluster()
Returns the parent cluster of this model.
|
Path |
getParentPath()
Returns the path of the parent of this model.
|
protected Path |
getPath()
Returns the path of the model.
|
String |
getPathName()
Returns the string of the path of the model.
|
protected PathfinderServices |
getServices()
Returns the pathfinder services object.
|
protected abstract T |
getThis()
Returns the current object represented by this.
|
boolean |
isConnected()
Returns if the model has connected to the Pathfinder server.
|
boolean |
isPathUnknown()
Returns true if the model's path is unknown.
|
protected boolean |
notifyUpdate(String reason,
JsonObject json)
Method called when an update occurs.
|
protected abstract void |
route(JsonObject json,
PathfinderServices services)
Updates the models routes.
|
protected void |
sendMessage(JsonObject json)
Sends a json message through the web socket connection if connected.
|
protected void |
setConnected(boolean connected)
Sets if the model has connected with the Pathfinder server.
|
protected void |
setPathName(String path)
Set the path of the model.
|
abstract JsonObject |
toJson()
Converts the
Model to JSON. |
protected abstract boolean |
updateFields(JsonObject json)
Updates the fields of the model.
|
private boolean |
updateType(String reason,
JsonObject json)
Invokes the model unspecific notifications.
|
addListener, getListeners, removeListenerprivate static final org.slf4j.Logger logger
private final Path path
private final PathfinderServices services
private boolean isConnected
private Queue<JsonObject> messageBacklog
public Model(String path, ModelType type, PathfinderServices services)
path - to the model on the Pathfinder server.type - of the model.services - a pathfinder services object.protected Path getPath()
public boolean isPathUnknown()
public String getPathName()
protected void setPathName(String path)
path - of the model.IllegalStateException - if the path is already known.protected Path getChildPath(String name, ModelType type)
name - the name to added on to the path.type - of the model.public Path getParentPath()
public String getName()
public Cluster getParentCluster()
public ModelType getModelType()
protected PathfinderServices getServices()
public boolean isConnected()
protected void setConnected(boolean connected)
connected - has connected with the Pathfinder server.private boolean updateType(String reason, JsonObject json)
reason - message typejson - the messageprotected boolean notifyUpdate(String reason, JsonObject json)
notifyUpdate in class Listenable<E extends ModelListener<T>,JsonObject>reason - for notifying the model.json - object of the updated model.protected void sendMessage(JsonObject json)
json - message to be sent.public abstract JsonObject toJson()
Model to JSON.Model as JSON.protected abstract boolean updateFields(JsonObject json)
json - of the model.protected abstract void route(JsonObject json, PathfinderServices services)
json - of the model.services - pathfinder services object.protected abstract T getThis()