cz.cuni.pogamut.Client
Class HistoryBatch

java.lang.Object
  extended by cz.cuni.pogamut.Client.HistoryBatch
All Implemented Interfaces:
java.lang.Cloneable

public class HistoryBatch
extends java.lang.Object
implements java.lang.Cloneable

HistoryBatch is a class that stores one batch of messages from Gamebots it therefore has a structure to save them to it is indexed by type of item and on this index, you can find HashMap with all items saved at the current batch - so some of them are mostly empty

Special attention should be payed to items without ID, those are stored under fantom ID which is negative and goes down from -1 to MIN_VALUE of int.

note that messages are mostly synchronized to ensure synchronized access to it


Field Summary
 java.util.logging.Logger batchLogger
           
static int counterForAnonymousID
          Counter for items without ID, which needs ID - like sounds for instance every sound has its ID, as integer got about at least 65536 values, there is no chance, that there will be two different objects of the same type with the same ID
private  java.util.HashMap<MessageType,java.util.HashMap<java.lang.Integer,MessageObject>> messages
           
private  HistoryBatch next
           
 
Constructor Summary
HistoryBatch(java.util.logging.Logger logger)
           
 
Method Summary
 void addMessage(MessageObject newMsg)
          This method is synchronized!
 HistoryBatch copyVisibleObjects()
          this method soft copies synchronous messages batch is used in History.
 java.util.HashMap<java.lang.Integer,MessageObject> getAllObjectsOfType(MessageType type)
          returns HashMap with objects of desired type, could return null for empty HashMaps
 MessageObject getFirstObjectOfType(MessageType type)
          returns first object of desired type or null if there is not any
 MessageObject getMessage(MessageType type, int ID)
          Returns message of type 'type' and id 'ID' if present in the batch, null otherwise.
 HistoryBatch getNext()
          for move to the next batch
 boolean hasObjectOfType(int type)
          indicates whether there is at least one object of desired type
 void remove(MessageType type, int id)
           
 void setNext(HistoryBatch next)
          set next batch
 java.lang.String toFormatedString()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

messages

private java.util.HashMap<MessageType,java.util.HashMap<java.lang.Integer,MessageObject>> messages

next

private HistoryBatch next

counterForAnonymousID

public static int counterForAnonymousID
Counter for items without ID, which needs ID - like sounds for instance every sound has its ID, as integer got about at least 65536 values, there is no chance, that there will be two different objects of the same type with the same ID


batchLogger

public java.util.logging.Logger batchLogger
Constructor Detail

HistoryBatch

public HistoryBatch(java.util.logging.Logger logger)
Method Detail

getNext

public HistoryBatch getNext()
for move to the next batch

Returns:
next HistoryBatch

setNext

public void setNext(HistoryBatch next)
set next batch

Parameters:
next -

getMessage

public MessageObject getMessage(MessageType type,
                                int ID)
Returns message of type 'type' and id 'ID' if present in the batch, null otherwise.

Parameters:
type -
ID -
Returns:
MessageObject

addMessage

public void addMessage(MessageObject newMsg)
This method is synchronized!
It is necessary to avoid data unconsistency when AgentBody thread adds items to messages and AgentMemory wants some information from messages

Parameters:
newMsg -

copyVisibleObjects

public HistoryBatch copyVisibleObjects()
this method soft copies synchronous messages

batch is used in History. Batch is storing all messages from Gamebots in the structure composed of ArrayList and HashMap. Messages are from one batch, there are both synchronous and asynchronous messages, but after the end of the batch, it is not necessary to send all synchronous messages again, so the synchronous messages are copied and asynchronous ommited

and exatly that is a purpose of this method

Returns:
new HistoryBatch with visible objects

hasObjectOfType

public boolean hasObjectOfType(int type)
indicates whether there is at least one object of desired type


getFirstObjectOfType

public MessageObject getFirstObjectOfType(MessageType type)
returns first object of desired type or null if there is not any


getAllObjectsOfType

public java.util.HashMap<java.lang.Integer,MessageObject> getAllObjectsOfType(MessageType type)
returns HashMap with objects of desired type, could return null for empty HashMaps

Parameters:
type -
Returns:
all objects (in hash map) of specified type - null if there are not any

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toFormatedString

public java.lang.String toFormatedString()

remove

public void remove(MessageType type,
                   int id)