input
stringlengths
10
828
output
stringlengths
5
107
static private binary string make quoted string binary string s s s duplicate s replace in place new binary string new binary string s replace in place new binary string new binary string return binary string concat new binary string mimeencoded word encode phrase s new binary string
returns a quoted string version of s
protected void next command throws ioexception result handler next handler null while command queue is empty pause get command next command queue remove first next handler next call if next handler null break if next handler null add result handler next handler
calls the commands in order until a result handler is returned at
static private binary string make quoted address binary string addr todo domain could be internationalized this would require doing mimeencoded word encoding but with some added complexity it is pretty doubtful anything does or can accept this now anyway return binary string concat make quoted string addr 0 new binary string addr 1
returns a quoted string version of the address
public void set charset string charset name throws unsupported charset exception this charset charset for name charset name
sets the charset for this binary string
public binary string encode binary string ret new binary string for field f headers values ret append f encode ret append header separator ret append body return ret
encodes this message as a mime formatted binary string
public void set raw binary string raw this raw raw
sets the raw data of the header
public string get charset return charset name
gets the name of this binary strings charset
public void set name binary string name raw null this name name
sets the name of the field
protected void switch connections throws ioexception sessions remove first if sessions is empty sessions get first start
removes the current connection and starts the next connection
public binary string get name return name
gets the name of the field
private void end while in list is empty buffer cache return buffer in list remove first
clears input data off of the connection
protected void push binary string messages throws ioexception if debug string buffer info new string buffer info append string value of selectee number get info append for binary string b string messages info append b string inspect info append n system err print info byte buffer to push new byte buffer messages length for int i 0 i messages length i to push i messages i as byte buffer sessions get last push to push
pushes the messages through to the sessions
public void set value binary string value raw null this value value
sets the value of the field
private void multi init list byte buffer buffers int size 0 for byte buffer buffer buffers size buffer remaining b allocate bb size for byte buffer buffer buffers int p buffer position b put buffer buffer position p b flip b remaining size
concatenates the buffers in order and sets binary string with the buffer data
private void expecting header size 1 reset size lexer expecting message new line max length
the message header is size n
public gregorian calendar get calendar return cal
gets the calendar
private void parse header binary string header throws ioexception try size integer parse int header to string trim try parsing the size value expecting message next comes the message catch number format exception e expecting header obviously that last message wasn t a header ioexception ioe new ioexception message passing session expected to parse int size n got header to string ioe init cause e throw ioe
parses the header and gets the size of the message to be read
public void set calendar gregorian calendar cal this cal cal
sets the calendar
private void expecting message lexer expecting message size
tell the lexer to parse for the message
private void parse message binary string message throws ioexception response handler handler handler list remove first handler handle response message expecting header the next input will be another header
gives the message to the result handler
private void init int block size int cache size boolean direct this block size block size this direct direct cache new array blocking queue byte buffer cache size block size while array blocking queue cache remaining capacity 0 if direct cache offer byte buffer allocate direct block size else cache offer byte buffer allocate block size
initializes this buffer cache
public byte buffer get empty buffer byte buffer ret cache poll if ret null return byte buffer allocate block size else ret clear return ret
returns an empty buffer
public int running selectees return running selectees get
gets the number of running selectees
public interface clonable result handler extends result handler generates a clonable result handler out of the context param context a context that will produce the clonable result handler return a clonable result handler generated from the context s result handler public clonable result handler clone programmable client context
a result handler that can be cloned
public long running time return running time
gets the running time
public interface command calls this command can returns a result handler if needed to process incoming data return a result handler to handle any results of this call throws ioexception if we couldn t get the handler public result handler call throws ioexception makes a deep copy of this command param context the context of this command used to generate the deep copy return a deeply copied version of this command public command clone programmable client context
a command can be called and cloned
private selectee descriptor new selectee descriptor selectee selectee selectee descriptor ret new selectee descriptor selectee if selectee instanceof server ret selectee number next selectee number get and increment integer max value else ret selectee number 1 next selectee number get and increment integer max value selectee set selectee number ret selectee number if keep statistics ret keep statistics selectee keep statistics return ret
generates a new selectee descriptor from selectee
public class null command implements command non javadoc see loq io client programmable client command clone loq io client programmable client public command clone programmable client context return context new null command non javadoc see loq io client programmable client command call public result handler call throws ioexception return null
the null command is used to wake things up properly
protected void log exception int client number throwable t if t instanceof closed channel exception don t clutter the logs with closed channel exceptions logger debug selectee client number closed logger trace client number t else logger error client number t
logs the exception with an associated client number
private void lock super lock only necessary for 1 5 r count set r count get 1
the lock method
protected void finish selectee selectee descriptor sd if sd keep statistics finished selectees add new selectee info sd selectee number sd start time system current time millis sd exception null if sd exception null log exception sd selectee number sd exception running selectees decrement and get
cleans up after a finished selectee
private void unlock super unlock only necessary for 1 5 r count set r count get 1
the unlock method
public binary string get text return text
gets the text entry for this unstructured field
protected boolean run condition return term get running selectees get 0 kill get
determines whether to stop after the current selectees are finished
private boolean run consensus while true for iterator future i running tasks iterator i has next future f i next if f is done i remove if run condition if running tasks is empty run condition is true join with next future and reevaluate try future f running tasks get first f get running tasks remove first catch interrupted exception e catch execution exception e log exception 0 e else return false else return true
determine whether or not to end
public void set text binary string text raw null this text text
sets the text entry for this unstructured field
public input stream as input stream return new binary string input stream
returns an input stream representing the current contents of the binary string
public void kill kill set true force wakeup
flags the ioloop to cleanly terminate as soon as possible
public void wakeup selector wakeup
ensures that the main thread wakes up by waking up the selector
private void end throws ioexception if closed return closed true event queue add ioevent close while in list is empty buffer cache return buffer in list remove first while out list is empty buffer cache return buffer out list remove first
finalizes session after it has closed registering a close event
public string to string string charset name throws unsupported charset exception byte buffer c synchronized b c b duplicate string ret charset for name charset name decode c to string return ret
generates a string representation of the binary string based on the given charset
private void connect throws ioexception channel finish connect
finishes the connection process
protected void set front separator binary string separator this front separator separator
sets the separator for the front channel
protected binary string get front separator return front separator
gets the separator for the front channel
protected void set back separator binary string separator this back separator separator
sets the separator for the back channel
protected lexer get front lexer return front lexer
gets the lexer that operates on the front channel
protected binary string get back separator return back separator
gets the separator for the back channel
public void register selectee selectee selectee blocking queue selectee descriptor queue selectee set caller this running selectees increment and get queue add new selectee descriptor selectee selector wakeup
register each selectee into ioloop
protected void back expecting message throws ioexception programmable lexer get back lexer expecting message back separator chunk size back data
registers the expectation of a message with
protected lexer get back lexer return back lexer
gets the lexer that operates on the back channel
public binary string to lower case return new binary string to string to lower case
returns a lowercase version of this binary string
public void set command map map binary string command command map this command map command map
sets the map of commands and their command names
public void register selectee selectee selectee register selectee selectee waiting selectees
registers the selectee with the waiting selectees
private void write throws ioexception channel write out list to array new byte buffer out list size while out list is empty out list get first has remaining buffer cache return buffer out list remove first
writes data out from the session to the channel
protected binary string extract command binary string data commands come in here int command end data index of space if command end 1 command end data index of crlf eol return data substring 0 command end to lower case the map contains all lowercase entries
extracts and returns the command portion in lowercase of the data
protected void command binary string data throws ioexception binary string command this extract command data extract the command if command map get command null doesn t call has command to avoid building extra binary strings handler command map get command command data if handler null back expecting message else front expecting message else command missing command data
passes the message to the correct command
protected void command missing binary string command binary string data throws ioexception by default throw an exception throw new protocol exception command command to string missing
generates and throws a protocol exception since the command is missing
protected void set front lexer lexer lexer front lexer lexer
sets the lexer that operates on the front channel
public byte buffer as byte buffer synchronized b return b duplicate
gets the byte buffer representing this binary string
protected void response binary string data throws ioexception if handler null handle greeting data front expecting message else result handler new handler handler handle result data if new handler null handler new handler back expecting message else front expecting message
handles the data and decides which side will be sending the next message
public string get parse string return m parse string
returns the string if provided to this class that could not parse
protected void set back lexer lexer lexer back lexer lexer
sets the lexer that operates on the back channel
private boolean can close return close out list is empty buffer util size remaining out list out optional
checks to see if this session is able to close
public void load byte xml throws transport error byte array input stream in new byte array input stream xml read xml in
loads a transport message from the xml data
private void write xml output stream out xmlencoder encoder new xmlencoder out encoder write object this encoder close
writes this transport message to the output stream
private void read xml input stream in throws transport error object result null try xmldecoder decoder new xmldecoder in result decoder read object decoder close load transport message result catch class cast exception e if result null throw new transport error transport utility load failed result get class get canonical name is not a transportable object n result was result to string e else throw new transport error transport utility load failed could not transport the input e catch throwable t throw new transport error some other exception occurred in transport utility load t
reads the input stream and uses the data to create this transport message
public void start if timer null return if tt compare and set null new timer task public void run process run timer schedule tt get timeout
starts the countdown to run the process
public boolean cancel timer task task tt get and set null if task null return true else return task cancel
stops the thread timer from counting down
private boolean add to set e obj if obj null addresses contains obj return false avoid null entries return addresses add obj
the only logic in this class adds the object to the set
protected void add temp command binary string temp command command the command throws ioexception binary string new command this extract command temp command if this has command temp command throw new ioexception simplex command filter add auth command tried to overwrite an existing command with the temporary command new command this get command map put new command the command
adds the temporary command to the command map
protected void remove temp command binary string temp command binary string command to remove this extract command temp command this get command map remove command to remove
removes the temporary command from the command map
protected void front close nothing by default
called when the front session is closed
public interface result handler processes the result data and possibly returns another result handler param result the data to process return a result hanlder that can handler any applicable result data throws ioexception if there is an io error public result handler handle result binary string result throws ioexception
a result handler knows how to handle result data
private int interest ops if channel is connection pending return selection key op connect if out list is empty don t write and read at the same time as per http rox xmlrpc sourceforge net niotut index html return selection key op write return read wanted
gets the operation this session wants to do
protected void back close likewise nothing by default
called when the back session is closed
protected void close throws ioexception try front session finish finally back session finish
finishes and closes both sessions
private void push isession session binary string messages throws ioexception if system get property webloq debug null string buffer info new string buffer info append string value of session get selectee number info append for binary string b string messages info append b string inspect info append n logger info info byte buffer to push new byte buffer messages length for int i 0 i messages length i to push i messages i as byte buffer session push to push
pushes the messages to the session sends the messages
protected void front push binary string message throws ioexception push front session message if debug debug last action message inspect
pushes the message to the front session
protected void back push binary string message throws ioexception push back session message if debug debug last action message inspect
pushes the message to the back session
private void throw events throws ioexception while event queue is empty try ioevent event event queue remove first list event listener to notify listeners get event if to notify null continue for event listener listener to notify listener notify event this if should close do close null finally for byte buffer empty buffer util scrub buffer list in list buffer cache return buffer empty
notifies all event listeners of any events on the queue
public void append string to append append new binary string charset encode to append
appends to append to the end of this binary string
public void append binary string to append invalidate caches ensure capacity length to append length b mark b position b limit b limit b capacity b put to append as byte buffer b limit b position b reset
appends to append to the end of this binary string
public void append byte to append invalidate caches ensure capacity length to append length b mark b position b limit b limit b capacity b put to append b limit b position b reset
appends to append to the end of this binary string
public int compare to ignore case binary string other return to string compare to ignore case other to string
compares this binary string to the other binary string ignoring case
public int compare to binary string other byte buffer c synchronized b c b duplicate return c compare to other as byte buffer
compares this binary string to the other binary string
public int index of byte needle return index of needle 0
returns the index of the first occurence of needle in this binary string
public boolean contains byte needle return index of needle 1
tests to see if needle is inside of this binary string
public byte byte at int index synchronized b return b get b position index
gets the byte at the given index
public int index of binary string needle return index of needle 0
gets the index of the first occurence of needle in this binary string
public int last index of binary string needle return last index of needle b limit needle length
gets the index of the last occurence of needle in this binary string
private void shuffle int old offset int new offset old offset b position new offset b position int length b remaining old offset if old offset new offset shuffling down for int i 0 i length i b put new offset i b get old offset i b limit new offset length else if new offset old offset shuffling up b limit new offset length for int i length 1 i 0 i b put new offset i b get old offset i else no movement return
shuffles out the bytes between old offest and nex offset
public binary string duplicate byte buffer c synchronized b c b duplicate byte buffer ret allocate bb c remaining ret put c ret flip return new binary string ret
returns a duplicate of this binary string
public void replace in place binary string search binary string replace invalidate caches list integer indices all indices search if indices size 0 return ensure capacity b remaining indices size replace length search length byte buffer replace buffer replace as byte buffer replace buffer mark b mark int offset 0 for integer i indices shuffle i offset search length i offset replace length b position b position i offset b put replace buffer offset replace length search length replace buffer reset b reset
replaces all occurences of search with replace in this binary string
public boolean region matches int toffset binary string other int ooffset int len return region matches false toffset other ooffset len
tests to see if the regions in this binary string and other match
public boolean region matches boolean ignore case int toffset binary string other int ooffset int len if ignore case return substring toffset toffset len equals ignore case other substring ooffset ooffset len else return substring toffset toffset len equals other substring ooffset ooffset len
tests to see if the regions in this binary string and other match
public int length if b remaining 1 synchronized b b remaining b remaining return b remaining
gets the current length of this binary string
public boolean starts with binary string prefix int offset if prefix length length offset return false byte buffer prefix buffer prefix as byte buffer byte buffer c synchronized b c b duplicate offset c position for int i offset prefix buffer has remaining i if c get i prefix buffer get return false return true
checks to see if this binary string starts at offset with prefix
public boolean ends with binary string postfix if postfix length length return false byte buffer postfix buffer postfix as byte buffer byte buffer c synchronized b c b duplicate for int i c limit postfix length postfix buffer has remaining i if c get i postfix buffer get return false return true
checks to see if this binary string ends with postfix
public boolean starts with binary string prefix return starts with prefix 0
checks to see if this binary string starts with prefix
public void substring in place int begin index int end index if begin index 0 end index begin index end index length throw out of bounds exception throw new index out of bounds exception invalidate caches b limit b position end index b position b position begin index
converts this binary string to the specified substring in place to save memory