Wednesday, September 30, 2009

Configuring cometd with Spring

I've been having fun hacking on cometd related things.

Just thought I'd post the details on how I got it work. I wanted to try and do the spring configuration with as little custom code as possible so I could keep up to date with the latest ContinuationCometdServlet.

Any suggestions for improvements on this process are appreciated. The timing of things initializing is important.

1: Configure the ContinuationCometdServlet (cometd) servlet as usual in web.xml just make sure it has a load-on-startup property set.

2: An important thing we need to put into our spring applicationContext.xml is:

<bean id="bayeux" class="org.cometd.server.continuation.ContinuationBayeux" />

<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux"><ref bean="bayeux"/></entry>
</map>
</property>
</bean>

This creates the Bayeux object and puts it into the ServletContext before the cometd servlet starts up.

3: Configure your Bayeux Services

<bean id="testService" class="com.testpackage.TestService" lazy-init="true" >
<constructor-arg><ref bean="bayeux"/></constructor-arg>
</bean>

<bean id="testService2" class="com.testpackage.TestService2" lazy-init="true" >
<constructor-arg><ref bean="bayeux"/></constructor-arg>
</bean>

<bean id="bayeuxServiceList" class="org.springframework.beans.factory.config.ListFactoryBean" lazy-init="true">
<property name="sourceList">
<list>
<ref bean="testService" />
<ref bean="testService2" />
</list>
</property>
</bean>

The important part here is that the services and the List holding them are set to lazy-init. The Bayeux object for the service constructors wont be ready until after the cometd servlet initializes.

4: The one custom piece of code I'm not sure how to do without yet is a servlet that simply initializes the spring configured Bayeux services after the Bayeux object has been properly initialized by the cometd servlet.

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class SpringBayeuxInitServlet extends GenericServlet
{

@Override
public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException
{
((HttpServletResponse)res).sendError(503);
}

@Override
public void init () throws ServletException
{
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
wac.getBean ("bayeuxServiceList");
}
}

This servlet must have a load-on-startup property set to initialize after the cometd just as the chat demo servlet does.

6 comments:

Anonymous said...

woori casino - Free online casino games for real money
Play the best 우리카지노 online slots, online planet win 365 roulette, カジノ シークレット blackjack, poker, video poker, keno and much more to win at Wild West Casino.

pallmauhles said...

Watch for extra data and ideas, plus when to hit, split, maintain and fold. Before you make your approach to Las Vegas we advocate you pack some fancy garments for an evening out at one of our incredible eating places followed by some cocktails at a thumping nightclub. Also certain to|make sure to|remember to} pack your sense of wonder earlier than you take in a well-known Las Vegas show, and take some time to discover ways to|learn to} win at blackjack in Vegas. A gambling recreation during which the item is to acquire from the supplier playing cards whose values add a lot as}, or near, 21 however don't exceed it. The inordinate factor about enjoying in} on-line Blackjack is that could 바카라 be} incomes bonuses and rewards irrespective of how much you stake. It is comparable to the systematic Blackjack recreation play but it permits the participant an opportunity to win the accumulative jackpot.

talbertcadd said...

I’d really like to be a part of|part of} community where I can get feedback from different 더킹카지노 knowledgeable individuals that share the identical interest. I even have have} learn this put up and if I could I desire to suggest you some attention-grabbing things or ideas. I respect you discovering the time and effort to put this informative article collectively.

uhayanoberholzer said...

Some jurisdictions, nevertheless, have taken steps corresponding to limiting promoting and imposing a every day betting cap to attenuate potential harms during the pandemic . The lockdown and social distancing rules imposed by the various international locations and governments have affected land-based casino operations. Several land-based playing venues corresponding to bingo halls, casinos, golf equipment, bars, horseracing tracks 카지노 사이트 추천 with electronic playing machines , betting outlets, poker rooms, and lottery retailers were pressured to shut.

zavadbacklund said...

Our immersive new game recreates the feel of a land-based casino for players, allowing them to place bets even after the spin was accomplished. Mega Wheel is a fun-filled stay casino game of chance, inspired by the ever-popular Big 6 or Money Wheels. Predominantly spinning-reel games that offer interactive top box options and bonuses. IGT proudly presents its ever-expanding library 1xbet of basic fruit games for players who get pleasure from fewer paylines and higher stakes.

abelhardtade said...

A vary of percentages is set within the recreation software program and 카지노사이트 chosen remotely. Historically, all slot machines used revolving mechanical reels to show and determine results. Although the original slot machine used 5 reels, simpler, and therefore more reliable, three reel machines rapidly grew to become the standard.