Package org.jgroups.protocols.pbcast
Class STATE_SOCK
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.pbcast.StreamingStateTransfer
-
- org.jgroups.protocols.pbcast.STATE_SOCK
-
- All Implemented Interfaces:
ProcessingQueue.Handler<Address>
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 implementingStateListener.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 aBufferedOutputStream
over the output stream handed to the application as argument of the callback. When implementing theStateListener.setState(java.io.InputStream)
callback, there is no need to use aBufferedOutputStream
, 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
Nested Classes Modifier and Type Class Description protected class
STATE_SOCK.StateProviderAcceptor
-
Nested classes/interfaces inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
StreamingStateTransfer.StateGetter, StreamingStateTransfer.StateHeader
-
-
Field Summary
Fields Modifier and Type Field Description 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, buffer_size, flushProtocolInStack, local_addr, max_pool, members, num_bytes_sent, num_state_reqs, pool_thread_keep_alive, state_provider, state_requesters, thread_pool
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description STATE_SOCK()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
close(java.lang.Object resource)
protected STATE_SOCK.StateProviderAcceptor
createAcceptor()
protected Tuple<java.io.InputStream,java.lang.Object>
createStreamToProvider(Address provider, StreamingStateTransfer.StateHeader hdr)
Creates an InputStream to the state provider to read 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 aJChannel.disconnect()
.-
Methods inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
closeBarrierAndSuspendStable, closeHoleFor, createStreamToRequester, createThreadPool, destroy, determineCoordinator, down, getAverageStateSize, getNumberOfStateBytesSent, getNumberOfStateRequests, getStateFromApplication, getThreadPoolCompletedTasks, getThreadPoolSize, handle, handleEOF, handleException, handleStateChunk, handleStateRsp, init, isDigestNeeded, openBarrier, openBarrierAndResumeStable, punchHoleFor, requiredDownServices, resetStats, resumeStable, sendEof, sendException, setStateInApplication, start, up, up, useAsyncStateDelivery
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredUpServices, resetStatistics, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, up
-
-
-
-
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
-
-
Method Detail
-
stop
public void stop()
Description copied from class:Protocol
This method is called on aJChannel.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 classStreamingStateTransfer
-
createAcceptor
protected STATE_SOCK.StateProviderAcceptor createAcceptor()
-
modifyStateResponseHeader
protected void modifyStateResponseHeader(StreamingStateTransfer.StateHeader hdr)
- Overrides:
modifyStateResponseHeader
in classStreamingStateTransfer
-
createStreamToProvider
protected Tuple<java.io.InputStream,java.lang.Object> createStreamToProvider(Address provider, StreamingStateTransfer.StateHeader hdr) throws java.lang.Exception
Description copied from class:StreamingStateTransfer
Creates an InputStream to the state provider to read the state. Return the input stream and a handback object as a tuple. The handback object is handed back to the subclass when done, or in case of an error (e.g. to clean up resources)- Specified by:
createStreamToProvider
in classStreamingStateTransfer
- Throws:
java.lang.Exception
-
close
protected void close(java.lang.Object resource)
- Overrides:
close
in classStreamingStateTransfer
-
handleStateReq
protected void handleStateReq(Address requester)
- Overrides:
handleStateReq
in classStreamingStateTransfer
-
handleViewChange
protected void handleViewChange(View v)
- Overrides:
handleViewChange
in classStreamingStateTransfer
-
handleConfig
protected void handleConfig(java.util.Map<java.lang.String,java.lang.Object> config)
- Overrides:
handleConfig
in classStreamingStateTransfer
-
-