KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > webapp > http > core > ReceivePing


1 package com.icesoft.faces.webapp.http.core;
2
3 import com.icesoft.faces.webapp.command.CommandQueue;
4 import com.icesoft.faces.webapp.command.Pong;
5 import com.icesoft.faces.webapp.http.common.Request;
6 import com.icesoft.faces.webapp.http.common.Response;
7 import com.icesoft.faces.webapp.http.common.ResponseHandler;
8 import com.icesoft.faces.webapp.http.common.Server;
9
10 import java.util.Map JavaDoc;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14
15 public class ReceivePing implements Server, ResponseHandler {
16
17     private static Log log = LogFactory.getLog(ReceivePing.class);
18
19     private static final Pong PONG = new Pong();
20     private Map JavaDoc commandQueues;
21
22     public ReceivePing(Map JavaDoc commandQueues) {
23         this.commandQueues = commandQueues;
24     }
25
26     public void service(Request request) throws Exception JavaDoc {
27         String JavaDoc[] viewIdentifiers = request.getParameterAsStrings("viewNumber");
28         for (int i = 0; i < viewIdentifiers.length; i++) {
29             CommandQueue queue = (CommandQueue) commandQueues.get(viewIdentifiers[i]);
30             if( queue != null ){
31                 queue.put(PONG);
32             } else {
33                 if( log.isWarnEnabled() ){
34                     log.warn( "could not get a valid queue for " + viewIdentifiers[i] );
35                 }
36             }
37         }
38         request.respondWith(this);
39     }
40
41     public void respond(Response response) throws Exception JavaDoc {
42         response.setHeader("Content-Length", 0);
43         response.writeBody().write("".getBytes());
44     }
45
46     public void shutdown() {
47     }
48 }
49
Popular Tags