Package com.cloud.clientpak
Class Connection
java.lang.Object
com.cloud.clientpak.Connection
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate ControllerApplication controller.private CountDownLatchSynchronization object, used when starting a connection, linked to the user's main GUI application.private io.netty.channel.ChannelThe current connection.private final StringServer address.private final intServer port. -
Constructor Summary
ConstructorsConstructorDescriptionConnection(Controller controller, CountDownLatch countDownLatch) The constructor saves a reference to the application controller and the synchronization object. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection channel.voidOpens a network connection.voidrun()Calls the method of opening a network connection, in a separate thread.io.netty.channel.ChannelFuturesend(AbstractMessage msg) Sends the message object through the current connection channel to the Netty pipeline.
-
Field Details
-
SERVER_ADDR
Server address.- See Also:
-
SERVER_PORT
private final int SERVER_PORTServer port.- See Also:
-
controller
Application controller. -
currentChannel
private io.netty.channel.Channel currentChannelThe current connection. -
countDownLatch
Synchronization object, used when starting a connection, linked to the user's main GUI application.
-
-
Constructor Details
-
Connection
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. -
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:
-
ObjectDecoderObjectEncoderMainHandlerBootstrap
-
send
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.
-