- 浏览: 2552335 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Comet Jetty(2)Go through the document
5. Java Libraries
5.3. Client Library
We can use CometD client implementation in any J2EE application. It consists of one main class, org.cometd.client.BayeuxClient, which implements the org.cometd.bayeux.client.ClientSession interface.
5.3.1. Handshaking
BayeuxClient.handshake()
HttpClient httpClient = new HttpClient();
//Here set up Jetty's HttpClient, for example:
// httpClient.setMaxConnectionsPerAddress(2);
httpClient.start();
// Prepare the transport
Map<String, Object> options = new HashMap<String, Object>();
ClientTransport transport = LongPollingTransport.create(options, httpClient);
ClientSession client = new BayeuxClient("http://localhost:8080/cometd", transport);
5.3.2. Subscribing and Unsubscribing
client.getChannel(CHANNEL).subscribe(fooListener);
client.getChannel(CHANNEL).unsubscribe(fooListener);
5.3.3. Publishing
Map<String, Object> data1 = new HashMap<String, Object>();
// Fill in the data1 map object
client.getChannel("/game/table/1").publish(data1);
5.3.5. Client Transports
// Prepare the WebSocket transport
WebSocketClientFactory wsFactory = new WebSocketClientFactory();
wsFactory.start();
ClientTransport wsTransport = new WebSocketTransport(null, wsFactory, null);
// Prepare the HTTP transport
HttpClient httpClient = new HttpClient();
httpClient.start();
ClientTransport httpTransport = new LongPollingTransport(null, httpClient);
// Configure the BayeuxClient, with the websocket transport listed before the http transport
BayeuxClient client = new BayeuxClient("http://localhost:8080/cometd", wsTransport, httpTransport);
// Handshake
client.handshake();
5.4. Server Library
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
The purpose for this is to perform cross-domain JavaScript requests.
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
Annotated Style
@org.cometd.annotation.Service("echoService")
public class EchoService
{
@javax.inject.Inject
private BayeuxServer bayeux;
}
Inherited Style
public class EchoService extends AbstractService
{
public EchoService(BayeuxServer bayeux)
{
super(bayeux, "echoService");
}
}
5.4.2.4 Services Integration with Spring
<bean id="otherService" class="com.acme..." />
<bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="3" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="bayeux" />
</bean>
</list>
</property>
</bean>
<bean id="echoService" class="com.acme.cometd.EchoService">
<constructor-arg><ref local="bayeux" /></constructor-arg>
<constructor-arg><ref local="otherService" /></constructor-arg>
</bean>
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="bayeux" />
</entry>
</map>
</property>
</bean>
5.4.3 Authorization
public class CustomSecurityPolicy extends DefaultSecurityPolicy
{
public boolean canHandshake(BayeuxServer server, ServerSession session, ServerMessage message)
{
// Always allow local clients
if (session.isLocalSession())
return true;
// Implement custom authentication logic
boolean authenticated = authenticate(server, session, message);
return authenticated;
}
}
org.cometd.bayeux.server.SecurityPolicy
org.cometd.server.DefaultSecurityPolicy
5.6. Scalability Clustering with Oort
Any CometD server can become an Oort comet by configuring an instance of org.cometd.oort.Oort.
Oort clustering is not a high availability clustering solution: if one of the nodes crashes, then all the clients are disconnected and reconnect to other nodes (with a new handshake).
<servlet>
<servlet-name>oort</servlet-name>
<servlet-class>org.cometd.oort.OortStaticConfigServlet</servlet-class>
<load-on-startup>2</load-on-startup>
<init-param>
<param-name>oort.url</param-name>
<param-value>http://host1:port/context/cometd</param-value>
</init-param>
<init-param>
<param-name>oort.cloud</param-name>
<param-value>http://host2:port/context/cometd,http://host3:port/context/cometd</param-value>
</init-param>
</servlet>
6. Extensions
...snip...
references:
http://www.ibm.com/developerworks/cn/web/wa-lo-comet/
http://hi.baidu.com/ztf704/blog/item/82674a08328881980b7b8266.html
http://www.ibm.com/developerworks/cn/web/wa-cometjava/?cmp=dwskl&cpb=dw&ct=dwcon&cr=cn_51CTO&ccy=cn
http://haidii.iteye.com/blog/481004
http://dynamiclu.iteye.com/blog/486533
http://akalius.iteye.com/blog/192727
http://wiki.eclipse.org/Jetty/Feature/Stress_Testing_CometD
http://magicgod.iteye.com/blog/741171
http://docs.cometd.org/reference/#d0e117
5. Java Libraries
5.3. Client Library
We can use CometD client implementation in any J2EE application. It consists of one main class, org.cometd.client.BayeuxClient, which implements the org.cometd.bayeux.client.ClientSession interface.
5.3.1. Handshaking
BayeuxClient.handshake()
HttpClient httpClient = new HttpClient();
//Here set up Jetty's HttpClient, for example:
// httpClient.setMaxConnectionsPerAddress(2);
httpClient.start();
// Prepare the transport
Map<String, Object> options = new HashMap<String, Object>();
ClientTransport transport = LongPollingTransport.create(options, httpClient);
ClientSession client = new BayeuxClient("http://localhost:8080/cometd", transport);
5.3.2. Subscribing and Unsubscribing
client.getChannel(CHANNEL).subscribe(fooListener);
client.getChannel(CHANNEL).unsubscribe(fooListener);
5.3.3. Publishing
Map<String, Object> data1 = new HashMap<String, Object>();
// Fill in the data1 map object
client.getChannel("/game/table/1").publish(data1);
5.3.5. Client Transports
// Prepare the WebSocket transport
WebSocketClientFactory wsFactory = new WebSocketClientFactory();
wsFactory.start();
ClientTransport wsTransport = new WebSocketTransport(null, wsFactory, null);
// Prepare the HTTP transport
HttpClient httpClient = new HttpClient();
httpClient.start();
ClientTransport httpTransport = new LongPollingTransport(null, httpClient);
// Configure the BayeuxClient, with the websocket transport listed before the http transport
BayeuxClient client = new BayeuxClient("http://localhost:8080/cometd", wsTransport, httpTransport);
// Handshake
client.handshake();
5.4. Server Library
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
The purpose for this is to perform cross-domain JavaScript requests.
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
Annotated Style
@org.cometd.annotation.Service("echoService")
public class EchoService
{
@javax.inject.Inject
private BayeuxServer bayeux;
}
Inherited Style
public class EchoService extends AbstractService
{
public EchoService(BayeuxServer bayeux)
{
super(bayeux, "echoService");
}
}
5.4.2.4 Services Integration with Spring
<bean id="otherService" class="com.acme..." />
<bean id="bayeux" class="org.cometd.server.BayeuxServerImpl" init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="3" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="bayeux" />
</bean>
</list>
</property>
</bean>
<bean id="echoService" class="com.acme.cometd.EchoService">
<constructor-arg><ref local="bayeux" /></constructor-arg>
<constructor-arg><ref local="otherService" /></constructor-arg>
</bean>
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="bayeux" />
</entry>
</map>
</property>
</bean>
5.4.3 Authorization
public class CustomSecurityPolicy extends DefaultSecurityPolicy
{
public boolean canHandshake(BayeuxServer server, ServerSession session, ServerMessage message)
{
// Always allow local clients
if (session.isLocalSession())
return true;
// Implement custom authentication logic
boolean authenticated = authenticate(server, session, message);
return authenticated;
}
}
org.cometd.bayeux.server.SecurityPolicy
org.cometd.server.DefaultSecurityPolicy
5.6. Scalability Clustering with Oort
Any CometD server can become an Oort comet by configuring an instance of org.cometd.oort.Oort.
Oort clustering is not a high availability clustering solution: if one of the nodes crashes, then all the clients are disconnected and reconnect to other nodes (with a new handshake).
<servlet>
<servlet-name>oort</servlet-name>
<servlet-class>org.cometd.oort.OortStaticConfigServlet</servlet-class>
<load-on-startup>2</load-on-startup>
<init-param>
<param-name>oort.url</param-name>
<param-value>http://host1:port/context/cometd</param-value>
</init-param>
<init-param>
<param-name>oort.cloud</param-name>
<param-value>http://host2:port/context/cometd,http://host3:port/context/cometd</param-value>
</init-param>
</servlet>
6. Extensions
...snip...
references:
http://www.ibm.com/developerworks/cn/web/wa-lo-comet/
http://hi.baidu.com/ztf704/blog/item/82674a08328881980b7b8266.html
http://www.ibm.com/developerworks/cn/web/wa-cometjava/?cmp=dwskl&cpb=dw&ct=dwcon&cr=cn_51CTO&ccy=cn
http://haidii.iteye.com/blog/481004
http://dynamiclu.iteye.com/blog/486533
http://akalius.iteye.com/blog/192727
http://wiki.eclipse.org/Jetty/Feature/Stress_Testing_CometD
http://magicgod.iteye.com/blog/741171
http://docs.cometd.org/reference/#d0e117
发表评论
-
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 241MongoDB 2019(3)Security and Aut ... -
Memory Leak in NodeJS
2018-12-20 06:26 736Memory Leak in NodeJS I have d ... -
Remote Desktop Client
2018-12-07 13:19 1200Remote Desktop Client There is ... -
MetaBase UI Console(2)Docker on MySQL
2018-11-29 06:58 944MetaBase UI Console(2)Docker on ... -
AWS Lambda and Serverless Timeout
2018-09-20 01:20 629AWS Lambda and Serverless Timeo ... -
2018 WebSocket(1)Introduction
2018-03-20 01:22 11102018 WebSocket(1)Introduction ... -
2018 TypeScript Update(3)Introduction Basic Grammar
2018-03-08 03:08 6092018 TypeScript Update(3)Introd ... -
2018 TypeScript Update(2)Introduction Basic Grammar - Classes and Functions
2018-03-06 05:32 5592018 TypeScript Update(2)Introd ... -
2018 TypeScript Update(1)Introduction Basic Grammar - Types and Interface
2018-03-03 01:15 6052018 TypeScript Update(1)Introd ... -
Charts and Console(6)Paging
2018-03-01 00:12 586Charts and Console(6)Paging Th ... -
Vue.JS(3)Google Login
2018-02-14 04:53 1317Vue.JS(3)Google Login I just p ... -
Vue.JS(2)Monitor Water Console - ChartJS and Axios
2018-02-14 03:17 726Vue.JS(2)Monitor Water Console ... -
Vue.JS(1)Introduction and Basic Demo
2018-02-08 06:47 615Vue.JS(1)Introduction and Basic ... -
Charts and Console(5)Validation Form
2017-10-03 05:12 811Charts and Console(5)Validation ... -
Charts and Console(4)Display and Enhancement
2017-09-20 05:39 639Charts and Console(4)Display an ... -
Charts and Console(3)Auth and Login
2017-09-13 03:45 667Charts and Console(3)Auth and L ... -
Charts and Console(2)Login and Proxy
2017-08-31 05:39 878Charts and Console(2)Login and ... -
Charts and Console(1)UI Console and RESTful Client
2017-08-29 11:02 771Charts and Console(1)UI Console ... -
Blog Project(2)Express Backend API - istanbul - mocha - bunyan
2017-06-09 00:05 485Blog Project(2)Express Backend ... -
ReactJS(5)Composition vs Inheritance
2017-06-06 05:55 1117ReactJS(5)Composition vs Inheri ...
相关推荐
jetty-6.1.9 jetty-util-6.1.9 servlet-api-2.5-6.1.9 全网搜索dojox.cometd实现WEBQQ,没有可以运行的源码包项目,搞了五天,分享给大家,真实可用,jar包就找了好久,花了5分,搞了5天5分。共10分。 付原作者地址...
文件名"jetty6.1.9(2)"表明这是Jetty 6.1.9的一部分,可能是因为文件过大,所以分成了两个部分。在实际使用时,你需要将这两个部分合并,以获得完整的Jetty 6.1.9安装包。合并过程通常包括解压每个部分,然后将解压...
Jetty 6 指南书是一本详细讲解 Jetty 6.x 版本的专著,由陈汝烨撰写,旨在填补网络上关于 Jetty 新颖、系统性资料的空白,推动 Jetty 在国内的普及。这本书不仅介绍了 Jetty 作为 Web 容器的基本功能,还深入探讨了...
Comet技术是Jetty的一个重要特性,它允许Web服务器与客户端之间建立持久连接,从而实现实时数据传输。在传统的HTTP请求/响应模型中,服务器在发送响应后会关闭连接,而Comet则保持连接打开,直到有新的数据需要发送...
Jetty是一款轻量级、高性能的Java Web服务器和Servlet容器,它被广泛用于开发、测试和部署Web应用程序。在Java生态系统中,Jetty以其高效、稳定和灵活性而受到开发者们的青睐。这里我们主要讨论三个核心的Jetty组件...
7. **类加载器**、**Jetty Connector的SSL配置**、**虚拟主机**、**管理服务器**、**JNDI配置**、**会话与集群**、**性能优化**、**异步Servlet、Ajax和Comet**以及**嵌入Jetty**等内容,都是指南中详细阐述的主题,...
Binding JAX-WS 2.x Endpoints to Jetty Contexts Java Management Extensions (JMX) 配置JMX教程 处理JVM NIO Bug Rewrite模块 Inversion of Control and Dependency Injection Frameworks Jetty XML IOC 如何使用...
### Jetty权威指南知识点梳理 #### 一、Jetty简介 **1.1 Jetty功能介绍** Jetty是一个完全由Java编写的高性能HTTP服务器及servlet容器,它不仅能够作为一个独立的服务运行,还具备强大的可嵌入性。Jetty的设计...
Comet是一种实现实时双向通信的技术,Jetty也支持通过Continuations实现Comet功能。 #### 十五、Embedding Jetty **15.1 嵌入式使用** Jetty的轻量级和灵活性使其非常适合嵌入到其他Java应用中。通过调用Jetty...
2. **CometD API**: "cometd-api-0.9.20080221.jar"是CometD API的早期版本,CometD是一个基于Bayeux协议的开源项目,用于实现浏览器与服务器之间的双向通信,也就是常说的Comet技术。这种技术允许服务器主动向...
面向Java开发人员的Ajax技术,特别是与Jetty服务器和Direct Web Remoting (DWR)框架的结合,为创建高性能、可扩展的Comet应用程序提供了强大的工具。Comet是一种Web交互模式,它允许服务器向客户端推送数据,而不...
1. **Jetty介绍**:Jetty是一个用Java语言编写的开源项目,它提供了执行JSP和servlet所需的环境。作为servlet容器,Jetty允许开发人员以对象的形式快速为独立的Java应用程序提供网络和web服务。Jetty的特点包括轻量...
2. Jetty Continuations:Jetty服务器提供的一个特性,可以方便地实现长轮询。 3. Grizzly Comet Support:Grizzly网络应用框架中的Comet支持,用于构建高性能的实时Web应用。 五、Java-Comet的挑战与解决方案 1. ...
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 modified were: - jetty-6.1.x.jar - jetty-naming-6.1.x.jar - jetty-...
综上所述,这个压缩包包含的`comet4j.js`、`comet4j-tomcat6.jar`和`comet4j-tomcat7.jar`是实现基于Java的Comet4j实时通信框架的关键组件。它们分别负责客户端的JavaScript交互、在Tomcat服务器上的集成和支持,为...
这个"comet demo"是一个展示如何在Java环境下利用Tomcat服务器实现Comet技术的实例。Tomcat 6.0是Apache软件基金会开发的开源Servlet容器,支持各种Java Web应用的部署,包括Comet技术。 首先,Comet的核心在于保持...
2. **高并发**:通过高效的连接管理和数据缓存策略,Comet4J能处理大量并发连接,确保大规模应用的稳定运行。 3. **可扩展性**:Comet4J允许开发者自定义消息处理器,方便集成到现有系统中,同时支持插件扩展,增强...
2. **Servlet Container**:Jetty支持Servlet 3.0规范,允许开发者编写和部署Servlet和JSP应用。它提供了对WebSocket、 Comet等高级特性的支持。 3. **WebApp Context**:Jetty允许你以独立的Context(Web应用程序...
4. **兼容性**:尽管这里的示例是针对Tomcat的,但Comet4J也可以与其他Java应用服务器(如Jetty)配合使用,只需要相应的适配器即可。 5. **性能优化**:在大规模应用中,需要考虑如何有效地管理大量并发的Comet...