File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/main/java/org/java_websocket Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -220,4 +220,19 @@ enum READYSTATE {
220220 * @return Returns the decoded path component of this URI.
221221 **/
222222 String getResourceDescriptor ();
223+
224+ /**
225+ * Setter for an attachment on the socket connection.
226+ * The attachment may be of any type.
227+ *
228+ * @param attachment The object to be attached to the user
229+ **/
230+ <T > void setAttachment (T attachment );
231+
232+ /**
233+ * Getter for the connection attachment.
234+ *
235+ * @return Returns the user attachment
236+ **/
237+ <T > T getAttachment ();
223238}
Original file line number Diff line number Diff line change @@ -145,6 +145,11 @@ public class WebSocketImpl implements WebSocket {
145145 */
146146 private PingFrame pingFrame ;
147147
148+ /**
149+ * Attribute to store connection attachment
150+ */
151+ private Object attachment ;
152+
148153 /**
149154 * Creates a websocket with server role
150155 *
@@ -799,4 +804,15 @@ public WebSocketListener getWebSocketListener() {
799804 return wsl ;
800805 }
801806
807+ @ Override
808+ @ SuppressWarnings ("unchecked" )
809+ public <T > T getAttachment () {
810+ return (T ) attachment ;
811+ }
812+
813+ @ Override
814+ public <T > void setAttachment (T attachment ) {
815+ this .attachment = attachment ;
816+ }
817+
802818}
You can’t perform that action at this time.
0 commit comments