Package it.polimi.ingsw.Server
Class SocketListener
java.lang.Object
it.polimi.ingsw.Server.SocketListener
- All Implemented Interfaces:
Runnable
Given a
SocketWrapper and a BlockingQueue<ClientEvent>, moves only the ClientEvent
received on the socket to the queue.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue<ClientEvent>private final SocketWrapper -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSocketListener(SocketWrapper socket, BlockingQueue<ClientEvent> queue) Construct the listener -
Method Summary
Modifier and TypeMethodDescriptionvoidrun()Listens on theSocketWrapperfor messages, passesMessages implementingClientEventto theBlockingQueue<ClientEvent>for the server to read from.static voidsubscribe(SocketWrapper socket, BlockingQueue<ClientEvent> queue) Given a socket and a queue, generate a listener and put it to work
-
Field Details
-
socket
-
queue
-
-
Constructor Details
-
SocketListener
Construct the listener- Parameters:
socket- theSocketWrapperto poll messages fromqueue- theBlockingQueue<ClientEvent>to push events to
-
-
Method Details
-
subscribe
Given a socket and a queue, generate a listener and put it to work- Parameters:
socket- theSocketWrapperto poll messages fromqueue- theBlockingQueue<ClientEvent>to push events to
-
run
public void run()Listens on theSocketWrapperfor messages, passesMessages implementingClientEventto theBlockingQueue<ClientEvent>for the server to read from.
Note: in case of read errors from the socket, the socket will be closed and the listener terminated.
-