The following code snippet provides an example of a server with a resource that responds with a "hello world" to any incoming GET request.
Server server = new Server(port); server.add(new ResourceBase("hello-world") { public void handleGET(CoapExchange exchange) { exchange.respond(ResponseCode.CONTENT, "hello world"); } }); server.start();The following figure shows the server's basic architecture.
+--------------------------------------- Server ----------------------------------------+ | | | +-----------------------+ | | | MessageDeliverer +--> (Resource Tree) | | +---------A-A-A---------+ | | | | | | | | | | | | .-------->>>------------' | '--------<<<------------. | | / | \ | | | | | | | * A * A * A | | +-----------------------+ +-----------------------+ +-----------------------+ | | | Endpoint | | Endpoint | | Endpoint | | | +-----------------------+ +-----------------------+ +-----------------------+ | +------------v-A--------------------------v-A-------------------------v-A---------------+ v A v A v A v A v A v A (Network) (Network) (Network)@see MessageDeliverer @see Endpoint
#SERVER#-default.xml
and #SERVER#-site.xml
. The default file is loaded from the classpath, the site file is laoded from the configuration directory. The Server collects all configuration properties prefixed with #SERVER#
. The property names are then trimmed from the #SERVER#
prefix. The Server log configuration is loaded from the #SERVICE#-log4j.properties
file in the configuration directory. The lifecycle of server is defined in by {@link Server.Status} enum.When a server is create, its status is UNDEF, when being initialized it is BOOTING, once initialization is complete by default transitions to NORMAL. The #SERVER#.startup.status
configuration property can be used to specify a different startup status (NORMAL, ADMIN or HALTED). Services classes are defined in the #SERVER#.services
and #SERVER#.services.ext
properties. They are loaded in order (services first, then services.ext). Before initializing the services, they are traversed and duplicate service interface are removed from the service list. The last service using a given interface wins (this enables a simple override mechanism). After the services have been resoloved by interface de-duplication they are initialized in order. Once all services are initialized they are post-initialized (this enables late/conditional service bindings).
Title:��������Bean Description: ��������Bean@author CaiJiuFa @version 1.00.00
�ļ�¼ �ĺ�汾: ���ˣ� ������: ������:
Server
object is instantiated at run time and its run
method is executed to start the JMS bridge server.
@see #run()
@author Baltic Amadeus, JSC
@author Antanas Kompanas
Server
element represents the entire Catalina servlet container. Its attributes represent the characteristics of the servlet container as a whole. A Server
may contain one or more Services
, and the top level set of naming resources. Normally, an implementation of this interface will also implement Lifecycle
, such that when the start()
and stop()
methods are called, all of the defined Services
are also started or stopped.
In between, the implementation must open a server socket on the port number specified by the port
property. When a connection is accepted, the first line is read and compared with the specified shutdown command. If the command matches, shutdown of the server is initiated.
NOTE - The concrete implementation of this class should register the (singleton) instance with the ServerFactory
class in its constructor(s).
@author Craig R. McClanahan
@version $Revision: 1433 $ $Date: 2010-04-09 00:33:40 +0200 (Fri, 09 Apr 2010) $
#SERVER#-default.xml
and #SERVER#-site.xml
. The default file is loaded from the classpath, the site file is laoded from the configuration directory. The Server collects all configuration properties prefixed with #SERVER#
. The property names are then trimmed from the #SERVER#
prefix. The Server log configuration is loaded from the #SERVICE#-log4j.properties
file in the configuration directory. The lifecycle of server is defined in by {@link Server.Status} enum.When a server is create, its status is UNDEF, when being initialized it is BOOTING, once initialization is complete by default transitions to NORMAL. The #SERVER#.startup.status
configuration property can be used to specify a different startup status (NORMAL, ADMIN or HALTED). Services classes are defined in the #SERVER#.services
and #SERVER#.services.ext
properties. They are loaded in order (services first, then services.ext). Before initializing the services, they are traversed and duplicate service interface are removed from the service list. The last service using a given interface wins (this enables a simple override mechanism). After the services have been resoloved by interface de-duplication they are initialized in order. Once all services are initialized they are post-initialized (this enables late/conditional service bindings).
<server>
element contains informations required to a server settings.
@version $Revision$ $Date$
This behaviour allows the previous database connection url format to work with essentially unchanged semantics.
From the 'server.properties' file, options can be set similarly, using a slightly different format.
Here is an example 'server.properties' file:
server.port=9001 server.database.0=test server.dbname.0=... ... server.database.n=... server.dbname.n=... server.silent=trueStarting with 1.7.2, Server has been refactored to become a simple JavaBean with non-blocking start() and stop() service methods. It is possible to configure a Server instance through the JavaBean API as well, but this part of the public interface is still under review and will not be finalized or documented fully until the final 1.7.2 release.
Note:
The 'no_system_exit' property is of particular interest.
If a Server instance is to run embedded in, say, an application server, such as when the jdbcDataSource or HsqlServerFactory classes are used, it is typically necessary to avoid calling System.exit() when the Server instance shuts down.
By default, 'no_system_exit' is set:
These values are natural to their context because the first case allows the JVM to exit by default on Server shutdown when a Server instance is started from a command line environment, whereas the second case prevents a typically unwanted JVM exit on Server shutdown when a Server intance is started as part of a larger framework.
Replaces original Hypersonic source of the same name. @author fredt@users @version 1.8.0 @since 1.7.2 @jmx.mbean description="HSQLDB Server" extends="org.hsqldb.mx.mbean.RegistrationSupportBaseMBean" @jboss.xmbean
This behaviour allows the previous database connection url format to work with essentially unchanged semantics.
From the 'server.properties' file, options can be set similarly, using a slightly different format.
Here is an example 'server.properties' file:
server.port=9001 server.database.0=test server.dbname.0=... ... server.database.n=... server.dbname.n=... server.silent=trueStarting with 1.7.2, Server has been refactored to become a simple JavaBean with non-blocking start() and stop() service methods. It is possible to configure a Server instance through the JavaBean API as well, but this part of the public interface is still under review and will not be finalized or documented fully until the final 1.7.2 release.
Note:
The 'no_system_exit' property is of particular interest.
If a Server instance is to run embedded in, say, an application server, such as when the JDBCDataSource or HsqlServerFactory classes are used, it is typically necessary to avoid calling System.exit() when the Server instance shuts down.
By default, 'no_system_exit' is set:
These values are natural to their context because the first case allows the JVM to exit by default on Server shutdown when a Server instance is started from a command line environment, whereas the second case prevents a typically unwanted JVM exit on Server shutdown when a Server intance is started as part of a larger framework.
@author Fred Toussi (fredt@users dot sourceforge.net) @version 1.9.0 @since 1.7.2 @jmx.mbean description="HSQLDB Server" extends="org.hsqldb.mx.mbean.RegistrationSupportBaseMBean" @jboss.xmbean
Server
interface represents a handler that is used to process Socket
objects. Implementations of this object will read HTTP requests for the provided sockets and dispatch the requests for processing by the core protocol handler. The intended use of a Server
is that it be used in conjunction with a Container
object, which acts as the primary protocol handler for a server. Typically the server will deliver callbacks to a container with both Request
and Response
objects encapsulating the transaction.
Core responsibilities of the server are to manage connections, to ensure that all HTTP requests are collected, and to dispatch the collected requests to an appropriate handler. It is also required to manage multiplexing such that many connections can be processed concurrently without a high latency period. @author Niall Gallagher
Limitations:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|