Source Code Cross Referenced for TunnelManager.java in  » Database-DBMS » myoodb-2.2.1 » org » myoodb » core » 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 » Database DBMS » myoodb 2.2.1 » org.myoodb.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:///////////////////////////////////////////////////////////////////////////////
002://
003://   Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004://
005://                          All Rights Reserved
006://
007://   This program is free software; you can redistribute it and/or modify
008://   it under the terms of the GNU General Public License and GNU Library
009://   General Public License as published by the Free Software Foundation;
010://   either version 2, or (at your option) any later version.
011://
012://   This program is distributed in the hope that it will be useful,
013://   but WITHOUT ANY WARRANTY; without even the implied warranty of
014://   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015://   GNU General Public License and GNU Library General Public License
016://   for more details.
017://
018://   You should have received a copy of the GNU General Public License
019://   and GNU Library General Public License along with this program; if
020://   not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021://   MA 02139, USA.
022://
023:///////////////////////////////////////////////////////////////////////////////
024:package org.myoodb.core;
025:
026:public class TunnelManager extends AbstractManager implements  Runnable
027:{
028:    protected interface Protocol
029:    {
030:        final static short KEEP_ALIVE = 0;
031:        final static short VERIFY_DATA = 1;
032:        final static short USER_DATA = 2;
033:        final static short USER_DATA_TUNNEL = 3;
034:    }
035:
036:    private static final org.myoodb.util.Logger LOGGER = org.myoodb.util.Logger.getLogger(TunnelManager.class);
037:
038:    private static int s_tunnelTimeout = @tunnelTimeoutMs@;
039:
040:    protected static final java.util.HashMap CONNECTIONS = new java.util.HashMap();
041:    protected static final java.util.HashMap INVOKE_COMMANDS = new java.util.HashMap();
042:
043:    private Thread m_cleanUpThread;
044:    private org.myoodb.MyOodbDatabase m_db;
045:
046:    public static void setTunnelTimeout(int timeout)
047:    {
048:        s_tunnelTimeout = timeout;
049:    }
050:
051:    public static int getTunnelTimeout()
052:    {
053:        return s_tunnelTimeout;
054:    }
055:
056:    public TunnelManager(org.myoodb.MyOodbDatabase db)
057:    {
058:        m_db = db;
059:    }
060:
061:    private void closeDatabaseConnection(Object[] connectionTuple)
062:    {
063:        org.myoodb.MyOodbDatabase.close((org.myoodb.core.DatabaseConnection) connectionTuple[0]);
064:    }
065:
066:    private void closeDatagramConnection(Object[] connectionTuple)
067:    {
068:        java.net.SocketAddress address = (java.net.SocketAddress) connectionTuple[1];
069:
070:        boolean found = false;
071:        java.util.ArrayList connnections = new java.util.ArrayList(CONNECTIONS.values());
072:        java.util.Iterator iter = connnections.iterator();
073:        while (iter.hasNext())
074:        {
075:            Object[] tuple = (Object[]) iter.next();
076:            if (address.equals(tuple[1]) == true)
077:            {
078:                found = true;
079:                break;
080:            }
081:        }
082:
083:        if (found == false)
084:        {
085:            connnections = new java.util.ArrayList(AbstractDatagramSocket.CONNECTIONS.values());
086:            iter = connnections.iterator();
087:            while (iter.hasNext())
088:            {
089:                AbstractDatagramSocket socket = (AbstractDatagramSocket) iter.next();
090:                if (address.equals(socket.getRemoteSocketAddress()) == true)
091:                {
092:                    if (LOGGER.isDebugEnabled() == true)
093:                    {
094:                        LOGGER.debug("Found gaming connection to close: " +  address + ", " + connectionTuple[3]);
095:                    }
096:
097:                    try
098:                    {
099:                        socket.close();
100:                    }
101:                    catch (java.io.IOException e)
102:                    {
103:                        // nothing to do
104:                    }
105:                }
106:            }
107:        }
108:    }
109:
110:    public void startup() throws Exception
111:    {
112:        m_cleanUpThread = new Thread(this );
113:        m_cleanUpThread.setDaemon(true);
114:        m_cleanUpThread.setName("MyOodb Tunnel CleanUp Thread: " + m_cleanUpThread.getId());
115:        m_cleanUpThread.start();
116:    }
117:
118:    public void shutdown() throws Exception
119:    {
120:        m_cleanUpThread = null;
121:    }
122:
123:    public org.myoodb.MyOodbDatabase getDatabase()
124:    {
125:        return m_db;
126:    }
127:
128:    public void run()
129:    {
130:        while (m_cleanUpThread != null)
131:        {
132:            try
133:            {
134:                Thread.sleep(getTunnelTimeout());
135:            }
136:            catch (InterruptedException e)
137:            {
138:                // nothing to do
139:            }
140:
141:            synchronized(CONNECTIONS)
142:            {
143:                java.util.Iterator iter = CONNECTIONS.values().iterator();
144:                while (iter.hasNext())
145:                {
146:                    Object[] tuple = (Object[]) iter.next();
147:                    long lastRequestTime = (Long) tuple[2];
148:
149:                    if ((System.currentTimeMillis() - lastRequestTime) > getTunnelTimeout())
150:                    {
151:                        iter.remove();
152:
153:                        if (LOGGER.isDebugEnabled() == true)
154:                        {
155:                            LOGGER.debug("Closing stale tunnel connection: " +  tuple[1]);
156:                        }
157:
158:                        closeDatabaseConnection(tuple);
159:
160:                        if (org.myoodb.MyOodbDatabase.getGameConfigurationFlag() == true)
161:                        {
162:                            closeDatagramConnection(tuple);
163:
164:                            synchronized(tuple)
165:                            {
166:                                tuple[4] = (long) -1;
167:                                tuple.notify();
168:                            }
169:                        }
170:
171:                        if (LOGGER.isDebugEnabled() == true)
172:                        {
173:                            LOGGER.debug("Closed stale tunnel connection: " +  tuple[1]);
174:                        }
175:                    }
176:                }
177:            }
178:        }
179:    }
180:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.