@@ -69,6 +69,7 @@ public void removeClient(Session session) {
6969 log .debug ("(" + name + ") Removing client: [{}]" , session .getRemoteAddress ());
7070 clientsConnected .removeIf (client -> client .session .equals (session ));
7171 clientsQuarantined .removeIf (client -> client .session .equals (session ));
72+ tenantIdsBySession .remove (session );
7273 }
7374
7475 public WsConnectContext getClient (Session session ) {
@@ -93,6 +94,10 @@ public boolean isConnected(Session session) {
9394
9495 @ Override
9596 public void onConnect (WsConnectContext ctx ) throws Exception {
97+ handleConnect (ctx );
98+ }
99+
100+ protected void handleConnect (WsConnectContext ctx ) throws Exception {
96101 log .debug ("(" + name + ") New client tries to connect: [{}]" , ctx .session .getRemoteAddress ());
97102 String token = ctx .header ("Authorization" );
98103 if (token == null || token .isEmpty ()) {
@@ -116,9 +121,10 @@ public void onConnect(WsConnectContext ctx) throws Exception {
116121
117122 @ Override
118123 public void onMsg (WsMessageContext ctx ) throws Exception {
124+ handleMessage (ctx );
119125 }
120126
121- public final void onMessage (WsMessageContext ctx ) throws Exception {
127+ protected void handleMessage (WsMessageContext ctx ) throws Exception {
122128 log .debug ("(" + name + ") Received from [{}]: [{}]" , ctx .session .getRemoteAddress (), ctx .message ());
123129 if (isQuarantined (ctx .session )) {
124130 log .warn (
@@ -152,7 +158,11 @@ public final void onMessage(WsMessageContext ctx) throws Exception {
152158 }
153159
154160 @ Override
155- public void onBinaryMessage (WsBinaryMessageContext ctx ) throws Exception {
161+ public void onBinaryMsg (WsBinaryMessageContext ctx ) throws Exception {
162+ handleBinaryMessage (ctx );
163+ }
164+
165+ protected void handleBinaryMessage (WsBinaryMessageContext ctx ) throws Exception {
156166 log .debug ("(" + name + ") Received binary message from [{}]: [{}] bytes" , ctx .session .getRemoteAddress (),
157167 ctx .data ().length );
158168 if (isQuarantined (ctx .session )) {
@@ -162,16 +172,25 @@ public void onBinaryMessage(WsBinaryMessageContext ctx) throws Exception {
162172 ctx .session .close (1000 , "(" + name + ") Unauthorized access from quarantined client" );
163173 return ;
164174 }
175+ onBinaryMsg (ctx );
165176 }
166177
167178 @ Override
168179 public void onClose (WsCloseContext ctx ) throws Exception {
180+ handleClose (ctx );
181+ }
182+
183+ protected void handleClose (WsCloseContext ctx ) throws Exception {
169184 log .debug ("(" + name + ") Disconnected client: [{}]" , ctx .session .getRemoteAddress ());
170185 removeClient (ctx .session );
171186 }
172187
173188 @ Override
174189 public void onError (WsErrorContext ctx ) throws Exception {
190+ handleError (ctx );
191+ }
192+
193+ protected void handleError (WsErrorContext ctx ) throws Exception {
175194 Throwable t = ctx .error ();
176195 if (t instanceof EOFException || t instanceof IOException ) {
177196 log .debug ("(" + name + ") Client disconnected [{}]." , ctx .session .getRemoteAddress ());
0 commit comments