Class Connection

java.lang.Object
com.cloud.clientpak.Connection
All Implemented Interfaces:
Runnable

public class Connection extends Object implements Runnable
Class describing the network connection, openConnection(). The connection must be opened in a separate thread, so as not to interfere with the operation of the application.
  • Field Details

    • SERVER_ADDR

      private final String SERVER_ADDR
      Server address.
      See Also:
    • SERVER_PORT

      private final int SERVER_PORT
      Server port.
      See Also:
    • controller

      private Controller controller
      Application controller.
    • currentChannel

      private io.netty.channel.Channel currentChannel
      The current connection.
    • countDownLatch

      private CountDownLatch countDownLatch
      Synchronization object, used when starting a connection, linked to the user's main GUI application.
  • Constructor Details

    • Connection

      public Connection(Controller controller, CountDownLatch countDownLatch)
      The constructor saves a reference to the application controller and the synchronization object.
      Parameters:
      controller - application controller.
      countDownLatch - synchronization object.
  • Method Details

    • run

      public void run()
      Calls the method of opening a network connection, in a separate thread.
      Specified by:
      run in interface Runnable
    • openConnection

      public void openConnection()
      Opens a network connection. Starts the Netty client. When configuring the client defines the pool of processing threads, the address and port of the server, builds a pipeline of handlers incoming and outgoing data. In this case, the serializer and deserializer are used objects, as well as the main listener having a link to the application controller.
      See Also:
    • send

      public io.netty.channel.ChannelFuture send(AbstractMessage msg)
      Sends the message object through the current connection channel to the Netty pipeline.
      Parameters:
      msg - Message.
      Returns:
      The current connection channel.
    • close

      public void close()
      Closes the connection channel.