Java Doc for Server.java in  » Web-Server » pygmy-httpd » pygmy » 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 » Web Server » pygmy httpd » pygmy.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   pygmy.core.Server

Server
public class Server implements Runnable(Code)

Server is the core of the system. A server glues together Handler s and EndPoint s. EndPoint s are responsible for reading the HttpRequest from a source and sending the HttpResponse over that source. EndPoint s then sends the request to the Handler by calling the post() method on the server to send the request to this server's Handler s. Handler s process the HttpRequest and produce an appropriate HttpResponse .

The server contains the configuration for the entire server. What are the expected values in the configuration is mainly controlled by what handlers and endpoints are configured. Depending on which handlers and endpoints have been enabled, the configuration will vary. The only two parameters are required: handler and <handler's name>.class. Here is an example configuration:

 
handler=my\ handler my\ handler.class=pygmy.handlers.DefaultChainHandler my\ handler.chain=handler1, handler2 my\ handler.url-prefix=/ handler1.class=pygmy.handlers.FileHandler handler1.root=C:\temp handler1.url-prefix=/home-directory handler2.class=pygmy.handlers.ResourceHandler handler2.url-prefix=/jar handler2.resourceMount=/html handler2.default=index.html
In the above configuration, handler property is the name of first handler. The name is used to find all the other properties for that particular handler. The .class property is used to tell the Server the name of the class to instantiate. The two other properties, .chain and .url-prefix, are particular to the pygmy.handlers.DefaultChainHandler .

Server's only have one Handler . However, the power of Handler s is the ability to have more than one. The pygmy.handlers.DefaultChainHandler provides the ability to create a chain of multiple handlers. See pygmy.handlers.DefaultChainHandler for information on configuring it.

Server also contains a set of pygmy.core.EndPoint s. When the server initializes itself it looks in the configuration for the endpoints parameter. The endpoints parameter contains a space seperated list of the names of the endpoints this server will create. For each name in the list it will look for a config parameter <name of endpoint>.class in the configuration. It will instantiate the classname using the no-argument constructor and add it to the set of endpoints in the server.

If the server does not find the endpoints parameter, then it will create a default EndPoint of type pygmy.core.ServerSocketEndPoint named http. Here is an example of using the endpoints parameter:

 endpoints=endpoint1 endpoint2
 handler=handler1
 endpoint1.class=my.package.MyEndPoint
 endpoint1.param1=foo
 endpoint1.param2=bar
 endpoint2.class=my.package.AnotherEndPoint
 endpoint2.param1=foo
 endpoint2.param2=bar
 endpoint2.param3=baz
 ...
 

Server class looks for the following properties in the configuration:

Parameter NameDefault ValueRequired
handlerNoneYes
endpointshttpNo
<handler name>.classNoneYes
<endpoint name>.classNoneiff endpoints param is defined
threadpool.size5No


Field Summary
 Propertiesconfig
    
 HashMapendpoints
    
 Handlerhandler
    
 ResponseListenerresponseListener
    
 ThreadPoolthreadPool
    

Constructor Summary
public  Server(String filename)
     This creates a server using the given filename as the configuration for this server.
public  Server(Properties config)
     This creates a server using the given configuration.
public  Server(String[] args)
     This creates a server from commandline arguments.
Parameters:
  args - an array of config parameters, the format of the list is a '-' followed by either 'config' or somename of a parameter (i.e.

Method Summary
public  voidaddEndPoint(String name, EndPoint endpoint)
     This method adds an EndPoint to this server.
public  ObjectconstructPygmyObject(String objectName)
     This is the method used to construct pygmy objects.
public  Objectget(Object key)
     This returns the object stored under the given key.
Parameters:
  key - the key to look up the stored object.
public  PropertiesgetConfig()
     Returns the configuration for the server.
public  StringgetProperty(String key)
     Returns the property stored under the key.
Parameters:
  key - the configuration key to look up.
public  StringgetProperty(String key, String defaultValue)
     Returns the property stored under the key.
public  ObjectgetRegisteredComponent(Class clazz)
    
public  ResponseListenergetResponseListeners()
     Returns the instance of the ResponseListener for this Server.
public  booleanhasProperty(String key)
     Returns true iff the key is in the configuration
Parameters:
  key - the name of the key.
protected  voidinitializeHandler()
    
protected  voidloadConfiguration(String config, Properties props)
    
public static  voidmain(String[] args)
    
public  booleanpost(Request request, Response response)
     This method is used to post a HttpRequest to the server's handler.
public  voidpost(Runnable runnable)
     This method posts a Runnable onto the Server's task queue.
protected  voidprocessArguments(String[] args, Properties props)
    
public  voidputProperty(Object key, Object value)
     This puts a configuration property into the server's configuration.
public  voidregisterComponent(Object object)
     This is called when a program wants to register a shared component for Handlers to have access to.
public  voidrun()
     This is called when the server is shutdown thread is called.
public  voidsetResponseListener(ResponseListener listener)
     This sets the ResponseListener for entire server.
public  voidshutdown()
     This method will shutdown the Handler, and call EndPoint.shutdown on each EndPoint.
public  voidstart()
     This method is called to start the web server.

Field Detail
config
Properties config(Code)



endpoints
HashMap endpoints(Code)



handler
Handler handler(Code)



responseListener
ResponseListener responseListener(Code)



threadPool
ThreadPool threadPool(Code)




Constructor Detail
Server
public Server(String filename) throws IOException(Code)
This creates a server using the given filename as the configuration for this server. The configuration file should follow format of normal java.util.Properties file.
Parameters:
  filename - the path to a file to use as the configuration of this server.
throws:
  IOException -



Server
public Server(Properties config)(Code)
This creates a server using the given configuration.
Parameters:
  config - the configuration to use for this server.



Server
public Server(String[] args) throws IOException(Code)
This creates a server from commandline arguments.
Parameters:
  args - an array of config parameters, the format of the list is a '-' followed by either 'config' or somename of a parameter (i.e. http.port), and a space and a value for that property. All -config will load a fileeither from the filesystem or the class path if the file doesn't exist on the filesystem.




Method Detail
addEndPoint
public void addEndPoint(String name, EndPoint endpoint)(Code)
This method adds an EndPoint to this server. It will be initialized once the Server.start method is called.
Parameters:
  name - The name of this EndPoint instance.
Parameters:
  endpoint - The instance of the endpoint to add.



constructPygmyObject
public Object constructPygmyObject(String objectName)(Code)
This is the method used to construct pygmy objects. Given the object name it appends .class onto the end and looks for the classname in the server's configuration. It then analyzes the class's constructor parameters for objects that it depends on. Then it looks those objects up by class in the registered object pool. Finally, it calls the constructor using reflection passing any registered objects as arguments. It returns the newly constructed object or null if there was a problem.
Parameters:
  objectName - the name of the object defined in the server's configuration. the newly constructed object, or null there was a problem instantiated the object.



get
public Object get(Object key)(Code)
This returns the object stored under the given key.
Parameters:
  key - the key to look up the stored object. the object stored at the given key.



getConfig
public Properties getConfig()(Code)
Returns the configuration for the server. the configuration for the server.



getProperty
public String getProperty(String key)(Code)
Returns the property stored under the key.
Parameters:
  key - the configuration key to look up. the value stored in the configuration at this key.



getProperty
public String getProperty(String key, String defaultValue)(Code)
Returns the property stored under the key. If there isn't a property called key, then it returns the defaultValue.
Parameters:
  key - the configuration key to look up.
Parameters:
  defaultValue - the defaultValue returned if nothing is found under the key. the value stored in the configuration at this key.



getRegisteredComponent
public Object getRegisteredComponent(Class clazz)(Code)



getResponseListeners
public ResponseListener getResponseListeners()(Code)
Returns the instance of the ResponseListener for this Server. the ResponseListener for this Server, or null if there is none.



hasProperty
public boolean hasProperty(String key)(Code)
Returns true iff the key is in the configuration
Parameters:
  key - the name of the key. true if and only if the key is contained in the configuration. False otherwise.



initializeHandler
protected void initializeHandler()(Code)



loadConfiguration
protected void loadConfiguration(String config, Properties props) throws IOException(Code)



main
public static void main(String[] args) throws IOException(Code)



post
public boolean post(Request request, Response response) throws IOException(Code)
This method is used to post a HttpRequest to the server's handler. It will create a HttpResponse for the EndPoint to send to the client.
Parameters:
  request - A HttpResponse that corresponds to the HttpRequest being handled.
throws:
  IOException -



post
public void post(Runnable runnable)(Code)
This method posts a Runnable onto the Server's task queue. The server's ThreadPool will service the runnable once a thread is freed up.
Parameters:
  runnable - An instance of Runnable that the user wishes to run on the server's ThreadPool.



processArguments
protected void processArguments(String[] args, Properties props) throws IOException(Code)



putProperty
public void putProperty(Object key, Object value)(Code)
This puts a configuration property into the server's configuration.
Parameters:
  key - The unique key to store the value under.
Parameters:
  value - The value of the key.



registerComponent
public void registerComponent(Object object)(Code)
This is called when a program wants to register a shared component for Handlers to have access to. The objects's class will be the defining key for identitying the object. Registering more than one instance will not be supported. If you're program must differ between two instances, then register a manager and allow the Handler's to interact with that to differentiate the individual instances.
Parameters:
  object - the object the user wants to make available to Handler instances.



run
public void run()(Code)
This is called when the server is shutdown thread is called.



setResponseListener
public void setResponseListener(ResponseListener listener)(Code)
This sets the ResponseListener for entire server. All replys being sent to any client will be notified to this instance.
Parameters:
  listener - the instance of a ResponseListener to use for this Server.



shutdown
public void shutdown()(Code)
This method will shutdown the Handler, and call EndPoint.shutdown on each EndPoint.



start
public void start()(Code)
This method is called to start the web server. It will initialize the server's Handler and all the EndPoints then call the EndPoint.start on each EndPoint. This method will return after the above steps are done.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.