Ila

org.topoweb.ila
Class IncommunicadoStateBuffer

java.lang.Object
  |
  +--org.topoweb.ila.StateBuffer
        |
        +--org.topoweb.ila.IncommunicadoStateBuffer
All Implemented Interfaces:
NodeConstants, StateConstants

public class IncommunicadoStateBuffer
extends StateBuffer

Creates and transmutes immutable State and IncommunicadoState instances. Depending on the State this instance represents, the toState method of this class returns either a State instance or an IncommunicadoState instance.

Implementation Notes

This class is not safe under concurrent access. Exceptions thrown by methods of this class are thrown in a fail-fast manner: if an exception is thrown (typically a java.lang.IllegalArgumentException instance), the state of the buffer remains unchanged.

Author:
Babak Farhang
See Also:
IncommunicadoState, StateBuffer

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
IncommunicadoStateBuffer()
           
 
Method Summary
 StateBuffer clear()
          Clears the buffer.
 int getErrorCode()
          Returns the error code, or zero if not set.
 java.lang.String getUserAgent()
          Returns the user-agent, or null if not set.
 StateBuffer load(IncommunicadoState state)
          Loads the given HttpState) instance.
 StateBuffer load(State state)
          Loads the given state object.
 StateBuffer setNotFound()
          Should not be invoked directly.
 IncommunicadoStateBuffer setNotFound(int errorCode, java.lang.String userAgent)
          Sets the state of this instance to indicate the resource cannot be found because the network service that is to serve it cannot be reached.
 StateBuffer setOkay(int linkCount, int coLinkCount)
          Should not be invoked.
 IncommunicadoState toIncommunicadoState()
          Returns this an IncommunicadoState representation of this instance.
 State toState()
          Returns the state of this buffer as an immutable State or IncommunicadoState instance.
 
Methods inherited from class org.topoweb.ila.StateBuffer
addBacklink, addCoBacklink, bumpSyncVersion, bumpVersion, getCoLinkCount, getLinkCount, getStatus, getSyncVersionId, getSyncVersionTimestamp, getVersionId, getVersionTimestamp, initCoLinked, initLinked, removeBacklink, removeCoBacklink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IncommunicadoStateBuffer

public IncommunicadoStateBuffer()
Method Detail

load

public StateBuffer load(State state)
Loads the given state object. After invocation, the fields of this buffer instance assume the corresponding values of the passed in state. If the state object passed in is an instance of IncommunicadoState, then the fields corresponding to that of an IncommunicadoState instance are also set; otherwise, they are cleared.

Overrides:
load in class StateBuffer
Parameters:
state - the object used to set the fields of this buffer
Returns:
this instance
See Also:
getUserAgent()

load

public StateBuffer load(IncommunicadoState state)
Loads the given HttpState) instance.

Returns:
this instance
See Also:
load(State)

toState

public State toState()
Returns the state of this buffer as an immutable State or IncommunicadoState instance. Specifically, if the instance has a user-agent field (getUserAgent() != null), then this method returns a IncommunicadoState instance; otherwise a State instance is returned.

Overrides:
toState in class StateBuffer
Returns:
an immutable State instance
See Also:
toIncommunicadoState()

toIncommunicadoState

public IncommunicadoState toIncommunicadoState()
                                        throws java.lang.IllegalStateException
Returns this an IncommunicadoState representation of this instance. This method is here so that a user can avoid a class cast when it is known that the toState method will return an IncommunicadoState instance.

Returns:
an IncommunicadoState representation of this instance
Throws:
java.lang.IllegalStateException - if this instance does not represent a IncommunicadoState instance
See Also:
toState()

setNotFound

public IncommunicadoStateBuffer setNotFound(int errorCode,
                                            java.lang.String userAgent)
                                     throws java.lang.IllegalArgumentException
Sets the state of this instance to indicate the resource cannot be found because the network service that is to serve it cannot be reached. The instance is either in the NF or NK state when this method returns. (Recall that if the total of fore- and back links is zero, then the node is elligible for removal and is in the NK state.)

Parameters:
errorCode - the error code
userAgent - the user-agent (not null)
Returns:
this instance
Throws:
java.lang.IllegalArgumentException - if any of the arguments voilate the constraints specified above

setOkay

public StateBuffer setOkay(int linkCount,
                           int coLinkCount)
                    throws java.lang.UnsupportedOperationException
Should not be invoked.

Overrides:
setOkay in class StateBuffer
Parameters:
linkCount - the total forelink count
coLinkCount - the co-forelink count
Returns:
this instance
Throws:
java.lang.UnsupportedOperationException - if invoked

setNotFound

public StateBuffer setNotFound()
                        throws java.lang.UnsupportedOperationException
Should not be invoked directly.

Overrides:
setNotFound in class StateBuffer
Returns:
this instance
Throws:
java.lang.UnsupportedOperationException - if invoked
See Also:
setNotFound(int,String)

clear

public StateBuffer clear()
Description copied from class: StateBuffer
Clears the buffer. The status is set to NK, and all the link counts and version data are set to zero.

Overrides:
clear in class StateBuffer
Returns:
this instance

getErrorCode

public int getErrorCode()
Returns the error code, or zero if not set.


getUserAgent

public java.lang.String getUserAgent()
Returns the user-agent, or null if not set. If the value returned is not null, then the instance is either in the NF or NK.


Ila

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.