You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2012/08/08 08:54:47 UTC
svn commit: r1370674 [2/12] - in
/db/derby/code/trunk/java/drda/org/apache/derby: drda/ impl/drda/
Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java?rev=1370674&r1=1370673&r2=1370674&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java Wed Aug 8 06:54:46 2012
@@ -34,267 +34,267 @@ import org.apache.derby.iapi.services.pr
import org.apache.derby.impl.drda.NetworkServerControlImpl;
/**
- NetworkServerControl provides the ability to start a Network Server or
- connect to a running Network Server to shutdown, configure or retreive
- diagnostic information. With the exception of ping, these commands
- can only be performed from the machine on which the server is running.
- Commands can be performed from the command line with the following
- arguments:
-
- <P>
- <UL>
- <LI>start [-h <host>] [-p <portnumber>] [-ssl <sslmode>]: This starts the network
- server on the port/host specified or on localhost, port 1527 if no
- host/port is specified and no properties are set to override the
- defaults. By default Network Server will only listen for
- connections from the machine on which it is running.
- Use -h 0.0.0.0 to listen on all interfaces or -h <hostname> to listen
- on a specific interface on a multiple IP machine.
+ NetworkServerControl provides the ability to start a Network Server or
+ connect to a running Network Server to shutdown, configure or retreive
+ diagnostic information. With the exception of ping, these commands
+ can only be performed from the machine on which the server is running.
+ Commands can be performed from the command line with the following
+ arguments:
+
+ <P>
+ <UL>
+ <LI>start [-h <host>] [-p <portnumber>] [-ssl <sslmode>]: This starts the network
+ server on the port/host specified or on localhost, port 1527 if no
+ host/port is specified and no properties are set to override the
+ defaults. By default Network Server will only listen for
+ connections from the machine on which it is running.
+ Use -h 0.0.0.0 to listen on all interfaces or -h <hostname> to listen
+ on a specific interface on a multiple IP machine.
For documentation on <sslmode>, consult the Server and Administration Guide.</LI>
- <LI>shutdown [-h <host>][-p <portnumber>] [-ssl <sslmode>] [-user <username>] [-password <password>]: This shutdowns the network server with given user credentials on the host and port specified or on the local host and port 1527(default) if no host or port is specified. </LI>
+ <LI>shutdown [-h <host>][-p <portnumber>] [-ssl <sslmode>] [-user <username>] [-password <password>]: This shutdowns the network server with given user credentials on the host and port specified or on the local host and port 1527(default) if no host or port is specified. </LI>
- <LI>ping [-h <host>] [-p <portnumber>] [-ssl <sslmode>]
- This will test whether the Network Server is up.
- </LI>
-
- <LI>sysinfo [-h <host>] [-p <portnumber>] [-ssl <sslmode>]: This prints
- classpath and version information about the Network Server,
- the JVM and the Derby engine.
- </LI>
-
- <LI>runtimeinfo [-h <host] [-p <portnumber] [-ssl <sslmode>]: This prints
- extensive debbugging information about sessions, threads,
- prepared statements, and memory usage for the running Network Server.
- </LI>
-
- <LI>logconnections {on | off} [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
- This turns logging of connections on or off.
- Connections are logged to derby.log.
- Default is off.</LI>
-
- <LI>maxthreads <max> [-h <host>][-p <portnumber>] [-ssl <sslmode>]:
- This sets the maximum number of threads that can be used for connections.
- Default 0 (unlimitted).
- </LI>
-
- <LI>timeslice <milliseconds> [-h <host>][-p <portnumber>] [-ssl <sslmode>]:
- This sets the time each session can have using a connection thread
- before yielding to a waiting session. Default is 0 (no yeild).
-
- </LI>
-
- <LI>trace {on | off} [-s <session id>] [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
- This turns drda tracing on or off for the specified session or if no
- session is specified for all sessions. Default is off</LI>
-
-
- <LI>tracedirectory <tracedirectory> [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
- This changes where new trace files will be placed.
- For sessions with tracing already turned on,
- trace files remain in the previous location.
- Default is derby.system.home, if it is set.
- Otherwise the default is the current directory.</LI>
-
- </UL>
- </P>
- <P>Properties can be set in the derby.properties file or on the command line.
- Properties on the command line take precedence over properties in the
- derby.properties file. Arguments on the command line take precedence
- over properties.
- The following is a list of properties that can be set for
- NetworkServerControl:
-
- <UL><LI>derby.drda.portNumber=<port number>: This property
- indicates which port should be used for the Network Server. </LI>
-
- <LI>derby.drda.host=<host name or ip address >: This property
- indicates the ip address to which NetworkServerControl should connect. </LI>
-
- <LI>derby.drda.traceDirectory=<trace directory>: This property
- indicates where to put trace files. </LI>
-
- <LI>derby.drda.traceAll=true: This property turns on tracing for
- all sessions. Default is tracing is off.</LI>
-
- <LI>derby.drda.logConnections=true: This property turns on logging
- of connections. Default is connections are not logged.</LI>
-
- <LI>derby.drda.minThreads=<value>: If this property
- is set, the <value> number of threads will be created when the Network Server is
- booted. </LI>
-
- <LI>derby.drda.maxThreads=<value>: If this property
- is set, the <value> is the maximum number of connection threads that will be
- created. If a session starts when there are no connection threads available
- and the maximum number of threads has been reached, it will wait until a
- conection thread becomes available. </LI>
-
- <LI>derby.drda.timeSlice=<milliseconds>: If this property
- is set, the connection threads will not check for waiting sessions until the
- current session has been working for <milliseconds>.
- A value of 0 causes the thread to work on the current session until the
- session exits. If this property is not set, the default value is 0. </LI>
+ <LI>ping [-h <host>] [-p <portnumber>] [-ssl <sslmode>]
+ This will test whether the Network Server is up.
+ </LI>
+
+ <LI>sysinfo [-h <host>] [-p <portnumber>] [-ssl <sslmode>]: This prints
+ classpath and version information about the Network Server,
+ the JVM and the Derby engine.
+ </LI>
+
+ <LI>runtimeinfo [-h <host] [-p <portnumber] [-ssl <sslmode>]: This prints
+ extensive debbugging information about sessions, threads,
+ prepared statements, and memory usage for the running Network Server.
+ </LI>
+
+ <LI>logconnections {on | off} [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
+ This turns logging of connections on or off.
+ Connections are logged to derby.log.
+ Default is off.</LI>
+
+ <LI>maxthreads <max> [-h <host>][-p <portnumber>] [-ssl <sslmode>]:
+ This sets the maximum number of threads that can be used for connections.
+ Default 0 (unlimitted).
+ </LI>
+
+ <LI>timeslice <milliseconds> [-h <host>][-p <portnumber>] [-ssl <sslmode>]:
+ This sets the time each session can have using a connection thread
+ before yielding to a waiting session. Default is 0 (no yeild).
+
+ </LI>
+
+ <LI>trace {on | off} [-s <session id>] [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
+ This turns drda tracing on or off for the specified session or if no
+ session is specified for all sessions. Default is off</LI>
+
+
+ <LI>tracedirectory <tracedirectory> [-h <host>] [-p <portnumber>] [-ssl <sslmode>]:
+ This changes where new trace files will be placed.
+ For sessions with tracing already turned on,
+ trace files remain in the previous location.
+ Default is derby.system.home, if it is set.
+ Otherwise the default is the current directory.</LI>
+
+ </UL>
+ </P>
+ <P>Properties can be set in the derby.properties file or on the command line.
+ Properties on the command line take precedence over properties in the
+ derby.properties file. Arguments on the command line take precedence
+ over properties.
+ The following is a list of properties that can be set for
+ NetworkServerControl:
+
+ <UL><LI>derby.drda.portNumber=<port number>: This property
+ indicates which port should be used for the Network Server. </LI>
+
+ <LI>derby.drda.host=<host name or ip address >: This property
+ indicates the ip address to which NetworkServerControl should connect. </LI>
+
+ <LI>derby.drda.traceDirectory=<trace directory>: This property
+ indicates where to put trace files. </LI>
+
+ <LI>derby.drda.traceAll=true: This property turns on tracing for
+ all sessions. Default is tracing is off.</LI>
+
+ <LI>derby.drda.logConnections=true: This property turns on logging
+ of connections. Default is connections are not logged.</LI>
+
+ <LI>derby.drda.minThreads=<value>: If this property
+ is set, the <value> number of threads will be created when the Network Server is
+ booted. </LI>
+
+ <LI>derby.drda.maxThreads=<value>: If this property
+ is set, the <value> is the maximum number of connection threads that will be
+ created. If a session starts when there are no connection threads available
+ and the maximum number of threads has been reached, it will wait until a
+ conection thread becomes available. </LI>
+
+ <LI>derby.drda.timeSlice=<milliseconds>: If this property
+ is set, the connection threads will not check for waiting sessions until the
+ current session has been working for <milliseconds>.
+ A value of 0 causes the thread to work on the current session until the
+ session exits. If this property is not set, the default value is 0. </LI>
<LI>derby.drda.sslMode=<sslmode>: This property sets the SSL
mode of the server.
-
+
</LI>
</UL>
</P>
<P><B>Examples.</B></P>
- <P>This is an example of shutting down the server on port 1621.
- <PRE>
- java org.apache.derby.drda.NetworkServerControl shutdown -p 1621
- </PRE>
- </P>
-
- <P>This is an example of turning tracing on for session 3
- <PRE>
- java org.apache.derby.drda.NetworkServerControl trace on -s 3
- </PRE>
- </P>
-
- <P>This is an example of starting and then shutting down the network
- server on port 1621 on machine myhost
- <PRE>
- java org.apache.derby.drda.NetworkServerControl start -h myhost -p 1621
- java org.apache.derby.drda.NetworkServerControl shutdown -h myhost -p 1621
- </PRE>
- </P>
-
- <P> This is an example of starting and shutting down the Network Server in the example
- above with the API.
- <PRE>
-
- NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("myhost"),1621)
-
- serverControl.shutdown();
- </PRE>
- </P>
+ <P>This is an example of shutting down the server on port 1621.
+ <PRE>
+ java org.apache.derby.drda.NetworkServerControl shutdown -p 1621
+ </PRE>
+ </P>
+
+ <P>This is an example of turning tracing on for session 3
+ <PRE>
+ java org.apache.derby.drda.NetworkServerControl trace on -s 3
+ </PRE>
+ </P>
+
+ <P>This is an example of starting and then shutting down the network
+ server on port 1621 on machine myhost
+ <PRE>
+ java org.apache.derby.drda.NetworkServerControl start -h myhost -p 1621
+ java org.apache.derby.drda.NetworkServerControl shutdown -h myhost -p 1621
+ </PRE>
+ </P>
+
+ <P> This is an example of starting and shutting down the Network Server in the example
+ above with the API.
+ <PRE>
+
+ NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("myhost"),1621)
+
+ serverControl.shutdown();
+ </PRE>
+ </P>
-
+
*/
public class NetworkServerControl{
-
- public final static int DEFAULT_PORTNUMBER = 1527;
+
+ public final static int DEFAULT_PORTNUMBER = 1527;
- private final static String DERBYNET_JAR = "derbynet.jar";
- private final static String POLICY_FILENAME = "server.policy";
- private final static String POLICY_FILE_PROPERTY = "java.security.policy";
- private final static String DERBY_HOSTNAME_WILDCARD = "0.0.0.0";
- private final static String IPV6_HOSTNAME_WILDCARD = "::";
- private final static String SOCKET_PERMISSION_HOSTNAME_WILDCARD = "*";
+ private final static String DERBYNET_JAR = "derbynet.jar";
+ private final static String POLICY_FILENAME = "server.policy";
+ private final static String POLICY_FILE_PROPERTY = "java.security.policy";
+ private final static String DERBY_HOSTNAME_WILDCARD = "0.0.0.0";
+ private final static String IPV6_HOSTNAME_WILDCARD = "::";
+ private final static String SOCKET_PERMISSION_HOSTNAME_WILDCARD = "*";
private NetworkServerControlImpl serverImpl;
- // constructor
+ // constructor
+
+ /**
+ * Creates a NetworkServerControl object that is configured to control
+ * a Network Server on a specified port and InetAddress with given
+ * user credentials.
+ *
+ * @param address The IP address of the Network Server host.
+ * address cannot be null.
+ *
+ * @param portNumber port number server is to used. If <= 0,
+ * default port number is used
+ *
+ * @param userName The user name for actions requiring authorization.
+ *
+ * @param password The password for actions requiring authorization.
+ *
+ * @throws Exception on error
+ */
+ public NetworkServerControl(InetAddress address, int portNumber,
+ String userName, String password)
+ throws Exception
+ {
+ serverImpl = new NetworkServerControlImpl(address, portNumber,
+ userName, password);
+ }
+
+ /**
+ * Creates a NetworkServerControl object that is configured to control
+ * a Network Server on the default host and the default port with given
+ * user credentials.
+ *
+ * @param userName The user name for actions requiring authorization.
+ *
+ * @param password The password for actions requiring authorization.
+ *
+ * @throws Exception on error
+ */
+ public NetworkServerControl(String userName, String password)
+ throws Exception
+ {
+ serverImpl = new NetworkServerControlImpl(userName, password);
+ }
- /**
- * Creates a NetworkServerControl object that is configured to control
- * a Network Server on a specified port and InetAddress with given
- * user credentials.
- *
- * @param address The IP address of the Network Server host.
- * address cannot be null.
- *
- * @param portNumber port number server is to used. If <= 0,
- * default port number is used
- *
- * @param userName The user name for actions requiring authorization.
- *
- * @param password The password for actions requiring authorization.
- *
- * @throws Exception on error
- */
- public NetworkServerControl(InetAddress address, int portNumber,
- String userName, String password)
- throws Exception
- {
- serverImpl = new NetworkServerControlImpl(address, portNumber,
- userName, password);
- }
-
- /**
- * Creates a NetworkServerControl object that is configured to control
- * a Network Server on the default host and the default port with given
- * user credentials.
- *
- * @param userName The user name for actions requiring authorization.
- *
- * @param password The password for actions requiring authorization.
- *
- * @throws Exception on error
- */
- public NetworkServerControl(String userName, String password)
- throws Exception
- {
- serverImpl = new NetworkServerControlImpl(userName, password);
- }
-
- /**
- *
- * Creates a NetworkServerControl object that is configured to control
- * a Network Server on a specified port and InetAddress.
- *<P>
- * <B> Examples: </B>
- * </P>
- * <P>
- * To configure for port 1621 and listen on the loopback address:
- *<PRE>
- * NetworkServerControl util = new
- * NetworkServerControl(InetAddress.getByName("localhost"), 1621);
- * </PRE>
- * </P>
- *
- * @param address The IP address of the Network Server host.
- * address cannot be null.
-
- * @param portNumber port number server is to used. If <= 0,
- * default port number is used
- *
- * @throws Exception on error
- */
- public NetworkServerControl(InetAddress address,int portNumber) throws Exception
- {
- serverImpl = new NetworkServerControlImpl(address, portNumber);
- }
-
-
- /**
- *
- * Creates a NetworkServerControl object that is configured to control
- * a Network Server on the default host(localhost)
- * and the default port(1527) unless derby.drda.portNumber and
- * derby.drda.host are set.
- * <P><PRE>
- * new NetworkServerControl()
- *
- * is equivalent to calling
- *
- * new NetworkServerControl(InetAddress.getByName("localhost"),1527);
- * </PRE>
- * </P>
- *
- * @throws Exception on error
- */
- public NetworkServerControl() throws Exception
- {
- serverImpl = new NetworkServerControlImpl();
- }
-
-
- /**
- * main routine for NetworkServerControl
- *
- * @param args array of arguments indicating command to be executed.
- * See class comments for more information
- */
+ /**
+ *
+ * Creates a NetworkServerControl object that is configured to control
+ * a Network Server on a specified port and InetAddress.
+ *<P>
+ * <B> Examples: </B>
+ * </P>
+ * <P>
+ * To configure for port 1621 and listen on the loopback address:
+ *<PRE>
+ * NetworkServerControl util = new
+ * NetworkServerControl(InetAddress.getByName("localhost"), 1621);
+ * </PRE>
+ * </P>
+ *
+ * @param address The IP address of the Network Server host.
+ * address cannot be null.
+
+ * @param portNumber port number server is to used. If <= 0,
+ * default port number is used
+ *
+ * @throws Exception on error
+ */
+ public NetworkServerControl(InetAddress address,int portNumber) throws Exception
+ {
+ serverImpl = new NetworkServerControlImpl(address, portNumber);
+ }
+
+
+ /**
+ *
+ * Creates a NetworkServerControl object that is configured to control
+ * a Network Server on the default host(localhost)
+ * and the default port(1527) unless derby.drda.portNumber and
+ * derby.drda.host are set.
+ * <P><PRE>
+ * new NetworkServerControl()
+ *
+ * is equivalent to calling
+ *
+ * new NetworkServerControl(InetAddress.getByName("localhost"),1527);
+ * </PRE>
+ * </P>
+ *
+ * @throws Exception on error
+ */
+ public NetworkServerControl() throws Exception
+ {
+ serverImpl = new NetworkServerControlImpl();
+ }
+
+
+ /**
+ * main routine for NetworkServerControl
+ *
+ * @param args array of arguments indicating command to be executed.
+ * See class comments for more information
+ */
public static void main(String args[]) {
NetworkServerControlImpl server = null;
@@ -352,254 +352,254 @@ public class NetworkServerControl{
}
catch (Exception e)
{
- //if there was an error, exit(1)
- if ((e.getMessage() == null) ||
- !e.getMessage().equals(NetworkServerControlImpl.UNEXPECTED_ERR) ||
- printErrors
- )
- {
- if (server != null)
- server.consoleExceptionPrint(e);
- else
- e.printStackTrace(); // default output stream is System.out
- }
- // else, we've already printed a trace, so just exit.
- System.exit(1);
- }
- System.exit(0);
-
- }
-
- /**********************************************************************
- * Public NetworkServerControl commands
- * The server commands throw exceptions for errors, so that users can handle
- * them themselves.
- ************************************************************************
- **/
-
- /** Start a Network Server
- * This method will launch a separate thread and start Network Server.
- * This method may return before the server is ready to accept connections.
- * Use the ping method to verify that the server has started.
- *
- * <P>
- * Note: an alternate method to starting the Network Server with the API,
- * is to use the derby.drda.startNetworkServer property in
- * derby.properties.
- * </P>
- *
- *
- * @param consoleWriter PrintWriter to which server console will be
- * output. Null will disable console output.
- *
- * @exception Exception if there is an error starting the server.
- *
- * @see #shutdown
- */
- public void start(PrintWriter consoleWriter) throws Exception
- {
- serverImpl.start(consoleWriter);
- }
-
-
-
- /**
- * Shutdown a Network Server.
- * Shuts down the Network Server listening on the port and InetAddress
- * specified in the constructor for this NetworkServerControl object.
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void shutdown()
- throws Exception
- {
- serverImpl.shutdown();
- }
-
- /**
- * Check if Network Server is started
- * Excecutes and returns without error if the server has started
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void ping() throws Exception
- {
- serverImpl.ping();
- }
-
- /**
- * Turn tracing on or off for the specified connection
- * on the Network Server.
- *
- * @param on true to turn tracing on, false to turn tracing off.
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void trace(boolean on)
- throws Exception
- {
- serverImpl.trace(on);
- }
-
-
- /**
- * Turn tracing on or off for all connections on the Network Server.
- *
- * @param connNum connection number. Note: Connection numbers will print
- * in the Derby error log if logConnections is on
- * @param on true to turn tracing on, false to turn tracing off.
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void trace(int connNum, boolean on)
- throws Exception
- {
- serverImpl.trace(connNum, on);
- }
-
- /**
- * Turn logging connections on or off. When logging is turned on a message is
- * written to the Derby error log each time a connection
- * is made.
- *
- * @param on true to turn on, false to turn off
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void logConnections(boolean on)
- throws Exception
- {
- serverImpl.logConnections(on);
- }
-
- /**
- * Set directory for trace files. The directory must be on the machine
- * where the server is running.
- *
- * @param traceDirectory directory for trace files on machine
- * where server is running
- *
- * @exception Exception throws an exception if an error occurs
- */
- public void setTraceDirectory(String traceDirectory)
- throws Exception
- {
- serverImpl.sendSetTraceDirectory(traceDirectory);
- }
-
- /**
- * Return classpath and version information about the running
- * Network Server.
- *
- * @return sysinfo output
- * @exception Exception throws an exception if an error occurs
- */
- public String getSysinfo()
- throws Exception
- {
-
- return serverImpl.sysinfo();
- }
-
- /**
- * Return detailed session runtime information about sessions,
- * prepared statements, and memory usage for the running Network Server.
- *
- * @return run time information
- * @exception Exception throws an exception if an error occurs
- */
- public String getRuntimeInfo()
- throws Exception
- {
- return serverImpl.runtimeInfo();
- }
-
-
- /**
- * Set Network Server maxthread parameter. This is the maximum number
- * of threads that will be used for JDBC client connections. setTimeSlice
- * should also be set so that clients will yield appropriately.
- *
- * @param max maximum number of connection threads.
- * If <= 0, connection threads will be created when
- * there are no free connection threads.
- *
- * @exception Exception throws an exception if an error occurs
- * @see #setTimeSlice
- */
- public void setMaxThreads(int max) throws Exception
- {
- serverImpl.netSetMaxThreads(max);
- }
-
-
- /** Returns the current maxThreads setting for the running Network Server
- *
- * @return maxThreads setting
- * @exception Exception throws an exception if an error occurs
- * @see #setMaxThreads
- */
- public int getMaxThreads() throws Exception
- {
- String val =serverImpl.getCurrentProperties().getProperty(Property.DRDA_PROP_MAXTHREADS);
-
-
- return Integer.parseInt(val);
- }
-
- /**
- * Set Network Server connection time slice parameter.
- * This should be set and is only relevant if setMaxThreads > 0.
- *
- * @param timeslice number of milliseconds given to each session before yielding to
- * another session, if <=0, never yield.
- *
- * @exception Exception throws an exception if an error occurs
- * @see #setMaxThreads
- */
- public void setTimeSlice(int timeslice) throws Exception
- {
- serverImpl.netSetTimeSlice(timeslice);
- }
-
- /** Return the current timeSlice setting for the running Network Server
- *
- * @return timeSlice setting
- * @exception Exception throws an exception if an error occurs
- * @see #setTimeSlice
- */
- public int getTimeSlice() throws Exception
- {
- String val =
- serverImpl.getCurrentProperties().getProperty(Property.DRDA_PROP_TIMESLICE);
- return Integer.parseInt(val);
- }
-
-
-
- /**
- * Get current Network server properties
- *
- * @return Properties object containing Network server properties
- * @exception Exception throws an exception if an error occurs
- */
- public Properties getCurrentProperties() throws Exception
- {
- return serverImpl.getCurrentProperties();
- }
-
- /** Protected methods ***/
-
- /***
- * set the client locale. Used by servlet for localization
- * @param locale Locale to use
- *
- */
-
- protected void setClientLocale(String locale)
- {
- serverImpl.clientLocale = locale;
- }
+ //if there was an error, exit(1)
+ if ((e.getMessage() == null) ||
+ !e.getMessage().equals(NetworkServerControlImpl.UNEXPECTED_ERR) ||
+ printErrors
+ )
+ {
+ if (server != null)
+ server.consoleExceptionPrint(e);
+ else
+ e.printStackTrace(); // default output stream is System.out
+ }
+ // else, we've already printed a trace, so just exit.
+ System.exit(1);
+ }
+ System.exit(0);
+
+ }
+
+ /**********************************************************************
+ * Public NetworkServerControl commands
+ * The server commands throw exceptions for errors, so that users can handle
+ * them themselves.
+ ************************************************************************
+ **/
+
+ /** Start a Network Server
+ * This method will launch a separate thread and start Network Server.
+ * This method may return before the server is ready to accept connections.
+ * Use the ping method to verify that the server has started.
+ *
+ * <P>
+ * Note: an alternate method to starting the Network Server with the API,
+ * is to use the derby.drda.startNetworkServer property in
+ * derby.properties.
+ * </P>
+ *
+ *
+ * @param consoleWriter PrintWriter to which server console will be
+ * output. Null will disable console output.
+ *
+ * @exception Exception if there is an error starting the server.
+ *
+ * @see #shutdown
+ */
+ public void start(PrintWriter consoleWriter) throws Exception
+ {
+ serverImpl.start(consoleWriter);
+ }
+
+
+
+ /**
+ * Shutdown a Network Server.
+ * Shuts down the Network Server listening on the port and InetAddress
+ * specified in the constructor for this NetworkServerControl object.
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void shutdown()
+ throws Exception
+ {
+ serverImpl.shutdown();
+ }
+
+ /**
+ * Check if Network Server is started
+ * Excecutes and returns without error if the server has started
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void ping() throws Exception
+ {
+ serverImpl.ping();
+ }
+
+ /**
+ * Turn tracing on or off for the specified connection
+ * on the Network Server.
+ *
+ * @param on true to turn tracing on, false to turn tracing off.
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void trace(boolean on)
+ throws Exception
+ {
+ serverImpl.trace(on);
+ }
+
+
+ /**
+ * Turn tracing on or off for all connections on the Network Server.
+ *
+ * @param connNum connection number. Note: Connection numbers will print
+ * in the Derby error log if logConnections is on
+ * @param on true to turn tracing on, false to turn tracing off.
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void trace(int connNum, boolean on)
+ throws Exception
+ {
+ serverImpl.trace(connNum, on);
+ }
+
+ /**
+ * Turn logging connections on or off. When logging is turned on a message is
+ * written to the Derby error log each time a connection
+ * is made.
+ *
+ * @param on true to turn on, false to turn off
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void logConnections(boolean on)
+ throws Exception
+ {
+ serverImpl.logConnections(on);
+ }
+
+ /**
+ * Set directory for trace files. The directory must be on the machine
+ * where the server is running.
+ *
+ * @param traceDirectory directory for trace files on machine
+ * where server is running
+ *
+ * @exception Exception throws an exception if an error occurs
+ */
+ public void setTraceDirectory(String traceDirectory)
+ throws Exception
+ {
+ serverImpl.sendSetTraceDirectory(traceDirectory);
+ }
+
+ /**
+ * Return classpath and version information about the running
+ * Network Server.
+ *
+ * @return sysinfo output
+ * @exception Exception throws an exception if an error occurs
+ */
+ public String getSysinfo()
+ throws Exception
+ {
+
+ return serverImpl.sysinfo();
+ }
+
+ /**
+ * Return detailed session runtime information about sessions,
+ * prepared statements, and memory usage for the running Network Server.
+ *
+ * @return run time information
+ * @exception Exception throws an exception if an error occurs
+ */
+ public String getRuntimeInfo()
+ throws Exception
+ {
+ return serverImpl.runtimeInfo();
+ }
+
+
+ /**
+ * Set Network Server maxthread parameter. This is the maximum number
+ * of threads that will be used for JDBC client connections. setTimeSlice
+ * should also be set so that clients will yield appropriately.
+ *
+ * @param max maximum number of connection threads.
+ * If <= 0, connection threads will be created when
+ * there are no free connection threads.
+ *
+ * @exception Exception throws an exception if an error occurs
+ * @see #setTimeSlice
+ */
+ public void setMaxThreads(int max) throws Exception
+ {
+ serverImpl.netSetMaxThreads(max);
+ }
+
+
+ /** Returns the current maxThreads setting for the running Network Server
+ *
+ * @return maxThreads setting
+ * @exception Exception throws an exception if an error occurs
+ * @see #setMaxThreads
+ */
+ public int getMaxThreads() throws Exception
+ {
+ String val =serverImpl.getCurrentProperties().getProperty(Property.DRDA_PROP_MAXTHREADS);
+
+
+ return Integer.parseInt(val);
+ }
+
+ /**
+ * Set Network Server connection time slice parameter.
+ * This should be set and is only relevant if setMaxThreads > 0.
+ *
+ * @param timeslice number of milliseconds given to each session before yielding to
+ * another session, if <=0, never yield.
+ *
+ * @exception Exception throws an exception if an error occurs
+ * @see #setMaxThreads
+ */
+ public void setTimeSlice(int timeslice) throws Exception
+ {
+ serverImpl.netSetTimeSlice(timeslice);
+ }
+
+ /** Return the current timeSlice setting for the running Network Server
+ *
+ * @return timeSlice setting
+ * @exception Exception throws an exception if an error occurs
+ * @see #setTimeSlice
+ */
+ public int getTimeSlice() throws Exception
+ {
+ String val =
+ serverImpl.getCurrentProperties().getProperty(Property.DRDA_PROP_TIMESLICE);
+ return Integer.parseInt(val);
+ }
+
+
+
+ /**
+ * Get current Network server properties
+ *
+ * @return Properties object containing Network server properties
+ * @exception Exception throws an exception if an error occurs
+ */
+ public Properties getCurrentProperties() throws Exception
+ {
+ return serverImpl.getCurrentProperties();
+ }
+
+ /** Protected methods ***/
+
+ /***
+ * set the client locale. Used by servlet for localization
+ * @param locale Locale to use
+ *
+ */
+
+ protected void setClientLocale(String locale)
+ {
+ serverImpl.clientLocale = locale;
+ }
/**
* Return true if we need to install a Security Manager. All of the
Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/build.xml?rev=1370674&r1=1370673&r2=1370674&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/drda/build.xml (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/drda/build.xml Wed Aug 8 06:54:46 2012
@@ -79,10 +79,10 @@
srcdir="${derby.drda.src.dir}"
destdir="${out.dir}">
<classpath>
- <pathelement location="${servlet24}"/>
+ <pathelement location="${servlet24}"/>
<pathelement path="${java15compile.classpath}"/>
</classpath>
- <include name="${derby.dir}/drda/NetServlet.java"/>
+ <include name="${derby.dir}/drda/NetServlet.java"/>
</javac>
</target>
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java?rev=1370674&r1=1370673&r2=1370674&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java Wed Aug 8 06:54:46 2012
@@ -25,256 +25,256 @@ import org.apache.derby.iapi.reference.L
import org.apache.derby.iapi.services.sanity.SanityManager;
/**
- AppRequester stores information about the application requester.
- It is used so that multiple sessions can share information when they are
- started from the same version of the application requester.
+ AppRequester stores information about the application requester.
+ It is used so that multiple sessions can share information when they are
+ started from the same version of the application requester.
*/
class AppRequester
{
- protected static final int MGR_LEVEL_UNKNOWN = -1;
+ protected static final int MGR_LEVEL_UNKNOWN = -1;
- protected static final int UNKNOWN_CLIENT = 0;
+ protected static final int UNKNOWN_CLIENT = 0;
- protected static final int DNC_CLIENT = 3; // derby net client
+ protected static final int DNC_CLIENT = 3; // derby net client
- private static final int [] MIN_MGR_LEVELS = {
- 3, // AGENT - JCC comes in at 3
- 4, // CCSIDMGR
- 3, // CMNAPPC,
- 4, // CMNSYNCPT
- 5, // CMNTCPIP
- 1, // DICTIONARY
- 3, // RDB
- 4, // RSYNCMGR
- 1, // SECMGR
- 6, // SQLAM
- 1, // SUPERVISOR
- 5, // SYNCPTMGR
- 1208, // UNICODEMGR
- 0 // XAMGR
- };
-
- // Application requester information
- protected String extnam; // External Name - EXCSAT
- protected String srvnam; // Server Name - EXCSAT
- protected String srvrlslv; // Server Product Release Level - EXCSAT
- protected String srvclsnm; // Server Class Name - EXCSAT
- protected String spvnam; // Supervisor Name - EXCSAT
- protected String prdid; // Product specific identifier - ACCRDB protected
- private int[] managerLevels = new int[CodePoint.MGR_CODEPOINTS.length];
- private int clientType;
- protected int versionLevel;
- protected int releaseLevel;
- protected int modifyLevel;
-
-
- // constructor
- /**
- * AppRequester constructor
- *
- * @exception throws IOException
- */
- AppRequester ()
- {
- for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++)
- managerLevels[i] = MGR_LEVEL_UNKNOWN;
- }
-
- /**
- * get the Application requester manager level
- *
- * @param manager codepoint for manager we are looking for
- *
- * @return manager level for that manager
- */
- protected int getManagerLevel(int manager)
- {
- int mindex = CodePoint.getManagerIndex(manager);
- if (SanityManager.DEBUG)
- {
- if (mindex < 0 || mindex > managerLevels.length)
- SanityManager.THROWASSERT("Unknown manager "+ manager + " mindex = "+
- mindex);
- }
- return managerLevels[mindex];
- }
-
- protected void setClientVersion(String productId)
- {
- prdid = productId;
-
- versionLevel = Integer.parseInt(prdid.substring (3, 5));
- releaseLevel = Integer.parseInt(prdid.substring (5, 7));
- modifyLevel = Integer.parseInt(prdid.substring (7, 8));
+ private static final int [] MIN_MGR_LEVELS = {
+ 3, // AGENT - JCC comes in at 3
+ 4, // CCSIDMGR
+ 3, // CMNAPPC,
+ 4, // CMNSYNCPT
+ 5, // CMNTCPIP
+ 1, // DICTIONARY
+ 3, // RDB
+ 4, // RSYNCMGR
+ 1, // SECMGR
+ 6, // SQLAM
+ 1, // SUPERVISOR
+ 5, // SYNCPTMGR
+ 1208, // UNICODEMGR
+ 0 // XAMGR
+ };
+
+ // Application requester information
+ protected String extnam; // External Name - EXCSAT
+ protected String srvnam; // Server Name - EXCSAT
+ protected String srvrlslv; // Server Product Release Level - EXCSAT
+ protected String srvclsnm; // Server Class Name - EXCSAT
+ protected String spvnam; // Supervisor Name - EXCSAT
+ protected String prdid; // Product specific identifier - ACCRDB protected
+ private int[] managerLevels = new int[CodePoint.MGR_CODEPOINTS.length];
+ private int clientType;
+ protected int versionLevel;
+ protected int releaseLevel;
+ protected int modifyLevel;
+
+
+ // constructor
+ /**
+ * AppRequester constructor
+ *
+ * @exception throws IOException
+ */
+ AppRequester ()
+ {
+ for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++)
+ managerLevels[i] = MGR_LEVEL_UNKNOWN;
+ }
+
+ /**
+ * get the Application requester manager level
+ *
+ * @param manager codepoint for manager we are looking for
+ *
+ * @return manager level for that manager
+ */
+ protected int getManagerLevel(int manager)
+ {
+ int mindex = CodePoint.getManagerIndex(manager);
+ if (SanityManager.DEBUG)
+ {
+ if (mindex < 0 || mindex > managerLevels.length)
+ SanityManager.THROWASSERT("Unknown manager "+ manager + " mindex = "+
+ mindex);
+ }
+ return managerLevels[mindex];
+ }
+
+ protected void setClientVersion(String productId)
+ {
+ prdid = productId;
+
+ versionLevel = Integer.parseInt(prdid.substring (3, 5));
+ releaseLevel = Integer.parseInt(prdid.substring (5, 7));
+ modifyLevel = Integer.parseInt(prdid.substring (7, 8));
if ((prdid.indexOf(DRDAConstants.DERBY_DRDA_CLIENT_ID) != -1)) {
clientType = DNC_CLIENT;
} else {
clientType = UNKNOWN_CLIENT;
}
- }
+ }
- /**
- * Returns true if Derby's client driver supports SECMEC_USRSSBPWD
- * DRDA security mechanism.
- */
- protected boolean supportsSecMecUSRSSBPWD()
- {
- return
- (
- ( clientType == DNC_CLIENT ) &&
- ( greaterThanOrEqualTo( 10, 2, 0 ) )
- );
- }
-
- /**
- * Check if the client expects QRYCLSIMP to be supported when the
- * protocol is LMTBLKPRC.
- *
- * @return <code>true</code> if QRYCLSIMP is supported for
- * LMTBLKPRC
- */
- protected final boolean supportsQryclsimpForLmtblkprc() {
- return clientType == DNC_CLIENT;
- }
-
- /**
- * Check if provided JCC version level is greaterThanOrEqualTo current level
- *
- * @param vLevel Version level
- * @param rLevel Release level
- * @param mLevel Modification level
- */
-
- protected boolean greaterThanOrEqualTo(int vLevel, int rLevel, int mLevel)
- {
- if (versionLevel > vLevel)
- return true;
- else if (versionLevel == vLevel) {
- if (releaseLevel > rLevel)
- return true;
- else if (releaseLevel == rLevel)
- if (modifyLevel >= mLevel)
- return true;
- }
- return false;
- }
-
- /**
- * set Application requester manager level
- * if the manager level is less than the minimum manager level,
- * set the manager level to zero (saying we can't handle this
- * level), this will be returned
- * to the application requester and he can decide whether or not to
- * proceed
- * For CCSIDMGR, if the target server supports the CCSID manager but
- * not the CCSID requested, the value returned is FFFF
- * For now, we won't support the CCSIDMGR since JCC doesn't request it.
- *
- * @param manager codepoint of the manager
- * @param managerLevel level for that manager
- *
- */
- protected void setManagerLevel(int manager, int managerLevel)
- {
- int i = CodePoint.getManagerIndex(manager);
- if (SanityManager.DEBUG)
- {
- if (i < 0 || i > managerLevels.length)
- SanityManager.THROWASSERT("Unknown manager "+ manager + " i = " + i);
- }
- if (managerLevel >= MIN_MGR_LEVELS[i])
- managerLevels[i] = managerLevel;
- else
- managerLevels[i] = 0;
- }
-
- /**
- * Check if the application requester is the same as this one
- *
- * @param a application requester to compare to
- * @return true if same false otherwise
- */
- protected boolean equals(AppRequester a)
- {
- // check prdid - this should be different if they are different
- if (!prdid.equals(a.prdid))
- return false;
-
- // check server product release level
- if (notEquals(srvrlslv, a.srvrlslv))
- return false;
-
- // check server names
- if (notEquals(extnam, a.extnam))
- return false;
-
- if (notEquals(srvnam, a.srvnam))
- return false;
-
- if (notEquals(srvclsnm, a.srvclsnm))
- return false;
-
- if (notEquals(spvnam, a.spvnam))
- return false;
-
- // check manager levels
- for (int i = 0; i < managerLevels.length; i++)
- if (managerLevels[i] != a.managerLevels[i])
- return false;
-
- // O.K. looks good
- return true;
- }
- /**
- * Check whether two objects are not equal when 1 of the objects could
- * be null
- *
- * @param a first object
- * @param b second object
- * @return true if not equals false otherwise
- */
- private boolean notEquals(Object a, Object b)
- {
- if (a != null && b == null)
- return true;
- if (a == null && b != null)
- return true;
- if (a != null && !a.equals(b))
- return true;
- return false;
- }
-
- /**
- * Get the maximum length supported for an exception's message
- * parameter string.
- */
+ /**
+ * Returns true if Derby's client driver supports SECMEC_USRSSBPWD
+ * DRDA security mechanism.
+ */
+ protected boolean supportsSecMecUSRSSBPWD()
+ {
+ return
+ (
+ ( clientType == DNC_CLIENT ) &&
+ ( greaterThanOrEqualTo( 10, 2, 0 ) )
+ );
+ }
+
+ /**
+ * Check if the client expects QRYCLSIMP to be supported when the
+ * protocol is LMTBLKPRC.
+ *
+ * @return <code>true</code> if QRYCLSIMP is supported for
+ * LMTBLKPRC
+ */
+ protected final boolean supportsQryclsimpForLmtblkprc() {
+ return clientType == DNC_CLIENT;
+ }
+
+ /**
+ * Check if provided JCC version level is greaterThanOrEqualTo current level
+ *
+ * @param vLevel Version level
+ * @param rLevel Release level
+ * @param mLevel Modification level
+ */
+
+ protected boolean greaterThanOrEqualTo(int vLevel, int rLevel, int mLevel)
+ {
+ if (versionLevel > vLevel)
+ return true;
+ else if (versionLevel == vLevel) {
+ if (releaseLevel > rLevel)
+ return true;
+ else if (releaseLevel == rLevel)
+ if (modifyLevel >= mLevel)
+ return true;
+ }
+ return false;
+ }
- protected int supportedMessageParamLength() {
+ /**
+ * set Application requester manager level
+ * if the manager level is less than the minimum manager level,
+ * set the manager level to zero (saying we can't handle this
+ * level), this will be returned
+ * to the application requester and he can decide whether or not to
+ * proceed
+ * For CCSIDMGR, if the target server supports the CCSID manager but
+ * not the CCSID requested, the value returned is FFFF
+ * For now, we won't support the CCSIDMGR since JCC doesn't request it.
+ *
+ * @param manager codepoint of the manager
+ * @param managerLevel level for that manager
+ *
+ */
+ protected void setManagerLevel(int manager, int managerLevel)
+ {
+ int i = CodePoint.getManagerIndex(manager);
+ if (SanityManager.DEBUG)
+ {
+ if (i < 0 || i > managerLevels.length)
+ SanityManager.THROWASSERT("Unknown manager "+ manager + " i = " + i);
+ }
+ if (managerLevel >= MIN_MGR_LEVELS[i])
+ managerLevels[i] = managerLevel;
+ else
+ managerLevels[i] = 0;
+ }
+
+ /**
+ * Check if the application requester is the same as this one
+ *
+ * @param a application requester to compare to
+ * @return true if same false otherwise
+ */
+ protected boolean equals(AppRequester a)
+ {
+ // check prdid - this should be different if they are different
+ if (!prdid.equals(a.prdid))
+ return false;
+
+ // check server product release level
+ if (notEquals(srvrlslv, a.srvrlslv))
+ return false;
+
+ // check server names
+ if (notEquals(extnam, a.extnam))
+ return false;
+
+ if (notEquals(srvnam, a.srvnam))
+ return false;
+
+ if (notEquals(srvclsnm, a.srvclsnm))
+ return false;
+
+ if (notEquals(spvnam, a.spvnam))
+ return false;
+
+ // check manager levels
+ for (int i = 0; i < managerLevels.length; i++)
+ if (managerLevels[i] != a.managerLevels[i])
+ return false;
+
+ // O.K. looks good
+ return true;
+ }
+ /**
+ * Check whether two objects are not equal when 1 of the objects could
+ * be null
+ *
+ * @param a first object
+ * @param b second object
+ * @return true if not equals false otherwise
+ */
+ private boolean notEquals(Object a, Object b)
+ {
+ if (a != null && b == null)
+ return true;
+ if (a == null && b != null)
+ return true;
+ if (a != null && !a.equals(b))
+ return true;
+ return false;
+ }
+
+ /**
+ * Get the maximum length supported for an exception's message
+ * parameter string.
+ */
+
+ protected int supportedMessageParamLength() {
return Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH;
- }
+ }
- /**
- * Get the type of the client.
- */
+ /**
+ * Get the type of the client.
+ */
- protected int getClientType() {
+ protected int getClientType() {
- return clientType;
+ return clientType;
- }
+ }
- /**
- * Is this an AppRequester that supports XA
- *
- * return true if XAMGR >= 7, false otherwise
- **/
+ /**
+ * Is this an AppRequester that supports XA
+ *
+ * return true if XAMGR >= 7, false otherwise
+ **/
- protected boolean isXARequester()
- {
- return (getManagerLevel(CodePoint.XAMGR) >= 7);
-
- }
+ protected boolean isXARequester()
+ {
+ return (getManagerLevel(CodePoint.XAMGR) >= 7);
+
+ }
/**
* Tells whether the client sends a trailing Derby-specific status byte
@@ -294,21 +294,21 @@ class AppRequester
return (getManagerLevel(CodePoint.UNICODEMGR) == CcsidManager.UTF8_CCSID);
}
- protected boolean supportsSessionDataCaching() {
- return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 4, 0));
- }
-
- protected boolean supportsUDTs() {
- return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 6, 0));
- }
-
- protected boolean supportsTimestampNanoseconds() {
- return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 6, 0));
- }
-
- protected boolean supportsBooleanValues() {
- return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 7, 0));
- }
+ protected boolean supportsSessionDataCaching() {
+ return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 4, 0));
+ }
+
+ protected boolean supportsUDTs() {
+ return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 6, 0));
+ }
+
+ protected boolean supportsTimestampNanoseconds() {
+ return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 6, 0));
+ }
+
+ protected boolean supportsBooleanValues() {
+ return (clientType == DNC_CLIENT && greaterThanOrEqualTo(10, 7, 0));
+ }
/**
* Return true if the client contains the fix for DERBY-5236, which allows
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java?rev=1370674&r1=1370673&r2=1370674&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java Wed Aug 8 06:54:46 2012
@@ -30,9 +30,9 @@ import java.security.PrivilegedActionExc
final class ClientThread extends Thread {
- NetworkServerControlImpl parent;
- ServerSocket serverSocket;
- private int timeSlice;
+ NetworkServerControlImpl parent;
+ ServerSocket serverSocket;
+ private int timeSlice;
ClientThread (NetworkServerControlImpl nsi, ServerSocket ss) {
// Use a more meaningful name for this thread.
@@ -43,7 +43,7 @@ final class ClientThread extends Thread
serverSocket=ss;
timeSlice=nsi.getTimeSlice();
}
-
+
public void run()
{
Socket clientSocket = null;
@@ -93,8 +93,8 @@ final class ClientThread extends Thread
// is allways the case, but will not alter the
// behaviour since it is not within the scope of
// this change (DERBY-2108).
- clientSocket.close();
- return;
+ clientSocket.close();
+ return;
}
parent.consoleExceptionPrintTrace(ie);
if (clientSocket != null)