Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.vrspace.server
Class Session  view Session download Session.java

java.lang.Object
  extended byjava.util.Observable
      extended byorg.vrspace.server.Session
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
BinarySession, PipedSession

public class Session
extends java.util.Observable
implements java.lang.Runnable

A Session is constructed and started when a client connects to the server.
If client authenticates passes, session calls Dispatcher.login()
Should it be a OwnedDBObject? Could we store session state then?


Nested Class Summary
 class Session.Status
          Session status info
 
Field Summary
protected  boolean active
           
protected  boolean cacheRequests
           
protected  Client client
           
protected  boolean daemon
           
protected  Dispatcher dispatcher
           
protected  long lastTime
           
protected  java.lang.String lf
           
private  java.lang.String login
           
private  java.lang.String password
           
private  java.io.BufferedReader reader
           
protected  long receivedChars
           
protected  long receivedRequests
           
private  java.util.LinkedList requests
           
static java.lang.String RESPONSE_ERR
           
static java.lang.String RESPONSE_NONE
           
static java.lang.String RESPONSE_OK
           
protected  long sentChars
           
protected  long sentRequests
           
protected  Server server
           
protected  java.net.Socket socket
           
protected  long startTime
           
protected  long stopTime
           
static char TERMINATOR
           
protected  java.io.PrintWriter writer
           
 
Fields inherited from class java.util.Observable
 
Constructor Summary
protected Session()
           
  Session(Server server, java.net.Socket s, Dispatcher d)
          Constructor, called by Server
 
Method Summary
 void close()
          end session
 void flushRequests()
          flush cached requests
 java.lang.String getId()
          Returns the session id in format remoteHost:remotePort
 Session.Status getStatus()
          Returns session status
 boolean isActive()
          active?
protected  java.lang.String read()
          Returns one line read from the network.
protected  void readln()
          Reads lines from the socket and calls Client.request().
 void run()
          Main loop, started from Server.
 void sendError(Request r)
          write( "-"+ r ) - ERROR response to a request
 void sendRequest(Request r)
          Sends a request to the client
 void sendResponse(Request r)
          write( "+"+ r ) - OK response to a request
protected  void write(java.lang.String type, org.vrspace.util.Message r)
          Sends response r of type type to the client, appending TERMINATOR as necessary.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSE_OK

public static final java.lang.String RESPONSE_OK
See Also:
Constant Field Values

RESPONSE_ERR

public static final java.lang.String RESPONSE_ERR
See Also:
Constant Field Values

RESPONSE_NONE

public static final java.lang.String RESPONSE_NONE
See Also:
Constant Field Values

socket

protected java.net.Socket socket

dispatcher

protected Dispatcher dispatcher

client

protected Client client

reader

private java.io.BufferedReader reader

writer

protected java.io.PrintWriter writer

TERMINATOR

public static final char TERMINATOR
See Also:
Constant Field Values

login

private java.lang.String login

password

private java.lang.String password

active

protected boolean active

cacheRequests

protected boolean cacheRequests

requests

private java.util.LinkedList requests

lf

protected java.lang.String lf

sentChars

protected long sentChars

sentRequests

protected long sentRequests

receivedChars

protected long receivedChars

receivedRequests

protected long receivedRequests

startTime

protected long startTime

stopTime

protected long stopTime

lastTime

protected long lastTime

daemon

protected boolean daemon

server

protected Server server
Constructor Detail

Session

protected Session()

Session

public Session(Server server,
               java.net.Socket s,
               Dispatcher d)
        throws java.lang.Exception
Constructor, called by Server

Method Detail

run

public void run()
Main loop, started from Server. After authentication, calls readln() method which actualy reads the data during the session.

Specified by:
run in interface java.lang.Runnable

readln

protected void readln()
Reads lines from the socket and calls Client.request(). Uses read() method to read one line from the client.


read

protected java.lang.String read()
                         throws java.io.IOException,
                                org.vrspace.util.ConnectionException
Returns one line read from the network.


write

protected void write(java.lang.String type,
                     org.vrspace.util.Message r)
Sends response r of type type to the client, appending TERMINATOR as necessary.


sendResponse

public void sendResponse(Request r)
write( "+"+ r ) - OK response to a request


sendError

public void sendError(Request r)
write( "-"+ r ) - ERROR response to a request


sendRequest

public void sendRequest(Request r)
Sends a request to the client


flushRequests

public void flushRequests()
flush cached requests


close

public void close()
end session


getId

public java.lang.String getId()
Returns the session id in format remoteHost:remotePort


isActive

public boolean isActive()
active?


getStatus

public Session.Status getStatus()
Returns session status