Class ConcordServer

java.lang.Object
nl.andrewl.concord_server.ConcordServer
All Implemented Interfaces:
Runnable

public class ConcordServer extends Object implements Runnable
The main server implementation, which handles accepting new clients.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ChannelManager
    Manager that handles the collection of channels in this server.
    private final ClientManager
    Manager that handles the collection of clients connected to this server.
    private final ServerConfig
    Server configuration data.
    private static final Path
    The path to this server's configuration file.
    private static final Path
    The path to this server's database file.
    private final org.dizitart.no2.Nitrite
    The database that contains all messages and other server information.
     
    private final EventManager
    Manager that handles incoming messages and events by clients.
    private final ExecutorService
    A general-purpose executor service that can be used to submit async tasks.
    private final IdProvider
    The component that generates new user and channel ids.
    private boolean
    Running flag that's used to signal this server's thread to shutdown.
     
    private final nl.andrewl.concord_core.msg.Serializer
    A utility serializer that's mostly used when preparing a message to broadcast to a set of users, which is more efficient than having each individual client thread serialize the same message before sending it.
    private final ServerSocket
    This server's socket, used to accept new client connections.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    nl.andrewl.concord_core.msg.types.ServerMetaData
     
    boolean
     
    static void
    main(String[] args)
     
    void
    run()
     
    private void
    Shuts down the server cleanly by doing the following things: Disconnecting all clients. Shutting down any executor services. Flushing and compacting the message database. Flushing the server configuration one last time.
    void
    Stops the server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CONFIG_FILE

      private static final Path CONFIG_FILE
      The path to this server's configuration file.
    • DATABASE_FILE

      private static final Path DATABASE_FILE
      The path to this server's database file.
    • running

      private volatile boolean running
      Running flag that's used to signal this server's thread to shutdown.
    • serverSocket

      private final ServerSocket serverSocket
      This server's socket, used to accept new client connections.
    • serializer

      private final nl.andrewl.concord_core.msg.Serializer serializer
      A utility serializer that's mostly used when preparing a message to broadcast to a set of users, which is more efficient than having each individual client thread serialize the same message before sending it.
    • config

      private final ServerConfig config
      Server configuration data. This is used to define channels, discovery server addresses, and more.
    • idProvider

      private final IdProvider idProvider
      The component that generates new user and channel ids.
    • db

      private final org.dizitart.no2.Nitrite db
      The database that contains all messages and other server information.
    • executorService

      private final ExecutorService executorService
      A general-purpose executor service that can be used to submit async tasks.
    • eventManager

      private final EventManager eventManager
      Manager that handles incoming messages and events by clients.
    • channelManager

      private final ChannelManager channelManager
      Manager that handles the collection of channels in this server.
    • clientManager

      private final ClientManager clientManager
      Manager that handles the collection of clients connected to this server.
    • discoveryServerPublisher

      private final DiscoveryServerPublisher discoveryServerPublisher
    • scheduledExecutorService

      private final ScheduledExecutorService scheduledExecutorService
  • Constructor Details

  • Method Details

    • isRunning

      public boolean isRunning()
      Returns:
      True if the server is currently running, meaning it is accepting connections, or false otherwise.
    • stop

      public void stop()
      Stops the server. Has no effect if the server has not started yet or has already been stopped.
    • getMetaData

      public nl.andrewl.concord_core.msg.types.ServerMetaData getMetaData()
      Returns:
      The server's metadata.
    • shutdown

      private void shutdown()
      Shuts down the server cleanly by doing the following things:
      1. Disconnecting all clients.
      2. Shutting down any executor services.
      3. Flushing and compacting the message database.
      4. Flushing the server configuration one last time.
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • main

      public static void main(String[] args) throws IOException
      Throws:
      IOException