Source Code Cross Referenced for DualSocketAcceptor.java in  » Web-Server » Acme-WebServer » rogatkin » web » 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 » Web Server » Acme WebServer » rogatkin.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* tjws - DualSocketAcceptor.java
002:         * Copyright (C) 1999-2007 Dmitriy Rogatkin.  All rights reserved.
003:         * Redistribution and use in source and binary forms, with or without
004:         * modification, are permitted provided that the following conditions
005:         * are met:
006:         * 1. Redistributions of source code must retain the above copyright
007:         *    notice, this list of conditions and the following disclaimer.
008:         * 2. Redistributions in binary form must reproduce the above copyright
009:         *    notice, this list of conditions and the following disclaimer in the
010:         *    documentation and/or other materials provided with the distribution.
011:         *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
012:         *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
013:         *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
014:         *  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
015:         *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
016:         *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
017:         *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
018:         *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
019:         *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
020:         *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
021:         *  SUCH DAMAGE.
022:         *  
023:         *  Visit http://tjws.sourceforge.net to get the latest infromation
024:         *  about Rogatkin's products.                                                        
025:         *  $Id: DualSocketAcceptor.java,v 1.2 2007/02/22 23:53:12 rogatkin Exp $                
026:         *  Created on Feb 21, 2007
027:         *  @author Dmitriy
028:         */
029:        package rogatkin.web;
030:
031:        import java.io.IOException;
032:        import java.net.InetAddress;
033:        import java.net.ServerSocket;
034:        import java.net.Socket;
035:        import java.util.Map;
036:        import java.util.concurrent.BlockingQueue;
037:        import java.util.concurrent.LinkedBlockingQueue;
038:        import java.util.concurrent.TimeUnit;
039:
040:        import Acme.Serve.SSLAcceptor;
041:        import Acme.Serve.Serve;
042:
043:        public class DualSocketAcceptor extends SSLAcceptor {
044:            protected static class TwoHeadServerSocket extends ServerSocket {
045:                protected BlockingQueue<Socket> requestQueue;
046:
047:                protected ServerSocket socket1, socket2;
048:
049:                private Thread currentThread;
050:
051:                public TwoHeadServerSocket(ServerSocket socket1,
052:                        ServerSocket socket2) throws IOException {
053:                    requestQueue = new LinkedBlockingQueue<Socket>(1000); // ?? backlog
054:                    //			 ArrayBlockingQueue
055:                    Thread thread;
056:                    if (socket1 != null) {
057:                        thread = new Thread(new AcceptQueuer(socket1),
058:                                "Accept processor 1");
059:                        thread.setDaemon(true);
060:                        thread.start();
061:                        this .socket1 = socket1;
062:                    }
063:                    if (socket2 != null) {
064:                        thread = new Thread(new AcceptQueuer(socket2),
065:                                "Accept processor 2");
066:                        thread.setDaemon(true);
067:                        thread.start();
068:                        this .socket2 = socket2;
069:                    }
070:                }
071:
072:                public Socket accept() throws IOException {
073:                    Socket result;
074:                    currentThread = Thread.currentThread();
075:                    for (;;) {
076:                        try {
077:                            result = requestQueue.poll(1000L, TimeUnit.SECONDS);
078:                            if (result != null)
079:                                return result;
080:                        } catch (InterruptedException e) {
081:                            break;
082:                        }
083:                    }
084:                    throw new IOException();
085:                }
086:
087:                public void close() throws IOException {
088:                    if (currentThread != null)
089:                        currentThread.interrupt();
090:                    IOException ioe = null;
091:                    try {
092:                        socket1.close();
093:                    } catch (IOException ioe1) {
094:                        ioe = ioe1;
095:                    }
096:                    socket2.close();
097:                    if (ioe != null)
098:                        throw ioe;
099:                }
100:
101:                public String toString() {
102:                    return "" + socket1 + "/" + socket2;
103:                }
104:
105:                class AcceptQueuer implements  Runnable {
106:                    ServerSocket socket;
107:
108:                    AcceptQueuer(ServerSocket socket) {
109:                        this .socket = socket;
110:                    }
111:
112:                    public void run() {
113:                        for (;;)
114:                            try {
115:                                requestQueue.put(socket.accept());
116:                            } catch (InterruptedException e) {
117:                                return;
118:                            } catch (IOException e) {
119:                                break;
120:                            }
121:                    }
122:                }
123:            }
124:
125:            public void init(Map inProperties, Map outProperties)
126:                    throws IOException {
127:                super .init(inProperties, outProperties);
128:                int port = inProperties.get(Serve.ARG_PORT) != null ? ((Integer) inProperties
129:                        .get(Serve.ARG_PORT)).intValue()
130:                        : Serve.DEF_PORT;
131:                int bl = 50;
132:                try {
133:                    // TODO: consider conversion at getting the argument
134:                    bl = Integer.parseInt((String) inProperties
135:                            .get(ARG_BACKLOG));
136:                    if (bl < 2)
137:                        bl = 2;
138:                } catch (Exception e) {
139:                }
140:                InetAddress ia = null;
141:                if (inProperties.get(Serve.ARG_BINDADDRESS) != null)
142:                    try {
143:                        ia = InetAddress.getByName((String) inProperties
144:                                .get(Serve.ARG_BINDADDRESS));
145:                    } catch (Exception e) {
146:                    }
147:
148:                socket = new TwoHeadServerSocket(
149:                        new ServerSocket(port, bl, ia), socket);
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.