1 23 package org.enhydra.barracuda.config; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import org.apache.log4j.*; 31 32 import org.enhydra.barracuda.config.events.*; 33 import org.enhydra.barracuda.core.comp.*; 34 import org.enhydra.barracuda.core.event.*; 35 import org.enhydra.barracuda.core.event.helper.*; 36 import org.enhydra.barracuda.core.forms.*; 37 import org.enhydra.barracuda.core.util.dom.*; 38 import org.enhydra.barracuda.core.util.srv.*; 39 import org.enhydra.barracuda.plankton.data.*; 40 import org.enhydra.barracuda.plankton.http.*; 41 42 46 public class EventConfig extends DefaultEventGateway { 47 48 protected static final Logger logger = Logger.getLogger(EventConfig.class.getName()); 49 50 public static final String FORM = EventConfig.class.getName()+".Form"; 52 53 public static final String MODEL_NAME = "Event"; 55 56 public static final String APPLICATION_GATEWAY_DL = "ApplicationGateway_DebugLevel"; 58 public static final String APPLICATION_GATEWAY_USE_EVENT_POOLING = "ApplicationGateway_UseEventPooling"; 59 public static final String APPLICATION_GATEWAY_FORCE_GC = "ApplicationGateway_ForceGC"; 60 public static final String DEFAULT_BASE_EVENT_USE_ID_ALIASES = "DefaultBaseEvent_UseIDAliases"; 61 public static final String DEFAULT_DOM_WRITER_DPP_FALSE = "DefaultDOMWriter_DefaultPrintPretty_False"; 62 public static final String DEFAULT_BASE_EVENT_LISTENER_DL = "DefaultBaseEventListener_DebugLevel"; 63 public static final String DEFAULT_DISPATCH_QUEUE_DL = "DefaultDispatchQueue_DebugLevel"; 64 public static final String DEFAULT_EVENT_BROKER_DL = "DefaultEventBroker_DebugLevel"; 65 public static final String DEFAULT_EVENT_CONTEXT_DL = "DefaultEventContext_DebugLevel"; 66 public static final String DEFAULT_EVENT_DISPATCHER_DL = "DefaultEventDispatcher_DebugLevel"; 67 public static final String DEFAULT_EVENT_DISPATCHER_MAX_POLY = "DefaultEventDispatcher_MaxPolyChainDepth"; 68 public static final String DEFAULT_EVENT_DISPATCHER_MAX_DISPATCH = "DefaultEventDispatcher_MaxDispatchQueueDepth"; 69 public static final String DEFAULT_EVENT_GATEWAY_DL = "DefaultEventGateway_DebugLevel"; 70 public static final String DEFAULT_EVENT_POOL_DL = "DefaultEventPool_DebugLevel"; 71 public static final String DEFAULT_EVENT_POOL_CLEANUP_LOCKED_EVENTS = "DefaultEventPool_CleanupLockedEvents"; 72 public static final String EVENT_FORWARDING_FACTORY_DL = "EventForwardingFactory_DebugLevel"; 73 public static final String EVENT_REDIRECT_FACTORY_DL = "EventRedirectFactory_DebugLevel"; 74 public static final String ERROR_MESSAGE = "ErrorMessage"; 75 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 76 public static final String UPDATE_BUTTON = "UpdateButton"; 77 78 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 80 private ListenerFactory forceGCFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new ForceGCHandler();} public String getListenerID() {return getID(ForceGCHandler.class);}}; 81 private ListenerFactory cleanupLockedEventsFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new CleanupLockedEventsHandler();} public String getListenerID() {return getID(CleanupLockedEventsHandler.class);}}; 82 83 public EventConfig() { 84 specifyLocalEventInterests(updateConfigFactory); 86 specifyLocalEventInterests(forceGCFactory); 87 specifyLocalEventInterests(cleanupLockedEventsFactory); 88 } 89 90 96 class EventModel extends AbstractTemplateModel { 97 98 public String getName() {return MODEL_NAME;} 100 101 public Object getItem(String key) { 103 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 104 ViewContext vc = getViewContext(); 105 106 if (key.equals(APPLICATION_GATEWAY_DL)) { 108 return ScreenUtil.getDebugLevelComp2(vc, key, ApplicationGateway.class); 109 } else if (key.equals(APPLICATION_GATEWAY_USE_EVENT_POOLING)) { 110 return ScreenUtil.getToggleButton(vc, APPLICATION_GATEWAY_USE_EVENT_POOLING, "true", ApplicationGateway.USE_EVENT_POOLING); 111 } else if (key.equals(APPLICATION_GATEWAY_FORCE_GC)) { 112 return ScreenUtil.getActionLink(vc, forceGCFactory); 113 } else if (key.equals(DEFAULT_BASE_EVENT_USE_ID_ALIASES)) { 114 BToggleButton bcomp = ScreenUtil.getToggleButton(vc, DEFAULT_BASE_EVENT_USE_ID_ALIASES, "true", DefaultBaseEvent.USE_ID_ALIASES); 115 bcomp.setEnabled(false); 118 return bcomp; 119 } else if (key.equals(DEFAULT_BASE_EVENT_LISTENER_DL)) { 120 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultBaseEventListener.class); 121 } else if (key.equals(DEFAULT_DISPATCH_QUEUE_DL)) { 122 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultDispatchQueue.class); 123 } else if (key.equals(DEFAULT_EVENT_BROKER_DL)) { 124 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultEventBroker.class); 125 } else if (key.equals(DEFAULT_EVENT_CONTEXT_DL)) { 126 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultEventContext.class); 127 } else if (key.equals(DEFAULT_EVENT_DISPATCHER_DL)) { 128 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultEventDispatcher.class); 129 } else if (key.equals(DEFAULT_EVENT_DISPATCHER_MAX_POLY)) { 130 DefaultListModel dlm = new DefaultListModel(); 131 for (int i=0; i<101; i++) dlm.add(new Integer (i)); 132 return ScreenUtil.getSelectComp(vc, key, dlm, DefaultEventDispatcher.MAX_POLY_CHAIN_DEPTH); 133 } else if (key.equals(DEFAULT_EVENT_DISPATCHER_MAX_DISPATCH)) { 134 DefaultListModel dlm = new DefaultListModel(); 135 for (int i=0; i<101; i++) dlm.add(new Integer (i)); 136 BSelect bselect = ScreenUtil.getSelectComp(vc, key, dlm, DefaultEventDispatcher.MAX_DISPATCH_QUEUE_DEPTH); 139 bselect.setEnabled(false); 140 return bselect; 141 } else if (key.equals(DEFAULT_EVENT_GATEWAY_DL)) { 142 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultEventGateway.class); 143 } else if (key.equals(DEFAULT_EVENT_POOL_DL)) { 144 return ScreenUtil.getDebugLevelComp2(vc, key, DefaultEventPool.class); 145 } else if (key.equals(DEFAULT_EVENT_POOL_CLEANUP_LOCKED_EVENTS)) { 146 BAction baction = ScreenUtil.getActionLink(vc, cleanupLockedEventsFactory); 147 baction.setEnabled(ApplicationGateway.USE_EVENT_POOLING); 148 return baction; 150 } else if (key.equals(EVENT_FORWARDING_FACTORY_DL)) { 151 return ScreenUtil.getDebugLevelComp2(vc, key, EventForwardingFactory.class); 152 } else if (key.equals(EVENT_REDIRECT_FACTORY_DL)) { 153 return ScreenUtil.getDebugLevelComp2(vc, key, EventRedirectFactory.class); 154 } else if (key.equals(ERROR_MESSAGE)) { 155 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 156 } else if (key.equals(SUCCESS_MESSAGE)) { 157 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 158 } else if (key.equals(UPDATE_BUTTON)) { 159 return ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 160 } else return super.getItem(key); 161 } 162 } 163 164 170 class EventForm extends DefaultFormMap { 171 public EventForm() { 172 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 177 this.defineElement(new DefaultFormElement(APPLICATION_GATEWAY_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(ApplicationGateway.class)), null, false)); 178 this.defineElement(new DefaultFormElement(APPLICATION_GATEWAY_USE_EVENT_POOLING, FormType.BOOLEAN, new Boolean (false), null, false)); 179 this.defineElement(new DefaultFormElement(DEFAULT_BASE_EVENT_USE_ID_ALIASES, FormType.BOOLEAN, new Boolean (false), null, false)); 180 this.defineElement(new DefaultFormElement(DEFAULT_BASE_EVENT_LISTENER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultBaseEventListener.class)), null, false)); 181 this.defineElement(new DefaultFormElement(DEFAULT_DISPATCH_QUEUE_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultDispatchQueue.class)), null, false)); 182 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_BROKER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultEventBroker.class)), null, false)); 183 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_CONTEXT_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultEventContext.class)), null, false)); 184 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_DISPATCHER_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultEventDispatcher.class)), null, false)); 185 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_DISPATCHER_MAX_POLY, FormType.INTEGER, new Integer (DefaultEventDispatcher.MAX_POLY_CHAIN_DEPTH), null, false)); 186 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_DISPATCHER_MAX_DISPATCH, FormType.INTEGER, new Integer (DefaultEventDispatcher.MAX_DISPATCH_QUEUE_DEPTH), null, false)); 187 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_GATEWAY_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultEventGateway.class)), null, false)); 188 this.defineElement(new DefaultFormElement(DEFAULT_EVENT_POOL_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(DefaultEventPool.class)), null, false)); 189 this.defineElement(new DefaultFormElement(EVENT_FORWARDING_FACTORY_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(EventForwardingFactory.class)), null, false)); 190 this.defineElement(new DefaultFormElement(EVENT_REDIRECT_FACTORY_DL, FormType.INTEGER, new Integer (ScreenUtil.cvtLevelToInt(EventRedirectFactory.class)), null, false)); 191 } 192 } 193 194 201 class UpdateConfigHandler extends DefaultBaseEventListener { 202 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 203 Locale locale = context.getViewCapabilities().getClientLocale(); 205 MasterScreen screen = new MasterScreenFactory().getInstance(EventConfig.this, context, locale); 206 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 207 208 ValidationException ve = null; 210 EventForm formMap = new EventForm(); 211 try { 212 formMap.map(context.getRequest()).validate(true); 214 215 ScreenUtil.setLevel(ApplicationGateway.class, formMap.getIntegerVal(APPLICATION_GATEWAY_DL).intValue()); 223 ApplicationGateway.USE_EVENT_POOLING = formMap.getBooleanVal(APPLICATION_GATEWAY_USE_EVENT_POOLING).booleanValue(); 224 ScreenUtil.setLevel(DefaultBaseEventListener.class, formMap.getIntegerVal(DEFAULT_BASE_EVENT_LISTENER_DL).intValue()); 225 ScreenUtil.setLevel(DefaultDispatchQueue.class, formMap.getIntegerVal(DEFAULT_DISPATCH_QUEUE_DL).intValue()); 226 ScreenUtil.setLevel(DefaultEventBroker.class, formMap.getIntegerVal(DEFAULT_EVENT_BROKER_DL).intValue()); 227 ScreenUtil.setLevel(DefaultEventContext.class, formMap.getIntegerVal(DEFAULT_EVENT_CONTEXT_DL).intValue()); 228 ScreenUtil.setLevel(DefaultEventDispatcher.class, formMap.getIntegerVal(DEFAULT_EVENT_DISPATCHER_DL).intValue()); 229 DefaultEventDispatcher.MAX_POLY_CHAIN_DEPTH = formMap.getIntegerVal(DEFAULT_EVENT_DISPATCHER_MAX_POLY).intValue(); 230 ScreenUtil.setLevel(DefaultEventGateway.class, formMap.getIntegerVal(DEFAULT_EVENT_GATEWAY_DL).intValue()); 231 ScreenUtil.setLevel(DefaultEventPool.class, formMap.getIntegerVal(DEFAULT_EVENT_POOL_DL).intValue()); 232 ScreenUtil.setLevel(EventForwardingFactory.class, formMap.getIntegerVal(EVENT_FORWARDING_FACTORY_DL).intValue()); 233 ScreenUtil.setLevel(EventRedirectFactory.class, formMap.getIntegerVal(EVENT_REDIRECT_FACTORY_DL).intValue()); 234 235 formMap.putState(SUCCESS_MESSAGE, new Boolean (true)); 237 238 } catch (ValidationException e) { 239 ve = e; 240 } 241 242 formMap.putState(ERROR_MESSAGE, ve); 245 context.putState(FORM, formMap); 246 247 ((EventModel) screen.eventModel).fireModelChanged(); 249 250 throw new ClientSideRedirectException(new GetBConfig()); 252 } 253 } 254 255 258 class ForceGCHandler extends DefaultBaseEventListener { 259 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 260 logger.debug("Forcing System.gc();"); 262 System.gc(); 263 264 throw new ClientSideRedirectException(new GetBConfig()); 266 } 267 } 268 269 272 class CleanupLockedEventsHandler extends DefaultBaseEventListener { 273 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 274 logger.debug("Looking for ApplicationGateway..."); 276 ApplicationGateway ag = (ApplicationGateway) SimpleServiceFinder.findInstance(ApplicationGateway.class, EventConfig.this); 277 if (ag!=null) { 278 logger.debug("Found it! Getting event pool and manually cleaning up locked events."); 279 EventPool ep = ag.getEventPool(); 280 if (ep!=null) ep.cleanupLockedEvents(); 281 } 282 283 Locale locale = context.getViewCapabilities().getClientLocale(); 285 MasterScreen screen = new MasterScreenFactory().getInstance(EventConfig.this, context, locale); 286 287 ((EventModel) screen.eventModel).fireModelChanged(); 289 290 throw new ClientSideRedirectException(new GetBConfig()); 292 } 293 } 294 295 296 public TemplateModel getModel() { 300 return new EventModel(); 301 } 302 } 303 304 | Popular Tags |