01: package com.icesoft.faces.webapp.http.core;
02:
03: import com.icesoft.faces.webapp.http.common.Configuration;
04: import com.icesoft.faces.webapp.http.common.Request;
05: import com.icesoft.faces.webapp.http.common.Server;
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08:
09: import javax.servlet.ServletContext;
10: import java.util.Collection;
11:
12: public class AsyncServerDetector implements Server {
13: private static final Log LOG = LogFactory
14: .getLog(AsyncServerDetector.class);
15: private Server server;
16:
17: public AsyncServerDetector(String icefacesID,
18: Collection synchronouslyUpdatedViews,
19: ViewQueue allUpdatedViews, ServletContext servletContext,
20: Configuration configuration) {
21: boolean useAsyncHttpServerByDefault;
22: try {
23: getClass()
24: .getClassLoader()
25: .loadClass(
26: "com.icesoft.faces.async.server.AsyncHttpServerAdaptingServlet");
27: useAsyncHttpServerByDefault = true;
28: } catch (ClassNotFoundException exception) {
29: useAsyncHttpServerByDefault = false;
30: }
31:
32: if (configuration.getAttributeAsBoolean("useAsyncHttpServer",
33: useAsyncHttpServerByDefault)) {
34: if (LOG.isDebugEnabled()) {
35: LOG
36: .debug("Adapting to Asynchronous HTTP Server environment.");
37: }
38: try {
39: server = (Server) this
40: .getClass()
41: .getClassLoader()
42: .loadClass(
43: "com.icesoft.faces.async.server.AsyncHttpServerAdaptingServlet")
44: .getDeclaredConstructor(
45: new Class[] { String.class,
46: Collection.class,
47: ViewQueue.class,
48: ServletContext.class })
49: .newInstance(
50: new Object[] { icefacesID,
51: synchronouslyUpdatedViews,
52: allUpdatedViews, servletContext });
53: } catch (Exception exception) {
54: // Possible exceptions: ClassNotFoundException,
55: // NoSuchMethodException,
56: // IntantiationException,
57: // InvocationTargetException,
58: // IllegalAccessException
59: if (LOG.isFatalEnabled()) {
60: LOG
61: .fatal(
62: "Failed to instantiate AsyncHttpServerAdaptingServlet!",
63: exception);
64: }
65: }
66: } else {
67: server = new SendUpdatedViews(synchronouslyUpdatedViews,
68: allUpdatedViews);
69: }
70: }
71:
72: public void service(Request request) throws Exception {
73: server.service(request);
74: }
75:
76: public void shutdown() {
77: server.shutdown();
78: }
79: }
|