final class MessageVector extends Object implements MessageQueue
MessageVector
represents a persistent vector of
Message (source and target agent identifier, notification).
As messages have a relatively short life span, then the messages
are kept in main memory. If possible, the list is backed by a persistent
image on the disk for reliability needs. In this case, we can use
SoftReference to avoid memory overflow.MessageVector
object state.Modifier and Type | Class and Description |
---|---|
(package private) static class |
MessageVector.Counter |
Modifier and Type | Field and Description |
---|---|
private int |
count
The number of messages in this MessageVector object.
|
(package private) Hashtable<Class,MessageVector.Counter> |
counters |
private long |
cpt1 |
private long |
cpt2 |
private Object[] |
data
The array buffer into which the
Message objects are stored
in memory. |
private int |
first
The index of the first message in the circular buffer.
|
private org.objectweb.util.monolog.api.Logger |
logmon |
private String |
logmsg |
static String |
MSG_TYPES_TRACKING
Name of property allowing to track the distribution of the types of messages,
by default false.
|
private static boolean |
msgTypesTracking
True if the tracking of the distribution of messages type is allowed.
|
private boolean |
persistent |
private int |
validated
The number of validated message in this MessageQueue.
|
Constructor and Description |
---|
MessageVector(String name,
boolean persistent) |
Modifier and Type | Method and Description |
---|---|
private void |
dec(Notification not) |
Message |
get()
Looks at the message at the top of this queue without removing
it from the queue.
|
Message |
get(long timeout)
Looks at the message at the top of this queue without removing
it from the queue.
|
private Message |
getMessageAt(int index)
Returns the message at the specified index.
|
Message |
getMessageTo(short to)
Looks at the first message of this queue where the destination server
is the specified one.
|
private void |
inc(Notification not) |
void |
insert(Message item)
Insert a message in the queue, it should only be used during
initialization for restoring the queue state.
|
private void |
insertMessageAt(Message item,
int index)
Inserts the specified message to this
MessageVector at
the specified index. |
Message |
pop()
Removes the message at the top of this queue.
|
void |
push(Message item)
Pushes a message onto the bottom of this queue.
|
void |
pushAndValidate(Message item)
Pushes and validates a message.
|
(package private) int |
remove(int stamp)
Removes all messages with a stamp less than the specified one.
|
(package private) Message |
removeExpired(long currentTimeMillis)
Removes the first messages with a timestamp less than the specified one.
|
(package private) void |
removeMessage(Message msg)
Removes the specified message from the queue if exists.
|
private void |
removeMessageAt(int index)
Deletes the message at the specified index.
|
String |
report()
Returns a report about the distribution of messages type in queue.
|
int |
size()
Returns the number of messages in this vector.
|
String |
toString()
Returns a string representation of this
MessageVector
object. |
void |
validate()
Atomically validates all messages pushed in queue during a reaction.
|
private org.objectweb.util.monolog.api.Logger logmon
private String logmsg
private long cpt1
private long cpt2
private Object[] data
Message
objects are stored
in memory. The capacity of this array buffer is at least large enough to
contain all the messages of the MessageVector
.Messages are stored in a circular way, first one in data[first] through data[(first+count-1)%length]. Any other array elements are null.
private int first
private int count
private int validated
private boolean persistent
public static final String MSG_TYPES_TRACKING
This property can be fixed either from java
launching command or
a3servers.xml configuration file.
private static boolean msgTypesTracking
Hashtable<Class,MessageVector.Counter> counters
MessageVector(String name, boolean persistent)
public void insert(Message item)
insert
in interface MessageQueue
item
- the message to be pushed onto this queue.public void push(Message item)
push
in interface MessageQueue
item
- the message to be pushed onto this queue.public void pushAndValidate(Message item)
pushAndValidate
in interface MessageQueue
item
- the message to be pushed and validatedpublic Message pop() throws EmptyQueueException
pop
in interface MessageQueue
EmptyQueueException
- if this queue is empty.public void validate()
validate
in interface MessageQueue
public Message get() throws InterruptedException
get
in interface MessageQueue
InterruptedException
- if another thread has interrupted the
current thread.public Message get(long timeout) throws InterruptedException
get
in interface MessageQueue
timeout
- the maximum time to wait in milliseconds.InterruptedException
- if another thread has interrupted the
current thread.IllegalArgumentException
- if the value of timeout is negative.public Message getMessageTo(short to)
to
- the unique server id.void removeMessage(Message msg)
msg
- the message to remove.int remove(int stamp)
Message removeExpired(long currentTimeMillis)
private void insertMessageAt(Message item, int index)
MessageVector
at
the specified index. Each component in this vector with an index greater
or equal to the specified index is shifted upward.item
- the message to be pushed onto this queue.index
- where to insert the new message.private Message getMessageAt(int index)
index
- the index of the message.private void removeMessageAt(int index)
index
- the index of the message to remove.public int size()
size
in interface MessageQueue
public String toString()
MessageVector
object. Be careful we scan the vector without synchronization, so the
result can be incoherent.private void inc(Notification not)
private void dec(Notification not)
public String report()
report
in interface MessageQueue
Copyright © 2018 ScalAgent D.T.. All Rights Reserved.