cz.cuni.pogamut.Parser
Class Parser

java.lang.Object
  extended by cz.cuni.pogamut.Parser.Parser
All Implemented Interfaces:
MediatorGBInterface, MediatorParserInterface, TranslateUnrealID2IntID

public class Parser
extends java.lang.Object
implements MediatorParserInterface, MediatorGBInterface, TranslateUnrealID2IntID

Gets messages (String) from GameBot translating them via Yylex into MessageObject, doing DeltaCompression and passing them out. Also may be used to send messages to GB. Is configured by GameBotConnection which must be already connected to GameBot!


Field Summary
private  java.util.Queue<MessageObject> bufferToSend
          Buffer of messages we have to send to the client ...
private  java.util.Set<java.lang.Integer> currentBatch
          Current batch of messages from GB.
private  java.util.HashMap<java.lang.Integer,MessageObject> dbInt2Msg
          Map for storing MessageObjects with hasID() true - ITEMS, NAVS, MOVERS... = basically objects
 boolean dontDiff
          Should Parser create batches and do diffs?
private  GameBotConnection gb
           
private  java.util.Set<java.lang.Integer> lastBatch
          Last batch of messages from GB.
 Yylex lex
          Lexical engine for recognizing GameBot messages.
private  java.util.logging.Logger log
           
protected  boolean pushIntoBatch
          Flag which tells us whether we have to put the message int batch, needed for processing initial nav points / items from the map.
private  TranslateUnrealID2IntID unrealID
           
 
Constructor Summary
Parser(GameBotConnection gb, TranslateUnrealID2IntID unrealID, java.util.logging.Logger log)
           
 
Method Summary
 void closeGB()
          Close the connection to the GameBots, if any exists.
 void closeParser()
          Close the connection to the parser (if any exists).
private  MessageObject diffMessage(MessageObject msg)
          Creates DELTA MESSAGE out of msg and writes new informations into dbInt2Msg message object
private  MessageObject getMessageFromYylex()
           
private  void handleEndMessage()
          Push some messages to bufferToSend if they should be removed from current batch of the client.
 MessageObject receiveParsedMessage()
          May block.
 void sendMessageToGB(java.lang.String msg)
          Sends data through GameBotConnection.
 int translateUnrealID2IntID(java.lang.String unrealId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gb

private GameBotConnection gb

unrealID

private TranslateUnrealID2IntID unrealID

log

private java.util.logging.Logger log

lex

public Yylex lex
Lexical engine for recognizing GameBot messages.


dbInt2Msg

private java.util.HashMap<java.lang.Integer,MessageObject> dbInt2Msg
Map for storing MessageObjects with hasID() true - ITEMS, NAVS, MOVERS... = basically objects


lastBatch

private java.util.Set<java.lang.Integer> lastBatch
Last batch of messages from GB.


currentBatch

private java.util.Set<java.lang.Integer> currentBatch
Current batch of messages from GB.


bufferToSend

private java.util.Queue<MessageObject> bufferToSend
Buffer of messages we have to send to the client ... is filled by END message if neccessary.


pushIntoBatch

protected boolean pushIntoBatch
Flag which tells us whether we have to put the message int batch, needed for processing initial nav points / items from the map.


dontDiff

public boolean dontDiff
Should Parser create batches and do diffs? Yes for GB, no for system control

Constructor Detail

Parser

public Parser(GameBotConnection gb,
              TranslateUnrealID2IntID unrealID,
              java.util.logging.Logger log)
Method Detail

getMessageFromYylex

private MessageObject getMessageFromYylex()
                                   throws CantReadException
Throws:
CantReadException

handleEndMessage

private void handleEndMessage()
Push some messages to bufferToSend if they should be removed from current batch of the client.


diffMessage

private MessageObject diffMessage(MessageObject msg)
Creates DELTA MESSAGE out of msg and writes new informations into dbInt2Msg message object

Parameters:
msg -

receiveParsedMessage

public MessageObject receiveParsedMessage()
                                   throws CantReadException
May block. May return null in the case that it process the message which the client already has (knows about it).

Specified by:
receiveParsedMessage in interface MediatorParserInterface
Throws:
CantReadException - Unable to read from GameBot connection

sendMessageToGB

public void sendMessageToGB(java.lang.String msg)
                     throws CantWriteException
Sends data through GameBotConnection.

Specified by:
sendMessageToGB in interface MediatorGBInterface
Throws:
CantWriteException - Unable to send data to GameBot.

translateUnrealID2IntID

public int translateUnrealID2IntID(java.lang.String unrealId)
Specified by:
translateUnrealID2IntID in interface TranslateUnrealID2IntID

closeGB

public void closeGB()
             throws CantCloseConnectionException
Description copied from interface: MediatorGBInterface
Close the connection to the GameBots, if any exists.

Specified by:
closeGB in interface MediatorGBInterface
Throws:
CantCloseConnectionException

closeParser

public void closeParser()
                 throws CantCloseConnectionException
Description copied from interface: MediatorParserInterface
Close the connection to the parser (if any exists).

Specified by:
closeParser in interface MediatorParserInterface
Throws:
CantCloseConnectionException