com.lyrisoft.chat.server.remote
Class TunnelServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--javax.servlet.http.HttpServlet
|
+--com.lyrisoft.chat.server.remote.TunnelServlet
- All Implemented Interfaces:
- java.lang.Runnable, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- public class TunnelServlet
- extends javax.servlet.http.HttpServlet
- implements java.lang.Runnable
A Servlet wrapper to the ChatServer.
- See Also:
- Serialized Form
Method Summary |
ChatClient |
createChatClient(ServletConnectionHandler handler)
|
ServletConnectionHandler |
createServletConnectionHandler(javax.servlet.http.HttpServletRequest request,
java.lang.String id)
|
void |
destroy()
|
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
doGet(): invoked by the client to read waiting messages
If called without params:
we assume this is a new connection
create a new ServletConnectionHandler with a unique ID
create a new ChatClient with the ServletConnectionHandler as its handler
|
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
doPost(): invoked by the client to send a new message
|
void |
init(javax.servlet.ServletConfig config)
|
void |
pleaseStop()
|
void |
run()
|
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_chatServer
protected ChatServer _chatServer
_runner
protected java.lang.Thread _runner
_connectionHandlers
protected java.util.HashMap _connectionHandlers
TunnelServlet
public TunnelServlet()
init
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
- Overrides:
init
in class javax.servlet.GenericServlet
pleaseStop
public void pleaseStop()
run
public void run()
- Specified by:
run
in interface java.lang.Runnable
doGet
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- doGet(): invoked by the client to read waiting messages
If called without params:
- we assume this is a new connection
- create a new ServletConnectionHandler with a unique ID
- create a new ChatClient with the ServletConnectionHandler as its handler
if called with a param named ID
- assume this is an existing connection
- pull the ServletConnectionHandler for this ID out of the hashmap
- tell the ServletConnectionHandler to flush any messages that are waiting
(or block until there is at least one message and send it)
It is the client's responsibility to make a new HTTP request after this one is
finished.
- Overrides:
doGet
in class javax.servlet.http.HttpServlet
createServletConnectionHandler
public ServletConnectionHandler createServletConnectionHandler(javax.servlet.http.HttpServletRequest request,
java.lang.String id)
createChatClient
public ChatClient createChatClient(ServletConnectionHandler handler)
doPost
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- doPost(): invoked by the client to send a new message
required params:
- id: the id which the servlet assigned returned during the first invocation
of doGet()
- arg: the message to send
- Overrides:
doPost
in class javax.servlet.http.HttpServlet
destroy
public void destroy()
- Overrides:
destroy
in class javax.servlet.GenericServlet
Copyright © 2000-2002 Taso Lyristis