org.jgroups.protocols.pbcast
Class STATE_SOCK

java.lang.Object
  extended by org.jgroups.stack.Protocol
      extended by org.jgroups.protocols.pbcast.StreamingStateTransfer
          extended by org.jgroups.protocols.pbcast.STATE_SOCK

public class STATE_SOCK
extends StreamingStateTransfer

STATE_SOCK has the state provider create a server socket to which the state requester connects and from which the latter reads the state.

When implementing MessageListener.getState(java.io.OutputStream), the state should be written in sizeable chunks, because the underlying output stream sends 1 message / write over the socket. So if there are 1000 writes of 1 byte each, this would generate 1000 messages ! We suggest using a BufferedOutputStream over the output stream handed to the application as argument of the callback.

When implementing the MessageListener.setState(java.io.InputStream) callback, there is no need to use a BufferedOutputStream, as the input stream handed to the application already buffers incoming data internally.

Since:
3.0
Author:
Vladimir Blagojevic, Bela Ban
See Also:
STATE_TRANSFER

Nested Class Summary
protected  class STATE_SOCK.StateProviderAcceptor
           
 
Nested classes/interfaces inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
StreamingStateTransfer.StateGetter, StreamingStateTransfer.StateHeader
 
Field Summary
protected  java.net.InetAddress bind_addr
           
protected  java.lang.String bind_interface_str
           
protected  int bind_port
           
protected  java.net.InetAddress external_addr
           
protected  int external_port
           
protected  STATE_SOCK.StateProviderAcceptor spawner
          Runnable that listens for state requests and spawns threads to serve those requests if socket transport is used
 
Fields inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
avg_state_size, barrier_closed, buffer_size, flushProtocolInStack, local_addr, max_pool, members, num_bytes_sent, num_state_reqs, pending_state_transfers, pool_thread_keep_alive, state_lock, state_provider, thread_pool
 
Fields inherited from class org.jgroups.stack.Protocol
down_prot, ergonomics, id, log, name, stack, stats, up_prot
 
Constructor Summary
STATE_SOCK()
           
 
Method Summary
protected  STATE_SOCK.StateProviderAcceptor createAcceptor()
           
protected  void createStreamToProvider(Address provider, StreamingStateTransfer.StateHeader hdr)
          Creates an InputStream to the state provider to read the state
protected  void createStreamToRequester(Address requester)
          Creates an OutputStream to the state requester to write the state
protected  void handleConfig(java.util.Map<java.lang.String,java.lang.Object> config)
           
protected  void handleStateReq(Address requester)
           
protected  void handleViewChange(View v)
           
protected  void modifyStateResponseHeader(StreamingStateTransfer.StateHeader hdr)
           
 void stop()
          This method is called on a Channel.disconnect().
 
Methods inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
closeBarrierAndSuspendStable, createThreadPool, destroy, determineCoordinator, down, getAverageStateSize, getNumberOfStateBytesSent, getNumberOfStateRequests, getStateFromApplication, getThreadPoolCompletedTasks, getThreadPoolSize, handleEOF, handleException, handleStateChunk, init, isDigestNeeded, openBarrierAndResumeStable, removeRequester, requiredDownServices, resetStats, sendEof, sendException, setStateInApplication, start, up
 
Methods inherited from class org.jgroups.stack.Protocol
dumpStats, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, printStats, providedDownServices, providedUpServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, setValues, statsEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bind_addr

protected java.net.InetAddress bind_addr

external_addr

protected java.net.InetAddress external_addr

external_port

protected int external_port

bind_interface_str

protected java.lang.String bind_interface_str

bind_port

protected int bind_port

spawner

protected volatile STATE_SOCK.StateProviderAcceptor spawner
Runnable that listens for state requests and spawns threads to serve those requests if socket transport is used

Constructor Detail

STATE_SOCK

public STATE_SOCK()
Method Detail

stop

public void stop()
Description copied from class: Protocol
This method is called on a Channel.disconnect(). Stops work (e.g. by closing multicast socket). Will be called from top to bottom. This means that at the time of the method invocation the neighbor protocol below is still working. This method will replace the STOP, STOP_OK, CLEANUP and CLEANUP_OK events. The ProtocolStack guarantees that when this method is called all messages in the down queue will have been flushed

Overrides:
stop in class StreamingStateTransfer

createAcceptor

protected STATE_SOCK.StateProviderAcceptor createAcceptor()

modifyStateResponseHeader

protected void modifyStateResponseHeader(StreamingStateTransfer.StateHeader hdr)
Overrides:
modifyStateResponseHeader in class StreamingStateTransfer

createStreamToRequester

protected void createStreamToRequester(Address requester)
Description copied from class: StreamingStateTransfer
Creates an OutputStream to the state requester to write the state

Specified by:
createStreamToRequester in class StreamingStateTransfer

createStreamToProvider

protected void createStreamToProvider(Address provider,
                                      StreamingStateTransfer.StateHeader hdr)
Description copied from class: StreamingStateTransfer
Creates an InputStream to the state provider to read the state

Specified by:
createStreamToProvider in class StreamingStateTransfer

handleStateReq

protected void handleStateReq(Address requester)
Overrides:
handleStateReq in class StreamingStateTransfer

handleViewChange

protected void handleViewChange(View v)
Overrides:
handleViewChange in class StreamingStateTransfer

handleConfig

protected void handleConfig(java.util.Map<java.lang.String,java.lang.Object> config)
Overrides:
handleConfig in class StreamingStateTransfer


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.