Top Description Fields Constructors Methods
org.apache.derby.impl.drda

public final Class NetworkServerControlImpl

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .DataOutputStream, .FilterOutputStream, .IOException, .InputStream, .OutputStream, .PrintStream, .PrintWriter, java.net.InetAddress, .ServerSocket, .Socket, .UnknownHostException, java.nio.charset.Charset, java.security.Permission, java.sql.Connection, .Driver, .SQLException, .SQLWarning, java.util.ArrayList, .Date, .Hashtable, .Properties, .StringTokenizer, .Vector, java.util.concurrent.atomic.AtomicInteger, javax.net.ServerSocketFactory, .SocketFactory, javax.net.ssl.SSLServerSocket, .SSLServerSocketFactory, .SSLSocket, .SSLSocketFactory, org.apache.derby.drda.NetworkServerControl, org.apache.derby.shared.common.error.StandardException, .MessageUtils, org.apache.derby.iapi.jdbc.AuthenticationService, .DRDAServerStarter, org.apache.derby.shared.common.reference.Attribute, .DRDAConstants, .MessageId, .Module, .Property, .SQLState, org.apache.derby.shared.common.i18n.MessageService, org.apache.derby.shared.common.info.ProductGenusNames, .ProductVersionHolder, org.apache.derby.mbeans.Version, .VersionMBean, org.apache.derby.iapi.services.jmx.ManagementService, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.iapi.services.property.PropertyUtil, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.tools.i18n.LocalizedOutput, .LocalizedResource, org.apache.derby.iapi.util.StringUtil, org.apache.derby.impl.jdbc.Util, org.apache.derby.mbeans.drda.NetworkServerMBean, org.apache.derby.shared.common.security.SystemPermission, org.apache.derby.shared.common.drda.NaiveTrustManager

NetworkServerControlImpl does all the work for NetworkServerControl
See Also
{@link NetworkServerControl} for description

Field Summary

Modifier and TypeField and Description
private int
private Hashtable<String, AppRequester>
private static String
private static String
protected static final String
private static String
private String
private static String
private ByteArrayOutputStream
protected static final int
protected static final int
private boolean
private InputStream
private String
private OutputStream
private Socket
private static final String
private static Driver
private PrintWriter
private static final int[]
private static final String
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private Vector<String>
private DataOutputStream
private static final String[]
private int
private Session
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private static final int
public static final int
public static final int
private static final String[]
private String
private boolean
protected static final int
pack-priv static final Charset
protected static final String
private static final String
private static final String
private static final String
private static final int
private static final int
private static final int
private static final String
private static final String
private static final String
private String
private String
private static final int
private static final int
private static final int
private static final int
private static final int
private int
private InetAddress
private String
protected static final int
private boolean
private LocalizedResource
pack-priv ArrayList<InetAddress>
localAddresses

List of local addresses for checking admin commands.

private boolean
private Object
private PrintWriter
private static final int
private int
private static final int
MAXREPLY

Maximum reply size.

private int
private memCheck
private static final int[]
private static final int
private static final int
private int
private int
private static final AtomicInteger
nextThreadNumber

Holds the sequence number to be assigned to the next thread that calls getUniqueThreadName(String).

private static final int
private static final int
private String
private Object
private int
private static String
private static byte[]
private String
private static final String
private static final int
private byte[]
private int
private int
private boolean
private Vector<Session>
private NetworkServerControlImpl
private ServerSocket
private Object
private int
private Hashtable<Integer, Session>
private boolean
private static final int
private static final int
private static final int
private boolean
private Object
protected static final byte
private static final int
private static final int
private static final int
private static final int
private static final int
private int
private static boolean
SUPPORTS_EUSRIDPWD

Can EUSRIDPWD security mechanism be used with the current JVM

private NetworkServerControlImpl
private Vector<DRDAConnThread>
private Object
private int
private Object
private boolean
private Object
private String
private Object
public static final String
private boolean
private static final int
private String
private static String
private static final int

Constructor Summary

AccessConstructor and Description
public
public
NetworkServerControlImpl(InetAddress
InetAddress to listen on, throws NPE if null
address
,
int
portNumber to listen on, -1 use property or default
portNumber
)

Internal constructor for NetworkServerControl API.

public
NetworkServerControlImpl(String
the user name for actions requiring authorization
userName
,
String
the password for actions requiring authorization
password
)

Internal constructor for NetworkServerControl API.

public
NetworkServerControlImpl(InetAddress
InetAddress to listen on, throws NPE if null
address
,
int
portNumber to listen on, -1 use property or default
portNumber
,
String
the user name for actions requiring authorization
userName
,
String
the password for actions requiring authorization
password
)

Internal constructor for NetworkServerControl API.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addSession(Socket
the socket to read from and write to
clientSocket
)

Add a session - for use by ClientThread.

public static String

Returns:

the att_extnam server attribut
att_extnam
()

Return the att_extnam server attribute

public static String

Returns:

the att_srvclsnm server attribute
att_srvclsnm
()

Return the att_srvclsnm server attribute

public static String

Returns:

the att_srvrlslv server attribute
att_srvrlslv
()

Return the att_srvrlslv server attribute

public void
blockingStart(PrintWriter
PrintWriter to which server console will be output. Null will disable console output.
consoleWriter
)

Start a network server

private void
buildLocalAddressList(InetAddress
Address on which server was started Note: Some systems may not support localhost. In that case a console message will print for the localhost entries, but the server will continue to start.
bindAddr
)

Build local address list to allow admin commands.

public String
private void
public void
private void
clientSocketError(IOException e)

Stream error writing to client socket

private void
closeSocket()

Close the resources associated with the opened socket.

public void
consoleError(String
error message
msg
)

Write an error message to console output stream and throw an exception for this error

public void
consoleExceptionPrint(Exception
exception
e
)

Write an exception to console output stream, but only if debugOutput is true.

public void
consoleExceptionPrintTrace(Throwable
exception
e
)

Write an exception (with trace) to console output stream.

public void
consoleMessage(String
message
msg
,
boolean
Whether to prepend a timestamp to the message or not
printTimeStamp
)

Write a message to console output stream

private void
consolePrintAndIgnore(String msgProp, Exception e, boolean printTimeStamp)

protected void
consolePropertyMessage(String
message property key
msgProp
,
boolean
whether to prepend a timestamp to the message
printTimeStamp
)

Put property message on console

protected void
consolePropertyMessage(String
message property key
msgProp
,
String
argument for message
arg
)

Put property message on console

protected void
consolePropertyMessage(String
message property key
msgProp
,
String[]
argument array for message
args
)

Put property message on console

private void
consolePropertyMessageWork(String
message key
messageKey
,
String[]
arguments to message
args
,
boolean
whether to prepend a timestamp to the message
printTimeStamp
)

Handle console error message - display on console and if it is a user error, display usage - if user error or severe error, throw exception with message key and message

private void
consoleTraceMessage(int connNum, boolean
true to print tracing on, false to print tracing off
on
)

Print trace change message to console

private ServerSocket
createServerSocket()

Create the right kind of server socket

public boolean

Returns:

true if we are in debug mode
debugOutput
()

Return the debug state

public void
pack-priv void
private void
ensureDataInBuffer(int
size of buffer required
minimumBytesNeeded
,
boolean
tells whether or not an error should be raised if end-of-stream is reached before the requested amount of bytes could be read
failOnEOS
)

Ensure the reply buffer is large enough to hold all the data; don't just rely on OS level defaults

public void
executeWork(int
The command to execute. The command itself was determined by an earlier call to parseArgs().
command
)

Execute the command given on the command line

private void
fillReplyBuffer()

Fill the reply buffer with the reply allocates a reply buffer if one doesn't exist

private int

Returns:

command
findCommand
(String[]
arguments to search
args
)

Go through the arguments and find the command and save the dash arguments and arguments to the command.

private static Object
findService(final String factoryInterface, final String serviceName)

Must be private so that user code can't call this entry point.

pack-priv int
protected AppRequester

Returns:

stored application requester
getAppRequester
(AppRequester
Application Requester to look for
appRequester
)

Get the stored application requester or store if we haven't seen it yet

pack-priv long
pack-priv long
private String

Returns:

system information for Derby
getCLSSysInfo
()

Get Derby information

pack-priv int
public Properties

Returns:

Properties object containing properties
getCurrentProperties
()

Get current properties

protected static Driver
private String
public String

Returns:

the host name
getHost
()

Get the host where we listen for connections.

private int

Returns:

integer value
getIntPropVal
(String
property name
propName
,
String
string property value
propVal
)

Get integer property values

protected boolean

Returns:

the current value of keepAlive
getKeepAlive
()

Get the current value of keepAlive to configure how long the server should keep the socket alive for a disconnected client

public boolean

Returns:

true if logging connections is on; false otherwise
getLogConnections
()

Get the current value of logging connections

protected int

Returns:

manager level
getManagerLevel
(int
codepoint for manager
manager
)

Get the server manager level for a given manager

private int

Returns:

value of maximum number of threads
getMaxThreads
()

Get the current value of maximum number of threads to create

private int

Returns:

message type
getMessageType
(String
message
msg
)

Determine type of message

private int

Returns:

value of minimum number of threads
getMinThreads
()

Get the current value of minimum number of threads to create at start

private ProductVersionHolder
getNetProductVersionHolder()

Retrieve product version information We need to make sure that this method gets the stream and passes it to ProductVersionHolder, because it lives in the Network Server jar and won't be readily available to ProductVersionHolder when running under security manager.

private String

Returns:

system information for the Network Server
getNetSysInfo
()

Get Net Server information

protected Session

Returns:

next session to work on, could be same as current session
getNextSession
(Session
session thread is currently working on
currentSession
)

Get the next session for the thread to work on Called from DRDAConnThread after session completes or timeslice exceeded.

public int

Returns:

the port number
getPort
()

Get the port where we listen for connections.

private void
getPropertyInfo()

Initialize fields from system properties

pack-priv Properties

Returns:

a collection of network server properties and their current values
getPropertyValues
()

Constructs an object containing network server related properties and their values.

pack-priv int
private String
private int

Returns:

integer value , return the SECMEC value for the security mechanism as defined by DRDA spec or INVALID_OR_NOTSET_SECURITYMECHANISM if 's' passed is invalid or not supported security mechanism
getSecMecValue
(String
security mechanism name
s
)

Retrieve the SECMEC integer value from the user friendly security mechanism name

protected int

Returns:

the securitymechanism value. It is value that the derby.drda.securityMechanism was set to, if it is not set, then it is equal to INVALID_OR_NOTSET_SECURITYMECHANISM
getSecurityMechanism
()

get the security mechanism (secmec value) that the server will accept connections from.

protected boolean
protected Object
protected int
private String

Returns:

The string representation ("off","on" or "autneticate"). Will default to SSL_OFF for other values than those listed above.
getSSLModeString
(int
The SSL-mode value (SSL_OFF, SSL_BASIC or SSL_PEER_AUTHENTICATION)
i
)

Get the string value of the SSL-mode.

private int

Returns:

SSL_OFF, SSL_BASIC or SSL_PEER_AUTHENTICATION. Will default to SSL_OFF if the input does not match one of the four listed above.
getSSLModeValue
(String
the SSL-mode string ("off"/"false", "on"/"true" or "authenticate"/"auth"
s
)

Get the SSL-mode from a string.

private Properties
getSSLProperties()

Retrieve the settings of the SSL properties

private String

Returns:

String - return the string name corresponding to the secmec value if recognized else returns null
getStringValueForSecMec
(int
secmec value
secmecVal
)

Retrieve the string name for the integer secmec value

private static Object
getSystemModule(final String factoryInterface)

Must be private so that user code can't call this entry point.

pack-priv int
protected int

Returns:

time slice value
getTimeSlice
()

Get the current value of the time slice

protected boolean

Returns:

true if tracing is on for all sessions; false otherwise
getTraceAll
()

Get the current value of whether to trace all the sessions

protected String

Returns:

trace directory
getTraceDirectory
()

Get the current value of trace directory

pack-priv static String

Returns:

a unique thread name that starts with base and is followed by an underscore and a unique sequence number
getUniqueThreadName
(String
the first part of the thread name (the meaningful part)
base
)

Get a thread name that is both meaningful and unique (primarily for debugging purposes).

private void
init()

protected static boolean

Returns:

true if the command is the protocol command
isCmd
(String
A command string
val
)

Is this the command protocol

private boolean

Returns:

true if it is a property key; false otherwise
isMsgProperty
(String
message
msg
)

Determine whether string is a property key or not property keys start with DRDA_MSG_PREFIX

private boolean

Returns:

true if string is "on", false if string is "off"
isOn
(String
string to check
arg
)

Is string "on" or "off"

public boolean

Returns:

true if the server has started
isServerStarted
()

Return true if the server has started.

public String

Returns:

the localized message
localizeMessage
(String
message key
msgProp
,
String[]
arguments to message
args
)

Convenience routine so that NetworkServerControl can localize messages.

private String
localizeMessage(String
message key
msgProp
,
LocalizedResource
LocalizedResource to use to localize message
localLangUtil
,
String[]
arguments to message
args
)

Localize a message given a particular AppUI

public void
logConnections(boolean
true to turn on, false to turn off
on
)

Turn logging connections on or off.

private void
logConnectionsChange(boolean on)

Record a change to the connection logging mode

public PrintWriter

Returns:

the log writer
logWriter
()

Get the log writer we're using

private PrintWriter
public void
netSetMaxThreads(int
maximum number of connections, if 0, connections created when no free connection available if -1, use default
max
)

Connect to network server and set connection maxthread parameter

public void
netSetTimeSlice(int
amount of time given to each session before yielding to another session, if 0, never yield. if -1, use default.
timeslice
)

Set network server connection timeslice parameter

public int

Returns:

the command to be executed
parseArgs
(String[]
array of arguments indicating command to be executed
args
)

Parse the command-line arguments.

public void
ping()

Ping opening an new socket and close it.

private void
pingWithNoOpen()

Ping the server using the client socket that is already open.

public static String

Returns:

the product id
prdId
()

Return the product id

public static byte[]

Returns:

the bytes of the product id
prdIdBytes
()

Return the bytes of the product id

protected synchronized void
processCommands(DDMReader
input reader for command
reader
,
DDMWriter
output writer for command
writer
,
Session
session information
session
)

processCommands reads and processes NetworkServerControlImpl commands sent to the network server over the socket.

private int

Returns:

command
processDashArg
(int
starting point
pos
,
String[]
arguments to search
args
)

Get the dash argument.

private byte[]

Returns:

string value or null
readBytesReply
(String
error message key
msgKey
)

Read Bytes reply

private void
readCommandReplyHeader()

Read the command reply header from the server

private int
readInt()

Read int from buffer

private byte[]

Returns:

byte array from buffer
readLDBytes
()

Read length delimited bytes from a buffer

private String

Returns:

string value from buffer
readLDString
()

Read length delimited string from a buffer

private void
readResult()

Read result from sending client message to server

private int
readShort()

Read short from buffer

private String

Returns:

string value or null
readStringReply
(String
error message key
msgKey
)

Read String reply

protected void
removeFromSessionTable(int
id of session to be removed
sessionid
)

Remove session from session table

private String[]
removeSSLv3andSSLv2Hello(String[] enabledProtocols)

pack-priv void
removeThread(DRDAConnThread
the closed thread
thread
)

Remove a thread from the thread list.

public boolean

Returns:

true if the customer forcibly overrode our decision
runningUnsecure
()

Return true if the customer forcibly overrode our decision to install a default SecurityManager.

private void
runQueueAdd(Session
session needing work
clientSession
)

Add session to the run queue

public String

Returns:

the runtime information
runtimeInfo
()

private void
send()

Send client message to server

private void
sendMessage(DDMWriter
writer to use for sending message
writer
,
int
1 for Warning, 2 for Error 3 for SQLError
messageType
,
String
message
message
)

Send Error or Warning from server to client after processing a command

private void
sendOK(DDMWriter
writer to use for sending OK
writer
)

Send OK from server to client after processing a command

private void
sendOKInt(DDMWriter
writer to use for sending
writer
,
int
int val to send
val
)

Send OK and int value

private void
sendPropInfo(DDMWriter
writer to use for sending sysinfo
writer
)

Send property information from server to client

private void
sendRuntimeInfo(DDMWriter
writer to use for sending sysinfo
writer
)

Send RuntimeInfo information from server to client

public void
sendSetTraceDirectory(String
Where to write traces
traceDirectory
)

private void
sendSQLMessage(DDMWriter
writer to use for sending message
writer
,
SQLException
Derby exception
se
,
int
type of exception, SQLERROR or SQLWARNING
type
)

Send SQL Exception from server to client after processing a command

private void
sendSysInfo(DDMWriter
writer to use for sending sysinfo
writer
)

Send SysInfo information from server to client

public void
private void
setLogConnections(boolean
true to turn logging connections on; false to turn it off
value
)

Set the current value of logging connections

public void
setLogWriter(PrintWriter
output stream for console messages
outWriter
)

Set the output stream for console messages If this is set to null, no messages will be written to the console

private void
setMaxThreads(int
value of maximum number of threads
value
)

Set the current value of maximum number of threads to create

private void
setMinThreads(int
value of minimum number of threads
value
)

Set the current value of minimum number of threads to create at start

private void
setSecurityMechanism(String
security mechanism string value
s
)

Set the security mechanism for derby.drda.securityMechanism If this property is set, server will only allow connections from client with this security mechanism.

protected void
setSSLMode(int mode)

private void
setTimeSlice(int
time slice value
value
)

Set the current value of time slice

private boolean

Returns:

true if set false if an error occurred
setTrace
(boolean
true to turn trace on; false to turn it off
on
)

Set the trace on/off for all sessions, or one session, depending on whether we got -s argument.

private void
setTraceAll(boolean
true if tracing is on for all sessions; false otherwise
value
)

Set the current value of whether to trace all the sessions

private void
setTraceDirectory(String
trace directory
value
)

Set the current value of trace directory

private void
setUpSocket()

Set up client socket to send a command to the network server

public void
shutdown()

Shutdown a network server

public void
start(PrintWriter
PrintWriter to which server console will be output. Null will disable console output.
consoleWriter
)

Start a network server.

protected void
startNetworkServer()

Start the network server.

protected boolean

Returns:

true if supported; false otherwise
supportsCCSID
(int
CCSID to check
ccsid
)

Check whether a CCSID code page is supported

pack-priv boolean

Returns:

true if EUSRIDPWD is supported, false otherwise
supportsEUSRIDPWD
()

This method returns whether EUSRIDPWD security mechanism is supported or not.

public String

Returns:

system information
sysinfo
()

private void
throwSQLException(String
msg containing SQL Exception
msg
)

Throw a SQL Exception which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized message

private void
throwSQLWarning(String
msg containing SQL Warning
msg
)

Throw a SQL Warning which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized message

private void
throwUnexpectedException(Exception
An unexpected exception.
e
)

Print a trace for the (unexpected) exception received, then throw a generic exception indicating that 1) an unexpected exception was thrown, and 2) we've already printed the trace (so don't do it again).

public void
trace(boolean
true to turn tracing on, false to turn tracing off
on
)

Turn tracing on or off for all sessions

public void
trace(int
the connNum of the session, 0 if all sessions
connNum
,
boolean
true to turn tracing on, false to turn tracing off
on
)

Turn tracing on or off for one session or all sessions

private void
public void
usage()

Display usage information

private void
wrapSQLError(String
Derby SQL Exception message id
messageKey
)

Wrap SQL Error - display to console and raise exception

private void
wrapSQLWarning(String
Derby SQL Exception message id
messageKey
)

Wrap SQL Warning - display to console and raise exception

private void
writeByte(int
value to be written
value
)

Write byte

private void
writeCommandHeader(int
command to be written
command
)

Write command header consisting of command header string and default protocol version and command.

private void
writeCommandHeader(int
command to be written
command
,
int
protocol version to be used for the given command
protocol_version_for_command
)

Write command header consisting of command header string and passed protocol version and command.

private void
writeCommandReplyHeader(DDMWriter
writer to use
writer
)

Write Command reply

private void
writeLDString(String
string to be written
msg
)

Write length delimited string string

private void
writeShort(int
value to be written
value
)

Write short

protected void
writeString(String
String to write
msg
)

Write string

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait