Class OutgoingMessageQueueImpl
java.lang.Object
com.biglybt.core.networkmanager.impl.OutgoingMessageQueueImpl
- All Implemented Interfaces:
OutgoingMessageQueue
Priority-based outbound peer message queue.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface OutgoingMessageQueue
OutgoingMessageQueue.MessageQueueListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ArrayListprivate final AEMonitorprivate booleanprivate ArrayListprivate final AEMonitorprivate static final intprivate WeakReferenceprivate final LinkedList<RawMessage> private booleanprivate int[]private intprivate final LinkedList<RawMessage> private final AEMonitorprivate WeakReferenceprivate MessageStreamEncoderprivate intprivate intprivate booleanprivate static final booleanprivate Transportprivate RawMessage -
Constructor Summary
ConstructorsConstructorDescriptionOutgoingMessageQueueImpl(MessageStreamEncoder stream_encoder) Create a new outgoing message queue. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMessage(Message message, boolean manual_listener_notify) Add a message to the message queue.voidCancel queue event notification listener.int[]deliverToTransport(long max_bytes, boolean protocol_is_free, boolean manual_listener_notify) Deliver (write) message(s) data to the underlying transport.voiddestroy()Destroy this queue; i.e.voidManually send any unsent listener notifications.voidflush()Force all pending messages to be deliveredint[]intintbooleanintintGet the total number of bytes ready to be transported.booleanWhether or not an urgent message (one that needs an immediate send, i.e.booleanbooleanvoidnotifyOfExternallySentMessage(Message message) Notifty the queue (and its listeners) of a message sent externally on the queue's behalf.voidAdd a listener to be notified of queue events.booleanremoveMessage(Message message, boolean manual_listener_notify) Remove a particular message from the queue.voidremoveMessagesOfType(Message[] message_types, boolean manual_listener_notify) Remove all messages of the given types from the queue.voidsetEncoder(MessageStreamEncoder stream_encoder) Set the message stream encoder that will be used to encode outgoing messages.voidsetPriorityBoost(boolean boost) voidsetTrace(boolean on) voidsetTransport(Transport _transport)
-
Field Details
-
queue
-
queue_mon
-
delayed_notifications
-
delayed_notifications_mon
-
listeners
-
listeners_mon
-
total_size
private int total_size -
total_data_size
private int total_data_size -
priority_boost
private boolean priority_boost -
urgent_message
-
destroyed
private boolean destroyed -
stream_encoder
-
transport
-
progress_id
private int progress_id -
progress
private int[] progress -
TRACE_HISTORY
private static final boolean TRACE_HISTORY- See Also:
-
MAX_HISTORY_TRACES
private static final int MAX_HISTORY_TRACES- See Also:
-
prev_sent
-
trace
private boolean trace -
rawBufferCache
-
origPositionsCache
-
-
Constructor Details
-
OutgoingMessageQueueImpl
Create a new outgoing message queue.- Parameters:
stream_encoder- default message encoder
-
-
Method Details
-
setTransport
- Specified by:
setTransportin interfaceOutgoingMessageQueue
-
getMssSize
public int getMssSize()- Specified by:
getMssSizein interfaceOutgoingMessageQueue
-
setEncoder
Set the message stream encoder that will be used to encode outgoing messages.- Specified by:
setEncoderin interfaceOutgoingMessageQueue- Parameters:
stream_encoder- to use
-
getEncoder
- Specified by:
getEncoderin interfaceOutgoingMessageQueue
-
getCurrentMessageProgress
public int[] getCurrentMessageProgress()- Specified by:
getCurrentMessageProgressin interfaceOutgoingMessageQueue- Returns:
- [ total, done] or null
-
destroy
public void destroy()Destroy this queue; i.e. perform cleanup actions.- Specified by:
destroyin interfaceOutgoingMessageQueue
-
getTotalSize
public int getTotalSize()Get the total number of bytes ready to be transported.- Specified by:
getTotalSizein interfaceOutgoingMessageQueue- Returns:
- total bytes remaining
-
getDataQueuedBytes
public int getDataQueuedBytes()- Specified by:
getDataQueuedBytesin interfaceOutgoingMessageQueue
-
getProtocolQueuedBytes
public int getProtocolQueuedBytes()- Specified by:
getProtocolQueuedBytesin interfaceOutgoingMessageQueue
-
getPriorityBoost
public boolean getPriorityBoost()- Specified by:
getPriorityBoostin interfaceOutgoingMessageQueue
-
setPriorityBoost
public void setPriorityBoost(boolean boost) - Specified by:
setPriorityBoostin interfaceOutgoingMessageQueue
-
isBlocked
public boolean isBlocked()- Specified by:
isBlockedin interfaceOutgoingMessageQueue
-
hasUrgentMessage
public boolean hasUrgentMessage()Whether or not an urgent message (one that needs an immediate send, i.e. a no-delay message) is queued.- Specified by:
hasUrgentMessagein interfaceOutgoingMessageQueue- Returns:
- true if there's a message tagged for immediate write
-
peekFirstMessage
- Specified by:
peekFirstMessagein interfaceOutgoingMessageQueue
-
addMessage
Add a message to the message queue. NOTE: Allows for manual listener notification at some later time, using doListenerNotifications(), instead of notifying immediately from within this method. This is useful if you want to invoke listeners outside of some greater synchronised block to avoid deadlock.- Specified by:
addMessagein interfaceOutgoingMessageQueue- Parameters:
message- message to addmanual_listener_notify- true for manual notification, false for automatic
-
removeMessagesOfType
Remove all messages of the given types from the queue. NOTE: Allows for manual listener notification at some later time, using doListenerNotifications(), instead of notifying immediately from within this method. This is useful if you want to invoke listeners outside of some greater synchronised block to avoid deadlock.- Specified by:
removeMessagesOfTypein interfaceOutgoingMessageQueue- Parameters:
message_types- type to removemanual_listener_notify- true for manual notification, false for automatic
-
removeMessage
Remove a particular message from the queue. NOTE: Only the original message found in the queue will be destroyed upon removal, which may not necessarily be the one passed as the method parameter, as some messages override equals() (i.e. BTRequest messages) instead of using reference equality, and could be a completely different object, and would need to be destroyed manually. If the message does not override equals, then any such method will likely *not* be found and removed, as internal queued object was a new allocation on insertion. NOTE: Allows for manual listener notification at some later time, using doListenerNotifications(), instead of notifying immediately from within this method. This is useful if you want to invoke listeners outside of some greater synchronised block to avoid deadlock.- Specified by:
removeMessagein interfaceOutgoingMessageQueue- Parameters:
message- to removemanual_listener_notify- true for manual notification, false for automatic- Returns:
- true if the message was removed, false otherwise
-
deliverToTransport
public int[] deliverToTransport(long max_bytes, boolean protocol_is_free, boolean manual_listener_notify) throws IOException Deliver (write) message(s) data to the underlying transport. NOTE: Allows for manual listener notification at some later time, using doListenerNotifications(), instead of notifying immediately from within this method. This is useful if you want to invoke listeners outside of some greater synchronised block to avoid deadlock.- Specified by:
deliverToTransportin interfaceOutgoingMessageQueue- Parameters:
max_bytes- maximum number of bytes to delivermanual_listener_notify- true for manual notification, false for automatic- Returns:
- number of bytes delivered
- Throws:
IOException- on delivery error
-
flush
public void flush()Description copied from interface:OutgoingMessageQueueForce all pending messages to be delivered- Specified by:
flushin interfaceOutgoingMessageQueue
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyedin interfaceOutgoingMessageQueue
-
doListenerNotifications
public void doListenerNotifications()Manually send any unsent listener notifications.- Specified by:
doListenerNotificationsin interfaceOutgoingMessageQueue
-
setTrace
public void setTrace(boolean on) - Specified by:
setTracein interfaceOutgoingMessageQueue
-
getQueueTrace
- Specified by:
getQueueTracein interfaceOutgoingMessageQueue
-
registerQueueListener
Add a listener to be notified of queue events.- Specified by:
registerQueueListenerin interfaceOutgoingMessageQueue- Parameters:
listener-
-
cancelQueueListener
Cancel queue event notification listener.- Specified by:
cancelQueueListenerin interfaceOutgoingMessageQueue- Parameters:
listener-
-
notifyOfExternallySentMessage
Notifty the queue (and its listeners) of a message sent externally on the queue's behalf.- Specified by:
notifyOfExternallySentMessagein interfaceOutgoingMessageQueue- Parameters:
message- sent externally
-