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 ; 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 commandQueues; 21 22 public ReceivePing(Map commandQueues) { 23 this.commandQueues = commandQueues; 24 } 25 26 public void service(Request request) throws Exception { 27 String [] 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 { 42 response.setHeader("Content-Length", 0); 43 response.writeBody().write("".getBytes()); 44 } 45 46 public void shutdown() { 47 } 48 } 49 | Popular Tags |