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

Quick Search    Search Deep

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

java.lang.Object
  extended byorg.vrspace.server.Dispatcher
Direct Known Subclasses:
ProxyDispatcher

public class Dispatcher
extends java.lang.Object

Main class responsible for event dispatching. It's also a DBManager.


Nested Class Summary
 class Dispatcher.DaemonLoader
           
 
Field Summary
protected  java.util.HashSet clients
           
protected  long daemonSessions
           
protected  boolean initialized
           
protected  long receivedBytes
           
protected  long receivedChars
           
protected  long receivedRequests
           
protected  long sentBytes
           
protected  long sentChars
           
protected  long sentRequests
           
protected  Server server
           
protected  DB space
           
protected  long startTime
           
 
Constructor Summary
protected Dispatcher()
           
  Dispatcher(Server s, DB db)
          Constructs new Dispatcher for Server s and database db
 
Method Summary
 VRObject get(Client c, java.lang.String className, long id)
          Fetch an object from the database.
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be retreived!
(package private)  AuthInfo getAuthInfo(Client c)
          Retreives Authinfo for the client.
 VRObject getByName(Client c, java.lang.String className, java.lang.String name)
          Fetch an object from the database having field name equal to name parameter
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be retreived!
 DB getDB(Client c)
          Returns the reference to the database.
 java.lang.Object[] getRange(Client c, java.lang.String className, java.lang.String field, java.lang.Object value)
          Returns the object of className class having field == value
 java.lang.Object[] getRange(Client c, VRObject o1, VRObject o2)
          Returns Object[] between o1 and o2 Class must have comparator() method to be searchable.
 Server getServer(Client c)
          Returns server instance
 Transform getTransform(org.vrspace.attributes.HasTransform o)
          Returns parent Transform of o
protected  void init()
          Initialize dispatcher - loads permanent Transforms and starts daemons
 Client login(Session session, java.lang.String login, java.lang.String password, boolean daemon)
          Constructs a new client object.
protected  void logout(Client c, Session s)
          Logout Client c from Session s
 void put(Client c, VRObject obj)
          Store an object to the database.
 void putTransform(Client c, Transform t)
          Add a Transform from the database.
 void remove(Client c, java.lang.String className, long id)
          Remove an object from the database.
 void remove(Client c, VRObject obj)
          Remove an object from the database.
 void removeTransform(Client c, Transform t)
          Remove a Transform from the database.
 void request(Request r)
          Process request from the client.
protected  void shutdown()
          Called from server upon shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

space

protected DB space

clients

protected java.util.HashSet clients

sentChars

protected long sentChars

receivedChars

protected long receivedChars

startTime

protected long startTime

sentRequests

protected long sentRequests

receivedRequests

protected long receivedRequests

sentBytes

protected long sentBytes

receivedBytes

protected long receivedBytes

daemonSessions

protected long daemonSessions

server

protected Server server

initialized

protected boolean initialized
Constructor Detail

Dispatcher

protected Dispatcher()

Dispatcher

public Dispatcher(Server s,
                  DB db)
Constructs new Dispatcher for Server s and database db

Method Detail

init

protected void init()
Initialize dispatcher - loads permanent Transforms and starts daemons


getServer

public Server getServer(Client c)
Returns server instance


getAuthInfo

AuthInfo getAuthInfo(Client c)
               throws java.lang.Exception
Retreives Authinfo for the client. Intended for bots/daemons, available only to classes withing this package.


get

public VRObject get(Client c,
                    java.lang.String className,
                    long id)
             throws java.lang.Exception
Fetch an object from the database.
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be retreived!


getByName

public VRObject getByName(Client c,
                          java.lang.String className,
                          java.lang.String name)
                   throws java.lang.Exception
Fetch an object from the database having field name equal to name parameter
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be retreived!


put

public void put(Client c,
                VRObject obj)
         throws java.lang.Exception
Store an object to the database.
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be stored!


remove

public void remove(Client c,
                   VRObject obj)
            throws java.lang.Exception
Remove an object from the database.
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be removed!


remove

public void remove(Client c,
                   java.lang.String className,
                   long id)
            throws java.lang.Exception
Remove an object from the database.
IMPORTANT: no protection mechanism, at least AuthInfo objects should not be removed!


getTransform

public Transform getTransform(org.vrspace.attributes.HasTransform o)
                       throws java.lang.Exception
Returns parent Transform of o


removeTransform

public void removeTransform(Client c,
                            Transform t)
                     throws java.lang.Exception
Remove a Transform from the database. Removes it's children too - use remove( Client, VRObject ) or remove( Client, String, long ) to leave it's children intact.
IMPORTANT: no protection mechanism!


putTransform

public void putTransform(Client c,
                         Transform t)
                  throws java.lang.Exception
Add a Transform from the database.
IMPORTANT: no protection mechanism!


getRange

public java.lang.Object[] getRange(Client c,
                                   VRObject o1,
                                   VRObject o2)
                            throws java.lang.Exception
Returns Object[] between o1 and o2 Class must have comparator() method to be searchable.


getRange

public java.lang.Object[] getRange(Client c,
                                   java.lang.String className,
                                   java.lang.String field,
                                   java.lang.Object value)
                            throws java.lang.Exception
Returns the object of className class having field == value


getDB

public DB getDB(Client c)
Returns the reference to the database. Only Admin client can get reference to the database.


request

public void request(Request r)
             throws RequestException
Process request from the client. Find an object, check whether client can set a variable's value. If so, set it, notify observers, update the database. If request is a command, constructs new command instance and calls exec( request )
Package search order:
"org.vrspace.command."+client class name+"."+command
"org.vrspace.command."+command


login

public Client login(Session session,
                    java.lang.String login,
                    java.lang.String password,
                    boolean daemon)
             throws java.lang.Exception
Constructs a new client object. This should look up the database, and construct new client of some class (User, Robot...) Sets Client's fields (session, authinfo, db, dispatcher, scene ). If client has transform field different than null, also looks up for appropriate Transform, and if found, calls scene.update( Transform ), and sets this client for Transform's owner.


logout

protected void logout(Client c,
                      Session s)
Logout Client c from Session s


shutdown

protected void shutdown()
Called from server upon shutdown