Class NetworkServerControlImpl
java.lang.Object
org.apache.derby.impl.drda.NetworkServerControlImpl
NetworkServerControlImpl does all the work for NetworkServerControl
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate Hashtable<String, AppRequester> private static Stringprivate static Stringprotected static final Stringprivate static Stringprivate Stringprivate static Stringprivate ByteArrayOutputStreamprotected static final intprotected static final intprivate booleanprivate InputStreamprivate Stringprivate OutputStreamprivate Socketprivate static final Stringprivate static Driverprivate PrintWriterprivate static final int[]private static final Stringstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprivate DataOutputStreamprivate static final String[]private intprivate Sessionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprivate static final intstatic final intstatic final intprivate static final String[]private Stringprivate booleanprotected static final int(package private) static final Charsetprotected static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final intprivate static final intprivate static final intprivate static final Stringprivate static final Stringprivate static final Stringprivate Stringprivate Stringprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate intprivate InetAddressprivate Stringprotected static final intprivate booleanprivate LocalizedResource(package private) ArrayList<InetAddress> List of local addresses for checking admin commands.private booleanprivate Objectprivate PrintWriterprivate static final intprivate intprivate static final intMaximum reply size.private intprivate memCheckprivate static final int[]private static final intprivate static final intprivate intprivate intprivate static final AtomicIntegerHolds the sequence number to be assigned to the next thread that callsgetUniqueThreadName(String).private static final intprivate static final intprivate Stringprivate Objectprivate intprivate static Stringprivate static byte[]private Stringprivate static final Stringprivate static final intprivate byte[]private intprivate intprivate booleanprivate NetworkServerControlImplprivate ServerSocketprivate Objectprivate intprivate booleanprivate static final intprivate static final intprivate static final intprivate booleanprivate Objectprotected static final byteprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate intprivate static booleanCan EUSRIDPWD security mechanism be used with the current JVMprivate NetworkServerControlImplprivate Vector<DRDAConnThread> private Objectprivate intprivate Objectprivate booleanprivate Objectprivate Stringprivate Objectstatic final Stringprivate booleanprivate static final intprivate Stringprivate static Stringprivate static final int -
Constructor Summary
ConstructorsConstructorDescriptionNetworkServerControlImpl(String userName, String password) Internal constructor for NetworkServerControl API.NetworkServerControlImpl(InetAddress address, int portNumber) Internal constructor for NetworkServerControl API.NetworkServerControlImpl(InetAddress address, int portNumber, String userName, String password) Internal constructor for NetworkServerControl API. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddSession(Socket clientSocket) Add a session - for use byClientThread.static StringReturn the att_extnam server attributestatic StringReturn the att_srvclsnm server attributestatic StringReturn the att_srvrlslv server attributevoidblockingStart(PrintWriter consoleWriter) Start a network serverprivate voidbuildLocalAddressList(InetAddress bindAddr) Build local address list to allow admin commands.buildRuntimeInfo(LocalizedResource locallangUtil) private voidcheckAddressIsLocal(InetAddress inetAddr) voidprivate voidStream error writing to client socketprivate voidClose the resources associated with the opened socket.voidconsoleError(String msg) Write an error message to console output stream and throw an exception for this errorvoidWrite an exception to console output stream, but only if debugOutput is true.voidWrite an exception (with trace) to console output stream.voidconsoleMessage(String msg, boolean printTimeStamp) Write a message to console output streamprivate voidconsolePrintAndIgnore(String msgProp, Exception e, boolean printTimeStamp) protected voidconsolePropertyMessage(String msgProp, boolean printTimeStamp) Put property message on consoleprotected voidconsolePropertyMessage(String msgProp, String arg) Put property message on consoleprotected voidconsolePropertyMessage(String msgProp, String[] args) Put property message on consoleprivate voidconsolePropertyMessageWork(String messageKey, String[] args, boolean 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 messageprivate voidconsoleTraceMessage(int connNum, boolean on) Print trace change message to consoleprivate ServerSocketCreate the right kind of server socketbooleanReturn the debug statevoid(package private) voidprivate voidensureDataInBuffer(int minimumBytesNeeded, boolean failOnEOS) Ensure the reply buffer is large enough to hold all the data; don't just rely on OS level defaultsvoidexecuteWork(int command) Execute the command given on the command lineprivate voidFill the reply buffer with the reply allocates a reply buffer if one doesn't existprivate intfindCommand(String[] args) Go through the arguments and find the command and save the dash arguments and arguments to the command.private static ObjectfindService(String factoryInterface, String serviceName) Privileged service lookup.(package private) intprotected AppRequestergetAppRequester(AppRequester appRequester) Get the stored application requester or store if we haven't seen it yet(package private) long(package private) longprivate StringGet Derby information(package private) intGet current propertiesprotected static Driverprivate StringgetEnabledProtocols(SSLServerSocket sslServerSocket) getHost()Get the host where we listen for connections.private intgetIntPropVal(String propName, String propVal) Get integer property valuesprotected booleanGet the current value of keepAlive to configure how long the server should keep the socket alive for a disconnected clientbooleanGet the current value of logging connectionsprotected intgetManagerLevel(int manager) Get the server manager level for a given managerprivate intGet the current value of maximum number of threads to createprivate intgetMessageType(String msg) Determine type of messageprivate intGet the current value of minimum number of threads to create at startprivate ProductVersionHolderRetrieve 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 StringGet Net Server informationprotected SessiongetNextSession(Session currentSession) Get the next session for the thread to work on Called from DRDAConnThread after session completes or timeslice exceeded.intgetPort()Get the port where we listen for connections.private voidInitialize fields from system properties(package private) PropertiesConstructs an object containing network server related properties and their values.(package private) intprivate Stringprivate intRetrieve the SECMEC integer value from the user friendly security mechanism nameprotected intget the security mechanism (secmec value) that the server will accept connections from.protected booleanprotected Objectprotected intprivate StringgetSSLModeString(int i) Get the string value of the SSL-mode.private intGet the SSL-mode from a string.private StringgetStringValueForSecMec(int secmecVal) Retrieve the string name for the integer secmec valueprivate static ObjectgetSystemModule(String factoryInterface) Privileged module lookup.(package private) intprotected intGet the current value of the time sliceprotected booleanGet the current value of whether to trace all the sessionsprotected StringGet the current value of trace directory(package private) static StringgetUniqueThreadName(String base) Get a thread name that is both meaningful and unique (primarily for debugging purposes).private voidinit()protected static booleanIs this the command protocolprivate booleanisMsgProperty(String msg) Determine whether string is a property key or not property keys start with DRDA_MSG_PREFIXprivate booleanIs string "on" or "off"booleanlocalizeMessage(String msgProp, String[] args) Convenience routine so that NetworkServerControl can localize messages.private StringlocalizeMessage(String msgProp, LocalizedResource localLangUtil, String[] args) Localize a message given a particular AppUIvoidlogConnections(boolean on) Turn logging connections on or off.private voidlogConnectionsChange(boolean on) Record a change to the connection logging modeGet the log writer we're usingprivate PrintWritervoidnetSetMaxThreads(int max) Connect to network server and set connection maxthread parametervoidnetSetTimeSlice(int timeslice) Set network server connection timeslice parameterintParse the command-line arguments.voidping()Ping opening an new socket and close it.private voidPing the server using the client socket that is already open.static StringprdId()Return the product idstatic byte[]Return the bytes of the product idprotected voidprocessCommands(DDMReader reader, DDMWriter writer, Session session) processCommands reads and processes NetworkServerControlImpl commands sent to the network server over the socket.private intprocessDashArg(int pos, String[] args) Get the dash argument.private byte[]readBytesReply(String msgKey) Read Bytes replyprivate voidRead the command reply header from the serverprivate intreadInt()Read int from bufferprivate byte[]Read length delimited bytes from a bufferprivate StringRead length delimited string from a bufferprivate voidRead result from sending client message to serverprivate intRead short from bufferprivate StringreadStringReply(String msgKey) Read String replyprotected voidremoveFromSessionTable(int sessionid) Remove session from session tableprivate String[]removeSSLv3andSSLv2Hello(String[] enabledProtocols) (package private) voidremoveThread(DRDAConnThread thread) Remove a thread from the thread list.booleanReturn true if the customer forcibly overrode our decision to install a default SecurityManager.private voidrunQueueAdd(Session clientSession) Add session to the run queueprivate voidsend()Send client message to serverprivate voidsendMessage(DDMWriter writer, int messageType, String message) Send Error or Warning from server to client after processing a commandprivate voidSend OK from server to client after processing a commandprivate voidSend OK and int valueprivate voidsendPropInfo(DDMWriter writer) Send property information from server to clientprivate voidsendRuntimeInfo(DDMWriter writer) Send RuntimeInfo information from server to clientvoidsendSetTraceDirectory(String traceDirectory) private voidsendSQLMessage(DDMWriter writer, SQLException se, int type) Send SQL Exception from server to client after processing a commandprivate voidsendSysInfo(DDMWriter writer) Send SysInfo information from server to clientvoidsetClientLocale(String locale) private voidsetLogConnections(boolean value) Set the current value of logging connectionsvoidsetLogWriter(PrintWriter outWriter) Set the output stream for console messages If this is set to null, no messages will be written to the consoleprivate voidsetMaxThreads(int value) Set the current value of maximum number of threads to createprivate voidsetMinThreads(int value) Set the current value of minimum number of threads to create at startprivate voidSet the security mechanism for derby.drda.securityMechanism If this property is set, server will only allow connections from client with this security mechanism.protected voidsetSSLMode(int mode) private voidsetTimeSlice(int value) Set the current value of time sliceprivate booleansetTrace(boolean on) Set the trace on/off for all sessions, or one session, depending on whether we got -s argument.private voidsetTraceAll(boolean value) Set the current value of whether to trace all the sessionsprivate voidsetTraceDirectory(String value) Set the current value of trace directoryprivate voidSet up client socket to send a command to the network servervoidshutdown()Shutdown a network servervoidstart(PrintWriter consoleWriter) Start a network server.protected voidLoad Derby and save driver for future use.protected booleansupportsCCSID(int ccsid) Check whether a CCSID code page is supported(package private) booleanThis method returns whether EUSRIDPWD security mechanism is supported or not.sysinfo()private voidthrowSQLException(String msg) Throw a SQL Exception which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized messageprivate voidthrowSQLWarning(String msg) Throw a SQL Warning which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized messageprivate voidPrint 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).voidtrace(boolean on) Turn tracing on or off for all sessionsvoidtrace(int connNum, boolean on) Turn tracing on or off for one session or all sessionsprivate voidvoidusage()Display usage informationprivate voidwrapSQLError(String messageKey) Wrap SQL Error - display to console and raise exceptionprivate voidwrapSQLWarning(String messageKey) Wrap SQL Warning - display to console and raise exceptionprivate voidwriteByte(int value) Write byteprivate voidwriteCommandHeader(int command) Write command header consisting of command header string and default protocol version and command.private voidwriteCommandHeader(int command, int protocol_version_for_command) Write command header consisting of command header string and passed protocol version and command.private voidwriteCommandReplyHeader(DDMWriter writer) Write Command replyprivate voidwriteLDString(String msg) Write length delimited string stringprivate voidwriteShort(int value) Write shortprotected voidwriteString(String msg) Write string
-
Field Details
-
NO_USAGE_MSGS
private static final int NO_USAGE_MSGS- See Also:
-
COMMANDS
-
COMMAND_ARGS
private static final int[] COMMAND_ARGS -
COMMAND_START
public static final int COMMAND_START- See Also:
-
COMMAND_SHUTDOWN
public static final int COMMAND_SHUTDOWN- See Also:
-
COMMAND_TRACE
public static final int COMMAND_TRACE- See Also:
-
COMMAND_TRACEDIRECTORY
public static final int COMMAND_TRACEDIRECTORY- See Also:
-
COMMAND_TESTCONNECTION
public static final int COMMAND_TESTCONNECTION- See Also:
-
COMMAND_LOGCONNECTIONS
public static final int COMMAND_LOGCONNECTIONS- See Also:
-
COMMAND_SYSINFO
public static final int COMMAND_SYSINFO- See Also:
-
COMMAND_RUNTIME_INFO
public static final int COMMAND_RUNTIME_INFO- See Also:
-
COMMAND_MAXTHREADS
public static final int COMMAND_MAXTHREADS- See Also:
-
COMMAND_TIMESLICE
public static final int COMMAND_TIMESLICE- See Also:
-
COMMAND_PROPERTIES
public static final int COMMAND_PROPERTIES- See Also:
-
COMMAND_UNKNOWN
public static final int COMMAND_UNKNOWN- See Also:
-
DASHARGS
-
DASHARG_PORT
public static final int DASHARG_PORT- See Also:
-
DASHARG_DATABASE
public static final int DASHARG_DATABASE- See Also:
-
DASHARG_USER
public static final int DASHARG_USER- See Also:
-
DASHARG_PASSWORD
public static final int DASHARG_PASSWORD- See Also:
-
DASHARG_LOADSYSIBM
public static final int DASHARG_LOADSYSIBM- See Also:
-
DASHARG_ENCALG
public static final int DASHARG_ENCALG- See Also:
-
DASHARG_ENCPRV
public static final int DASHARG_ENCPRV- See Also:
-
DASHARG_BOOTPASSWORD
public static final int DASHARG_BOOTPASSWORD- See Also:
-
DASHARG_HOST
public static final int DASHARG_HOST- See Also:
-
DASHARG_SESSION
public static final int DASHARG_SESSION- See Also:
-
DASHARG_UNSECURE
public static final int DASHARG_UNSECURE- See Also:
-
DASHARG_SSL
private static final int DASHARG_SSL- See Also:
-
DEFAULT_PROTOCOL_VERSION
private static final int DEFAULT_PROTOCOL_VERSION- See Also:
-
SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION
private static final int SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION- See Also:
-
MAX_ALLOWED_PROTOCOL_VERSION
private static final int MAX_ALLOWED_PROTOCOL_VERSION- See Also:
-
COMMAND_HEADER
- See Also:
-
REPLY_HEADER
- See Also:
-
REPLY_HEADER_LENGTH
private static final int REPLY_HEADER_LENGTH -
OK
private static final int OK- See Also:
-
WARNING
private static final int WARNING- See Also:
-
ERROR
private static final int ERROR- See Also:
-
SQLERROR
private static final int SQLERROR- See Also:
-
SQLWARNING
private static final int SQLWARNING- See Also:
-
DRDA_PROP_MESSAGES
- See Also:
-
DRDA_PROP_DEBUG
- See Also:
-
CLOUDSCAPE_DRIVER
- See Also:
-
UNEXPECTED_ERR
- See Also:
-
MIN_MAXTHREADS
private static final int MIN_MAXTHREADS- See Also:
-
MIN_TIMESLICE
private static final int MIN_TIMESLICE- See Also:
-
USE_DEFAULT
private static final int USE_DEFAULT- See Also:
-
DEFAULT_MAXTHREADS
private static final int DEFAULT_MAXTHREADS- See Also:
-
DEFAULT_TIMESLICE
private static final int DEFAULT_TIMESLICE- See Also:
-
DEFAULT_HOST
- See Also:
-
DRDA_MSG_PREFIX
- See Also:
-
DEFAULT_LOCALE
- See Also:
-
DEFAULT_LOCALE_COUNTRY
- See Also:
-
SHUTDOWN_CHECK_ATTEMPTS
private static final int SHUTDOWN_CHECK_ATTEMPTS- See Also:
-
SHUTDOWN_CHECK_INTERVAL
private static final int SHUTDOWN_CHECK_INTERVAL- See Also:
-
MAXREPLY
private static final int MAXREPLYMaximum reply size. The reply buffer must be large enough to hold the largest reply thatreadBytesReply(String)andreadStringReply(String)can receive. That is, a reply header (4 bytes), a status byte (1 byte), a length field (2 bytes) and the longest value (in bytes) that could be written byDDMWriter.writeLDBytes(byte[])orDDMWriter.writeLDString(String). -
att_srvclsnm
-
ATT_SRVNAM
- See Also:
-
att_extnam
-
att_srvrlslv
-
prdId
-
prdIdBytes_
private static byte[] prdIdBytes_ -
buildNumber
-
versionString
-
CCSIDSBC
protected static final int CCSIDSBC- See Also:
-
CCSIDMBC
protected static final int CCSIDMBC- See Also:
-
DEFAULT_ENCODING
- See Also:
-
DEFAULT_CHARSET
-
DEFAULT_CCSID
protected static final int DEFAULT_CCSID- See Also:
-
SPACE_CHAR
protected static final byte SPACE_CHAR- See Also:
-
MGR_LEVELS
private static final int[] MGR_LEVELS -
logWriter
-
cloudscapeLogWriter
-
cloudscapeDriver
-
ERRTYPE_SEVERE
private static final int ERRTYPE_SEVERE- See Also:
-
ERRTYPE_USER
private static final int ERRTYPE_USER- See Also:
-
ERRTYPE_INFO
private static final int ERRTYPE_INFO- See Also:
-
ERRTYPE_UNKNOWN
private static final int ERRTYPE_UNKNOWN- See Also:
-
commandArgs
-
databaseArg
-
userArg
-
passwordArg
-
bootPasswordArg
-
encAlgArg
-
encPrvArg
-
hostArg
-
hostAddress
-
sessionArg
private int sessionArg -
unsecureArg
private boolean unsecureArg -
mc
-
replyBuffer
private byte[] replyBuffer -
replyBufferCount
private int replyBufferCount -
replyBufferPos
private int replyBufferPos -
portNumber
private int portNumber -
traceDirectory
-
traceDirectorySync
-
traceAll
private boolean traceAll -
traceAllSync
-
serverStartSync
-
logConnections
private boolean logConnections -
logConnectionsSync
-
minThreads
private int minThreads -
maxThreads
private int maxThreads -
threadsSync
-
timeSlice
private int timeSlice -
timeSliceSync
-
keepAlive
private boolean keepAlive -
minPoolSize
private int minPoolSize -
maxPoolSize
private int maxPoolSize -
poolSync
-
debugOutput
private boolean debugOutput -
cleanupOnStart
private boolean cleanupOnStart -
restartFlag
private boolean restartFlag -
INVALID_OR_NOTSET_SECURITYMECHANISM
protected static final int INVALID_OR_NOTSET_SECURITYMECHANISM- See Also:
-
allowOnlySecurityMechanism
private int allowOnlySecurityMechanism -
clientSocket
-
clientIs
-
clientOs
-
byteArrayOs
-
commandOs
-
shutdownSync
-
shutdown
private boolean shutdown -
connNum
private int connNum -
serverSocket
-
serverInstance
-
langUtil
-
clientLocale
-
localAddresses
ArrayList<InetAddress> localAddressesList of local addresses for checking admin commands. -
sessionTable
-
currentSession
-
threadList
-
runQueue
-
freeThreads
private int freeThreads -
appRequesterTable
-
propertyFileName
-
thisControl
-
shutdownDatabasesOnShutdown
private boolean shutdownDatabasesOnShutdown -
SSL_OFF
private static final int SSL_OFF- See Also:
-
SSL_BASIC
private static final int SSL_BASIC- See Also:
-
SSL_PEER_AUTHENTICATION
private static final int SSL_PEER_AUTHENTICATION- See Also:
-
sslMode
private int sslMode -
SUPPORTS_EUSRIDPWD
private static boolean SUPPORTS_EUSRIDPWDCan EUSRIDPWD security mechanism be used with the current JVM -
nextThreadNumber
Holds the sequence number to be assigned to the next thread that callsgetUniqueThreadName(String).
-
-
Constructor Details
-
NetworkServerControlImpl
-
NetworkServerControlImpl
Internal constructor for NetworkServerControl API.- Parameters:
address- InetAddress to listen on, throws NPE if nullportNumber- portNumber to listen on, -1 use property or default- Throws:
Exception- on error- See Also:
-
NetworkServerControlImpl
Internal constructor for NetworkServerControl API.- Parameters:
userName- the user name for actions requiring authorizationpassword- the password for actions requiring authorization- Throws:
Exception- on error- See Also:
-
NetworkServerControlImpl
public NetworkServerControlImpl(InetAddress address, int portNumber, String userName, String password) throws Exception Internal constructor for NetworkServerControl API.- Parameters:
address- InetAddress to listen on, throws NPE if nullportNumber- portNumber to listen on, -1 use property or defaultuserName- the user name for actions requiring authorizationpassword- the password for actions requiring authorization- Throws:
Exception- on error- See Also:
-
-
Method Details
-
logWriter
Get the log writer we're using -
getHost
Get the host where we listen for connections. -
getPort
public int getPort()Get the port where we listen for connections.- Returns:
- the port number
-
runningUnsecure
public boolean runningUnsecure()Return true if the customer forcibly overrode our decision to install a default SecurityManager. -
init
-
makePrintWriter
-
getDriver
-
setLogWriter
Set the output stream for console messages If this is set to null, no messages will be written to the console- Parameters:
outWriter- output stream for console messages
-
consoleError
-
debugOutput
public boolean debugOutput()Return the debug state -
att_extnam
Return the att_extnam server attribute -
att_srvclsnm
Return the att_srvclsnm server attribute -
att_srvrlslv
Return the att_srvrlslv server attribute -
prdId
Return the product id -
prdIdBytes
public static byte[] prdIdBytes()Return the bytes of the product id -
consoleExceptionPrint
Write an exception to console output stream, but only if debugOutput is true.- Parameters:
e- exception
-
consoleExceptionPrintTrace
Write an exception (with trace) to console output stream.- Parameters:
e- exception
-
consoleMessage
Write a message to console output stream- Parameters:
msg- messageprintTimeStamp- Whether to prepend a timestamp to the message or not
-
start
Start a network server. Launches a separate thread with DRDAServerStarter. Want to use Monitor.startModule, so it can all get shutdown when Derby shuts down, but can't get it working right now.- Parameters:
consoleWriter- PrintWriter to which server console will be output. Null will disable console output.- Throws:
Exception- throws an exception if an error occurs
-
createServerSocket
Create the right kind of server socket- Throws:
IOException
-
getEnabledProtocols
-
blockingStart
Start a network server- Parameters:
consoleWriter- PrintWriter to which server console will be output. Null will disable console output.- Throws:
Exception- throws an exception if an error occurs
-
consolePrintAndIgnore
-
startNetworkServer
-
shutdown
-
checkShutdownPrivileges
- Throws:
SQLException- if authentication or privileges check fails
-
directShutdown
- Throws:
SQLException
-
directShutdownInternal
void directShutdownInternal() -
isServerStarted
-
ping
-
pingWithNoOpen
-
trace
-
trace
-
consoleTraceMessage
-
logConnections
-
sendSetTraceDirectory
-
sysinfo
-
runtimeInfo
-
usage
public void usage()Display usage information -
netSetMaxThreads
Connect to network server and set connection maxthread parameter- Parameters:
max- maximum number of connections, if 0, connections created when no free connection available if -1, use default- Throws:
Exception- throws an exception if an error occurs
-
netSetTimeSlice
Set network server connection timeslice parameter- Parameters:
timeslice- amount of time given to each session before yielding to another session, if 0, never yield. if -1, use default.- Throws:
Exception- throws an exception if an error occurs
-
getCurrentProperties
Get current properties- Returns:
- Properties object containing properties
- Throws:
Exception- throws an exception if an error occurs
-
getUniqueThreadName
Get a thread name that is both meaningful and unique (primarily for debugging purposes).- Parameters:
base- the first part of the thread name (the meaningful part)- Returns:
- a unique thread name that starts with
baseand is followed by an underscore and a unique sequence number
-
removeFromSessionTable
protected void removeFromSessionTable(int sessionid) Remove session from session table- Parameters:
sessionid- id of session to be removed
-
processCommands
protected void processCommands(DDMReader reader, DDMWriter writer, Session session) throws Throwable processCommands reads and processes NetworkServerControlImpl commands sent to the network server over the socket. The protocol used is 4 bytes - String CMD: 2 bytes - Protocol version 1 byte - length of locale (0 for default) n bytes - locale 1 byte - length of codeset (0 for default) n bytes - codeset 1 byte - command n bytes - parameters for the command The server returns 4 bytes - String RPY: for most commands 1 byte - command result, 0 - OK, 1 - warning, 2 - error if warning or error 1 bytes - length of message key n bytes - message key 1 byte - number of parameters to message {2 bytes - length of parameter n bytes - parameter} for each parameter for sysinfo 1 byte - command result, 0 - OK, 1 - warning, 2 - error if OK 2 bytes - length of sysinfo n bytes - sysinfo Note, the 3rd byte of the command must not be 'D0' to distinquish it from DSS structures. The protocol for the parameters for each command follows: Command: trace{on | off} Protocol: 4 bytes - connection id - connection id of 0 means all sessions 1 byte - 0 off, 1 on Command: logConnections {on | off} Protocol: 1 byte - 0 off, 1 on Command: shutdown // DERBY-2109: transmit user credentials for System Privileges check 2 bytes - length of user name n bytes - user name 2 bytes - length of password n bytes - password Command: sysinfo No parameters Command: dbstart Protocol: 2 bytes - length of database name n bytes - database name 2 bytes - length of boot password n bytes - boot password 2 bytes - length of encryption algorithm n bytes - encryption algorithm 2 bytes - length of encryption provider n bytes - encryption provider 2 bytes - length of user name n bytes - user name 2 bytes - length of password n bytes - password Command: dbshutdown Protocol: 2 bytes - length of database name n bytes - database name 2 bytes - length of user name n bytes - user name 2 bytes - length of password n bytes - password Command: connpool Protocol: 2 bytes - length of database name, if 0, default for all databases is set n bytes - database name 2 bytes - minimum number of connections, if 0, connection pool not used if value is -1 use default 2 bytes - maximum number of connections, if 0, connections are created as needed, if value is -1 use default Command: maxthreads Protocol: 2 bytes - maximum number of threads Command: timeslice Protocol: 4 bytes - timeslice value Command: tracedirectory Protocol: 2 bytes - length of directory name n bytes - directory name Command: test connection Protocol: 2 bytes - length of database name if 0, just the connection to the network server is tested and user name and password aren't sent n bytes - database name 2 bytes - length of user name (optional) n bytes - user name 2 bytes - length of password (optional) n bytes - password The calling routine is synchronized so that multiple threads don't clobber each other. This means that configuration commands will be serialized. This shouldn't be a problem since they should be fairly rare. - Parameters:
reader- input reader for commandwriter- output writer for commandsession- session information- Throws:
Throwable- throws an exception if an error occurs
-
logConnectionsChange
-
getNextSession
Get the next session for the thread to work on Called from DRDAConnThread after session completes or timeslice exceeded. If there is a waiting session, pick it up and put currentSession at the back of the queue if there is one.- Parameters:
currentSession- session thread is currently working on- Returns:
- next session to work on, could be same as current session
-
getAppRequester
Get the stored application requester or store if we haven't seen it yet- Parameters:
appRequester- Application Requester to look for- Returns:
- stored application requester
-
getManagerLevel
protected int getManagerLevel(int manager) Get the server manager level for a given manager- Parameters:
manager- codepoint for manager- Returns:
- manager level
-
supportsCCSID
protected boolean supportsCCSID(int ccsid) Check whether a CCSID code page is supported- Parameters:
ccsid- CCSID to check- Returns:
- true if supported; false otherwise
-
consolePropertyMessage
-
consolePropertyMessage
-
consolePropertyMessage
-
isCmd
-
writeCommandReplyHeader
-
sendOK
-
sendOKInt
-
sendMessage
Send Error or Warning from server to client after processing a command- Parameters:
writer- writer to use for sending messagemessageType- 1 for Warning, 2 for Error 3 for SQLErrormessage- message- Throws:
Exception- if a problem occurs sending message
-
sendSQLMessage
Send SQL Exception from server to client after processing a command- Parameters:
writer- writer to use for sending messagese- Derby exceptiontype- type of exception, SQLERROR or SQLWARNING- Throws:
Exception- if a problem occurs sending message
-
sendSysInfo
-
sendRuntimeInfo
-
sendPropInfo
-
getNetSysInfo
Get Net Server information- Returns:
- system information for the Network Server
-
getRuntimeInfo
- See Also:
-
getCLSSysInfo
Get Derby information- Returns:
- system information for Derby
- Throws:
IOException- if a problem occurs encoding string
-
parseArgs
Parse the command-line arguments. As a side-effect, fills in various instance fields. This method was carved out of executeWork() so that NetworkServerControl can figure out whether to install a security manager before the server actually comes up. This is part of the work for DERBY-2196.- Parameters:
args- array of arguments indicating command to be executed- Returns:
- the command to be executed
- Throws:
Exception
-
executeWork
Execute the command given on the command line- Parameters:
command- The command to execute. The command itself was determined by an earlier call to parseArgs().- Throws:
Exception- throws an exception if an error occurs see class comments for more information
-
runQueueAdd
Add session to the run queue- Parameters:
clientSession- session needing work
-
findCommand
-
processDashArg
-
isOn
-
closeSocket
Close the resources associated with the opened socket.- Throws:
IOException
-
setUpSocket
-
removeSSLv3andSSLv2Hello
-
checkAddressIsLocal
- Throws:
UnknownHostExceptionException
-
buildLocalAddressList
Build local address list to allow admin commands.- Parameters:
bindAddr- 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.
-
unknownHostException
-
writeCommandHeader
Write command header consisting of command header string and default protocol version and command. At this point, all the commands except shutdown with username/passwrod use default protocol version.- Parameters:
command- command to be written- Throws:
Exception- throws an exception if an error occurs
-
writeCommandHeader
Write command header consisting of command header string and passed protocol version and command. At this point, all the commands except shutdown with username/passwrod use default protocol version.- Parameters:
command- command to be writtenprotocol_version_for_command- protocol version to be used for the given command- Throws:
Exception- throws an exception if an error occurs
-
writeLDString
-
writeString
-
writeShort
-
writeByte
-
send
-
clientSocketError
Stream error writing to client socket- Throws:
IOException
-
readResult
-
ensureDataInBuffer
Ensure the reply buffer is large enough to hold all the data; don't just rely on OS level defaults- Parameters:
minimumBytesNeeded- size of buffer requiredfailOnEOS- tells whether or not an error should be raised if end-of-stream is reached before the requested amount of bytes could be read- Throws:
Exception- throws an exception if a problem reading the reply
-
fillReplyBuffer
-
readCommandReplyHeader
-
readShort
-
readInt
-
readStringReply
-
readLDString
-
readBytesReply
-
readLDBytes
-
getPropertyInfo
-
getSecMecValue
Retrieve the SECMEC integer value from the user friendly security mechanism name- Parameters:
s- security mechanism name- 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
-
getStringValueForSecMec
Retrieve the string name for the integer secmec value- Parameters:
secmecVal- secmec value- Returns:
- String - return the string name corresponding to the secmec value if recognized else returns null
-
supportsEUSRIDPWD
boolean supportsEUSRIDPWD()This method returns whether EUSRIDPWD security mechanism is supported or not. See class static block for more info.- Returns:
- true if EUSRIDPWD is supported, false otherwise
-
getSSLModeValue
Get the SSL-mode from a string.- Parameters:
s- the SSL-mode string ("off"/"false", "on"/"true" or "authenticate"/"auth"- 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.
- Throws:
Exception
-
getSSLModeString
Get the string value of the SSL-mode. This is the inverse of getSSLModeValue.- Parameters:
i- The SSL-mode value (SSL_OFF, SSL_BASIC or SSL_PEER_AUTHENTICATION)- Returns:
- The string representation ("off","on" or "autneticate"). Will default to SSL_OFF for other values than those listed above.
-
getIntPropVal
-
consolePropertyMessageWork
private void consolePropertyMessageWork(String messageKey, String[] args, boolean printTimeStamp) throws Exception 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- Parameters:
messageKey- message keyargs- arguments to messageprintTimeStamp- whether to prepend a timestamp to the message- Throws:
Exception- if an error occurs
-
throwSQLException
Throw a SQL Exception which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized message- Parameters:
msg- msg containing SQL Exception- Throws:
SQLException
-
throwSQLWarning
Throw a SQL Warning which was sent over by a server Format of the msg is SQLSTATE:localized message\nSQLSTATE:next localized message- Parameters:
msg- msg containing SQL Warning- Throws:
SQLWarning
-
throwUnexpectedException
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).- Parameters:
e- An unexpected exception.- Throws:
Exception- with message UNEXPECTED_ERR.
-
localizeMessage
-
localizeMessage
Localize a message given a particular AppUI- Parameters:
msgProp- message keylocalLangUtil- LocalizedResource to use to localize messageargs- arguments to message
-
getMessageType
Determine type of message- Parameters:
msg- message- Returns:
- message type
-
isMsgProperty
Determine whether string is a property key or not property keys start with DRDA_MSG_PREFIX- Parameters:
msg- message- Returns:
- true if it is a property key; false otherwise
-
getLogConnections
public boolean getLogConnections()Get the current value of logging connections- Returns:
- true if logging connections is on; false otherwise
-
setLogConnections
private void setLogConnections(boolean value) Set the current value of logging connections- Parameters:
value- true to turn logging connections on; false to turn it off
-
setSecurityMechanism
Set the security mechanism for derby.drda.securityMechanism If this property is set, server will only allow connections from client with this security mechanism. This method will map the user friendly string representing the security mechanism to the corresponding drda secmec value- Parameters:
s- security mechanism string value- Throws:
Exception- if value to set is invalid- See Also:
-
getSecurityMechanism
protected int getSecurityMechanism()get the security mechanism (secmec value) that the server will accept connections from.- 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
- See Also:
-
setTrace
private boolean setTrace(boolean on) Set the trace on/off for all sessions, or one session, depending on whether we got -s argument.- Parameters:
on- true to turn trace on; false to turn it off- Returns:
- true if set false if an error occurred
-
getTimeSlice
protected int getTimeSlice()Get the current value of the time slice- Returns:
- time slice value
-
setTimeSlice
-
getKeepAlive
protected boolean getKeepAlive()Get the current value of keepAlive to configure how long the server should keep the socket alive for a disconnected client -
getMinThreads
private int getMinThreads()Get the current value of minimum number of threads to create at start- Returns:
- value of minimum number of threads
-
setMinThreads
private void setMinThreads(int value) Set the current value of minimum number of threads to create at start- Parameters:
value- value of minimum number of threads
-
getMaxThreads
private int getMaxThreads()Get the current value of maximum number of threads to create- Returns:
- value of maximum number of threads
-
setMaxThreads
-
setSSLMode
protected void setSSLMode(int mode) -
getSSLMode
protected int getSSLMode() -
getTraceAll
protected boolean getTraceAll()Get the current value of whether to trace all the sessions- Returns:
- true if tracing is on for all sessions; false otherwise
-
setTraceAll
private void setTraceAll(boolean value) Set the current value of whether to trace all the sessions- Parameters:
value- true if tracing is on for all sessions; false otherwise
-
getTraceDirectory
Get the current value of trace directory- Returns:
- trace directory
-
setTraceDirectory
Set the current value of trace directory- Parameters:
value- trace directory
-
wrapSQLError
-
wrapSQLWarning
-
getPropertyValues
Properties getPropertyValues()Constructs an object containing network server related properties and their values. Some properties are only included if set. Some other properties are included with a default value if not set.
This method is accessing the local JVM in which the network server instance is actually running (i.e. no networking).
This method is package private to allow access from relevant MBean implementations in the same package.
- Returns:
- a collection of network server properties and their current values
-
addSession
Add a session - for use byClientThread. Put the session into the session table and the run queue. Start a newDRDAConnThreadif there are more sessions waiting than there are free threads, and the maximum number of threads is not exceeded.addSession()should only be called from one thread at a time.- Parameters:
clientSocket- the socket to read from and write to- Throws:
Exception
-
removeThread
Remove a thread from the thread list. Should be called when aDRDAConnThreadhas been closed.- Parameters:
thread- the closed thread
-
getShutdownSync
-
getShutdown
protected boolean getShutdown() -
buildRuntimeInfo
-
getBytesRead
long getBytesRead() -
getBytesWritten
long getBytesWritten() -
getActiveSessions
int getActiveSessions() -
getRunQueueSize
int getRunQueueSize() -
getThreadListSize
int getThreadListSize() -
getConnectionNumber
int getConnectionNumber() -
setClientLocale
-
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.- Throws:
Exception
-
getSystemModule
-
findService
-