edu.nyu.cs.pdsg.switchboard
Class SbLayer

java.lang.Object
  extended byedu.nyu.cs.pdsg.switchboard.SbStatus
      extended byedu.nyu.cs.pdsg.switchboard.SbLayer
All Implemented Interfaces:
SbAsyncTransportClient, SbAsyncTransportProvider, SbAsyncTransportRecipient, SbClient, SbLayerable, SbProvider
Direct Known Subclasses:
SbAuthorizationLayer, SbCipherLayer, SbClientStreamsLayer, SbIoLayer, SbLivenessLayer, SbMux, SbRpcLayer

public class SbLayer
extends SbStatus
implements SbAsyncTransportClient, SbAsyncTransportProvider


Field Summary
protected  SbClient client
          The layer which will write to this layer and which we will deliver to.
protected  java.lang.String createStackTrace
           
protected  SbEventHandler eventHandler
           
private  boolean openFlag
          Identifiers
protected  SbProvider provider
          The layer which will deliver to this layer and which we will write to.
private  java.lang.Exception providerException
           
private  java.lang.String providerStackTrace
           
private  int providerStatus
          The current status of the layer.
private  boolean ready
          Called when a layer provider is ready and setup properly.
protected  SbAsyncTransportRecipient recipient
          The layer which this layer will deliver to.
 
Fields inherited from class edu.nyu.cs.pdsg.switchboard.SbStatus
STATUS_CLOSED, STATUS_LIVE, STATUS_PARTNER_CLOSED, STATUS_RECOVERABLE, STATUS_UNRECOVERABLE
 
Constructor Summary
SbLayer()
          Constructs a layer with no layer underneath (to the bottom) of it and which sets the name of the stack in this base class.
SbLayer(SbProvider _provider)
          Constructs a layer with a specified layer to the bottom (underneath) it.
 
Method Summary
 void _close()
          Closes this layer and all layers underneath it.
protected static boolean behavesLike(java.lang.Object obj, java.lang.Class _type)
          Checks whether or not an Object has the behavior of a particular Class.
 void close()
           
 void closeQuiet()
           
 void deliver(java.lang.Object obj)
          Defines the behavior how to deliver an Object to the layer above.
 void finalize()
           
 SbLayer find(java.lang.Class layerType)
          Find first lower layer with the requested type; null otherwise.
 java.lang.String getLayerType()
           
 java.lang.Exception getProviderException()
           
 java.lang.String getProviderStackTrace()
           
 int getProviderStatus()
          Returns this layer's status.
 java.lang.String getTransportName()
           
 void handleEvent()
          Starts the chain of event handling
 void handleEvent(SbProvider layer)
          Defines how to handle the event when it receives one.
 void init()
          Run all initialization code.
protected static boolean instanceOf(java.lang.Object obj, java.lang.Class type)
          Checks whether or not an Object is an instance of a type Class.
protected static boolean isKindOf(java.lang.Object obj, java.lang.Class _type)
          Checks whether or not an Object is a kind of Class.
 boolean isOpen()
           
 boolean isReady()
           
 void providerReady()
          called when provider is ready
 java.lang.String providerStatusString()
           
 void recipientReady()
           
protected  void sendDown(java.lang.Object msg)
          Utility method which sends an Object to the layer provider (writes to that layer).
(package private)  void sendEventUp(SbProvider layer)
          Send events up using setProviderStatus() or setProviderStatusSend() Will direct event to this layer if none client!
protected  void sendUp(java.lang.Object msg)
          Utility method which sends an Object to the layer client (delivers to that layer).
protected  byte[] serialize(java.lang.Object msg)
          Serializes an Object into a byte array.
 void setClient(SbClient _client)
          Defines the behavior how to deliver an Object to the layer above.
 void setEventHandler(SbEventHandler _eventHandler)
          Sets the event handler for this layer to whom this layer will forward Switchboard events, expecting it to act appropriately
 void setProvider(SbProvider _provider)
          Set the layer which will write to this one and which we will deliver to.
protected  void setProviderStatus(int _providerStatus)
          Sets the status of the layer.
 void setProviderStatus(int _providerStatus, java.lang.Exception _providerException)
          Sets the status of the layer.
protected  void setProviderStatusSend(int _providerStatus)
          Sets the status of the layer.
 void setRecipient(SbAsyncTransportRecipient _recipient)
          Sets the recipient for this layer that this layer will deliver to.
 java.lang.String toShortString()
           
 java.lang.String toString()
           
protected  java.lang.Object unserialize(byte[] msg)
          Unserializes an Object from a byte array.
 void write(java.lang.Object obj)
          Defines the behavior how to deliver an Object to the layer above.
 
Methods inherited from class edu.nyu.cs.pdsg.switchboard.SbStatus
statusString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

openFlag

private boolean openFlag
Identifiers


createStackTrace

protected java.lang.String createStackTrace

client

protected SbClient client
The layer which will write to this layer and which we will deliver to.


provider

protected SbProvider provider
The layer which will deliver to this layer and which we will write to.


recipient

protected SbAsyncTransportRecipient recipient
The layer which this layer will deliver to. Allows for easy delivery up and down the chain.


providerStatus

private int providerStatus
The current status of the layer.


providerStackTrace

private java.lang.String providerStackTrace

providerException

private java.lang.Exception providerException

eventHandler

protected SbEventHandler eventHandler

ready

private boolean ready
Called when a layer provider is ready and setup properly.

Constructor Detail

SbLayer

public SbLayer()
Constructs a layer with no layer underneath (to the bottom) of it and which sets the name of the stack in this base class.


SbLayer

public SbLayer(SbProvider _provider)
Constructs a layer with a specified layer to the bottom (underneath) it.

Parameters:
_provider - the layer underneath the one being constructed
Method Detail

init

public void init()
Run all initialization code. No messages should be sent prior to init() being called. Don't call lower layer until ready to receive messages.

Specified by:
init in interface SbProvider

setProvider

public void setProvider(SbProvider _provider)
Set the layer which will write to this one and which we will deliver to.


setClient

public void setClient(SbClient _client)
Description copied from interface: SbProvider
Defines the behavior how to deliver an Object to the layer above.

Specified by:
setClient in interface SbProvider
Returns:
the resulting Object after delivery is delivered

closeQuiet

public void closeQuiet()

_close

public void _close()
Closes this layer and all layers underneath it.


close

public void close()
Specified by:
close in interface SbProvider

providerReady

public void providerReady()
Description copied from interface: SbClient
called when provider is ready

Specified by:
providerReady in interface SbClient

isReady

public boolean isReady()

providerStatusString

public java.lang.String providerStatusString()
Specified by:
providerStatusString in interface SbProvider

setProviderStatus

protected void setProviderStatus(int _providerStatus)
Sets the status of the layer. If the status specified is not what the previous status was, then, the layer will notify the layer client to handle the event.

Parameters:
_providerStatus - the new layer status

setProviderStatus

public void setProviderStatus(int _providerStatus,
                              java.lang.Exception _providerException)
Sets the status of the layer. If the status specified is not what the previous status was, then the layer will notify the layer client to handle the event.

Parameters:
_providerStatus - the new layer status
_providerException - the exception that caused the event

setProviderStatusSend

protected void setProviderStatusSend(int _providerStatus)
Sets the status of the layer. Then, the layer will notify the layer client to handle the event, regardless of the previous layer status.

Parameters:
_providerStatus - the new layer status

getProviderStatus

public int getProviderStatus()
Returns this layer's status.

Specified by:
getProviderStatus in interface SbProvider
Returns:
the layer status

getProviderStackTrace

public java.lang.String getProviderStackTrace()

getProviderException

public java.lang.Exception getProviderException()

handleEvent

public void handleEvent(SbProvider layer)
Defines how to handle the event when it receives one. If the event is never handled (the layer client is null and sending layer is not live) then the switchboard will be closed.

Specified by:
handleEvent in interface SbClient
Parameters:
layer - the layer which threw the event
Returns:
the resulting Object after delivery is delivered

handleEvent

public void handleEvent()
Starts the chain of event handling


sendEventUp

final void sendEventUp(SbProvider layer)
Send events up using setProviderStatus() or setProviderStatusSend() Will direct event to this layer if none client!


setRecipient

public final void setRecipient(SbAsyncTransportRecipient _recipient)
Sets the recipient for this layer that this layer will deliver to.

Specified by:
setRecipient in interface SbAsyncTransportProvider
Parameters:
_recipient - the recipient of this layer

setEventHandler

public void setEventHandler(SbEventHandler _eventHandler)
Sets the event handler for this layer to whom this layer will forward Switchboard events, expecting it to act appropriately

Parameters:
_eventHandler - the event handler of this layer

sendDown

protected void sendDown(java.lang.Object msg)
Utility method which sends an Object to the layer provider (writes to that layer).

Parameters:
msg - the Object to write provider

sendUp

protected void sendUp(java.lang.Object msg)
Utility method which sends an Object to the layer client (delivers to that layer).

Parameters:
msg - the Object to deliver to the layer client
Returns:
the Object which will receive in response to a delivered Object

serialize

protected byte[] serialize(java.lang.Object msg)
                    throws java.io.IOException
Serializes an Object into a byte array.

Parameters:
msg - the Object to serialize
Returns:
the byte array which contains the serialized Object
Throws:
java.io.IOException - the Object could not be serialized into a byte array

unserialize

protected java.lang.Object unserialize(byte[] msg)
                                throws java.io.IOException
Unserializes an Object from a byte array.

Parameters:
msg - the byte array to deserialize
Returns:
the Object which contains the deserialized byte array
Throws:
java.io.IOException - the byte array could not be deserialized into an Object

find

public SbLayer find(java.lang.Class layerType)
Find first lower layer with the requested type; null otherwise.

Parameters:
layerType - the layer to find
Returns:
SbLayer the layer which corresponds to the layerType, or null if not found

behavesLike

protected static boolean behavesLike(java.lang.Object obj,
                                     java.lang.Class _type)
Checks whether or not an Object has the behavior of a particular Class.

Parameters:
obj - the Object to check
_type - the Class type to check against
Returns:
whether or not the obj behaves like _type

isKindOf

protected static boolean isKindOf(java.lang.Object obj,
                                  java.lang.Class _type)
Checks whether or not an Object is a kind of Class.

Parameters:
obj - the Object to check
_type - the Class type to check against
Returns:
whether or not the obj is a kind of _type

instanceOf

protected static boolean instanceOf(java.lang.Object obj,
                                    java.lang.Class type)
Checks whether or not an Object is an instance of a type Class.

Parameters:
obj - the Object to check
Returns:
whether or not the obj is an instance of _type

isOpen

public boolean isOpen()
Specified by:
isOpen in interface SbProvider

toString

public java.lang.String toString()

toShortString

public java.lang.String toShortString()

getTransportName

public java.lang.String getTransportName()

getLayerType

public java.lang.String getLayerType()

finalize

public void finalize()

deliver

public void deliver(java.lang.Object obj)
Description copied from interface: SbAsyncTransportRecipient
Defines the behavior how to deliver an Object to the layer above.

Specified by:
deliver in interface SbAsyncTransportRecipient
Parameters:
obj - the Object to deliver
Returns:
the resulting Object after delivery is delivered

write

public void write(java.lang.Object obj)
Description copied from interface: SbAsyncTransportProvider
Defines the behavior how to deliver an Object to the layer above.

Specified by:
write in interface SbAsyncTransportProvider
Returns:
the resulting Object after delivery is delivered

recipientReady

public final void recipientReady()


Copyright (c) 2002-2003 New York University RLAB