Source Code Cross Referenced for HoTcpIpSession.java in  » J2EE » WiSerFramework » de » ug2t » channel » ho » session » 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.ho.session 
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.ho.session;
032:
033:        import java.io.*;
034:        import java.net.*;
035:        import java.util.*;
036:        import java.util.zip.*;
037:
038:        import de.ug2t.kernel.*;
039:        import de.ug2t.unifiedGui.interfaces.*;
040:        import de.ug2t.xmlScript.*;
041:
042:        public final class HoTcpIpSession extends KeNameSpaceThread implements 
043:                IHoSession {
044:            // @@
045:
046:            protected BufferedReader pdm_in = null;
047:            protected PrintWriter pdm_out = null;
048:
049:            private HoXmlRpcDispatcher pem_rpcDisp = new HoXmlRpcDispatcher();
050:            private Map pem_sessionContext = Collections
051:                    .synchronizedMap(new HashMap());
052:            private int pem_port;
053:            private InetAddress pem_host;
054:            private volatile boolean pem_clientSide = false;
055:            private boolean pem_alive = false;
056:            private HoTcpIpSessionReader pem_reader = new HoTcpIpSessionReader();
057:            private boolean pem_inResume = false;
058:
059:            // @@
060:
061:            protected boolean pdm_compress = false;
062:            private boolean pem_collectReplies = true;
063:            protected Socket pdm_sock = null;
064:
065:            private boolean pem_terminateOnSessionClose = false;
066:
067:            private IHoClientCommandDispatcher pem_cmdDisp = null;
068:
069:            class HoTcpIpSessionReader extends Thread {
070:                private KeFiFo pem_buffer = new KeFiFo();
071:                private boolean pem_exit = false;
072:
073:                public void run() {
074:                    KeLog
075:                            .pcmf_log(
076:                                    "ug2t",
077:                                    "tcp/ip socket session HoTcpIpSessionReader-queue started",
078:                                    this , KeLog.MESSAGE);
079:
080:                    try {
081:                        while (true) {
082:                            // @@
083:
084:                            String l_inMessage = HoTcpIpSession.this .pdm_in
085:                                    .readLine();
086:
087:                            // Handle Fileupload ==> file://len,fname ==> file
088:                            if (l_inMessage.startsWith("file://")) {
089:                                l_inMessage = KeTools.pcmf_stringSingleSubst(
090:                                        l_inMessage, "file://", "");
091:                                ArrayList l_tokens = KeTools.pcmf_stringTokens(
092:                                        l_inMessage, ",", 2);
093:                                int l_fsize = Integer.parseInt(l_tokens.get(0)
094:                                        .toString());
095:                                String l_fname = KeEnvironment
096:                                        .pcmf_getSessionTmpDir()
097:                                        + l_tokens.get(1).toString();
098:
099:                                byte l_file[] = new byte[l_fsize];
100:                                pdm_sock.getInputStream().read(l_file, 0,
101:                                        l_fsize);
102:
103:                                FileOutputStream oStream = new FileOutputStream(
104:                                        l_fname);
105:                                oStream.write(l_file);
106:                                oStream.flush();
107:                                oStream.close();
108:                            } else
109:                                this .pem_buffer.pcmf_addObj(l_inMessage);
110:
111:                            // @@
112:
113:                            // System.out.println(l_inMessage);
114:                        }
115:                    } catch (Exception e) {
116:                        KeLog.pcmf_log("ug2t", "socket read failed", this ,
117:                                KeLog.MESSAGE);
118:                        this .pem_exit = true;
119:                    }
120:                };
121:
122:                protected String pcmf_getMessage() {
123:                    Object l_res = null;
124:
125:                    try {
126:                        do {
127:                            l_res = this .pem_buffer.pcmf_getObj();
128:
129:                            if (l_res == null)
130:                                Thread.sleep(100);
131:                        } while (l_res == null && this .pem_exit == false);
132:                    } catch (Exception e) {
133:                        KeLog.pcmf_logException("ug2t", this , e);
134:                    }
135:                    ;
136:
137:                    return (l_res == null ? null : l_res.toString());
138:                };
139:            };
140:
141:            public HoTcpIpSession(Socket l_sock) {
142:                this .setName("HO_TCPIP"
143:                        + Long.toHexString(new Date().getTime())
144:                        + Integer.toHexString(this .hashCode()));
145:
146:                KeLog.pcmf_log("ug2t", "tcp/ip socket session created", this ,
147:                        KeLog.MESSAGE);
148:
149:                pem_port = l_sock.getPort();
150:                pem_host = l_sock.getInetAddress();
151:                pdm_sock = l_sock;
152:
153:                this .pem_alive = true;
154:
155:                try {
156:                    pdm_in = new BufferedReader(new InputStreamReader(l_sock
157:                            .getInputStream()));
158:                    pdm_out = new PrintWriter(new BufferedWriter(
159:                            new OutputStreamWriter(l_sock.getOutputStream())),
160:                            true);
161:                } catch (Exception e) {
162:                    KeLog.pcmf_logException("ug2t", this , e);
163:                }
164:                ;
165:            };
166:
167:            public HoTcpIpSession(Socket l_sock, boolean xCompress) {
168:                this .setName("HO_TCPIP"
169:                        + Long.toHexString(new Date().getTime())
170:                        + Integer.toHexString(this .hashCode()));
171:
172:                // @@
173:
174:                KeLog.pcmf_log("ug2t", "tcp/ip socket session created", this ,
175:                        KeLog.MESSAGE);
176:
177:                pem_port = l_sock.getPort();
178:                pem_host = l_sock.getInetAddress();
179:                pdm_sock = l_sock;
180:                pdm_compress = xCompress;
181:
182:                this .pem_alive = true;
183:
184:                try {
185:                    pdm_in = new BufferedReader(new InputStreamReader(l_sock
186:                            .getInputStream()));
187:                    pdm_out = new PrintWriter(new BufferedWriter(
188:                            new OutputStreamWriter(l_sock.getOutputStream())),
189:                            true);
190:                } catch (Exception e) {
191:                    KeLog.pcmf_logException("ug2t", this , e);
192:                }
193:                ;
194:            };
195:
196:            public synchronized boolean pcmf_beginLazy() {
197:                // @@
198:
199:                return (true);
200:            };
201:
202:            public synchronized boolean pcmf_endLazy() {
203:                // @@
204:
205:                return (true);
206:            };
207:
208:            public synchronized boolean pcmf_beginTr() {
209:                // @@
210:
211:                return (true);
212:            };
213:
214:            public synchronized boolean pcmf_isInTransaction() {
215:                boolean l_ret = false;
216:
217:                // @@
218:
219:                return (l_ret);
220:            };
221:
222:            public synchronized boolean pcmf_rollbackTr() {
223:                // @@
224:
225:                return (true);
226:            }
227:
228:            public synchronized boolean pcmf_rollbackAllTr() {
229:                // @@
230:
231:                return (true);
232:            }
233:
234:            public synchronized boolean pcmf_commitAllTr() {
235:                // @@
236:
237:                return (true);
238:            }
239:
240:            public synchronized boolean pcmf_commitTr() {
241:                // @@
242:
243:                return (true);
244:            };
245:
246:            public synchronized void pcmf_setClientSide(boolean xClSide,
247:                    IHoClientCommandDispatcher xCmd) {
248:                this .pem_clientSide = xClSide;
249:                this .pem_cmdDisp = xCmd;
250:            }
251:
252:            private int pcmf_answer() {
253:                int l_fret = 0;
254:                String l_inMessage = null;
255:
256:                try {
257:                    l_inMessage = this .pem_reader.pcmf_getMessage();
258:                    if (l_inMessage != null) {
259:                        if (KeLog.pcmf_testLog(KeLog.DEBUG)) {
260:                            if (l_inMessage.length() > 256)
261:                                KeLog
262:                                        .pcmf_log("ug2t",
263:                                                "rec (first 250 signs): "
264:                                                        + l_inMessage
265:                                                                .substring(0,
266:                                                                        250),
267:                                                this , KeLog.DEBUG);
268:                            else
269:                                KeLog.pcmf_log("ug2t", "rec: " + l_inMessage,
270:                                        this , KeLog.DEBUG);
271:                        }
272:                        if (this .pem_clientSide) {
273:                            pem_rpcDisp.pcmf_setAdditionalInfo(l_inMessage);
274:                            this .pem_cmdDisp.pcmf_dispatchCommand(pem_rpcDisp);
275:                        } else
276:                            pem_rpcDisp.pcmf_execObj(l_inMessage);
277:                    } else {
278:                        KeLog
279:                                .pcmf_log(
280:                                        "ug2t",
281:                                        "tcp/ip socket session closed by remote socket",
282:                                        this , KeLog.MESSAGE);
283:                        l_fret = -1;
284:                    }
285:                    ;
286:                } catch (Exception e) {
287:                    KeLog.pcmf_log("ug2t",
288:                            "unknown error, tcp/ip socket session closed",
289:                            this , KeLog.ERROR);
290:                    l_fret = -1;
291:                }
292:                ;
293:                return (l_fret);
294:            };
295:
296:            public synchronized Object pcmf_call(String xCall,
297:                    IUnLazyComponent xObj) {
298:                // @@
299:
300:                return (this .pcmf_call(xCall));
301:            }
302:
303:            public synchronized void pcmf_setLazyEnabled(boolean xEn) {
304:                // @@
305:            }
306:
307:            // @@
308:
309:            public synchronized void pcmf_writeFile(String xFileName) {
310:                String l_fname = KeEnvironment.pcmf_buildPath(xFileName);
311:
312:                try {
313:                    FileInputStream iStream = new FileInputStream(l_fname);
314:                    int l_len = iStream.available();
315:                    byte[] l_fdata = new byte[l_len];
316:                    iStream.read(l_fdata);
317:
318:                    this .pdm_sock.getOutputStream().write(
319:                            ("file://" + l_len + ","
320:                                    + new File(l_fname).getName() + "\n")
321:                                    .getBytes());
322:                    this .pdm_sock.getOutputStream().write(l_fdata);
323:                    this .pdm_sock.getOutputStream().flush();
324:                } catch (Exception e) {
325:                    KeLog.pcmf_log("ug2t", "error sending file" + l_fname,
326:                            this , KeLog.ERROR);
327:                }
328:            }
329:
330:            public void pcmf_setClientCommandDispatcher(
331:                    IHoClientCommandDispatcher xCmd) {
332:                this .pem_cmdDisp = xCmd;
333:            }
334:
335:            public synchronized Object pcmf_call(String xCall) {
336:                // @@
337:
338:                if (this .pem_alive == false) {
339:                    KeLog.pcmf_log("ug2t",
340:                            "cannot send data, tcp/ip socket session is not alive"
341:                                    + xCall, this , KeLog.DEBUG);
342:                    return (null);
343:                }
344:
345:                try {
346:                    // @@
347:
348:                    KeLog.pcmf_log("ug2t", "send: " + xCall, this , KeLog.DEBUG);
349:
350:                    // @@
351:
352:                    this .pdm_out.println(xCall);
353:
354:                    // @@
355:                } catch (Exception e) {
356:                    KeLog.pcmf_log("ug2t",
357:                            "tcp/ip socket session closed by remote socket",
358:                            this , KeLog.MESSAGE);
359:                }
360:                ;
361:                return (null);
362:            };
363:
364:            // @@
365:
366:            public synchronized void pcmf_setCollectReplies(boolean xCol) {
367:                this .pem_collectReplies = xCol;
368:            }
369:
370:            public synchronized boolean pcmf_getCollectReplies() {
371:                return (this .pem_collectReplies);
372:            }
373:
374:            public void run() {
375:                KeLog.pcmf_log("ug2t", "tcp/ip socket session started", this ,
376:                        KeLog.MESSAGE);
377:                KeRegisteredObject.pcmf_register(IHoSession.SESSION_NAME, this );
378:
379:                this .pem_reader.start();
380:
381:                while (true) {
382:                    if (this .pcmf_answer() == -1)
383:                        break;
384:                }
385:                ;
386:
387:                pcmf_kill();
388:            };
389:
390:            public synchronized void pcmf_kill() {
391:                if (this .pem_alive == true) {
392:                    this .pem_alive = false;
393:
394:                    KeLog.pcmf_log("ug2t", "tcp/ip socket session killed",
395:                            this , KeLog.MESSAGE);
396:
397:                    Iterator l_it = this .pem_sessionContext.values().iterator();
398:                    Object l_obj = null;
399:
400:                    while (l_it.hasNext()) {
401:                        l_obj = l_it.next();
402:                        if (l_obj instanceof  IHoSessionBindEvent)
403:                            ((IHoSessionBindEvent) l_obj).pcmf_unBind(this );
404:                    }
405:                    ;
406:
407:                    KeRegisteredObject.pcmf_unRegister(this );
408:                    this .pem_rpcDisp.pcmf_unRegister();
409:
410:                    KeRegisteredObject.pcmf_deleteContext(null);
411:
412:                    if (this .pem_terminateOnSessionClose)
413:                        Runtime.getRuntime().exit(0);
414:                } else {
415:                    KeLog.pcmf_log("ug2t",
416:                            "tcp/ip socket session is alreary killed", this ,
417:                            KeLog.DEBUG);
418:                }
419:                return;
420:            }
421:
422:            public synchronized Object pcmf_addCtxValue(Object xName,
423:                    Object xVal) {
424:                Object l_obj = this .pem_sessionContext.put(xName, xVal);
425:                if (l_obj != null && l_obj instanceof  IHoSessionBindEvent)
426:                    ((IHoSessionBindEvent) l_obj).pcmf_unBind(this );
427:
428:                if (xVal instanceof  IHoSessionBindEvent)
429:                    ((IHoSessionBindEvent) xVal).pcmf_bind(this );
430:
431:                return (l_obj);
432:            };
433:
434:            public synchronized Object pcmf_getCtxValue(Object xName) {
435:                return (this .pem_sessionContext.get(xName));
436:            };
437:
438:            public synchronized Object pcmf_removeCtxValue(Object xName) {
439:                Object l_obj = this .pem_sessionContext.remove(xName);
440:                if (l_obj != null && l_obj instanceof  IHoSessionBindEvent)
441:                    ((IHoSessionBindEvent) l_obj).pcmf_unBind(this );
442:
443:                return (l_obj);
444:            };
445:
446:            public synchronized int pcmf_getPort() {
447:                return (pem_port);
448:            };
449:
450:            public synchronized InetAddress pcmf_getHost() {
451:                return (pem_host);
452:            };
453:
454:            public String pcmf_getHostName() {
455:                return (this .pem_host.getHostName());
456:            }
457:
458:            public synchronized boolean pcmf_isClientSide() {
459:                return (this .pem_clientSide);
460:            }
461:
462:            public synchronized boolean pcmf_isAlive() {
463:                return (this .pem_alive);
464:            }
465:
466:            public synchronized void pcmf_setTerminateOnSessionClose(
467:                    boolean xTerminate) {
468:                this .pem_terminateOnSessionClose = xTerminate;
469:            }
470:
471:            public boolean pcmf_supportsFileUpload() {
472:                boolean l_ret = false;
473:                // @@;
474:
475:                return (l_ret);
476:            }
477:
478:            public boolean pcmf_supportsLazyLoading() {
479:                boolean l_ret = false;
480:                // @@;
481:
482:                return (l_ret);
483:            }
484:
485:            public boolean pcmf_supportsSSL() {
486:                boolean l_ret = false;
487:                // @@;
488:
489:                return (l_ret);
490:            }
491:
492:            public boolean pcmf_supportsTransactions() {
493:                boolean l_ret = false;
494:                // @@;
495:
496:                return (l_ret);
497:            }
498:
499:            public boolean pcmf_supportsCompression() {
500:                boolean l_ret = false;
501:                // @@;
502:
503:                return (l_ret);
504:            }
505:
506:            public void pcmf_execRpcDirect(Object xRpc) {
507:                this .pem_rpcDisp.pcmf_execObj(xRpc);
508:            }
509:
510:            public byte[] pcmf_getMessage() {
511:                return (null);
512:            }
513:
514:            public boolean pcmf_supportsPush() {
515:                return (true);
516:            }
517:
518:            public String pcmf_record(boolean xRecord) {
519:                String l_ret = null;
520:                // @@
521:                return (l_ret);
522:            }
523:
524:            public boolean pcmf_isRecord() {
525:                boolean l_ret = false;
526:                // @@
527:                return (l_ret);
528:            }
529:
530:            public void pcmf_setDisabled(boolean xDis) {
531:                // @@;
532:            }
533:
534:            public boolean pcmf_isDisabled() {
535:                boolean l_ret = false;
536:                // @@;
537:                return (l_ret);
538:            }
539:
540:            public void pcmf_playback(String xFile, int xMax) {
541:                // @@
542:                return;
543:            }
544:
545:            public void pcmf_toCheckPoint(int xPoint) {
546:                // @@
547:                return;
548:            }
549:
550:            public int pcmf_getCheckPointValue() {
551:                // @@
552:                return (-1);
553:            }
554:
555:            public void pcmf_setSessionRecorder(IHoSessionRecorder xRecorder) {
556:                // @@
557:            }
558:
559:            public String pcmf_getId() {
560:                return (this .getName());
561:            }
562:
563:            public void pcmf_echoCall(String xCall) {
564:                // @@
565:            }
566:
567:            public void pcmf_setAutoEcho(boolean xAuto) {
568:                // @@
569:            }
570:
571:            public boolean pcmf_doAutoEcho() {
572:                boolean l_ret = false;
573:                // @@
574:                return (l_ret);
575:            }
576:
577:            public boolean pcmf_inResume() {
578:                boolean l_ret = false;
579:                // @@
580:                return (l_ret);
581:            }
582:
583:            public void pcmf_setInResume(boolean xResume) {
584:                // @@
585:            }
586:
587:            public boolean pcmf_supportsDurableConnection() {
588:                return (true);
589:            }
590:
591:            private javax.swing.Timer pem_timer = null;
592:            private int pem_timeout = -1;
593:
594:            public void pcmf_startTimeout(String xId, IKeExecutable xCleaner) {
595:                if (this .pem_timeout == -1)
596:                    return;
597:
598:                if (this .pem_timer == null) {
599:                    this .pem_timer = new javax.swing.Timer(this .pem_timeout,
600:                            new HoSessionTimeoutTimer(this , xId, xCleaner));
601:                    this .pem_timer.setRepeats(false);
602:                    this .pem_timer.start();
603:                } else
604:                    this .pem_timer.restart();
605:            }
606:
607:            public void pcmf_setTimeout(int xTimeout) {
608:                this .pem_timeout = xTimeout * 1000;
609:            }
610:
611:            public Object pcmf_getRequest() {
612:                return (null);
613:            }
614:
615:            public void pcmf_setRequest(Object xReq) {
616:                throw (new UnsupportedOperationException());
617:            }
618:        };
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.