`
huangxx
  • 浏览: 322629 次
  • 来自: ...
社区版块
存档分类
最新评论

cometd: jetty

阅读更多

http://docs.codehaus.org/display/JETTY/Cometd+%28aka+Bayeux%29

 

 

 

Jetty includes a servlet implementation of the Bayuex protocol of cometd from the Dojo Foundation.

Cometd is a message bus for Ajax web applications that allows multi channel messaging between client and server - and more importantly - between server and client. The paradigm is publish/subscribe to named channels.

 

 

http://www.webtide.com/downloads/whitePaperAjaxJetty.html

 

 

To deal with the need for servlets to have an efficient waiting mechanism, Jetty 6 introduced a Continuation Mechanism, which allows the current threads handler to be suspended and resumed at a later time in response to a timeout or an asynchronous event. A continuation is obtained by a servlet via a portable API that will work in any Servlet container. In containers other than Jetty, a simple WaitingContinuation is used where suspend is the equivalent to a wait() and resume the equivalent of an notify(), so the application works but does not avoid the problem of thread allocation.

 

When run in Jetty, the continuation instance obtained will be a RetryContinuation, which when suspended actually throws a special RuntimeException that allows the request thread to exit the Filter/RequestDispatcher/Servlet chain and unwind the statck to the container. The thread is returned to the pool while Jetty holds the request until either a timeout occurs or the resume method is called.

 

This mechanisms relies on the stateless nature of HTTP and the ability to retry idempotent requests. It allows requests to wait within the container rather than within the servlet, without the expense of the allocated thread and buffers.

 

 

http://docs.codehaus.org/display/JETTY/Continuations

 

 Continuations will be replaced by standard Servlet-3.0 suspendable requests once the specification is finalized. Early releases of Jetty-7 are now available that implement the proposed standard suspend/resume API

  

How it works

Behind the scenes, Jetty has to be a bit sneaky to work around Java and the Servlet specification as there is no mechanism in Java to suspend a thread and then resume it later. The first time the request handler calls continuation.suspend(timeoutMS) a RetryRequest runtime exception is thrown. This exception propagates out of all the request handling code and is caught by Jetty and handled specially. Instead of producing an error response, Jetty places the request on a timeout queue and returns the thread to the thread pool.

When the timeout expires, or if another thread calls continuation.resume(event) then the request is retried. This time, when continuation.suspend(timeoutMS) is called, either the event is returned or null is returned to indicate a timeout. The request handler then produces a response as it normally would.

Thus this mechanism uses the stateless nature of HTTP request handling to simulate a suspend and resume. The runtime exception allows the thread to legally exit the request handler and any upstream filters/servlets plus any associated security context. The retry of the request, re-enters the filter/servlet chain and any security context and continues normal handling at the point of continuation.

Furthermore, the API of Continuations is portable. If it is run on a non-Jetty6 server it will simply use wait/notify to block the request in getEvent. If Continuations prove to work as well as I hope, I plan to propose them as part of the 3.0 Servlet JSR.

评论

相关推荐

    Jetty cometd(Continuation)学习笔记

    【Jetty彗星技术(Cometd)及Continuation机制详解】 Jetty是一个高效、轻量级的Java Servlet容器,不仅可作为HTTP服务器,还能作为HTTP客户端。它以其小巧、稳定和高性能的特点受到广泛赞誉,适合企业级应用的需求。...

    源码部署javaTomcat-cometd:CometD项目,用于Web消息传递的可扩展Comet(服务器推送)实现

    Jetty 11.0.x - jakarta.servlet.* 6.0.x ⇒ Java 11 - 码头 10.0.x - javax.servlet.* 5.0.x ⇒ Java 8 - 码头 9.4.x - javax.servlet.* CometD许可证 CometD 源代码在 Apache 2.0 许可下发布。 项目目录布局 ...

    cometd-archetype-spring-dojo-jetty7-2.8.0-RC1.zip

    【标题】"cometd-archetype-spring-dojo-jetty7-2.8.0-RC1.zip" 提供的是一个开源项目构建模版,主要用于创建基于CometD、Spring、Dojo以及Jetty 7的应用。这个压缩包的核心是帮助开发者快速搭建一个实时Web应用,...

    jetty-6.1.9.zip

    在此次提供的"jetty-6.1.9.zip"压缩包中,包含了两个与CometD相关的JAR文件,分别是"cometd-api-0.9.20080221.jar"和"cometd-bayeux-6.1.9.jar"。这两个文件对于理解Jetty在实现长连接和实时通信方面的应用至关重要...

    cometd-1.0.0rc0 源码

    4. **Jetty适配器**:CometD通常与Jetty服务器一起使用,因为Jetty提供了良好的WebSocket和长轮询支持。在这个源码包中,可以看到Jetty适配器的相关代码,这有助于理解CometD如何与Jetty集成,提供实时通信服务。 ...

    cometd 框架实现的几个小程序

    总的来说,CometD结合Jetty提供了强大的实时通信能力,使开发者能够快速构建高效、低延迟的Web应用。通过深入理解和实践,你可以掌握这些技术并应用于实际项目中,提升用户体验并降低服务器压力。

    cometd-bayeux-6.1.10.jar.zip

    CometD库实现了Bayeux协议,并提供了多种客户端库,包括JavaScript、Java、iOS、Android等多种平台,以及服务器端适配器,支持多种服务器环境,如Jetty、Tomcat、GlassFish等。`cometd-bayeux-6.1.10.jar`是Java...

    cometd-5.0.x.zip

    3. **跨平台支持**:CometD支持多种服务器端环境,如Java(Jetty和Tomcat)、JavaScript(Node.js)以及Python等,同时也提供了JavaScript客户端库,方便在浏览器中使用。 4. **模块化设计**:CometD采用模块化设计...

    cometd-jquery的jar

    CometD支持多种服务器端和客户端技术,包括Java、JavaScript、JavaScript库如jQuery,以及多种服务器实现,如Jetty、Tomcat等。 jQuery是一个广泛使用的JavaScript库,简化了HTML文档遍历、事件处理、动画和Ajax...

    Jetty+Dojo+Tomcat的Comet配置

    cometd-api-0.9.20080221 cometd-bayeux-6.1.9 jetty-6.1.9 jetty-util-6.1.9 servlet-api-2.5-6.1.9 全网搜索dojox.cometd实现WEBQQ,没有可以运行的源码包项目,搞了五天,分享给大家,真实可用,jar包就找了好久...

    cometd-3.0.0.beta2-distribution.tar.gz

    5. **跨平台**:CometD可以在多种服务器平台上运行,如Jetty、Tomcat、GlassFish、WildFly等。 6. **容错和恢复**:CometD具有强大的故障恢复机制,能处理网络中断、服务器重启等情况,确保消息的可靠传输。 在解压...

    cometd-2.9.0-distribution.tar.gz

    在服务器端,可以将CometD部署到支持Servlet 2.5或更高版本的Web容器(如Tomcat、Jetty)中。客户端库则可以用于JavaScript、Java、iOS、Android等多种平台,实现跨平台的实时通信。 在配置方面,开发者需要设置...

    cometd实例demo

    9. **部署与集成**:CometD可以与各种Web服务器和应用服务器如Jetty、Tomcat、Glassfish等集成,也可以与Spring框架无缝配合。 通过“cometd-demo”这个压缩包,你可以学习到如何设置CometD的配置、创建频道、订阅...

    cometd注解实现java端代码实例

    本例是通过注解的形式写的cometd服务器端代码。通过spring的自动注入的功能,把cometd的服务可以注入到web controller中,controller可以调用cometd的服务方法向客户端发送任何...jetty 8.1、spring3.2 、cometd2.9 。

    Jetty中文手册

    Stress Testing CometD 使用Servlets和Filters Jetty中绑定的Servlets Quality of Service Filter Cross Origin Filter 配置安全策略(Security Policies) 安全领域(Security Realms) 安全域配置教程 Java ...

    实时动态显示的domo系统

    该系统利用了多种技术,包括JBoss、CometD、Dojo、Jetty等,以实现数据的实时更新与展示。在汽车供应链管理领域,为了跟踪托盘的位置,开发了一个实时仪表板来直观地展示这些位置信息。在项目初期,存在多种用于向...

    CometD-jQuery:CometD 服务器 + jQuery + 示例

    CometD-jQuery CometD 服务器 + jQuery + 示例 安装 将此“/cometd”目录复制到您的 Tomcat/Jetty(Servlet 容器)“webapps”目录中。 启动你的 HTTP 服务器(Servlet 容器) 打开浏览器并转到

    Comet Reverse Ajax

    The Jetty cometd examples require Jetty 6.1.11 or higher, so... 2. Download a recent version of Jetty (e.g. 6.1.11) and replace the Jetty jar files in your grails installation. The files that I ...

    cometd-archetype-jquery-jetty7-2.5.1.jar

    jar包,官方版本,自测可用

Global site tag (gtag.js) - Google Analytics