galaxy.server
Class DataOutBroker

java.lang.Object
  |
  +--galaxy.server.DataOutBroker
All Implemented Interfaces:
java.lang.Runnable

public class DataOutBroker
extends java.lang.Object
implements java.lang.Runnable

This class represents the supplier of a brokering connection. It accepts multiple client connections and serves data to these clients. A timeout can be specified for DataOutBroker. Once the timeout expires, no new client connections are accepted, but the broker will continue to serve up data until it is done (i.e., when a DisconnectMessage is written to its output data structure). The brokered data is cached and the broker can serve this data to new clients as they connect.


Constructor Summary
DataOutBroker(Server server, int pollMilliseconds, int timeoutSeconds)
          Constructor.
 
Method Summary
 void close()
          Tells this broker to disconnect from its clients once it times out.
protected  void connectionEstablished()
          This method is called when this broker establishes a connection with a new inbound broker.
protected  void disconnectReceived()
          This method is called when this broker is told to disconnect from its client inbound brokers (once it times out).
 void expire()
          Forces this broker to time out, preventing any additional client connections from being established.
 java.lang.String getCallId()
          Returns the call id associated with this broker.
static int getCallIdIndex()
          Returns a call id unique to the current Java virtual machine.
 boolean isExpired()
          Indicates if this broker has timed out.
 boolean isStopped()
          Indicates if this broker is stopped.
 void populateFrame(GFrame frame, java.lang.String hostKey, java.lang.String portKey)
          Populates a frame that is announcing the availability of brokered data with the broker's contact information.
 void run()
          Outgoing broker thread runs a polling loop, waiting for data to write to clients.
 void stop()
          Marks this broker's thread as being stopped.
 void write(java.lang.Object obj)
          Adds data to this broker's incoming data buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataOutBroker

public DataOutBroker(Server server,
                     int pollMilliseconds,
                     int timeoutSeconds)
Constructor.
Parameters:
server - the Server that created this broker
pollMilliseconds - the polling cycle in milliseconds. If less than or equal to zero, default poll is used.
timeoutSeconds - timeout in seconds for this broker. If zero, default timeout is used. If less than zero, broker never times out.
Method Detail

getCallIdIndex

public static int getCallIdIndex()
Returns a call id unique to the current Java virtual machine. This method is only used internally and should not be called by other code.
Returns:
the call id

getCallId

public java.lang.String getCallId()
Returns the call id associated with this broker.
Returns:
the call id

isExpired

public boolean isExpired()
Indicates if this broker has timed out.
Returns:
true this broker has timed out, false otherwise

expire

public void expire()
Forces this broker to time out, preventing any additional client connections from being established.

isStopped

public boolean isStopped()
Indicates if this broker is stopped.
Returns:
true if stopped, false otherwise

run

public void run()
Outgoing broker thread runs a polling loop, waiting for data to write to clients. It also writes cached data to new clients as they connect.
Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Marks this broker's thread as being stopped.

populateFrame

public void populateFrame(GFrame frame,
                          java.lang.String hostKey,
                          java.lang.String portKey)
Populates a frame that is announcing the availability of brokered data with the broker's contact information. This includes the name of the machine hosting the broker, the broker's listener port, and the broker's call id.
Parameters:
frame - the frame to populate
hostKey - the name of the broker's host name frame key
portKey - the name of the broker's listener port frame key

write

public void write(java.lang.Object obj)
Adds data to this broker's incoming data buffer. This data will be written out to the broker's clients during the next polling cycle.
Parameters:
obj - the data object to add to the buffer

close

public void close()
Tells this broker to disconnect from its clients once it times out.

connectionEstablished

protected void connectionEstablished()
This method is called when this broker establishes a connection with a new inbound broker.

disconnectReceived

protected void disconnectReceived()
This method is called when this broker is told to disconnect from its client inbound brokers (once it times out).