Class AbstractReactiveServer

java.lang.Object
io.activej.reactor.AbstractNioReactive
io.activej.net.AbstractReactiveServer
All Implemented Interfaces:
ReactiveServer, WorkerServer, io.activej.reactor.jmx.ReactiveJmxBean, io.activej.reactor.jmx.ReactiveJmxBeanWithStats, io.activej.reactor.NioReactive, io.activej.reactor.Reactive
Direct Known Subclasses:
PrimaryServer, SimpleServer

public abstract class AbstractReactiveServer extends io.activej.reactor.AbstractNioReactive implements ReactiveServer, WorkerServer, io.activej.reactor.jmx.ReactiveJmxBeanWithStats
This is an implementation of ReactiveServer. It is a non-blocking server which works on top of the NIO reactor. Thus, it runs in the NIO reactor, and all events are fired on that reactor.

This is simply a higher-level wrapper around NioReactor.listen(java.net.InetSocketAddress, io.activej.reactor.net.ServerSocketSettings, java.util.function.Consumer<java.nio.channels.SocketChannel>) call.

  • Field Details

    • logger

      protected org.slf4j.Logger logger
    • serverSocketSettings

      protected io.activej.reactor.net.ServerSocketSettings serverSocketSettings
    • socketSettings

      protected io.activej.reactor.net.SocketSettings socketSettings
    • acceptOnce

      protected boolean acceptOnce
    • listenAddresses

      protected List<InetSocketAddress> listenAddresses
    • sslListenAddresses

      protected List<InetSocketAddress> sslListenAddresses
  • Constructor Details

    • AbstractReactiveServer

      protected AbstractReactiveServer(io.activej.reactor.nio.NioReactor reactor)
  • Method Details

    • serve

      protected abstract void serve(ITcpSocket socket, InetAddress remoteAddress)
    • onListen

      protected void onListen()
    • onClose

      protected void onClose(SettableCallback<Void> cb)
    • onAccept

      protected void onAccept(SocketChannel socketChannel, InetSocketAddress localAddress, InetAddress remoteAddress, boolean ssl)
    • onFilteredAccept

      protected void onFilteredAccept(SocketChannel socketChannel, InetSocketAddress localAddress, InetAddress remoteAddress, boolean ssl)
    • listen

      public final void listen() throws IOException
      Begins listening asynchronously for incoming connections. Creates an ServerSocketChannel for each listening address and registers them in NIO reactor selector. Reactor then asynchronously listens for network events and dispatches them to their listeners (us).
      Specified by:
      listen in interface ReactiveServer
      Throws:
      IOException - if the socket can not be created.
    • close

      public final Promise<?> close()
      Description copied from interface: ReactiveServer
      Closes the server. Any open channels will be closed.
      Specified by:
      close in interface ReactiveServer
    • closeFuture

      public final Future<?> closeFuture()
    • isRunning

      public final boolean isRunning()
    • closeServerSockets

      protected void closeServerSockets()
    • getWorkerServer

      protected WorkerServer getWorkerServer()
    • getSocketInspector

      protected TcpSocket.Inspector getSocketInspector(InetAddress remoteAddress, InetSocketAddress localAddress, boolean ssl)
    • doAccept

      public final void doAccept(SocketChannel socketChannel, InetSocketAddress localAddress, InetSocketAddress remoteSocketAddress, boolean ssl, io.activej.reactor.net.SocketSettings socketSettings)
      Specified by:
      doAccept in interface WorkerServer
    • getServerSocketSettings

      public io.activej.reactor.net.ServerSocketSettings getServerSocketSettings()
    • getListenAddresses

      public List<InetSocketAddress> getListenAddresses()
    • getSslListenAddresses

      public List<InetSocketAddress> getSslListenAddresses()
    • getBoundAddresses

      public List<InetSocketAddress> getBoundAddresses()
      The IP socket addresses this server is bound to after it started listening. Use this method to get the actual port numbers in case any listen address uses port 0.
    • getSslBoundAddresses

      public List<InetSocketAddress> getSslBoundAddresses()
      The IP socket addresses this server is bound to with SSL after it started listening. Use this method to get the actual port numbers in case any SSL listen address uses port 0.
    • getSocketSettings

      public io.activej.reactor.net.SocketSettings getSocketSettings()
    • getAccepts

      @Nullable public final @Nullable io.activej.jmx.stats.EventStats getAccepts()
    • getAcceptsSsl

      @Nullable public final @Nullable io.activej.jmx.stats.EventStats getAcceptsSsl()
    • getFilteredAccepts

      @Nullable public final @Nullable io.activej.jmx.stats.EventStats getFilteredAccepts()
    • getSocketStats

      @Nullable public final TcpSocket.JmxInspector getSocketStats()
    • getSocketStatsSsl

      @Nullable public final TcpSocket.JmxInspector getSocketStatsSsl()
    • toString

      public String toString()
      Overrides:
      toString in class Object