Skip to content

Commit 168ee82

Browse files
committed
优化注释
1 parent 9fab08e commit 168ee82

File tree

4 files changed

+169
-106
lines changed

4 files changed

+169
-106
lines changed

__test/pom.xml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,36 +312,41 @@
312312
<!-- </dependency>-->
313313

314314

315-
<!-- <dependency>-->
316-
<!-- <groupId>org.noear</groupId>-->
317-
<!-- <artifactId>solon-server-tomcat-jakarta</artifactId>-->
318-
<!-- </dependency>-->
315+
<dependency>
316+
<groupId>org.noear</groupId>
317+
<artifactId>solon-server-tomcat-jakarta</artifactId>
318+
</dependency>
319319

320-
<!-- <dependency>-->
321-
<!-- <groupId>org.noear</groupId>-->
322-
<!-- <artifactId>solon-server-tomcat-add-jsp-jakarta</artifactId>-->
323-
<!-- </dependency>-->
320+
<dependency>
321+
<groupId>org.noear</groupId>
322+
<artifactId>solon-server-tomcat-add-jsp-jakarta</artifactId>
323+
</dependency>
324+
325+
<dependency>
326+
<groupId>org.noear</groupId>
327+
<artifactId>solon-server-tomcat-add-websocket-jakarta</artifactId>
328+
</dependency>
324329

325330
<!-- <dependency>-->
326331
<!-- <groupId>org.noear</groupId>-->
327332
<!-- <artifactId>solon-server-undertow-jakarta</artifactId>-->
328333
<!-- </dependency>-->
329334

330335

331-
<dependency>
332-
<groupId>org.noear</groupId>
333-
<artifactId>solon-server-jetty-jakarta</artifactId>
334-
</dependency>
336+
<!-- <dependency>-->
337+
<!-- <groupId>org.noear</groupId>-->
338+
<!-- <artifactId>solon-server-jetty-jakarta</artifactId>-->
339+
<!-- </dependency>-->
335340

336-
<dependency>
337-
<groupId>org.noear</groupId>
338-
<artifactId>solon-server-jetty-add-websocket-jakarta</artifactId>
339-
</dependency>
341+
<!-- <dependency>-->
342+
<!-- <groupId>org.noear</groupId>-->
343+
<!-- <artifactId>solon-server-jetty-add-websocket-jakarta</artifactId>-->
344+
<!-- </dependency>-->
340345

341-
<dependency>
342-
<groupId>org.noear</groupId>
343-
<artifactId>solon-server-jetty-add-jsp-jakarta</artifactId>
344-
</dependency>
346+
<!-- <dependency>-->
347+
<!-- <groupId>org.noear</groupId>-->
348+
<!-- <artifactId>solon-server-jetty-add-jsp-jakarta</artifactId>-->
349+
<!-- </dependency>-->
345350

346351

347352
<dependency>
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
/*
2+
* Copyright 2017-2025 noear.org and authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.noear.solon.server.tomcat.websocket;
217

3-
import java.net.InetSocketAddress;
418
import java.nio.ByteBuffer;
5-
import java.util.concurrent.Future;
619

720
import org.noear.solon.net.websocket.WebSocket;
8-
import org.noear.solon.net.websocket.WebSocketBase;
921
import org.noear.solon.net.websocket.WebSocketRouter;
10-
import org.slf4j.Logger;
11-
import org.slf4j.LoggerFactory;
1222

1323
import jakarta.websocket.CloseReason;
1424
import jakarta.websocket.Endpoint;
@@ -19,6 +29,8 @@
1929
/**
2030
* Tomcat WebSocket端点实现
2131
*
32+
* @author 小xu中年
33+
* @since 3.7
2234
*/
2335
public class TcWebSocketEndpoint extends Endpoint {
2436
private final String SESSION_KEY = "session";
@@ -52,7 +64,7 @@ public void onError(Session session, Throwable thr) {
5264
}
5365

5466
private static class TextMessageHandler implements MessageHandler.Whole<String> {
55-
private WebSocket socket;
67+
private final WebSocket socket;
5668

5769
public TextMessageHandler(WebSocket socket) {
5870
this.socket = socket;
@@ -69,7 +81,7 @@ public void onMessage(String s) {
6981
}
7082

7183
private static class BufferMessageHandler implements MessageHandler.Whole<ByteBuffer> {
72-
private WebSocket socket;
84+
private final WebSocket socket;
7385

7486
public BufferMessageHandler(WebSocket socket) {
7587
this.socket = socket;
@@ -84,80 +96,4 @@ public void onMessage(ByteBuffer s) {
8496
}
8597
}
8698
}
87-
88-
private static class WebSocketImpl extends WebSocketBase {
89-
private static final Logger log = LoggerFactory.getLogger(WebSocketImpl.class);
90-
private Session real;
91-
92-
public WebSocketImpl(Session real) {
93-
this.real = real;
94-
this.init(real.getRequestURI());
95-
}
96-
97-
@Override
98-
public boolean isValid() {
99-
return isClosed() == false && real.isOpen();
100-
}
101-
102-
@Override
103-
public boolean isSecure() {
104-
return real.isSecure();
105-
}
106-
107-
@Override
108-
public InetSocketAddress remoteAddress() {
109-
// Tomcat的Session不直接提供远程地址,这里返回null
110-
return null;
111-
}
112-
113-
@Override
114-
public InetSocketAddress localAddress() {
115-
// Tomcat的Session不直接提供本地地址,这里返回null
116-
return null;
117-
}
118-
119-
@Override
120-
public long getIdleTimeout() {
121-
return real.getMaxIdleTimeout();
122-
}
123-
124-
@Override
125-
public void setIdleTimeout(long idleTimeout) {
126-
real.setMaxIdleTimeout(idleTimeout);
127-
}
128-
129-
@Override
130-
public Future<Void> send(String text) {
131-
return real.getAsyncRemote().sendText(text);
132-
}
133-
134-
@Override
135-
public Future<Void> send(ByteBuffer binary) {
136-
return real.getAsyncRemote().sendBinary(binary);
137-
}
138-
139-
@Override
140-
public void close() {
141-
super.close();
142-
try {
143-
real.close();
144-
} catch (Throwable ignore) {
145-
if (log.isDebugEnabled()) {
146-
log.debug("Close failure: {}", ignore.getMessage());
147-
}
148-
}
149-
}
150-
151-
@Override
152-
public void close(int code, String reason) {
153-
super.close(code, reason);
154-
try {
155-
real.close(new CloseReason(CloseReason.CloseCodes.getCloseCode(code), reason));
156-
} catch (Throwable ignore) {
157-
if (log.isDebugEnabled()) {
158-
log.debug("Close failure: {}", ignore.getMessage());
159-
}
160-
}
161-
}
162-
}
16399
}

solon-jakarta-projects/solon-server/solon-server-tomcat-jakarta/src/main/java/org/noear/solon/server/tomcat/websocket/TcWebSocketManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2017-2025 noear.org and authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.noear.solon.server.tomcat.websocket;
217

318
import java.util.Collection;
@@ -13,9 +28,9 @@
1328

1429
/**
1530
* Tomcat WebSocket 管理器
16-
*
17-
* @author noear
18-
* @since 3.7.3
31+
*
32+
* @author 小xu中年
33+
* @since 3.7
1934
*/
2035
public class TcWebSocketManager {
2136
private static final Logger log = LoggerFactory.getLogger(TcWebSocketManager.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2017-2025 noear.org and authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.noear.solon.server.tomcat.websocket;
17+
18+
import jakarta.websocket.CloseReason;
19+
import jakarta.websocket.Session;
20+
import org.noear.solon.net.websocket.WebSocketBase;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
import java.net.InetSocketAddress;
25+
import java.nio.ByteBuffer;
26+
import java.util.concurrent.Future;
27+
28+
/**
29+
*
30+
* @author 小xu中年
31+
* @since 3.7
32+
* */
33+
public class WebSocketImpl extends WebSocketBase {
34+
private static final Logger log = LoggerFactory.getLogger(WebSocketImpl.class);
35+
private Session real;
36+
37+
public WebSocketImpl(Session real) {
38+
this.real = real;
39+
this.init(real.getRequestURI());
40+
}
41+
42+
@Override
43+
public boolean isValid() {
44+
return isClosed() == false && real.isOpen();
45+
}
46+
47+
@Override
48+
public boolean isSecure() {
49+
return real.isSecure();
50+
}
51+
52+
@Override
53+
public InetSocketAddress remoteAddress() {
54+
// Tomcat的Session不直接提供远程地址,这里返回null
55+
return null;
56+
}
57+
58+
@Override
59+
public InetSocketAddress localAddress() {
60+
// Tomcat的Session不直接提供本地地址,这里返回null
61+
return null;
62+
}
63+
64+
@Override
65+
public long getIdleTimeout() {
66+
return real.getMaxIdleTimeout();
67+
}
68+
69+
@Override
70+
public void setIdleTimeout(long idleTimeout) {
71+
real.setMaxIdleTimeout(idleTimeout);
72+
}
73+
74+
@Override
75+
public Future<Void> send(String text) {
76+
return real.getAsyncRemote().sendText(text);
77+
}
78+
79+
@Override
80+
public Future<Void> send(ByteBuffer binary) {
81+
return real.getAsyncRemote().sendBinary(binary);
82+
}
83+
84+
@Override
85+
public void close() {
86+
super.close();
87+
try {
88+
real.close();
89+
} catch (Throwable ignore) {
90+
if (log.isDebugEnabled()) {
91+
log.debug("Close failure: {}", ignore.getMessage());
92+
}
93+
}
94+
}
95+
96+
@Override
97+
public void close(int code, String reason) {
98+
super.close(code, reason);
99+
try {
100+
real.close(new CloseReason(CloseReason.CloseCodes.getCloseCode(code), reason));
101+
} catch (Throwable ignore) {
102+
if (log.isDebugEnabled()) {
103+
log.debug("Close failure: {}", ignore.getMessage());
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)