Package org.jgroups.protocols.pbcast
Class STATE
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.pbcast.StreamingStateTransfer
-
- org.jgroups.protocols.pbcast.STATE
-
- All Implemented Interfaces:
Lifecycle
,ProcessingQueue.Handler<Address>
public class STATE extends StreamingStateTransfer
STATE streams the state (written to an OutputStream) to the state requester in chunks (defined by chunk_size). Every chunk is sent via a unicast message. The state requester writes the chunks into a blocking input stream (BlockingInputStream
) from which theReceiver.setState(java.io.InputStream)
reads it. The size of the BlockingInputStream is buffer_size bytes. When implementingReceiver.getState(java.io.OutputStream)
, the state should be written in sizeable chunks, because the underlying output stream generates 1 message / write. 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:
- 2.4
- Author:
- Bela Ban, Vladimir Blagojevic
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
STATE.StateOutputStream
-
Nested classes/interfaces inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
StreamingStateTransfer.StateGetter, StreamingStateTransfer.StateHeader
-
-
Field Summary
Fields Modifier and Type Field Description protected BlockingInputStream
input_stream
If use_default_transport is true, we consume bytes off of this blocking queue.-
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()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
createStreamToRequester(Address requester)
Creates an OutputStream to the state requester to write the stateprotected void
handleEOF(Address sender)
protected void
handleException(java.lang.Throwable exception)
protected void
handleStateChunk(Address sender, byte[] buffer, int offset, int length)
protected void
handleViewChange(View v)
protected boolean
useAsyncStateDelivery()
-
Methods inherited from class org.jgroups.protocols.pbcast.StreamingStateTransfer
close, closeBarrierAndSuspendStable, closeHoleFor, createThreadPool, destroy, determineCoordinator, down, getAverageStateSize, getNumberOfStateBytesSent, getNumberOfStateRequests, getStateFromApplication, getThreadPoolCompletedTasks, getThreadPoolSize, handle, handle, handleConfig, handleStateReq, handleStateRsp, init, modifyStateResponseHeader, openBarrier, openBarrierAndResumeStable, punchHoleFor, requiredDownServices, resetStats, resumeStable, sendEof, sendException, setStateInApplication, start, stop, up, up, up
-
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
-
input_stream
protected volatile BlockingInputStream input_stream
If use_default_transport is true, we consume bytes off of this blocking queue. Used on the state requester side only. Note that we cannot use a PipedInputStream as we have multiple writer threads pushing data into the input stream
-
-
Method Detail
-
handleViewChange
protected void handleViewChange(View v)
- Overrides:
handleViewChange
in classStreamingStateTransfer
-
handleEOF
protected void handleEOF(Address sender)
- Overrides:
handleEOF
in classStreamingStateTransfer
-
handleException
protected void handleException(java.lang.Throwable exception)
- Overrides:
handleException
in classStreamingStateTransfer
-
handleStateChunk
protected void handleStateChunk(Address sender, byte[] buffer, int offset, int length)
- Overrides:
handleStateChunk
in classStreamingStateTransfer
-
createStreamToRequester
protected void createStreamToRequester(Address requester)
Description copied from class:StreamingStateTransfer
Creates an OutputStream to the state requester to write the state- Overrides:
createStreamToRequester
in classStreamingStateTransfer
-
createStreamToProvider
protected Tuple<java.io.InputStream,java.lang.Object> createStreamToProvider(Address provider, StreamingStateTransfer.StateHeader hdr)
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
-
useAsyncStateDelivery
protected boolean useAsyncStateDelivery()
- Overrides:
useAsyncStateDelivery
in classStreamingStateTransfer
-
-