com.asdf.server
Class Server

java.lang.Object
  extended by com.asdf.server.Server

public class Server
extends java.lang.Object

Contains server and client socket handling functionality.


Field Summary
 boolean running
          Switch for running Can be set false from anywhere to stop execution gracefully.
 
Constructor Summary
Server()
           
 
Method Summary
 void ban(ClientConnection client)
          Ban client by IP.
 int clientsConnected()
          Get number of clients connected.
 void dispose()
          Can be called to free resources.
 AccountManager getAccountManager()
          Getter for AccountManager
 GameManager getGameManager()
          Getter for GameManager
 SessionManager getSessionManager()
          Getter for SessionManager
 void run()
          Server event loop.
 void runOnce()
          Main event loop of the server.
 void send(java.nio.channels.SocketChannel socket, java.nio.ByteBuffer data)
          Adds data to socket's queue for sending.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

running

public boolean running
Switch for running Can be set false from anywhere to stop execution gracefully.

Constructor Detail

Server

public Server()
Method Detail

run

public void run()
         throws java.io.IOException
Server event loop. Execution is looping on this loop for the whole execution time. Loop asks events from the selector and handles them accordingly.

Throws:
java.io.IOException

runOnce

public void runOnce()
             throws java.io.IOException
Main event loop of the server. Select is called continuously to catch events on server and client sockets. Events may include read, accept and write available. Only read and accept events are listened on default. Default may be overridden by add ChangeRequest to the pendingChanges queue.

Throws:
java.io.IOException

send

public void send(java.nio.channels.SocketChannel socket,
                 java.nio.ByteBuffer data)
          throws java.io.IOException
Adds data to socket's queue for sending. Selector is waken up with a wakeup call and select returns write available response in runOnce method.

Parameters:
socket -
data - Data to be sent
Throws:
java.io.IOException

clientsConnected

public int clientsConnected()
Get number of clients connected. Number of clients is number of keys on selector minus one. Minus one because serversocket's key isn't a client.

Returns:
number of clients connected

ban

public void ban(ClientConnection client)
Ban client by IP.

Parameters:
client - Client to ban

getGameManager

public GameManager getGameManager()
Getter for GameManager

Returns:
the GameManager

getAccountManager

public AccountManager getAccountManager()
Getter for AccountManager

Returns:
the AccountManager

getSessionManager

public SessionManager getSessionManager()
Getter for SessionManager

Returns:
SessionManager

dispose

public void dispose()
Can be called to free resources.