Source Code Cross Referenced for Threads.java in  » GIS » GeoServer » org » vfny » geoserver » 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 » GIS » GeoServer » org.vfny.geoserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.vfny.geoserver;
006:
007:        import java.io.BufferedReader;
008:        import java.io.IOException;
009:        import java.io.InputStream;
010:        import java.io.InputStreamReader;
011:        import java.io.OutputStreamWriter;
012:        import java.net.HttpURLConnection;
013:        import java.net.MalformedURLException;
014:        import java.net.URL;
015:        import java.util.Date;
016:
017:        class TestGetThread extends Thread {
018:            private static final boolean concurrent = false;
019:            URL url;
020:            int result = 0;
021:            Date t1;
022:            Date t2;
023:            Date t3;
024:            protected HttpURLConnection hc;
025:
026:            TestGetThread(URL u) throws MalformedURLException {
027:                url = new URL(u.toString());
028:            }
029:
030:            int getResult() {
031:                return result;
032:            }
033:
034:            public void connect() throws IOException {
035:                //HttpURLConnection hc = null;
036:                hc = (HttpURLConnection) url.openConnection();
037:                hc.setRequestMethod("GET");
038:                t1 = new Date();
039:                yield(); //wait to let everyone else connect before getting result
040:                hc.connect();
041:                //return hc;
042:            }
043:
044:            public void run() {
045:                try {
046:                    //HttpURLConnection hc = connect();
047:                    //Unsure if we want this, this is an experiment to try to connect
048:                    //more than once, which is what a reasonable web browser would
049:                    //do I believe.  Or maybe web browsers only try once?  It's a bit
050:                    //imperfect, as the input stream stuff should probably be here too
051:                    //since if this is running it just shifts more errors to BindExceptions
052:                    //when hc.getInputStream is called, since it's connected but not yet
053:                    //bound - it doesn't have the actual stream yet.  So perhaps it needs
054:                    //to be in the loop too, though would that cause it to get a new 
055:                    //connection (from the connect method) if it failed?  And/or is that
056:                    //maybe the behavior that we want?  Or do we want it to try to bind
057:                    //on the same connection - ch. (should also make these options
058:                    //user configurable...hmmm - how did I get roped in to writing
059:                    //a java wfs client?  This is essentially what the wfsTester that
060:                    //rob wrote does, and it's about as naive, it just doesn't do
061:                    //threads.  If anyone wants to expand on this the one nice thing
062:                    //to have, that rob never got to, would be some validation
063:                    //as well.  Shouldn't be too hard, just run xerces schema
064:                    //checking on it.  But then again this class was written to test
065:                    //a ton of requests at once, not to be a full tester.  One thing
066:                    //that would be cool though is to take a list of requests and
067:                    //fire them all off at different intervals.  Though I feel like
068:                    //we might be able to find some better framework to do that,
069:                    //rather than just writing our own.  
070:                    int tries = 0;
071:                    while (tries < 15) {
072:                        try {
073:                            connect();
074:                            break;
075:                        } catch (IOException ioe) {
076:                            System.out.println("IOException: "
077:                                    + ioe.getMessage() + ", try: " + tries);
078:
079:                            sleep(5);
080:                            tries++;
081:                        }
082:                    }
083:
084:                    t2 = new Date();
085:
086:                    InputStream input = hc.getInputStream();
087:                    BufferedReader br = new BufferedReader(
088:                            new InputStreamReader(input));
089:
090:                    if (concurrent) {
091:                        yield();
092:                    }
093:
094:                    //This reading bit seems to be damned if you do damned if you dont
095:                    //The first way ensures that the client doesn't prematurely close
096:                    //the socket, which happens on big GetFeature requests all the 
097:                    //time, I'm not too sure why, perhaps it gets set to not ready
098:                    //when the underlying stream from the server pauses or something.
099:
100:                    //The second way ensures that we don't get errors with the input
101:                    //stream closing on us, but for some reason I can't seem to reproduce
102:                    //them right now - the only reason I can think of is because I 
103:                    //changed it to explicitly create the InputStream, so it doesn't 
104:                    //get gced or something?  I'm not too sure though, but as the first
105:                    //isn't messing up at all we'll stick with it, as the second (original)
106:                    //way wasn't actually reading everything, so it was returning false 
107:                    //response times.
108:
109:                    //Oh ok, it seems that the exception is only on resin, with ready
110:                    //it works with getCaps, but with read it messes up about one in
111:                    //40 or so with java.net.SocketException: socket closed - so it
112:                    //looks like resin decides to close the socket prematurely under
113:                    //heavy duress or something.  I'm not sure, but I definitely feel
114:                    //like I'm testing servlet containers far more than GeoServer
115:                    //itself with this solid day of testing. 
116:
117:                    while (br.read() != -1)
118:                        ;
119:
120:                    //while(br.ready())
121:                    //	br.readLine();
122:                    result = hc.getResponseCode();
123:                    t3 = new Date();
124:
125:                    yield(); //wait to let everyone else hit before disconnecting
126:                    hc.disconnect();
127:                    ThreadedBatchTester.threadDone();
128:                } catch (Exception e) {
129:                    e.printStackTrace();
130:                    try {
131:                        result = hc.getResponseCode();
132:                    } catch (IOException ioe) {
133:                        result = 0;
134:                    }
135:                    ThreadedBatchTester.threadDone();
136:                }
137:            }
138:
139:            Date getTime1() {
140:                return t1;
141:            }
142:
143:            Date getTime2() {
144:                return t2;
145:            }
146:
147:            Date getTime3() {
148:                return t3;
149:            }
150:        }
151:
152:        class TestPostThread extends TestGetThread {
153:            String request;
154:
155:            TestPostThread(URL u, String request) throws MalformedURLException {
156:                super (u);
157:                this .request = request;
158:            }
159:
160:            public void connect() throws IOException {
161:                //HttpURLConnection hc = null;
162:                hc = (HttpURLConnection) url.openConnection();
163:                hc.setRequestMethod("POST");
164:                hc.setDoOutput(true);
165:                t1 = new Date();
166:                yield(); //wait to let everyone else connect before getting result
167:                hc.connect();
168:
169:                OutputStreamWriter osw = new OutputStreamWriter(hc
170:                        .getOutputStream());
171:                osw.write(request);
172:                osw.flush();
173:            }
174:
175:            /*public void run(){
176:               try{
177:                       HttpURLConnection hc = null;
178:                       hc = (HttpURLConnection)url.openConnection();
179:                       hc.setRequestMethod("POST");
180:                       hc.setDoOutput(true);
181:                       yield(); //wait to let everyone else connect before getting result
182:            
183:                       t1 = new Date();
184:                       hc.connect();
185:                       OutputStreamWriter osw = new OutputStreamWriter(hc.getOutputStream());
186:                       osw.write(request);
187:                       osw.flush();
188:            
189:                       t2 = new Date();
190:                   BufferedReader br = new BufferedReader(new InputStreamReader(hc.getInputStream()));
191:                   while(br.ready()){
192:                           br.readLine();
193:                   }
194:                       result = hc.getResponseCode();
195:                       t3 = new Date();
196:                       yield(); //wait to let everyone else hit before disconnecting
197:                       hc.disconnect();
198:               }catch(Exception e){
199:                       e.printStackTrace();
200:                       result = 0;
201:               }
202:               }*/
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.