|
Ila | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.topoweb.ila.StateBuffer
Creates and transmutes immutable State
instances. This class
makes the model for State
transitions more concrete. Each
node in an Ila system undergoes a series of state transitions -- from the time it is first added to the system, to
the time when it is finally removed from the system. A StateBuffer
instance is used to transition from one state to another. To do
so, you first load a node's state, then apply one of the mutator methods (e.g. initLink
), followed by the toState
method. The diagram
below illustrates the allowed status changes.
NK
(not known) status,
and an arrow from NK
to NV
or
OK
represents the addition (creation) of a node
with NV
or OK
state status, respectively;
conversely, an arrow to NK
represents the removal
(deletion) of a node from Ila. The allowed transitions are listed below:
NK --> NV:
Addition of a "not visited"
(NV
) node to the system. The node is referenced by
another node, but the node has not yet been visited or parsed. Immediately
after addition, the backlink count of the "not visited" node is
one. (See initLinked()
and initCoLink()
.)
NV --> NK:
Removal of a "not visited"
(NV
) node from the system. When an NV
node is no longer referenced by any other node (zero backlinks), the node is
subject to removal and its state is adjusted to NK
. (See
removeBacklink()
and removeCoBacklink()
.)
NK --> OK:
Addition of a successfully visited
(e.g. parsed) node to the system. No other nodes in the system reference the
added node. (See setOkay()
.)
OK --> NK:
Removal of an OK
node from the system. The node is no longer available.
Had the node been referenced by some other node in Ila, it would have
transitioned to NF
status, but because no other
node references it, it is subject to removal and is therefore transitioned to
NK
. (See setNotFound()
.)
NF --> NK:
Removal of a node an
NF
node from the system. The node is no longer
referenced by any other node in the system. (See removeBacklink()
and removeCoBacklink()
.)
NV --> OK:
Successful visit of a previously
unvistited node. (See setOkay()
.)
NV --> NF:
Unsuccessful visit of a previously
unvistited node. (See setNotFound()
.)
OK --> NF:
Unsuccessful visit of a previously
successfully visited node. (See setNotFound()
.)
NF --> OK:
Successful visit of a previous
"not found" node. (See setOkay()
.)
At any point in time, a StateBuffer
's toState
method can be invoked successfully (no exceptions will be raised).
This means the internal state of this class is always consistent with that
of a State
instance.
Although not a State
subclass, this class exposes the same
accessor methods. The semantics of these accessors are intended to be the
same. The mutator methods of this class return the instance itself so that
as per the informal contract for buffer types, mutator methods can be
chained.
java.lang.IllegalArgumentException
instance), the state of the buffer remains unchanged.
State
,
State.State(int,int,long,int,long,int,int,long,long)
,
Node.getState()
Field Summary |
Fields inherited from interface org.topoweb.ila.StateConstants |
NF, NK, NV, OK |
Fields inherited from interface org.topoweb.ila.NodeConstants |
BACK, FIRST_PAGE, FORE, LAST_PAGE, LINK_MASK, PAGE_MASK |
Constructor Summary | |
StateBuffer()
|
Method Summary | |
StateBuffer |
addBacklink()
Adds one to the backlink count and bumps the version. |
StateBuffer |
addCoBacklink()
Adds one to the co-backlink count and bumps the version. |
StateBuffer |
bumpSyncVersion()
Bumps the current version and sets the sync version to the current version. |
StateBuffer |
bumpVersion()
Bumps the current version. |
StateBuffer |
clear()
Clears the buffer. |
long |
getCoLinkCount(int type)
Returns the co-link count for the specified link type . |
long |
getLinkCount(int type)
Returns the link count for the specified link type . |
int |
getStatus()
Returns the status code. |
int |
getSyncVersionId()
Returns the sync version ID for this instance. |
long |
getSyncVersionTimestamp()
Returns the version timestamp for this instance. |
int |
getVersionId()
Returns the version ID. |
long |
getVersionTimestamp()
Returns the version timestamp. |
StateBuffer |
initCoLinked()
Initializes the instance to NV status with
exactly one backlink and one co-backlink. |
StateBuffer |
initLinked()
Initializes the instance to NV status with
exactly one backlink and zero co-backlinks. |
StateBuffer |
load(State state)
Loads the given state object. |
StateBuffer |
removeBacklink()
Removes one from the backlink count and bumps the version. |
StateBuffer |
removeCoBacklink()
Removes one from the backlink count and bumps the version. |
StateBuffer |
setNotFound()
Sets the result of an unsuccessful visit. |
StateBuffer |
setOkay(int linkCount,
int coLinkCount)
Sets the result of a successful visit of a node with the specified [fore-] link and co-link counts. |
State |
toState()
Returns the state of this buffer as an immutable State
instance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StateBuffer()
Method Detail |
public StateBuffer load(State state)
state
object. After invocation, the fields
of this buffer instance assume the corresponding values of the passed in
state
. This is typically the first step of a state
transition.
state
- the object used to set the fields of this buffer
this
instancepublic State toState()
State
instance. The state of the buffer, itself, remains unchanged.
State
instance.load(State)
public int getStatus()
OK
, or NF
, or NV
, or NK
.
StateConstants
public StateBuffer setOkay(int linkCount, int coLinkCount)
OK
if either the forelink or backlink count is
non-zero; otherwise (a rare event), the node represented by this instance
is subject to removal from Ila and its status is adjusted to NK
. The version is bumped. If the previous status
was not OK
, then the sync version is set to new current
version.
linkCount
- the total forelink countcoLinkCount
- the co-forelink count
this
instance
java.lang.IllegalArgumentException
- if either argument is < 0; if linkCount
< coLinkCount
public StateBuffer initLinked()
NV
status with
exactly one backlink and zero co-backlinks. Invocation clear
s any previous data in the buffer. The version is bumped and the
sync version is adjusted to the new bumped version.
this
instanceaddBacklink()
,
removeBacklink()
,
initCoLinked()
public StateBuffer addBacklink()
NK
(in
which case the sync version is set to the new current version).
this
instanceinitLinked()
,
removeBacklink()
,
addCoBacklink()
public StateBuffer removeBacklink()
this
instanceinitLinked()
,
addBacklink()
,
removeCoBacklink()
public StateBuffer initCoLinked()
NV
status with
exactly one backlink and one co-backlink. Invocation clear
s any previous data in the buffer.
this
instanceaddCoBacklink()
,
removeCoBacklink()
,
initLinked()
public StateBuffer addCoBacklink()
NK
(in
which case the sync version is set to the new current version).
this
instanceinitCoLinked()
,
removeCoBacklink()
,
addBacklink()
public StateBuffer removeCoBacklink()
this
instanceinitCoLinked()
,
addCoBacklink()
,
removeBacklink()
public StateBuffer setNotFound()
NK
; otherwise (the more common case), the status will
be NF
. If invocation causes a change in
status, then the sync version is set to the current new version.
this
instancepublic StateBuffer clear()
NK
,
and all the link counts and version data are set to zero.
this
instancepublic StateBuffer bumpVersion()
this
instancepublic StateBuffer bumpSyncVersion()
this
instancebumpVersion()
public int getVersionId()
public long getVersionTimestamp()
public int getSyncVersionId()
node
when its information was last
synchronized with the node
s it is linked to.
public long getSyncVersionTimestamp()
public long getLinkCount(int type)
type
.
type
- the link type
(type & LINK_MASK)
== FORE
; the backlink count, o.w.public long getCoLinkCount(int type)
type
.
type
- the link type
(type &
LINK_MASK) == FORE
; the co-backlink count,
o.w.
|
Ila | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |