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:
Lifecycle
,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 implementingReceiver.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 theReceiver.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 int
recv_buf_size
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, 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, local_addr, log, policies, 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()
Called on aJChannel.disconnect()
; stops work (e.g.-
Methods inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
closeBarrierAndSuspendStable, closeHoleFor, createStreamToRequester, createThreadPool, destroy, determineCoordinator, down, getAverageStateSize, getNumberOfStateBytesSent, getNumberOfStateRequests, getStateFromApplication, getThreadPoolCompletedTasks, getThreadPoolSize, handle, handle, handleEOF, handleException, handleStateChunk, handleStateRsp, init, openBarrier, openBarrierAndResumeStable, punchHoleFor, requiredDownServices, resetStats, resumeStable, sendEof, sendException, setStateInApplication, start, up, up, up, useAsyncStateDelivery
-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, statsEnabled, toString
-
-
-
-
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
-
recv_buf_size
protected int recv_buf_size
-
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
Called on aJChannel.disconnect()
; stops work (e.g. by closing multicast socket). Will be called from top to bottom.- Specified by:
stop
in interfaceLifecycle
- Overrides:
stop
in classStreamingStateTransfer
-
createAcceptor
protected STATE_SOCK.StateProviderAcceptor createAcceptor() throws java.lang.Exception
- Throws:
java.lang.Exception
-
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) throws java.lang.Exception
- Overrides:
handleStateReq
in classStreamingStateTransfer
- Throws:
java.lang.Exception
-
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
-
-