public class BufferSizeManager
extends java.lang.Object
BufferSizeManager acts a singleton and tracks stream opening and closing,
blocking operations and output operations. It can tell whether it is time
to raise the STOP condition for a given stream. It makes decision basing on
the array of "reference" buffer sizes, which were generated from the
results of testcases. These testcases allowed us to get buffer sizes for
the different conditions. To know what buffer size may depend on, read
BufferSizeDependency
.
Modifier and Type | Class and Description |
---|---|
private class |
BufferSizeManager.StreamInfo
Stores information about the current state of the output stream and acts
as a helper for determining whether we have exceeded the buffer size.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
aStreamWasBroken
Determines whether a stream (any process stream) was ever broken
during the session.
|
private java.lang.Object |
closeArray
Multidimensional array which stores "reference" buffer sizes for
close operations.
|
private java.util.Map<BufferSizeDependency,java.lang.Integer> |
closeParamIndexes
"type of dependency -> index of the corresponding dimension" for the
close operations array.
|
private java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> |
closeValuesIndexes
"type of dependency -> mapping 'dependency value -> index inside the
dimension'" for the close operations array.
|
private java.lang.Object |
flushArray
Multidimensional array which stores "reference" buffer sizes for
flush operations.
|
private java.util.Map<BufferSizeDependency,java.lang.Integer> |
flushParamIndexes
"type of dependency -> index of the corresponding dimension" for the
flush operations array.
|
private java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> |
flushValuesIndexes
"type of dependency -> mapping 'dependency value -> index inside the
dimension'" for the flush operations array.
|
private boolean |
initialized
Determines whether "reference" buffer sizes were successfully loaded
|
private static ContextLocal<BufferSizeManager> |
local
Context local instance of this class.
|
private java.util.Map<ProcessStream,BufferSizeManager.StreamInfo> |
streams
Map which stores information about opened streams.
|
Modifier | Constructor and Description |
---|---|
private |
BufferSizeManager()
Private c'tor which performs BufferSizeManager initialization.
|
Modifier and Type | Method and Description |
---|---|
private int |
getBufferSize(boolean close,
BufferSizeManager.StreamInfo info,
OutputOperationType outputOperationType)
Get the buffer size for the given stream and output operation.
|
private int |
getBufferSize(boolean close,
java.util.Map<BufferSizeDependency,java.lang.Object> parameters)
Get buffer size for the given stream state.
|
private int |
getBufferSize(java.util.Map<BufferSizeDependency,java.lang.Object> parameters,
java.lang.Object dataArray,
java.util.Map<BufferSizeDependency,java.lang.Integer> paramMap,
java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> valuesMap,
int defaultBufferSize)
Get the buffer size for the given stream state from the given array of
"reference" buffer sizes.
|
private int |
getDefaultBufferSize(boolean close,
java.util.Map<BufferSizeDependency,java.lang.Object> parameters)
Get the default buffer size for the given set of stream parameters.
|
private java.lang.Object |
getElement(java.lang.Object array,
int[] indexes)
Return the element of the given multidimensional array which position
position is specified by the given indexes.
|
static BufferSizeManager |
getInstance()
Returns singleton instance of this class.
|
private org.w3c.dom.Element |
getNodeByPath(org.w3c.dom.Element root,
java.lang.String path)
Get XML node by the given path.
|
private byte[] |
getNodeByteArray(org.w3c.dom.Element root,
java.lang.String path)
Get the byte array which is stored under the given node.
|
private java.lang.String[] |
getNodeStrings(org.w3c.dom.Element root,
java.lang.String path)
Get the string values which are stored under the given node.
|
private OutputOperationType |
getOutputDataEnumByNumber(boolean put,
int bytesWritten)
Get the OutputOperationType enumeration value for the given operation
type and number of bytes written by this operation.
|
void |
notifyBlockingOperation(BlockingOperation blockingOperation)
Notify that a blocking operation has been performed.
|
void |
notifyBroken(ProcessStream stream)
Notify that a process stream has been broken.
|
void |
notifyCloseStream(ProcessStream stream)
Notify that a stream has been closed.
|
void |
notifyOutputError(ProcessStream stream)
Notify that an output error has occured in the process stream.
|
void |
notifyOutputOperation(boolean put,
Stream stream,
int bytesWritten)
Notify that an output operation has been performed.
|
private java.lang.Object |
readReferenceArray(org.w3c.dom.Element root,
java.lang.String paramNode,
java.util.Map<BufferSizeDependency,java.lang.Integer> paramMap,
java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> valuesMap,
java.lang.String dataNode)
Read the array of "reference" buffer size from the given XML tree.
|
void |
reset()
Reset buffer size manager to its initial state (this does not reset
its configuration).
|
boolean |
shouldRaiseStop(boolean close,
ProcessStream stream)
Determines whether we have exceeded the buffer size limit for a given
stream and the STOP condition should be raised.
|
private static final ContextLocal<BufferSizeManager> local
private final java.util.Map<ProcessStream,BufferSizeManager.StreamInfo> streams
private boolean aStreamWasBroken
private java.lang.Object flushArray
private java.lang.Object closeArray
private java.util.Map<BufferSizeDependency,java.lang.Integer> flushParamIndexes
flushArray
determines whether the stream
is buffered or unbuffered one.private java.util.Map<BufferSizeDependency,java.lang.Integer> closeParamIndexes
closeArray
determines whether the stream
is buffered or unbuffered one.private java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> flushValuesIndexes
private java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> closeValuesIndexes
private boolean initialized
private BufferSizeManager()
public static BufferSizeManager getInstance()
public void notifyBroken(ProcessStream stream)
stream
- The stream that was broken.public void notifyOutputError(ProcessStream stream)
stream
- The stream that has failed to perform output.public void notifyBlockingOperation(BlockingOperation blockingOperation)
blockingOperation
- Blocking operation that was performed.public void notifyCloseStream(ProcessStream stream)
stream
- The stream that was closed.public void notifyOutputOperation(boolean put, Stream stream, int bytesWritten)
put
- true
if a PUT operation was performed,
false
if a DISPLAY operation was performedstream
- Target stream of the output operation.bytesWritten
- Number of bytes that has been written by this operation.public void reset()
public boolean shouldRaiseStop(boolean close, ProcessStream stream)
close
- true
if we are performing a close operation,
false
if we are performing a flush operation.stream
- The stream we are questioning for.true
if we have exceeded the buffer size limit.private int getBufferSize(boolean close, BufferSizeManager.StreamInfo info, OutputOperationType outputOperationType)
close
- true
if we are performing a close operation,
false
if we are performing a flush operation.info
- Stream info object for the stream which buffer size should be
returned.outputOperationType
- Output operation for which the buffer size should be calculated.private int getBufferSize(boolean close, java.util.Map<BufferSizeDependency,java.lang.Object> parameters)
close
- true
if we are performing a close operation,
false
if we are performing a flush operation.parameters
- Parameters which specify the state of the stream.private int getBufferSize(java.util.Map<BufferSizeDependency,java.lang.Object> parameters, java.lang.Object dataArray, java.util.Map<BufferSizeDependency,java.lang.Integer> paramMap, java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> valuesMap, int defaultBufferSize)
parameters
- Parameters which specify the state of the stream.dataArray
- Array which contains the "reference" buffer sizes.paramMap
- Target map which will store the information about array
dimensions. See flushParamIndexes
.valuesMap
- Target map which will store the information about indexes
inside dimensions. See flushValuesIndexes
.defaultBufferSize
- Buffer size value to be used if we haven't found an appropriate
value in the array of "reference" buffer sizes.private int getDefaultBufferSize(boolean close, java.util.Map<BufferSizeDependency,java.lang.Object> parameters)
close
- true
if the buffer size for a close operation is
requested, false
if the buffer size for a flush
operation is requested.parameters
- Parameters which describe the current state of the stream.private java.lang.Object readReferenceArray(org.w3c.dom.Element root, java.lang.String paramNode, java.util.Map<BufferSizeDependency,java.lang.Integer> paramMap, java.util.Map<BufferSizeDependency,java.util.Map<java.lang.Object,java.lang.Integer>> valuesMap, java.lang.String dataNode) throws java.io.IOException, java.lang.ClassNotFoundException
root
- The root node of the source XML tree.paramNode
- The name of the node which contains the array metadata.paramMap
- Target map which will store the information about array
dimensions. See flushParamIndexes
.valuesMap
- Target map which will store the information about indexes
inside dimensions. See flushValuesIndexes
.dataNode
- The name of the node which contains the array data.java.io.IOException
- If we couldn't read the required array.java.lang.ClassNotFoundException
- If we couldn't read the required array.private org.w3c.dom.Element getNodeByPath(org.w3c.dom.Element root, java.lang.String path)
root
- The root node of the source XML.path
- Path to the required node (names of the nodes starting from the
root node (exclusive), separated by "/", e.g.
"parameters/param1/description").private java.lang.String[] getNodeStrings(org.w3c.dom.Element root, java.lang.String path)
root
- The root node of the source XML.path
- Path to the required node (names of the nodes starting from the
root node (exclusive), separated by "/", e.g.
"parameters/names").private byte[] getNodeByteArray(org.w3c.dom.Element root, java.lang.String path)
root
- The root node of the source XML.path
- Path to the required node (names of the nodes starting from the
root node (exclusive), separated by "/", e.g.
"parameters/data").private java.lang.Object getElement(java.lang.Object array, int[] indexes)
array
- Array from which the required element will be retrieved.indexes
- Array of indexes which specify the position of the required
element in the array.private OutputOperationType getOutputDataEnumByNumber(boolean put, int bytesWritten)
OutputOperationType
put
- true
if a PUT operation was performed,
false
if a DISPLAY operation was performedbytesWritten
- Number of bytes that has been written by this operation.