org.vrspace.server
Class Dispatcher

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

public class Dispatcher
extends java.util.Observable

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  java.lang.Object clientsSync
           
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
 void addClient(Client c)
           
 void addTransformToScene(Transform t)
           
protected  void buildDefaultDatabase(DB db)
           
 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!
 java.lang.Object[] getAll(java.lang.String className)
          Returns all objects of class className
 VRObject getByName(Client c, 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!
 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!
 java.util.HashSet getClientsOnline()
          To allow VRObjects to get a list of the clients that are online.
 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(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
protected  void logout(Client c, Session s, boolean relogin)
          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 removeClient(Client c)
           
 void removeTransform(Client c, Transform t)
          Remove a Transform from the database.
 void removeTransformFromScene(Transform t)
           
 void request(Request r)
          Process request from the client.
 void requestSceneUpdates()
          Request scene updates for all clients.
Most likely inapropriate to be located in the dispatcher, but for now the dispatcher is the most centralized object.
protected  void shutdown()
          Called from server upon shutdown
 void updateScene()
           
 
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

space

protected DB space

clients

protected java.util.HashSet clients

clientsSync

protected java.lang.Object clientsSync

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

buildDefaultDatabase

protected void buildDefaultDatabase(DB db)

init

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


getServer

public Server getServer(Client c)
Returns server instance


getClientsOnline

public java.util.HashSet getClientsOnline()
To allow VRObjects to get a list of the clients that are online. Security Breach possible...


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!

Throws:
java.lang.Exception

getByName

public VRObject getByName(Client c,
                          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!

Throws:
java.lang.Exception

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!

Throws:
java.lang.Exception

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!

Throws:
java.lang.Exception

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!

Throws:
java.lang.Exception

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!

Throws:
java.lang.Exception

getTransform

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

Throws:
java.lang.Exception

removeTransformFromScene

public void removeTransformFromScene(Transform t)
                              throws java.lang.Exception
Throws:
java.lang.Exception

addTransformToScene

public void addTransformToScene(Transform t)
                         throws java.lang.Exception
Throws:
java.lang.Exception

updateScene

public void updateScene()
                 throws java.lang.Exception
Throws:
java.lang.Exception

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!

Throws:
java.lang.Exception

putTransform

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

Throws:
java.lang.Exception

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.

Throws:
java.lang.Exception
See Also:
VRObjectComparator, TransformComparator

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

Throws:
java.lang.Exception

getAll

public java.lang.Object[] getAll(java.lang.String className)
                          throws java.lang.Exception
Returns all objects of class className

Throws:
java.lang.Exception

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

Throws:
RequestException

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.

Throws:
java.lang.Exception

logout

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


logout

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


addClient

public void addClient(Client c)

removeClient

public void removeClient(Client c)

shutdown

protected void shutdown()
Called from server upon shutdown


requestSceneUpdates

public void requestSceneUpdates()
Request scene updates for all clients.
Most likely inapropriate to be located in the dispatcher, but for now the dispatcher is the most centralized object.