2.Creating WebSocket Applications in the Java EE Platform



            官网英文参考:

             中文解析:

                    Java EE 平台提供了create,配置,部署server端点的Java API(JSR 356),Websocket client API(JSR 356)提供连接任何远程服务器端点的接口。

                    Websocket Java API 包括下面两个包:
  • The javax.websocket.server package contains annotations, classes, and interfaces to create and configure server endpoints.

  • The javax.websocket package contains annotations, classes, interfaces, and exceptions that are common to client and server endpoints.

                    Websocket endpoints 就是javax.websocket.endpoint 类的实例化。Websocket Java API 提供两种类型的endpoint: programmatic endpoints and annotated endpoints.  
                         programmatic endpoint :通过继承endpoint类,然后重写其生命周期方法。
                         annotated endpoint : 通过decorator模式装入对象,其方法通过注释的方式 由前面的提到的包提供。
                    一旦你建立的endpoint,你可以将其部署到应用中,等待客户端连接。

Note:

In most cases, it is easier to create and deploy an annotated endpoint than a programmatic endpoint. This chapter provides a simple example of a programmatic endpoint, but it focuses on annotated endpoints.

大多数情况下,注释方式比编程方式要更容易创建和部署。下面部分就会提供一个简单的编程方式的例子,但重点应该放在注释方式上。


                    创建和部署Websocket 端点的过程如下:
                            1. 新建一个endpoint 类
                            2. 实现其生命周期的方法
                            3. 添加你的业务逻辑
                            4. 部署到一个web 应用中。
                   编码方式和注释方式的实现有所不同,具体不同,下面章节会讲到。

Note:

As opposed to servlets, WebSocket endpoints are instantiated multiple times. The container creates an instance of an endpoint per connection to its deployment URI. Each instance is associated with one and only one connection. This facilitates keeping user state for each connection and makes development easier, because there is only one thread executing the code of an endpoint instance at any given time.


跟servlet不同,Websocket会初始化多次。容器会为每一个连接初始化一个endpoint连接。每次初始化有且只能关联一个连接。这样有利于用户的状态,也使得部署更加容易(因为任何时候只有一个线程来初始化endpoint实例)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值