Source Code Cross Referenced for RemoteDaemonHttpServlet.java in  » Groupware » hipergate » com » oreilly » servlet » 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 » Groupware » hipergate » com.oreilly.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 1998-2001 by Jason Hunter <jhunter_AT_acm_DOT_org>.
002:        // All rights reserved.  Use of this class is limited.
003:        // Please see the LICENSE for more information.
004:
005:        package com.oreilly.servlet;
006:
007:        import java.io.*;
008:        import java.net.*;
009:        import java.rmi.*;
010:        import java.rmi.server.*;
011:        import java.rmi.registry.*;
012:        import java.util.*;
013:        import javax.servlet.*;
014:        import javax.servlet.http.*;
015:
016:        /** 
017:         * A superclass for any HTTP servlet that wishes to act as an RMI server
018:         * and, additionally, accept raw socket connections.  Includes the 
019:         * functionality from both RemoteHttpServlet and DaemonHttpServlet, by
020:         * extending DaemonHttpServlet and re-implementing RemoteHttpServlet.
021:         *
022:         * @see com.oreilly.servlet.RemoteHttpServlet
023:         * @see com.oreilly.servlet.DaemonHttpServlet
024:         *
025:         * @author <b>Jason Hunter</b>, Copyright &#169; 1998
026:         * @version 1.0, 98/09/18
027:         */
028:        public abstract class RemoteDaemonHttpServlet extends DaemonHttpServlet
029:                implements  Remote {
030:            /**
031:             * The registry for the servlet
032:             */
033:            protected Registry registry;
034:
035:            /**
036:             * Begins the servlet's RMI operations and begins a thread listening for
037:             * socket connections.
038:             * Subclasses that override this method must be sure to first call 
039:             * <tt>super.init(config)</tt>.
040:             * 
041:             * @param config the servlet config
042:             * @exception ServletException if a servlet exception occurs
043:             */
044:            public void init(ServletConfig config) throws ServletException {
045:                super .init(config);
046:                try {
047:                    UnicastRemoteObject.exportObject(this );
048:                    bind();
049:                } catch (RemoteException e) {
050:                    log("Problem binding to RMI registry: " + e.getMessage());
051:                }
052:            }
053:
054:            /**
055:             * Halts the servlet's RMI operations and halts the thread listening for
056:             * socket connections.  Subclasses that 
057:             * override this method must be sure to first call <tt>super.destroy()</tt>.
058:             */
059:            public void destroy() {
060:                super .destroy();
061:                unbind();
062:            }
063:
064:            /**
065:             * Returns the name under which the servlet should be bound in the
066:             * registry.  By default the name is the servlet's class name.  This
067:             * can be overridden with the <tt>registryName</tt> init parameter.
068:             *
069:             * @return the name under which the servlet should be bound in the registry
070:             */
071:            protected String getRegistryName() {
072:                // First name choice is the "registryName" init parameter
073:                String name = getInitParameter("registryName");
074:                if (name != null)
075:                    return name;
076:
077:                // Fallback choice is the name of this class
078:                return this .getClass().getName();
079:            }
080:
081:            /**
082:             * Returns the port where the registry should be running.  By default 
083:             * the port is the default registry port (1099).  This can be 
084:             * overridden with the <tt>registryPort</tt> init parameter.
085:             *
086:             * @return the port for the registry
087:             */
088:            protected int getRegistryPort() {
089:                // First port choice is the "registryPort" init parameter
090:                try {
091:                    return Integer.parseInt(getInitParameter("registryPort"));
092:                }
093:
094:                // Fallback choice is the default registry port (1099)
095:                catch (NumberFormatException e) {
096:                    return Registry.REGISTRY_PORT;
097:                }
098:            }
099:
100:            /**
101:             * Binds the servlet to the registry.  Creates the registry if necessary.
102:             * Logs any errors.
103:             */
104:            protected void bind() {
105:                // Try to find the appropriate registry already running
106:                try {
107:                    registry = LocateRegistry.getRegistry(getRegistryPort());
108:                    registry.list(); // Verify it's alive and well
109:                } catch (Exception e) {
110:                    // Couldn't get a valid registry
111:                    registry = null;
112:                }
113:
114:                // If we couldn't find it, we need to create it.
115:                // (Equivalent to running "rmiregistry")
116:                if (registry == null) {
117:                    try {
118:                        registry = LocateRegistry
119:                                .createRegistry(getRegistryPort());
120:                    } catch (Exception e) {
121:                        log("Could not get or create RMI registry on port "
122:                                + getRegistryPort() + ": " + e.getMessage());
123:                        return;
124:                    }
125:                }
126:
127:                // If we get here, we must have a valid registry.
128:                // Now register this servlet instance with that registry.
129:                try {
130:                    registry.rebind(getRegistryName(), this );
131:                } catch (Exception e) {
132:                    log("humbug Could not bind to RMI registry: "
133:                            + e.getMessage());
134:                    return;
135:                }
136:            }
137:
138:            /**
139:             * Unbinds the servlet from the registry.
140:             * Logs any errors.
141:             */
142:            protected void unbind() {
143:                try {
144:                    if (registry != null)
145:                        registry.unbind(getRegistryName());
146:                } catch (Exception e) {
147:                    log("Problem unbinding from RMI registry: "
148:                            + e.getMessage());
149:                }
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.