Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/OldServer/src/org/litesoft/GWT/eventbus/server/AbstractServerApp.java

Diff revisions: vs.
  @@ -1,19 +1,12 @@
1 1 // This Source Code is in the Public Domain per: http://unlicense.org
2 2 package org.litesoft.GWT.eventbus.server;
3 3
4 - import java.io.*;
5 -
6 - import org.litesoft.commonfoundation.typeutils.*;
7 -
8 - import java.util.*;
9 - import javax.servlet.*;
10 - import javax.servlet.http.*;
11 -
12 4 import org.litesoft.GWT.eventbus.client.*;
13 5 import org.litesoft.GWT.eventbus.client.eventpackages.*;
14 6 import org.litesoft.GWT.eventbus.client.nonpublic.*;
15 7 import org.litesoft.GWT.eventbus.client.rpc.*;
16 8 import org.litesoft.GWT.eventbus.server.nonpublic.*;
9 + import org.litesoft.commonfoundation.typeutils.*;
17 10 import org.litesoft.commonfoundation.typeutils.gregorian.*;
18 11 import org.litesoft.configuration.*;
19 12 import org.litesoft.logger.*;
  @@ -26,19 +19,22 @@
26 19 import com.google.gwt.user.client.rpc.*;
27 20 import com.google.gwt.user.server.rpc.*;
28 21
22 + import javax.servlet.*;
23 + import javax.servlet.http.*;
24 + import java.io.*;
25 + import java.util.*;
26 +
29 27 public abstract class AbstractServerApp extends RemoteServiceServlet // don't forget this!
30 28 implements EventBusRemoteService, // don't forget this!
31 29 ConfigLoadedListener,
32 - ThreadLocalContextFactory
33 - {
30 + ThreadLocalContextFactory {
34 31 public static final String HINT_CATEGORY = "Configuration";
35 32
36 33 protected static final String PLUS_OVERFLOW_HIDDEN = " overflow: hidden;";
37 34 protected static final String BODY_STYLE_LESS_OVERFLOW = "border: none; padding: 0; margin: 0;";
38 35 protected static final String FULL_BODY_STYLE = BODY_STYLE_LESS_OVERFLOW + PLUS_OVERFLOW_HIDDEN;
39 36
40 - protected static Logger getLogger()
41 - {
37 + protected static Logger getLogger() {
42 38 Configuration.chkInstantiated();
43 39 return ___NEVER_EVER_TO_USE_DIRECTLY_LOGGER_____USE_GetLogger_METHOD___;
44 40 }
  @@ -52,46 +48,37 @@
52 48 private Map<String, String> mClientConfig = new HashMap<String, String>();
53 49
54 50 public void init()
55 - throws ServletException
56 - {
51 + throws ServletException {
57 52 super.init();
58 - synchronized ( AbstractServerApp.class )
59 - {
60 - if ( getOneTimeInitException() != null )
61 - {
53 + synchronized ( AbstractServerApp.class ) {
54 + if ( getOneTimeInitException() != null ) {
62 55 throw getOneTimeInitException();
63 56 }
64 - if ( !isOneTimeInitComplete() )
65 - {
57 + if ( !isOneTimeInitComplete() ) {
66 58 oneTimeInit();
67 59 }
68 60 }
69 61 }
70 62
71 - private static synchronized boolean isOneTimeInitComplete()
72 - {
63 + private static synchronized boolean isOneTimeInitComplete() {
73 64 return sOneTimeInitComplete;
74 65 }
75 66
76 - private static synchronized RuntimeException getOneTimeInitException()
77 - {
67 + private static synchronized RuntimeException getOneTimeInitException() {
78 68 return sOneTimeInitException;
79 69 }
80 70
81 - private static synchronized void setOneTimeInitException( RuntimeException pOneTimeInitException )
82 - {
71 + private static synchronized void setOneTimeInitException( RuntimeException pOneTimeInitException ) {
83 72 sOneTimeInitException = pOneTimeInitException;
84 73 }
85 74
86 75 /**
87 76 * Assumption is that this method will ALWAYS be called under synchronized( AbstractServerApp.class )!
88 77 */
89 - protected void oneTimeInit()
90 - {
78 + protected void oneTimeInit() {
91 79 System.err.println( new UtilDateAdaptor() + " | Application Server Start Up" );
92 80 Configuration.add( this );
93 - try
94 - {
81 + try {
95 82 // todo: translate: FormQueryFilter.registerRehydrateFactories();
96 83 initializeHintValidators();
97 84 instantiateConfiguration();
  @@ -102,49 +89,38 @@
102 89 initComplete();
103 90 System.err.println( new UtilDateAdaptor() + " | Application Server Start Up Complete" );
104 91 }
105 - catch ( RuntimeException e )
106 - {
92 + catch ( RuntimeException e ) {
107 93 setOneTimeInitException( e );
108 94 throw e;
109 95 }
110 - finally
111 - {
96 + finally {
112 97 sOneTimeInitComplete = true;
113 98 }
114 99 }
115 100
116 - private void logServletContextInitParameterNames()
117 - {
118 - if ( getLogger().info.isEnabled() )
119 - {
101 + private void logServletContextInitParameterNames() {
102 + if ( getLogger().info.isEnabled() ) {
120 103 Enumeration zParamNames = getServletContext().getInitParameterNames();
121 - while ( zParamNames.hasMoreElements() )
122 - {
104 + while ( zParamNames.hasMoreElements() ) {
123 105 String zParamName = (String) zParamNames.nextElement();
124 106 getLogger().info.log( "Context Param " + zParamName, " value is ", getServletContext().getInitParameter( zParamName ) );
125 107 }
126 108 }
127 109 }
128 110
129 - protected void initializeHintValidators()
130 - {
111 + protected void initializeHintValidators() {
131 112 CommonHintValidators.register();
132 113 }
133 114
134 - protected void addClientLoggingLevel( String pName, String pEffectiveLevel )
135 - {
115 + protected void addClientLoggingLevel( String pName, String pEffectiveLevel ) {
136 116 mClientConfig.put( LoggerLevel.CONFIGURATION_BASE + pName, pEffectiveLevel );
137 117 }
138 118
139 - private void logConfigurationLoadingWarnings()
140 - {
141 - if ( !mConfigurationLoadingWarning.isEmpty() )
142 - {
119 + private void logConfigurationLoadingWarnings() {
120 + if ( !mConfigurationLoadingWarning.isEmpty() ) {
143 121 AbstractLogger logger = getLogger().warn;
144 - if ( logger.isEnabled() )
145 - {
146 - for ( String warning : mConfigurationLoadingWarning )
147 - {
122 + if ( logger.isEnabled() ) {
123 + for ( String warning : mConfigurationLoadingWarning ) {
148 124 logger.log( warning );
149 125 }
150 126 }
  @@ -153,37 +129,26 @@
153 129
154 130 private List<String> mConfigurationLoadingWarning = new ArrayList<String>();
155 131
156 - protected void addConfigurationLoadingWarning( String pWarning )
157 - {
132 + protected void addConfigurationLoadingWarning( String pWarning ) {
158 133 mConfigurationLoadingWarning.add( pWarning );
159 134 }
160 135
161 - public void configurationJustLoaded()
162 - {
136 + public void configurationJustLoaded() {
163 137 loadClientConfigPath();
164 138
165 139 String[] keys = Configuration.getAllKeys();
166 - for ( String key : keys )
167 - {
168 - if ( key.startsWith( LoggerLevel.CONFIGURATION_BASE ) )
169 - {
140 + for ( String key : keys ) {
141 + if ( key.startsWith( LoggerLevel.CONFIGURATION_BASE ) ) {
170 142 mClientConfig.put( key, Configuration.getString( key ) );
171 - }
172 - else if ( key.startsWith( HintController.HINT_PROPERTY_PREFIX ) )
173 - {
143 + } else if ( key.startsWith( HintController.HINT_PROPERTY_PREFIX ) ) {
174 144 String zName = key.substring( HintController.HINT_PROPERTY_PREFIX.length() ).trim();
175 - if ( zName.length() == 0 )
176 - {
145 + if ( zName.length() == 0 ) {
177 146 addConfigurationLoadingWarning( "Configuration has entry with nothing after '" + HintController.HINT_PROPERTY_PREFIX + "'" );
178 - }
179 - else
180 - {
147 + } else {
181 148 String zValue = Configuration.getString( key );
182 149 String problem = HintController.validate( HINT_CATEGORY, null, zName, zValue );
183 - if ( problem != null )
184 - {
185 - if ( problem.length() != 0 )
186 - {
150 + if ( problem != null ) {
151 + if ( problem.length() != 0 ) {
187 152 throw new IllegalStateException( "Unacceptable Configuration entry '" + key + "'='" + zValue + "':" + problem );
188 153 }
189 154 addConfigurationLoadingWarning( HintController.noValidatorText( HINT_CATEGORY, null, zName ) );
  @@ -194,21 +159,15 @@
194 159 }
195 160 }
196 161
197 - protected void loadClientConfigPath()
198 - {
162 + protected void loadClientConfigPath() {
199 163 File dir = ServerConfiguration.configFilesSubDirectoryByKey( "ClientConfigPath", null );
200 - if ( dir != null )
201 - {
164 + if ( dir != null ) {
202 165 Properties prop = loadProperties( dir.getAbsolutePath() );
203 - if ( prop != null )
204 - {
205 - for ( Object key : prop.keySet() )
206 - {
207 - if ( key != null )
208 - {
166 + if ( prop != null ) {
167 + for ( Object key : prop.keySet() ) {
168 + if ( key != null ) {
209 169 Object value = prop.get( key );
210 - if ( value != null )
211 - {
170 + if ( value != null ) {
212 171 mClientConfig.put( key.toString(), value.toString() );
213 172 }
214 173 }
  @@ -217,168 +176,134 @@
217 176 }
218 177 }
219 178
220 - private Properties loadProperties( String pPath )
221 - {
179 + private Properties loadProperties( String pPath ) {
222 180 File fileAt = new File( pPath );
223 181 FileInputStream is;
224 - try
225 - {
182 + try {
226 183 is = new FileInputStream( fileAt );
227 184 }
228 - catch ( IOException e )
229 - {
185 + catch ( IOException e ) {
230 186 getLogger().error.log( e, "Unable to open: ", fileAt.getAbsolutePath() );
231 187 return null;
232 188 }
233 - try
234 - {
189 + try {
235 190 Properties props = new Properties();
236 191 props.load( is );
237 192 System.out.println( "Loaded Client Configuration from: " + fileAt.getAbsolutePath() );
238 193 return props;
239 194 }
240 - catch ( IOException e )
241 - {
195 + catch ( IOException e ) {
242 196 getLogger().error.log( e, "Unable to load: ", fileAt.getAbsolutePath() );
243 197 return null;
244 198 }
245 - finally
246 - {
247 - try
248 - {
199 + finally {
200 + try {
249 201 is.close();
250 202 }
251 - catch ( IOException e )
252 - {
203 + catch ( IOException e ) {
253 204 // Whatever...
254 205 }
255 206 }
256 207 }
257 208
258 - protected void loadClientConfigConfigurationLoggerLevels()
259 - {
209 + protected void loadClientConfigConfigurationLoggerLevels() {
260 210 String[] keys = Configuration.getAllKeys();
261 - for ( String key : keys )
262 - {
263 - if ( key.startsWith( LoggerLevel.CONFIGURATION_BASE ) )
264 - {
211 + for ( String key : keys ) {
212 + if ( key.startsWith( LoggerLevel.CONFIGURATION_BASE ) ) {
265 213 mClientConfig.put( key, Configuration.getString( key ) );
266 214 }
267 215 }
268 216 }
269 217
270 - public synchronized AppInitializationResult initialize( String pEncodedClientId )
271 - {
218 + public synchronized AppInitializationResult initialize( String pEncodedClientId ) {
272 219 Integer existingClientIdNumber;
273 - try
274 - {
220 + try {
275 221 existingClientIdNumber = ClientIdCodec.decode( pEncodedClientId );
276 222 }
277 - catch ( RuntimeException e )
278 - {
223 + catch ( RuntimeException e ) {
279 224 getLogger().error.log( e, "initialize '", pEncodedClientId, "'" );
280 225 throw e;
281 226 }
282 227 AppInitializationResult result;
283 - try
284 - {
228 + try {
285 229 result = initializeForBrowserPageRequest( existingClientIdNumber );
286 230 }
287 - catch ( RuntimeException e )
288 - {
231 + catch ( RuntimeException e ) {
289 232 getLogger().error.log( e, "initialize: ", existingClientIdNumber );
290 233 throw e;
291 234 }
292 235 return result;
293 236 }
294 237
295 - public ChannelServiceResult propagate( int pClientIdNumber, int pMessageSequenceNumber, int pPollMillisecs, ChannelServicePackage pToServer )
296 - {
297 - try
298 - {
238 + public ChannelServiceResult propagate( int pClientIdNumber, int pMessageSequenceNumber, int pPollMillisecs, ChannelServicePackage pToServer ) {
239 + try {
299 240 return propagateFromChannelClientProcess( pClientIdNumber, pMessageSequenceNumber, pPollMillisecs, pToServer );
300 241 }
301 - catch ( RuntimeException e )
302 - {
242 + catch ( RuntimeException e ) {
303 243 getLogger().error.log( e, "Problem processing Client (", pClientIdNumber, ")", pToServer );
304 244 throw e;
305 245 }
306 246 }
307 247
308 - public void clientDead( int pClientIdNumber )
309 - {
310 - try
311 - {
248 + public void clientDead( int pClientIdNumber ) {
249 + try {
312 250 clientDeadFromChannelClientProcess( pClientIdNumber );
313 251 }
314 - catch ( RuntimeException e )
315 - {
252 + catch ( RuntimeException e ) {
316 253 getLogger().error.log( e, "Problem processing Client Dead from Client: ", pClientIdNumber );
317 254 // eat it as there is no longer a client to notify!
318 255 }
319 256 }
320 257
321 - protected void clientDeadFromChannelClientProcess( int pClientIdNumber )
322 - {
258 + protected void clientDeadFromChannelClientProcess( int pClientIdNumber ) {
323 259 HttpServletRequest zRequest = getThreadLocalRequest();
324 260
325 - try
326 - {
261 + try {
327 262 ServerEventBus zSEB = ServerEventBusSessionMapper.getServerEventBus( zRequest, this, pClientIdNumber );
328 - if ( (zSEB != null) && zSEB.isAliveAndWell() )
329 - {
263 + if ( (zSEB != null) && zSEB.isAliveAndWell() ) {
330 264 setThreadLocalContextFrom( zSEB );
331 - try
332 - {
265 + try {
333 266 zSEB.publishIfNotDisposed( WindowClosingEventPackage.INSTANCE );
334 267 zSEB.dispose( "ClientDead" );
335 268 }
336 - finally
337 - {
269 + finally {
338 270 clrThreadLocalContext();
339 271 }
340 272 }
341 273 }
342 - catch ( InvalidSessionException e )
343 - {
274 + catch ( InvalidSessionException e ) {
344 275 // Logged by ServerEventBusSessionMapper
345 276 return;
346 277 }
347 278 getLogger().debug.log( "ClientDead: ", pClientIdNumber );
348 279 }
349 280
350 - protected ChannelServiceResult propagateFromChannelClientProcess( int pClientIdNumber, int pMessageSequenceNumber, int pPollMillisecs, ChannelServicePackage pFromClient )
351 - {
281 + protected ChannelServiceResult propagateFromChannelClientProcess( int pClientIdNumber, int pMessageSequenceNumber, int pPollMillisecs,
282 + ChannelServicePackage pFromClient ) {
352 283 HttpServletRequest zRequest = getThreadLocalRequest();
353 284
354 285 ServerEventBus zSEB;
355 - try
356 - {
286 + try {
357 287 zSEB = ServerEventBusSessionMapper.getServerEventBus( zRequest, this, pClientIdNumber );
358 288 }
359 - catch ( InvalidSessionException e )
360 - {
289 + catch ( InvalidSessionException e ) {
361 290 // Logged by ServerEventBusSessionMapper
362 291 return ChannelServiceResult.forceClose( pMessageSequenceNumber );
363 292 }
364 - if ( (zSEB != null) && !zSEB.isAliveAndWell() )
365 - {
293 + if ( (zSEB != null) && !zSEB.isAliveAndWell() ) {
366 294 getLogger().trace.log( "ServerEventBus Disposed for pClientIdNumber=", pClientIdNumber, //
367 295 " is ", zSEB, "!" );
368 296 return ChannelServiceResult.forceClose( pMessageSequenceNumber );
369 297 }
370 - if ( !(zSEB instanceof NonTemporaryServerEventBus) )
371 - {
298 + if ( !(zSEB instanceof NonTemporaryServerEventBus) ) {
372 299 getLogger().warn.log( "ServerEventBus for pClientIdNumber=", pClientIdNumber, //
373 300 " is ", zSEB, "!" );
374 301 return ChannelServiceResult.serverLost( pMessageSequenceNumber );
375 302 }
376 303 setThreadLocalContextFrom( zSEB );
377 - try
378 - {
304 + try {
379 305 RemotePeerService zRemotePeerService = ((NonTemporaryServerEventBus) zSEB).getRemotePeerService();
380 - if ( zRemotePeerService instanceof ServerSideRemotePeerService )
381 - {
306 + if ( zRemotePeerService instanceof ServerSideRemotePeerService ) {
382 307 ServerSideRemotePeerService ssrps = (ServerSideRemotePeerService) zRemotePeerService;
383 308 ChannelServicePackage zPackage = ssrps.processClientRequest( pPollMillisecs, pFromClient );
384 309 return ChannelServiceResult.normal( pMessageSequenceNumber, zPackage );
  @@ -387,21 +312,18 @@
387 312 " RemotePeerService is ", zRemotePeerService, "!" );
388 313 return ChannelServiceResult.serverLost( pMessageSequenceNumber );
389 314 }
390 - finally
391 - {
315 + finally {
392 316 clrThreadLocalContext();
393 317 }
394 318 }
395 319
396 320 protected AppInitializationResult initializeForBrowserPageRequest( Integer existingClientIdNumber )
397 - throws InvalidSessionException
398 - {
321 + throws InvalidSessionException {
399 322 HttpServletRequest zRequest = getThreadLocalRequest();
400 323
401 324 Integer zClientIdNumber = getClientIdNumber( zRequest, existingClientIdNumber );
402 325
403 - if ( zClientIdNumber == null )
404 - {
326 + if ( zClientIdNumber == null ) {
405 327 return null; // Force Close!
406 328 }
407 329
  @@ -414,8 +336,7 @@
414 336 ServerEventBusSessionMapper.addServerEventBus( zRequest, this, zSEB );
415 337 setThreadLocalContextFrom( zSEB );
416 338
417 - try
418 - {
339 + try {
419 340 ServerEventBusSubscriptionCollector collector = new ServerEventBusSubscriptionCollector();
420 341
421 342 addEventListenersForNewClient( collector );
  @@ -438,19 +359,16 @@
438 359 getApplicationVersion(), //
439 360 zSEB.getAuthenticationData() );
440 361 }
441 - finally
442 - {
362 + finally {
443 363 clrThreadLocalContext();
444 364 }
445 365 }
446 366
447 - protected NonTemporaryServerEventBus createRealServerEventBus( int pClientIdNumber )
448 - {
367 + protected NonTemporaryServerEventBus createRealServerEventBus( int pClientIdNumber ) {
449 368 return new RegularServerEventBus( pClientIdNumber );
450 369 }
451 370
452 - protected void finalInitializationBeforeInitializationResultReturned( ServerEventBus pSEB )
453 - {
371 + protected void finalInitializationBeforeInitializationResultReturned( ServerEventBus pSEB ) {
454 372 }
455 373
456 374 abstract protected String getApplicationVersion();
  @@ -459,21 +377,17 @@
459 377 * @return !null will be Client ID to use, null means it was Disposed!
460 378 */
461 379 private Integer getClientIdNumber( HttpServletRequest pRequest, Integer pExistingClientIdNumber )
462 - throws InvalidSessionException
463 - {
464 - if ( pExistingClientIdNumber != null )
465 - {
380 + throws InvalidSessionException {
381 + if ( pExistingClientIdNumber != null ) {
466 382 ServerEventBus zSEB = ServerEventBusSessionMapper.getServerEventBus( pRequest, this, pExistingClientIdNumber );
467 - if ( zSEB != null )
468 - {
383 + if ( zSEB != null ) {
469 384 return zSEB.isAliveAndWell() ? pExistingClientIdNumber : null;
470 385 }
471 386 }
472 387 return ServerEventBusManager.getNextClientIdNumber();
473 388 }
474 389
475 - protected void setClientIdNumberSequenceSource( SequenceSource pSequenceSource )
476 - {
390 + protected void setClientIdNumberSequenceSource( SequenceSource pSequenceSource ) {
477 391 ServerEventBusManager.setClientIdNumberSequenceSource( pSequenceSource );
478 392 }
479 393
  @@ -481,16 +395,13 @@
481 395
482 396 abstract protected void startUpApplication();
483 397
484 - protected void initComplete()
485 - {
398 + protected void initComplete() {
486 399 }
487 400
488 - public void setThreadLocalContextFrom( ServerEventBus pSEB )
489 - {
401 + public void setThreadLocalContextFrom( ServerEventBus pSEB ) {
490 402 }
491 403
492 - public void clrThreadLocalContext()
493 - {
404 + public void clrThreadLocalContext() {
494 405 }
495 406
496 407 abstract protected void addEventListenersForNewClient( ServerEventBusSubscriptionCollector pCollector );
  @@ -505,30 +416,24 @@
505 416 *
506 417 * @return a new BrowserDataManager, or <code>null</code>
507 418 */
508 - protected ClientWindowInstanceDataManager createChildWindowInstanceData( RequestNewClientEventPackage pEvent, EventBus pParentEventBus )
509 - {
419 + protected ClientWindowInstanceDataManager createChildWindowInstanceData( RequestNewClientEventPackage pEvent, EventBus pParentEventBus ) {
510 420 return new ClientWindowInstanceDataManager( pParentEventBus.getClientWindowInstanceDataManager() );
511 421 }
512 422
513 - private class RequestNewClientPackageListener implements EventPackageSubscriber
514 - {
515 - public String subscribeWith()
516 - {
423 + private class RequestNewClientPackageListener implements EventPackageSubscriber {
424 + public String subscribeWith() {
517 425 return RequestNewClientEventPackage.SubscribeWith;
518 426 }
519 427
520 - public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus )
521 - {
428 + public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) {
522 429 RequestNewClientEventPackage zEvent = (RequestNewClientEventPackage) pEventPackage;
523 430
524 431 ClientWindowInstanceDataManager zInitialClientData;
525 432
526 - try
527 - {
433 + try {
528 434 zInitialClientData = createChildWindowInstanceData( zEvent, pEventBus );
529 435 }
530 - catch ( RuntimeException e )
531 - {
436 + catch ( RuntimeException e ) {
532 437 getLogger().error.log( e );
533 438 pEventBus.publish( (EventPackage) null ); // todo - George: Client Error from Server!!!!
534 439 return;
  @@ -544,28 +449,22 @@
544 449 }
545 450 }
546 451
547 - protected TemporaryServerEventBus createTemporarySEB( String pWhy, ServerEventBus pParent, ClientWindowInstanceDataManager pInitialClientData )
548 - {
452 + protected TemporaryServerEventBus createTemporarySEB( String pWhy, ServerEventBus pParent, ClientWindowInstanceDataManager pInitialClientData ) {
549 453 return ServerEventBusManager.INSTANCE.createTemporaryServerEventBus( pWhy, pParent, pInitialClientData );
550 454 }
551 455
552 - protected TemporaryServerEventBus createTemporarySEB( String pWhy, HttpServletRequest pRequest, ClientWindowInstanceDataManager pInitialClientData )
553 - {
456 + protected TemporaryServerEventBus createTemporarySEB( String pWhy, HttpServletRequest pRequest, ClientWindowInstanceDataManager pInitialClientData ) {
554 457 return ServerEventBusManager.INSTANCE.createTemporaryServerEventBus( pWhy, pRequest, this, pInitialClientData );
555 458 }
556 459
557 - private abstract static class MsgOtherBus implements EventPackageSubscriber
558 - {
559 - public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus )
560 - {
460 + private abstract static class MsgOtherBus implements EventPackageSubscriber {
461 + public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) {
561 462 EventPackagePayloadEventPackage eventEventPackage = (EventPackagePayloadEventPackage) pEventPackage;
562 463 ChannelEventPackage event = eventEventPackage.getEventToForward();
563 - if ( event != null )
564 - {
464 + if ( event != null ) {
565 465 ServerEventBus bus = getAppropriateServerEventBus( (ServerEventBus) pEventBus, //
566 466 eventEventPackage );
567 - if ( bus != null )
568 - {
467 + if ( bus != null ) {
569 468 bus.publishIfNotDisposed( event );
570 469 }
571 470 }
  @@ -574,22 +473,16 @@
574 473 abstract protected ServerEventBus getAppropriateServerEventBus( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage );
575 474 }
576 475
577 - private abstract static class MsgOtherBuses implements EventPackageSubscriber
578 - {
579 - public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus )
580 - {
476 + private abstract static class MsgOtherBuses implements EventPackageSubscriber {
477 + public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) {
581 478 EventPackagePayloadEventPackage eventEventPackage = (EventPackagePayloadEventPackage) pEventPackage;
582 479 ChannelEventPackage event = eventEventPackage.getEventToForward();
583 - if ( event != null )
584 - {
480 + if ( event != null ) {
585 481 ServerEventBus serverEventBus = (ServerEventBus) pEventBus;
586 482 ServerEventBus[] buses = getAppropriateServerEventBuses( serverEventBus, eventEventPackage );
587 - if ( buses != null )
588 - {
589 - for ( ServerEventBus bus : buses )
590 - {
591 - if ( (bus != null) && (bus != pEventBus) )
592 - {
483 + if ( buses != null ) {
484 + for ( ServerEventBus bus : buses ) {
485 + if ( (bus != null) && (bus != pEventBus) ) {
593 486 bus.publishIfNotDisposed( event );
594 487 }
595 488 }
  @@ -600,67 +493,52 @@
600 493 abstract protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage );
601 494 }
602 495
603 - private static class MsgParentPackageListener extends MsgOtherBus
604 - {
605 - public String subscribeWith()
606 - {
496 + private static class MsgParentPackageListener extends MsgOtherBus {
497 + public String subscribeWith() {
607 498 return MsgParentWindowEventPackage.SubscribeWith;
608 499 }
609 500
610 - protected ServerEventBus getAppropriateServerEventBus( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage )
611 - {
501 + protected ServerEventBus getAppropriateServerEventBus( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage ) {
612 502 return pEventBus.getParentServerEventBus();
613 503 }
614 504 }
615 505
616 - private static class MsgChildrenPackageListener extends MsgOtherBuses
617 - {
618 - public String subscribeWith()
619 - {
506 + private static class MsgChildrenPackageListener extends MsgOtherBuses {
507 + public String subscribeWith() {
620 508 return MsgChildWindowsEventPackage.SubscribeWith;
621 509 }
622 510
623 - protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage )
624 - {
511 + protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage ) {
625 512 return pEventBus.getChildrenServerEventBuses();
626 513 }
627 514 }
628 515
629 - private static class MsgRelatedPackageListener extends MsgOtherBuses
630 - {
631 - public String subscribeWith()
632 - {
516 + private static class MsgRelatedPackageListener extends MsgOtherBuses {
517 + public String subscribeWith() {
633 518 return MsgRelatedWindowsEventPackage.SubscribeWith;
634 519 }
635 520
636 - protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage )
637 - {
521 + protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage ) {
638 522 return pEventBus.getAllRelatedServerEventBuses();
639 523 }
640 524 }
641 525
642 - private static class MsgAllPackageListener extends MsgOtherBuses
643 - {
644 - public String subscribeWith()
645 - {
526 + private static class MsgAllPackageListener extends MsgOtherBuses {
527 + public String subscribeWith() {
646 528 return MsgAllWindowsEventPackage.SubscribeWith;
647 529 }
648 530
649 - protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage )
650 - {
531 + protected ServerEventBus[] getAppropriateServerEventBuses( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage ) {
651 532 return pEventBus.getAllServerEventBuses();
652 533 }
653 534 }
654 535
655 - private static class MsgSpecificPackageListener extends MsgOtherBus
656 - {
657 - public String subscribeWith()
658 - {
536 + private static class MsgSpecificPackageListener extends MsgOtherBus {
537 + public String subscribeWith() {
659 538 return MsgSpecificWindowEventPackage.SubscribeWith;
660 539 }
661 540
662 - protected ServerEventBus getAppropriateServerEventBus( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage )
663 - {
541 + protected ServerEventBus getAppropriateServerEventBus( ServerEventBus pEventBus, EventPackagePayloadEventPackage pEventEventPackage ) {
664 542 int clientIdNumber = ((MsgSpecificWindowEventPackage) pEventEventPackage).getClientIdNumber();
665 543 return ServerEventBusManager.INSTANCE.getServerEventBus( clientIdNumber );
666 544 }
  @@ -670,46 +548,36 @@
670 548 * The keepAliveSession accesses the GWT ThreadLocalRequest forcing it to getSession() and logging the
671 549 * particulars of the session at DEBUG level.
672 550 */
673 - private void keepAliveSession()
674 - {
551 + private void keepAliveSession() {
675 552 HttpServletRequest zReq = getThreadLocalRequest();
676 553 HttpSession zSession = zReq.getSession();
677 - if ( zSession == null )
678 - {
554 + if ( zSession == null ) {
679 555 getLogger().debug.log( "zSession is Null" );
680 - }
681 - else if ( zSession.isNew() )
682 - {
556 + } else if ( zSession.isNew() ) {
683 557 getLogger().debug.log( "zSession.getId()=", zSession.getId() );
684 558 }
685 559 }
686 560
687 561 public String processCall( String payload )
688 - throws SerializationException
689 - {
690 - try
691 - {
562 + throws SerializationException {
563 + try {
692 564 keepAliveSession();
693 565 return super.processCall( payload );
694 566 }
695 - catch ( SerializationException e )
696 - {
567 + catch ( SerializationException e ) {
697 568 getLogger().error.log( e, "payload:", payload );
698 569 throw e;
699 570 }
700 - catch ( RuntimeException e )
701 - {
571 + catch ( RuntimeException e ) {
702 572 getLogger().error.log( e, "payload:", payload );
703 573 throw e;
704 574 }
705 575 }
706 576
707 577 protected void service( HttpServletRequest pRequest, HttpServletResponse pResponse )
708 - throws ServletException, IOException
709 - {
578 + throws ServletException, IOException {
710 579 String query = Strings.noEmpty( pRequest.getQueryString() );
711 - if ( query == null )
712 - {
580 + if ( query == null ) {
713 581 super.service( pRequest, pResponse );
714 582 return;
715 583 }
  @@ -719,33 +587,27 @@
719 587 // System.out.println( "PathInfo: " + pHttpServletRequest.getPathInfo() );
720 588 // System.out.println( "PathTranslated: " + pHttpServletRequest.getPathTranslated() );
721 589 TemplateControl zTC = resolveQuery( pRequest, query );
722 - if ( zTC == null )
723 - {
590 + if ( zTC == null ) {
724 591 throw new ServletException( "Unable to process request: " + query );
725 592 }
726 - try
727 - {
593 + try {
728 594 pResponse.setCharacterEncoding( FileUtils.UTF_8 );
729 595 ServletUtils.noCache( pResponse );
730 596 Writer zWriter = new OutputStreamWriter( pResponse.getOutputStream(), FileUtils.UTF_8 );
731 - try
732 - {
597 + try {
733 598 zTC.applyTo( zWriter, "&nbsp;" );
734 599 }
735 - finally
736 - {
600 + finally {
737 601 zWriter.close();
738 602 }
739 603 }
740 - finally
741 - {
604 + finally {
742 605 zTC.dispose();
743 606 }
744 607 }
745 608
746 609 protected TemplateControl resolveQuery( HttpServletRequest pRequest, String pQuery )
747 - throws IOException
748 - {
610 + throws IOException {
749 611 return null;
750 612 }
751 613 }