简体   繁体   English

从服务器端点内部关闭连接的最佳实践是什么?

[英]What is the best practice for closing a connection from within a server endpoint?

I have a custom configurator set up that grabs the cookie and processes it. 我有一个自定义配置器,可以抓取cookie并对其进行处理。 The output is added to the user properties on the config. 输出将添加到配置的用户属性中。

In the @OnOpen -annotated method, I compare that value with a value from the path. @OnOpen -annotated方法中,我将该值与路径中的值进行比较。 If there is a mismatch, then I want to close the socket, with a 1008, Violated Policy reason. 如果不匹配,则出于1008违反政策的原因,我想关闭套接字。

What is the best way to accomplish this? 做到这一点的最佳方法是什么?

I could: 我可以:

  1. Manually call the @OnClose method, passing the reason 手动调用@OnClose方法,并传递原因
  2. Throw an exception and let @OnError be invoked 引发异常并让@OnError被调用
  3. Something else? 还有吗

I'd like the socket to be closed and Tyrus to clean up the resources. 我希望关闭插座,并希望Tyrus清理资源。 I've looked over the documentation, but didn't see an answer to how resources are cleaned up. 我查看了文档,但是没有找到有关如何清理资源的答案。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

never invoke @OnClose manually - that won't accomplish anything. 永远@OnClose手动调用@OnClose不会完成任何事情。

See Session.close(CloseReason) . 请参见Session.close(CloseReason)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自客户端或服务器的时间戳-最佳做法是什么? - Timestamp from the client or the server - What's the best practice? 关闭ftp连接的最佳做法是什么? - What's the best practice to close an ftp connection? 从 docker 文件中获取 pom.xml 中定义的文件名的最佳实践是什么? - What is the best practice to get the file name that was defined in the pom.xml, from within the docker file? 从Docker容器中运行的JVM应用程序将日志发送到graylog的最佳做法是什么? - What's the best practice to send logs to graylog from a JVM application which runs within a docker container? JDBC 连接/结果集/语句的最佳实践是什么 - What's the best practice for JDBC connection/resultset/statement 处理jdbc时关闭连接的最佳实践是什么 - what is the best practice to close connection when dealing with jdbc 从Servlet输出HTML的最佳实践是什么? - What is the best practice for outputing HTML from a Servlet? 在View.OnClick中更新RecyclerView的最佳实践是什么? - What is the best practice for updating a RecyclerView within View.OnClick? 从客户端到实现线程事件的服务器端应用程序调用方法的最佳实践是什么? - What is the best practice to call a method from client to a server side application that implements a thread event? 将CSS编译到SWF服务器端Java,最佳实践是什么? - Compiling CSS to SWF server side Java, What is the best practice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM