Source Code Cross Referenced for MuApplInstanceDispatcher.java in  » J2EE » WiSerFramework » de » ug2t » channel » markup » service » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » WiSerFramework » de.ug2t.channel.markup.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // @@
002:        // @@
003:        /*
004:         * Wi.Ser Framework
005:         *
006:         * Version: 1.8.1, 20-September-2007  
007:         * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008:         *
009:         * This library is free software; you can redistribute it and/or
010:         * modify it under the terms of the GNU Lesser General Public
011:         * License as published by the Free Software Foundation; either
012:         * version 2 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         * Lesser General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library located in LGPL.txt in the 
021:         * license directory; if not, write to the 
022:         * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023:         * Boston, MA  02111-1307, USA.
024:         * 
025:         * If this agreement does not cover your requirements, please contact us
026:         * via email to get detailed information about the commercial license 
027:         * or our service offerings!
028:         *
029:         */
030:        // @@
031:        package de.ug2t.channel.markup.service;
032:
033:        import java.io.*;
034:        import java.net.*;
035:        import java.util.*;
036:
037:        import javax.servlet.*;
038:        import javax.servlet.http.*;
039:
040:        import de.ug2t.channel.markup.generic.*;
041:        import de.ug2t.channel.markup.html.*;
042:        import de.ug2t.channel.markup.session.*;
043:        import de.ug2t.kernel.*;
044:        import de.ug2t.unifiedGui.*;
045:        import de.ug2t.unifiedGui.interfaces.*;
046:        import de.ug2t.unifiedGui.session.*;
047:
048:        public final class MuApplInstanceDispatcher implements 
049:                HttpSessionBindingListener {
050:            class MyApplWorker extends Thread {
051:                private String pem_xName = null;
052:                private HttpServletRequest pem_xReq = null;
053:                private HttpServletResponse pem_xRes = null;
054:                private MuGenericApplication pem_l_appl = null;
055:                private HttpSession pem_l_session = null;
056:                private ServletConfig pem_l_config = null;
057:
058:                /**
059:                 * @param target
060:                 * @param name
061:                 */
062:                public MyApplWorker(String xAppName, String xThName,
063:                        HttpServletRequest xReq, HttpServletResponse xResp,
064:                        MuGenericApplication xAppl, HttpSession xSess,
065:                        ServletConfig xConf) {
066:                    super (xThName);
067:
068:                    pem_xName = xAppName;
069:                    pem_xReq = xReq;
070:                    pem_xRes = xResp;
071:                    pem_l_appl = xAppl;
072:                    pem_l_session = xSess;
073:                    pem_l_config = xConf;
074:                }
075:
076:                public MuGenericApplication pcmf_getAppl() {
077:                    return (this .pem_l_appl);
078:                };
079:
080:                public MuGenericApplication pcmf_newAppl() {
081:                    try {
082:                        do {
083:                            if (MuApplInstanceDispatcher.this .pdm_Inst == MuApplInstanceDispatcher.this .pdm_maxInst) {
084:                                String l_scor = this .pem_l_config
085:                                        .getInitParameter("SYSADM_LOGIN");
086:                                if (l_scor != null) {
087:                                    String l_login = this .pem_xReq
088:                                            .getParameter("SYSADM_LOGIN");
089:                                    if (l_scor.equals(l_login))
090:                                        break;
091:                                }
092:
093:                                KeLog
094:                                        .pcmf_log(
095:                                                "ug2t",
096:                                                "session count overflow, to many sessions",
097:                                                this , KeLog.ERROR);
098:
099:                                // Redirect auf FehlerSeite
100:                                String l_rov = this .pem_l_config
101:                                        .getInitParameter("REDIRECT_ON_OVERFLOW");
102:                                if (l_rov != null)
103:                                    this .pem_xRes.sendRedirect(l_rov);
104:
105:                                return (null);
106:                            }
107:                            ;
108:                        } while (false);
109:
110:                        // Cookie Test
111:                        String l_doct = this .pem_l_config
112:                                .getInitParameter("TEST_COOKIE");
113:                        if (l_doct != null && l_doct.equalsIgnoreCase("TRUE")) {
114:                            if (this .pem_l_session.isNew()) {
115:                                if (this .pem_xReq.getParameter("COOKIE_TEST") == null) {
116:                                    Cookie l_cookie = new Cookie("Test",
117:                                            this .pem_xReq.getServletPath());
118:                                    l_cookie.setComment("t");
119:                                    l_cookie.setMaxAge(90);
120:                                    this .pem_xRes.addCookie(l_cookie);
121:                                    String queryString = this .pem_xReq
122:                                            .getQueryString();
123:                                    this .pem_xRes.sendRedirect(this .pem_xReq
124:                                            .getRequestURL().toString()
125:                                            + ((queryString != null) ? ("?"
126:                                                    + queryString + "&") : "?")
127:                                            + "COOKIE_TEST=TRUE");
128:
129:                                    return (null);
130:                                } else {
131:                                    if (this .pem_xReq.getCookies() == null) {
132:                                        String l_noc = this .pem_l_config
133:                                                .getInitParameter("REDIRECT_ON_NOCOOKIE");
134:                                        if (l_noc != null)
135:                                            this .pem_xRes.sendRedirect(l_noc);
136:
137:                                        return (null);
138:                                    }
139:                                }
140:                            }
141:                        }
142:
143:                        MuGenericTemplateKit l_kit = this .pcmf_setTplKit();
144:                        if (l_kit == null)
145:                            return (null);
146:
147:                        pem_l_session.setMaxInactiveInterval(pdm_timeOut);
148:                        pdm_Inst++;
149:                        KeLog.pcmf_log("ug2t",
150:                                "created new websession for application: "
151:                                        + this .pem_xName, this , KeLog.MESSAGE);
152:                        KeRegisteredObject.pcmf_register(
153:                                MuGenericApplication.MY_SESSION,
154:                                new MuHttpSessionWrapper(this .pem_l_session));
155:                        pem_l_appl = (MuGenericApplication) KeObjectFactory
156:                                .pcmf_produce(pem_xName, null);
157:
158:                        pem_l_appl.pcmf_setProtocol(pdm_protocol);
159:                        KeLog.pcmf_log("ug2t", "set http protocol to to: "
160:                                + pem_l_appl.pcmf_getProtocol(), this ,
161:                                KeLog.MESSAGE);
162:
163:                        pem_l_appl.pcmf_setAppName(pem_xName);
164:
165:                        // @@
166:
167:                        {
168:                            pem_l_appl
169:                                    .pcmf_setRenderer(new HtmlFullPageRenderer(
170:                                            pem_l_appl, l_kit));
171:                            KeLog.pcmf_log("ug2t",
172:                                    "partial rendering disabled", this ,
173:                                    KeLog.MESSAGE);
174:                        }
175:
176:                        String l_domain = this .pem_l_config
177:                                .getInitParameter("domain");
178:                        if (l_domain != null) {
179:                            if (l_domain.equals("READFROMURL")) {
180:                                URL url = new URL(pem_xReq.getRequestURL()
181:                                        .toString());
182:                                this .pem_l_appl.pcmf_setHostName(url.getHost());
183:                            } else
184:                                this .pem_l_appl.pcmf_setHostName(l_domain);
185:                        } else {
186:                            String uln = this .pem_l_config
187:                                    .getInitParameter("useLocalServerName");
188:                            if (uln == null || uln.equals("false"))
189:                                this .pem_l_appl.pcmf_setHostName(pem_xReq
190:                                        .getServerName());
191:                        }
192:
193:                        String l_port = this .pem_l_config
194:                                .getInitParameter("port");
195:                        if (l_port != null)
196:                            this .pem_l_appl.pcmf_setHttpPort(Integer
197:                                    .parseInt(l_port));
198:                        else
199:                            this .pem_l_appl.pcmf_setHttpPort(this .pem_xReq
200:                                    .getServerPort());
201:
202:                        KeLog.pcmf_log("ug2t", "set port to: "
203:                                + pem_l_appl.pcmf_getPort(), this ,
204:                                KeLog.MESSAGE);
205:
206:                        String l_url = this .pem_l_config
207:                                .getInitParameter("rootURL");
208:                        if (l_url != null)
209:                            this .pem_l_appl.pcmf_setRootUrl(l_url);
210:
211:                        KeLog.pcmf_log("ug2t", "set rootURL to: "
212:                                + pem_l_appl.pcmf_getRootUrl(), this ,
213:                                KeLog.MESSAGE);
214:
215:                        String l_overrideRemHost = this .pem_l_config
216:                                .getInitParameter("overrideAutomaticHostDetection");
217:                        if (!(l_overrideRemHost != null && l_overrideRemHost
218:                                .equals("true")))
219:                            if (pem_xReq.getRemoteHost().equals("127.0.0.1"))
220:                                this .pem_l_appl.pcmf_setHostName("localhost");
221:
222:                        KeLog.pcmf_log("ug2t", "set domain to: "
223:                                + pem_l_appl.pcmf_getHostName(), this ,
224:                                KeLog.MESSAGE);
225:
226:                        String l_robe = this .pem_l_config
227:                                .getInitParameter("RELEASE_ON_BROWSER_EXIT");
228:                        if (l_robe != null && l_robe.equalsIgnoreCase("false")) {
229:                            this .pem_l_appl.pcmf_setReleaseOnBrowserExit(false);
230:                            KeLog
231:                                    .pcmf_log(
232:                                            "ug2t",
233:                                            "automatic session release on browser exit has been disabled",
234:                                            this , KeLog.MESSAGE);
235:                        }
236:
237:                        pem_l_session.getAttribute("");
238:                        pem_l_session.setAttribute(pem_xName,
239:                                new UnFailoverSessionWrapper(
240:                                        MuApplInstanceDispatcher.this ,
241:                                        KeRegisteredObject
242:                                                .pcmf_getCurrentContext(),
243:                                        pem_l_appl));
244:                    } catch (Exception e) {
245:                        if (pem_l_appl == null)
246:                            KeLog
247:                                    .pcmf_log(
248:                                            "ug2t",
249:                                            "catch exception during initialise of new application-session",
250:                                            this , KeLog.FATAL);
251:                        else
252:                            KeLog
253:                                    .pcmf_log(
254:                                            pem_l_appl.pcmf_getObjName(),
255:                                            "catch exception during initialise of new application-session",
256:                                            this , KeLog.FATAL);
257:
258:                        e.printStackTrace(System.out);
259:
260:                        if (pdm_errorHandler == null)
261:                            pdm_errorHandler = (MuGenericApplication) KeObjectFactory
262:                                    .pcmf_produce(pdm_errorHdl, null);
263:
264:                        if (pdm_errorHandler != null) {
265:                            try {
266:                                pdm_errorHandler.pcmf_work(pem_xReq, pem_xRes,
267:                                        true);
268:                            } catch (Exception e1) {
269:                                KeLog
270:                                        .pcmf_log(
271:                                                "ug2t",
272:                                                "catch exception during error-handling",
273:                                                this , KeLog.FATAL);
274:                                KeLog.pcmf_logException("ug2t", this , e1);
275:                            }
276:                            ;
277:                        }
278:                        ;
279:                    }
280:                    ;
281:
282:                    return (pem_l_appl);
283:                }
284:
285:                private MuGenericTemplateKit pcmf_setTplKit() {
286:                    // liest den Browser und die Sprache aus
287:                    // System.out.println (req.getHeader("User-Agent"));
288:
289:                    try {
290:                        String l_lang = this .pem_xReq
291:                                .getParameter(IUnApplication.MY_LANGUAGE);
292:                        if (l_lang == null) {
293:                            l_lang = this .pem_xReq.getHeader("Accept-Language");
294:                        }
295:
296:                        if (l_lang != null) {
297:                            KeLog
298:                                    .pcmf_log("ug2t",
299:                                            "try to set language definition: "
300:                                                    + l_lang, this , KeLog.DEBUG);
301:
302:                            String l_langCode = null;
303:                            Object l_langMap = null;
304:
305:                            String[] acceptedLanguageTags = l_lang.split(",");
306:                            ArrayList acceptedLanguageCodes = new ArrayList(
307:                                    acceptedLanguageTags.length);
308:                            ArrayList acceptedCountryCodes = new ArrayList(
309:                                    acceptedLanguageTags.length);
310:                            for (int i = 0; i < acceptedLanguageTags.length; i++) {
311:                                String languageTag = acceptedLanguageTags[i];
312:                                // ignore "Quality Value" settings (e.g. Mozilla):
313:                                int indexOfQValue = languageTag.indexOf(';');
314:                                if (indexOfQValue >= 0) {
315:                                    languageTag = languageTag.substring(0,
316:                                            indexOfQValue);
317:                                }
318:                                // take subtags into account:
319:                                String[] subTags = languageTag.split("-");
320:                                String languageCode = subTags[0];
321:                                String countryCode = (subTags.length > 1) ? subTags[1]
322:                                        : "";
323:                                Locale l_locale = new Locale(languageCode,
324:                                        countryCode);
325:                                if (!acceptedLanguageCodes
326:                                        .contains(languageCode)) {
327:                                    acceptedLanguageCodes.add(languageCode);
328:                                }
329:                                if (!acceptedCountryCodes.contains(countryCode)) {
330:                                    acceptedCountryCodes.add(countryCode);
331:                                }
332:
333:                                l_langMap = KeEnvironment.pcmf_getParameter(
334:                                        "environment.xml",
335:                                        IUnApplication.MY_LANGUAGE, l_locale
336:                                                .toString());
337:                                if (l_langMap != null) {
338:                                    l_langCode = l_locale.toString();
339:                                    break;
340:                                }
341:                            }
342:                            if (l_langMap == null) {
343:                                // try only language codes in the order of Accept-Language:
344:                                for (Iterator i = acceptedLanguageCodes
345:                                        .iterator(); i.hasNext();) {
346:                                    String code = i.next().toString();
347:                                    l_langMap = KeEnvironment
348:                                            .pcmf_getParameter(
349:                                                    "environment.xml",
350:                                                    IUnApplication.MY_LANGUAGE,
351:                                                    code);
352:                                    if (l_langMap != null) {
353:                                        l_langCode = code;
354:                                        break;
355:                                    }
356:                                }
357:                            }
358:                            if (l_langMap == null) {
359:                                // finally, try only country codes in the order of Accept-Language:
360:                                for (Iterator i = acceptedLanguageCodes
361:                                        .iterator(); i.hasNext();) {
362:                                    String code = i.next().toString();
363:                                    l_langMap = KeEnvironment
364:                                            .pcmf_getParameter(
365:                                                    "environment.xml",
366:                                                    IUnApplication.MY_LANGUAGE,
367:                                                    code);
368:                                    if (l_langMap != null) {
369:                                        l_langCode = code;
370:                                        break;
371:                                    }
372:                                }
373:                            }
374:                            if (l_langMap == null) {
375:                                KeLog
376:                                        .pcmf_log(
377:                                                "ug2t",
378:                                                "definition not found, try to assign default",
379:                                                this , KeLog.DEBUG);
380:                                l_langCode = "DEFAULT";
381:                                l_langMap = KeEnvironment.pcmf_getParameter(
382:                                        "environment.xml",
383:                                        IUnApplication.MY_LANGUAGE, l_langCode);
384:                            }
385:                            KeRegisteredObject.pcmf_register(
386:                                    IUnApplication.MY_LANGUAGE_CODE,
387:                                    new KeStringWrapper(l_langCode));
388:                            if (l_langMap == null) {
389:                                throw (new Exception());
390:                            }
391:
392:                            KeRegisteredObject.pcmf_register(
393:                                    IUnApplication.MY_LANGUAGE,
394:                                    new KeStringWrapper(l_langMap.toString()));
395:                            KeLog.pcmf_log("ug2t", "set language from '"
396:                                    + l_lang + "' to: " + l_langCode + "=>"
397:                                    + l_langMap, this , KeLog.MESSAGE);
398:                        }
399:                    } catch (Exception e) {
400:                        KeLog.pcmf_log("ug2t",
401:                                "no valid language definition found", this ,
402:                                KeLog.MESSAGE);
403:                    }
404:
405:                    String l_header = this .pem_xReq.getHeader("User-Agent");
406:                    String l_rnc = this .pem_l_config
407:                            .getInitParameter("REDIRECT_ON_INVALID_CLIENT");
408:                    MuGenericTemplateKit l_kit = null;
409:                    if (l_rnc != null) {
410:                        l_kit = MuApplInstanceDispatcher.this .pem_tplSel
411:                                .pcmf_getKit(l_header, false);
412:                        if (l_kit == null) {
413:                            try {
414:                                this .pem_xRes.sendRedirect(l_rnc);
415:                            } catch (Exception e) {
416:                                KeLog.pcmf_logException("ug2t", this , e);
417:                            }
418:                            return (null);
419:                        }
420:                    } else
421:                        l_kit = MuApplInstanceDispatcher.this .pem_tplSel
422:                                .pcmf_getKit(l_header);
423:
424:                    KeRegisteredObject.pcmf_register(
425:                            MuGenericTemplateKit.TEMPLATE_KIT_NAME, l_kit);
426:                    KeRegisteredObject.pcmf_register(
427:                            IUnApplication.MY_CLIENT_TYPE, new KeStringWrapper(
428:                                    l_kit.pcmf_getCurrentTemplateKitName()));
429:
430:                    return (l_kit);
431:                }
432:
433:                public void run() {
434:                    KeLog.pcmf_log("ug2t", "run dispatcher thread", this ,
435:                            KeLog.TRACE);
436:
437:                    if (this .pem_l_appl == null) {
438:                        this .pcmf_newAppl();
439:                        return;
440:                    }
441:
442:                    try {
443:                        pem_l_appl.pcmf_work(pem_xReq, pem_xRes, false);
444:                    } catch (Exception e) {
445:                        KeLog.pcmf_log("ug2t",
446:                                "catch exception during application-Work",
447:                                this , KeLog.FATAL);
448:                        KeLog.pcmf_logException("ug2t", this , e);
449:
450:                        if (pdm_errorHandler == null) {
451:                            try {
452:                                pdm_errorHandler = (MuGenericApplication) KeObjectFactory
453:                                        .pcmf_produce(pdm_errorHdl, null);
454:                            } catch (Exception e2) {
455:                                KeLog.pcmf_log("ug2t",
456:                                        "no valid error handler configured",
457:                                        this , KeLog.ERROR);
458:                                KeLog.pcmf_logException("ug2t", this , e2);
459:                            }
460:                        }
461:
462:                        if (pdm_errorHandler != null) {
463:                            try {
464:                                pdm_errorHandler.pcmf_work(pem_xReq, pem_xRes,
465:                                        true);
466:                            } catch (Exception e1) {
467:                                KeLog
468:                                        .pcmf_log(
469:                                                "ug2t",
470:                                                "catch exception during error-handling",
471:                                                this , KeLog.FATAL);
472:                                KeLog.pcmf_logException("ug2t", this , e1);
473:                            }
474:                            ;
475:                        }
476:                        ;
477:                    }
478:                    ;
479:                    KeLog.pcmf_log("ug2t", "terminate dispatcher thread", this ,
480:                            KeLog.DEBUG);
481:
482:                    return;
483:                };
484:            }
485:
486:            protected int pdm_maxInst = 500;
487:            protected int pdm_Inst = 0;
488:            protected MuGenericApplication pdm_errorHandler = null;
489:            protected int pdm_timeOut = 1800;
490:            protected int pdm_resDel = 100;
491:            protected int pdm_deadLock = 600;
492:            protected ServletConfig pdm_config = null;
493:            protected String pdm_errorHdl = null;
494:            protected String pdm_protocol = "http";
495:            private static Object pem_semaphor = new Object();
496:
497:            private MuGenericTemplateKitSelector pem_tplSel = null;
498:
499:            public MuApplInstanceDispatcher(int xMaxInst, String xErrorHandler,
500:                    int xTimeOut, ServletConfig xConfig) {
501:                pdm_maxInst = xMaxInst;
502:                pdm_timeOut = xTimeOut;
503:                pdm_config = xConfig;
504:                pdm_errorHdl = xErrorHandler;
505:
506:                return;
507:            }
508:
509:            public MuApplInstanceDispatcher(int xMaxInst, String xErrorHandler,
510:                    int xTimeOut, MuGenericTemplateKitSelector xTplSel,
511:                    String xProtocol, int xResDel, int xDeadLock) {
512:                pdm_maxInst = xMaxInst;
513:                pdm_timeOut = xTimeOut;
514:                pdm_errorHdl = xErrorHandler;
515:                pem_tplSel = xTplSel;
516:                pdm_protocol = xProtocol;
517:                pdm_resDel = xResDel;
518:                pdm_deadLock = xDeadLock;
519:
520:                return;
521:            }
522:
523:            public void valueBound(HttpSessionBindingEvent event) {
524:                return;
525:            };
526:
527:            public void valueUnbound(HttpSessionBindingEvent event) {
528:                synchronized (pem_semaphor) {
529:                    pdm_Inst--;
530:                }
531:                ;
532:
533:                return;
534:            };
535:
536:            public void pcmf_work(String xName, HttpServletRequest xReq,
537:                    HttpServletResponse xRes, ServletConfig xConf)
538:                    throws Exception {
539:                HttpSession l_session = xReq.getSession();
540:                String l_sid = l_session.getId();
541:
542:                MuGenericApplication l_appl = null;
543:
544:                UnFailoverSessionWrapper l_wrapper = (UnFailoverSessionWrapper) l_session
545:                        .getAttribute(xName);
546:
547:                // @@
548:
549:                if (l_wrapper != null) {
550:                    l_appl = (MuGenericApplication) l_wrapper.pcmf_getAppl();
551:
552:                    // @@
553:                }
554:
555:                MyApplWorker l_thread = null;
556:
557:                if (l_appl == null) {
558:                    synchronized (pem_semaphor) {
559:                        KeLog.pcmf_log("ug2t",
560:                                "request new application instance", this ,
561:                                KeLog.MESSAGE);
562:                        l_thread = new MyApplWorker(xName, l_sid, xReq, xRes,
563:                                l_appl, l_session, xConf);
564:                        l_thread.start();
565:                        pemf_waitForWorker(l_session, l_appl, l_thread);
566:                        l_appl = l_thread.pcmf_getAppl();
567:                        if (l_appl == null) {
568:                            l_session.invalidate();
569:                            return;
570:                        }
571:                    }
572:                    ;
573:                }
574:                // Immer nur ein Req pro Session
575:                synchronized (l_appl) {
576:                    if (l_appl.pcmf_isDeleted()) {
577:                        String l_rd = this .pdm_config
578:                                .getInitParameter("REDIRECT_ON_EXIT");
579:                        boolean l_pr = l_appl.pcmf_getTemplateKit()
580:                                .pcmf_getSupportPartialRender();
581:
582:                        if (l_rd == null || l_pr)
583:                            xRes.sendRedirect(xReq.getRequestURL().toString()
584:                                    + "?RELOAD=true");
585:                        else if (l_rd != null)
586:                            xRes.sendRedirect(l_rd);
587:                        else
588:                            xRes.sendRedirect(xReq.getRequestURL().toString()
589:                                    + "?RELOAD=true");
590:
591:                        return;
592:                    }
593:
594:                    UnEventDispatcher.pcmf_incReqCnt();
595:                    pcmf_handleRequest(xName, xReq, xRes, xConf, l_session,
596:                            l_sid, l_appl);
597:                    UnEventDispatcher.pcmf_decReqCnt();
598:                }
599:
600:                return;
601:            }
602:
603:            private void pcmf_handleRequest(String xName,
604:                    HttpServletRequest xReq, HttpServletResponse xRes,
605:                    ServletConfig xConf, HttpSession xSession, String xSid,
606:                    MuGenericApplication xAppl) {
607:                MyApplWorker l_thread;
608:                l_thread = new MyApplWorker(xName, xSid, xReq, xRes, xAppl,
609:                        xSession, xConf);
610:
611:                // KeLog.pcmf_log("ug2t", "starting dispatcher thread: " +
612:                // l_thread, this, KeLog.DEBUG);
613:                try {
614:                    l_thread.start();
615:                    pemf_waitForWorker(xSession, xAppl, l_thread);
616:                } catch (Exception e) {
617:                    KeLog.pcmf_logException("ug2t", this , e);
618:                } catch (Throwable e) {
619:                    KeLog.pcmf_logThrowable("ug2t", this , e);
620:                }
621:            }
622:
623:            private void pemf_waitForWorker(HttpSession xSession,
624:                    MuGenericApplication xAppl, MyApplWorker l_thread)
625:                    throws InterruptedException {
626:                int i = 0;
627:                if (this .pdm_resDel > 0) {
628:                    while (l_thread.isAlive() == true) {
629:                        i += this .pdm_resDel;
630:
631:                        // KeLog.pcmf_log("ug2t", "waiting for termination of
632:                        // dispatcher thread: " + l_thread, this, KeLog.DEBUG);          
633:                        Thread.sleep(this .pdm_resDel);
634:
635:                        if (i > this .pdm_deadLock) {
636:                            KeLog.pcmf_log("ug2t",
637:                                    "deadlock detected, try to close session: "
638:                                            + l_thread, this , KeLog.ERROR);
639:
640:                            try {
641:                                l_thread.interrupt();
642:                                xSession.invalidate();
643:                                xAppl.notifyAll();
644:                                i = 1;
645:                                KeLog.pcmf_log("ug2t",
646:                                        "Work thread has been interrupted: "
647:                                                + l_thread, this , KeLog.FATAL);
648:                            } catch (SecurityException se) {
649:                                KeLog.pcmf_log("ug2t",
650:                                        "cannot interrupt thread: " + l_thread,
651:                                        this , KeLog.ERROR);
652:                            } catch (Exception e) {
653:                                KeLog.pcmf_log("ug2t",
654:                                        "session is already closed: "
655:                                                + l_thread, this , KeLog.ERROR);
656:                            }
657:                            break;
658:                        }
659:                    }
660:                } else if (this .pdm_resDel == 0) {
661:                    l_thread.join(this .pdm_deadLock);
662:                    if (l_thread.isAlive()) {
663:                        KeLog.pcmf_log("ug2t",
664:                                "deadlock detected, try to close session: "
665:                                        + l_thread, this , KeLog.ERROR);
666:
667:                        try {
668:                            l_thread.interrupt();
669:                            xSession.invalidate();
670:                            xAppl.notifyAll();
671:                            KeLog.pcmf_log("ug2t",
672:                                    "Work thread has been interrupted: "
673:                                            + l_thread, this , KeLog.FATAL);
674:                        } catch (SecurityException se) {
675:                            KeLog.pcmf_log("ug2t", "cannot interrupt thread: "
676:                                    + l_thread, this , KeLog.ERROR);
677:                        } catch (Exception e) {
678:                            KeLog.pcmf_log("ug2t",
679:                                    "session is already closed: " + l_thread,
680:                                    this , KeLog.ERROR);
681:                        }
682:                    }
683:                } else
684:                    l_thread.join();
685:            };
686:
687:            public void pcmf_create(String xName, HttpServletRequest xReq,
688:                    HttpServletResponse xRes, ServletConfig xConf)
689:                    throws Exception {
690:                HttpSession l_session = xReq.getSession();
691:                String l_sid = l_session.getId();
692:
693:                MuGenericApplication l_appl = null;
694:
695:                UnFailoverSessionWrapper l_wrapper = (UnFailoverSessionWrapper) l_session
696:                        .getAttribute(xName);
697:                if (l_wrapper != null) {
698:                    l_appl = (MuGenericApplication) l_wrapper.pcmf_getAppl();
699:
700:                    // @@
701:                }
702:
703:                MyApplWorker l_thread = null;
704:
705:                if (l_appl == null) {
706:                    synchronized (pem_semaphor) {
707:                        KeLog.pcmf_log("ug2t",
708:                                "request new application instance", this ,
709:                                KeLog.MESSAGE);
710:                        l_thread = new MyApplWorker(xName, l_sid, xReq, xRes,
711:                                l_appl, l_session, xConf);
712:                        l_thread.start();
713:                        l_thread.join();
714:                        l_appl = l_thread.pcmf_getAppl();
715:                        if (l_appl == null) {
716:                            l_session.invalidate();
717:                            return;
718:                        }
719:                    }
720:                    ;
721:                }
722:
723:                return;
724:            };
725:
726:            // @@
727:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.