com.thimbleware.jmemcached
Class ServerSessionHandler

java.lang.Object
  extended by com.thimbleware.jmemcached.ServerSessionHandler
All Implemented Interfaces:
org.apache.mina.common.IoHandler

public final class ServerSessionHandler
extends java.lang.Object
implements org.apache.mina.common.IoHandler

The heart of the daemon, responsible for handling the creation and destruction of network sessions, keeping cache statistics, and (most importantly) processing inbound (parsed) commands and then passing on a response message for output.


Field Summary
static long bytes_read
           
static long bytes_written
           
protected  Cache cache
           
static long curr_bytes
           
 int curr_conns
           
static java.nio.charset.CharsetEncoder ENCODER
           
 int idle_limit
           
 int started
           
 int total_conns
           
 boolean verbose
           
 java.lang.String version
           
 
Constructor Summary
ServerSessionHandler(Cache cache, java.lang.String memcachedVersion, boolean verbosity, int idle)
          Construct the server session handler
 
Method Summary
protected  java.lang.String add(MCElement e)
          Add an element to the cache
protected  java.lang.String delete(java.lang.String key, int time)
          Handle the deletion of an item from the cache.
 void exceptionCaught(org.apache.mina.common.IoSession session, java.lang.Throwable cause)
          Triggered when an exception is caught by the protocol handler
protected  boolean flush_all()
          Flush all cache entries
protected  java.lang.String flush_all(int expire)
          Flush all cache entries with a timestamp after a given expiration time
protected  java.lang.String get_add(java.lang.String key, int mod)
          Increment an (integer) element inthe cache
protected  MCElement get(java.lang.String key)
          Get an element from the cache
protected  void initStats()
          Initialize all statistic counters
protected  boolean is_there(java.lang.String key)
          Check whether an element is in the cache and non-expired
 void messageReceived(org.apache.mina.common.IoSession session, java.lang.Object message)
          Handle the reception of an inbound command, which has already been pre-processed by the CommandDecoder.
 void messageSent(org.apache.mina.common.IoSession session, java.lang.Object message)
          Called on message delivery.
protected  int Now()
           
protected  java.lang.String replace(MCElement e)
          Replace an element in the cache
 void sessionClosed(org.apache.mina.common.IoSession session)
          Handle the closing of a session.
 void sessionCreated(org.apache.mina.common.IoSession session)
          Handle the creation of a new protocol session.
 void sessionIdle(org.apache.mina.common.IoSession session, org.apache.mina.common.IdleStatus status)
          Triggered when a session has gone idle.
 void sessionOpened(org.apache.mina.common.IoSession session)
          Handle the opening of a new session.
protected  java.lang.String set(MCElement e)
          Set an element in the cache
protected  java.lang.String stat(java.lang.String arg)
          Return runtime statistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public java.lang.String version

curr_conns

public int curr_conns

total_conns

public int total_conns

started

public int started

bytes_read

public static long bytes_read

bytes_written

public static long bytes_written

curr_bytes

public static long curr_bytes

idle_limit

public int idle_limit

verbose

public boolean verbose

ENCODER

public static java.nio.charset.CharsetEncoder ENCODER

cache

protected Cache cache
Constructor Detail

ServerSessionHandler

public ServerSessionHandler(Cache cache,
                            java.lang.String memcachedVersion,
                            boolean verbosity,
                            int idle)
Construct the server session handler

Parameters:
cache - the cache to use
memcachedVersion - the version string to return to clients
verbosity - verbosity level for debugging
idle - how long sessions can be idle for
Method Detail

sessionCreated

public void sessionCreated(org.apache.mina.common.IoSession session)
Handle the creation of a new protocol session.

Specified by:
sessionCreated in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session object

sessionOpened

public void sessionOpened(org.apache.mina.common.IoSession session)
Handle the opening of a new session.

Specified by:
sessionOpened in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session object

sessionClosed

public void sessionClosed(org.apache.mina.common.IoSession session)
Handle the closing of a session.

Specified by:
sessionClosed in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session object

messageReceived

public void messageReceived(org.apache.mina.common.IoSession session,
                            java.lang.Object message)
                     throws java.nio.charset.CharacterCodingException
Handle the reception of an inbound command, which has already been pre-processed by the CommandDecoder.

Specified by:
messageReceived in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session
message - the message itself
Throws:
java.nio.charset.CharacterCodingException

messageSent

public void messageSent(org.apache.mina.common.IoSession session,
                        java.lang.Object message)
Called on message delivery.

Specified by:
messageSent in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session
message - the message sent

sessionIdle

public void sessionIdle(org.apache.mina.common.IoSession session,
                        org.apache.mina.common.IdleStatus status)
Triggered when a session has gone idle.

Specified by:
sessionIdle in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session
status - the idle status

exceptionCaught

public void exceptionCaught(org.apache.mina.common.IoSession session,
                            java.lang.Throwable cause)
Triggered when an exception is caught by the protocol handler

Specified by:
exceptionCaught in interface org.apache.mina.common.IoHandler
Parameters:
session - the MINA session
cause - the exception

delete

protected java.lang.String delete(java.lang.String key,
                                  int time)
Handle the deletion of an item from the cache.

Parameters:
key - the key for the item
time - only delete the element if time (time in seconds)
Returns:
the message response

add

protected java.lang.String add(MCElement e)
Add an element to the cache

Parameters:
e - the element to add
Returns:
the message response string

replace

protected java.lang.String replace(MCElement e)
Replace an element in the cache

Parameters:
e - the element to replace
Returns:
the message response string

set

protected java.lang.String set(MCElement e)
Set an element in the cache

Parameters:
e - the element to set
Returns:
the message response string

get_add

protected java.lang.String get_add(java.lang.String key,
                                   int mod)
Increment an (integer) element inthe cache

Parameters:
key - the key to increment
mod - the amount to add to the value
Returns:
the message response

is_there

protected boolean is_there(java.lang.String key)
Check whether an element is in the cache and non-expired

Parameters:
key - the key for the element to lookup
Returns:
whether the element is in the cache and is live

get

protected MCElement get(java.lang.String key)
Get an element from the cache

Parameters:
key - the key for the element to lookup
Returns:
the element, or 'null' in case of cache miss.

Now

protected final int Now()
Returns:
the current time in seconds (from epoch), used for expiries, etc.

initStats

protected void initStats()
Initialize all statistic counters


stat

protected java.lang.String stat(java.lang.String arg)
Return runtime statistics

Parameters:
arg - additional arguments to the stats command
Returns:
the full command response

flush_all

protected boolean flush_all()
Flush all cache entries

Returns:
command response

flush_all

protected java.lang.String flush_all(int expire)
Flush all cache entries with a timestamp after a given expiration time

Parameters:
expire - the flush time in seconds
Returns:
command response


Copyright © 2008. All Rights Reserved.