ServletHolder demo=context.addServlet(CometdDemoServlet.class, "/demo");
demo.setInitOrder(3);
server.start();
final AbstractBayeux bayeux = ((ContinuationCometdServlet)comet.getServlet()).getBayeux();
bayeux.setSecurityPolicy(new AbstractBayeux.DefaultPolicy()
{
public boolean canHandshake(Message message)
{
if (_testHandshakeFailure<0)
{
_testHandshakeFailure++;
return false;
}
return true;
}
});
// Demo lazy messages
if (Boolean.getBoolean("LAZY"))
{
bayeux.addExtension(new Extension()
{
public Message rcv(Client from, Message message)
{
if (message.getChannel().startsWith("/chat/") && message.getData()!=null && message.getData().toString().indexOf("lazy")>=0)
((MessageImpl)message).setLazy(true);
return message;
}
public Message rcvMeta(Client from, Message message)
{
return message;
}
public Message send(Client from, Message message)
{
return message;
}
public Message sendMeta(Client from, Message message)
{
return message;
}
});
}
// Demo lazy messages
if (Boolean.getBoolean("LAZYCHAT"))
{
final ChannelImpl chat_demo = (ChannelImpl)bayeux.getChannel("/chat/demo",true);
chat_demo.setLazy(true);
chat_demo.setPersistent(true);
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
chat_demo.publish(null,new JSON.Literal("{\"user\":\"TICK\",\"chat\":\""+new Date()+"\"}"),null);
}
},2000,2000);
}
if (Boolean.getBoolean("STATS"))
{
StatisticsExtension ext = new StatisticsExtension();
ext.setStatsRequestKeys(new String[]{"chat"});
ext.setStatsRequestSentinel("//stats");
ext.setStatsRequestChannel("/chat/demo");
ext.setStatsResultSentinel("//stats-results");
ext.setStatsConfirmSentinel("//stats-confirm");
ext.setProbeChannel("/chat/demo");
ext.setProbeSentinel("//stats-probe");
ext.setProbeReplySentinel("//stats-reply");
ext.setProbeReplyChannel("/chat/demo");
ext.setProbeReplyKeys(new String[]{"chat"});
bayeux.addExtension(ext);
}
}