The socket class for Socket.IO Client.
| 18 | * The socket class for Socket.IO Client. |
| 19 | */ |
| 20 | public class Socket extends Emitter { |
| 21 | |
| 22 | private static final Logger logger = Logger.getLogger(Socket.class.getName()); |
| 23 | |
| 24 | /** |
| 25 | * Called on a connection. |
| 26 | */ |
| 27 | public static final String EVENT_CONNECT = "connect"; |
| 28 | |
| 29 | /** |
| 30 | * Called on a disconnection. |
| 31 | */ |
| 32 | public static final String EVENT_DISCONNECT = "disconnect"; |
| 33 | |
| 34 | /** |
| 35 | * Called on a connection error. |
| 36 | * |
| 37 | * <p>Parameters:</p> |
| 38 | * <ul> |
| 39 | * <li>(Exception) error data.</li> |
| 40 | * </ul> |
| 41 | */ |
| 42 | public static final String EVENT_CONNECT_ERROR = "connect_error"; |
| 43 | |
| 44 | static final String EVENT_MESSAGE = "message"; |
| 45 | |
| 46 | protected static Map<String, Integer> RESERVED_EVENTS = new HashMap<String, Integer>() {{ |
| 47 | put(EVENT_CONNECT, 1); |
| 48 | put(EVENT_CONNECT_ERROR, 1); |
| 49 | put(EVENT_DISCONNECT, 1); |
| 50 | // used on the server-side |
| 51 | put("disconnecting", 1); |
| 52 | put("newListener", 1); |
| 53 | put("removeListener", 1); |
| 54 | }}; |
| 55 | |
| 56 | /*package*/ String id; |
| 57 | |
| 58 | private volatile boolean connected; |
| 59 | private int ids; |
| 60 | private final String nsp; |
| 61 | private final Manager io; |
| 62 | private final Map<String, String> auth; |
| 63 | private final Map<Integer, Ack> acks = new ConcurrentHashMap<>(); |
| 64 | private Queue<On.Handle> subs; |
| 65 | private final Queue<List<Object>> receiveBuffer = new ConcurrentLinkedQueue<>(); |
| 66 | private final Queue<Packet<JSONArray>> sendBuffer = new ConcurrentLinkedQueue<>(); |
| 67 | |
| 68 | private final ConcurrentLinkedQueue<Listener> onAnyIncomingListeners = new ConcurrentLinkedQueue<>(); |
| 69 | private final ConcurrentLinkedQueue<Listener> onAnyOutgoingListeners = new ConcurrentLinkedQueue<>(); |
| 70 | |
| 71 | public Socket(Manager io, String nsp, Manager.Options opts) { |
| 72 | this.io = io; |
| 73 | this.nsp = nsp; |
| 74 | this.auth = opts != null ? opts.auth : null; |
| 75 | } |
| 76 | |
| 77 | private void subEvents() { |
nothing calls this directly
no outgoing calls
no test coverage detected