Class WorldManager

java.lang.Object
org.vrspace.server.core.WorldManager

@Component("world") @DependsOn("database") public class WorldManager extends Object
Main component that manages all interactions with virtual worlds.
Author:
joe
  • Field Details

    • config

      @Autowired protected ServerConfig config
    • worldConfig

      @Autowired protected WorldConfig worldConfig
    • sceneProperties

      @Autowired protected SceneProperties sceneProperties
    • jackson

      @Autowired @Qualifier("objectMapper") protected com.fasterxml.jackson.databind.ObjectMapper jackson
    • privateJackson

      @Autowired @Qualifier("privateMapper") protected com.fasterxml.jackson.databind.ObjectMapper privateJackson
    • clientFactory

      @Autowired protected ClientFactory clientFactory
    • dispatcher

      protected Dispatcher dispatcher
    • sessionTracker

      protected SessionTracker sessionTracker
    • cache

      protected ConcurrentHashMap<ID,Entity> cache
  • Constructor Details

    • WorldManager

      public WorldManager()
  • Method Details

    • init

      @PostConstruct public void init()
    • get

      public VRObject get(ID id)
      Get a cached VRObject
      Parameters:
      id -
      Returns:
    • get

      public <T extends VRObject> T get(Class<T> cls, String id)
    • find

      public List<Entity> find(Predicate<? super Entity> filter)
      Find some objects, in-memory operation on cache.
      Parameters:
      filter - Predicate to select objects, e.g. o->o.isActive()
      Returns:
    • listClasses

      public List<Class<?>> listClasses()
    • getWorld

      public World getWorld(String name)
    • getOrCreateWorld

      public World getOrCreateWorld(String name)
    • saveWorld

      public World saveWorld(World world)
    • deleteWorld

      protected void deleteWorld(World world)
    • getClient

      public Client getClient(String id)
    • getClientByName

      public Client getClientByName(String name)
    • getCachedClient

      public Client getCachedClient(Client c)
      If the client is currently active, cached version of the client, otherwise null
    • getClientByName

      public <T extends Client> T getClientByName(String name, Class<T> cls)
    • save

      public <T extends VRObject> T save(T obj)
    • getRange

      public Set<VRObject> getRange(Client client, Point from, Point to)
    • getPermanents

      public Set<VRObject> getPermanents(Client client)
    • add

      public VRObject add(Client client, VRObject o)
      Add an object to client's current position
      Parameters:
      client - Client adding objects
      o - A VRObject
      Returns:
      saved VRObject
    • isOwner

      public boolean isOwner(Client client, VRObject o)
    • add

      public List<VRObject> add(Client client, List<VRObject> objects)
      Add objects to client's current position
      Parameters:
      client - client adding objects
      objects - objects to add
      Returns:
      list of added objects
    • remove

      public void remove(Client client, VRObject obj)
    • login

      @Transactional public Welcome login(org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator session)
      Remote user login over websocket. Called from SessionManager, after websocket session has been established. Uses session security context (principal) to identify user and fetch/create the appropriate Client object from the ClientFactory. May create a new guest client, if guest (anonymous) connections are allowed.
      Parameters:
      session - websocket session
      Returns:
      Welcome message
    • serverLogin

      @Transactional public Welcome serverLogin(org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator session)
      Login for remote servers
      See Also:
    • login

      @Transactional public Welcome login(org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator session, Class<? extends Client> clientClass)
      Common login procedure for both users and remote servers. This may change, same for the time being.
      Parameters:
      session - web socket session
      clientClass - either User or RemoteServer
      clientFactory - either userFactory or serverFactory
      Returns:
      See Also:
    • login

      public void login(Client client)
      Stage 2 of login, executed once client has been identified. Does not depend on websocket session, can be used for internal login, e.g. bots. Sets internal variables on the client, including new instance of scene properties with default values.
    • enter

      public Welcome enter(Client client, String worldName)
    • enter

      public Welcome enter(Client client, World world)
    • startSession

      public int startSession(Client client) throws SessionException
      The client has set own properties, entered a world, and going online. Starting a session sets client active flag, and creates the scene for the client by calling createScene() method of the Client implementation.
      Parameters:
      client - a connected Client, typically User, that starts the session
      Returns:
      scene size
      Throws:
      SessionException - if the client with the same name but different id already exists
    • logout

      @Transactional public void logout(Client client)
      Called by SessionManager after the client closes the web socket
    • dispatch

      @Transactional public void dispatch(VREvent event) throws Exception
      Throws:
      Exception
    • getStreamManager

      public StreamManager getStreamManager()
      CHECKME Commands need access to StreamManager
      Returns:
      StreamManager
    • getDb

      public VRObjectRepository getDb()
      CHECKME Commands need access to database
      Returns:
      VRObjectRepository
    • worldFactory

      public WorldFactory worldFactory()
      Returns:
      world factory