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
Modifier and TypeFieldDescriptionprivate final BlockingQueue<ClientEvent>
private final SocketWrapper
-
Constructor Summary
ModifierConstructorDescriptionprivate
SocketListener
(SocketWrapper socket, BlockingQueue<ClientEvent> queue) Construct the listener -
Method Summary
Modifier and TypeMethodDescriptionvoid
run()
Listens on theSocketWrapper
for messages, passesMessage
s implementingClientEvent
to theBlockingQueue<ClientEvent>
for the server to read from.static void
subscribe
(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
- theSocketWrapper
to 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
- theSocketWrapper
to poll messages fromqueue
- theBlockingQueue<ClientEvent>
to push events to
-
run
public void run()Listens on theSocketWrapper
for messages, passesMessage
s implementingClientEvent
to 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.
-