org.apache.derby.impl.drda

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.drda 
org.apache.derby.impl.drda

Network Server Implementation

Network Server accepts connections from DRDA clients, translates incoming DRDA Requests into embedded JDBC calls and then translates results back into DRDA for return to the client. Below is a summary of the implementation.

Classes Summary

NetworkServerControlImpl - This class implements methods used by the public API and main. It's functions include:

    • Launching a ConnectionThread to accept incomming connections.

    • Manaintaining a list of sessions, a queue of Sessions waiting for free thread and free list of DRDAConnections which are available for reuse.

    • Handling non-DRDA proprietary protocol requests (e.g. turning tracing on/off)



ClientThread - A single instance of this thread is launced to accept connections. It is responsible for

    • accepting connections

    • creating a new Sessions and adding them to the session table.

    • Starting a DRDAConnThread (either one from the free list or a new one) or putting the sessions waiting for a thread if maxThreads is exceeded.

ApplicationRequester - this contains information about a particular application requester(e.g, type, version, level of protocol it supports).

Session - this contains information about the client session, (e.g., client socket, AppRequester , current state, etc). It refers to a Database object which contains information about the database connection.

Database - this contains info about the database connection, prepared statements etc. It contains a hash table of DRDAStatements that are keyed by the package name and section number for the statement. Prepared statements are identified in the DRDA protocol by a package and section number.

DRDAStatement - This contains the Statement and all of its DRDA related information as well as the statement's DRDAResultSets which contain result set information. DRDA type information for the parameter metadata is also contained in this class. (It would be good to break it out). For JCC each statement has its isolation level encoded in the package name, and the isolation level is asssociated with the statement instead of the the connection. The isoloation level for the statement will be set accordingly if the client is JCC. DerbyClient sets the isololation on the connection per the JDBC spec and does not use the statement isolation level.

DRDAResultSet - Contains the result set and related metadata and DRDA type information. There is a package name and section number associated with the ResultSet as well. If a statement has only a single ResultSet the package and section number is the same as the statement. Additional ResultSets (created by stored procedures) are assigned a different section number by the server.

DRDAConnThread - This is the main workhorse for the DRDA connections. It sets up the input streams, creates instances of the DDMReader and DDMWriter classes and processes DRDA commands. Most of the DRDA protocol is in this class.

DDMReader - This class contains the utility methods for reading the incoming DRDA protocol and command protocol.

DDMWriter - This class contains the utility methods for writing the outgoing DRDA protocol and command protocol.

DRDAProtocolException - This class handles DRDA protocol errors.

EXTDTAInputStream - An input stream for externalized data (large object).

CcsidManager - This is an abstract class for performing character conversions.

EbcdicCcsidManager- This class converts from EBCDIC to Java Unicode. The DDM parameters are transmitted in EBCDIC and need to be converted to Java Unicode.

CodePoint- static values for DDM Codepoints. These are predefined values used in the DRDA protocol.

CodePointNameTable - hash table with codepoint names, used to produce tracing information.

DssTrace - provides server side tracing for the DRDA protocol.

FdocaConstants -FDOCA (Formatted Data Object Content Architecture) describes the layout and data types of the data being transmitted between the requester and server. This class defines statics for the constant values.

SQLTypes - DRDA describes SQL Types for the data types being transmitted. This class defines statics for the constant values.

EncryptionManager- routines for decrypting userid and password to handle encrypted userid and password security. This requires IBM JCE

SignedBinary - this is a conversion class that translates the incoming values from the client into the correct byte order. The DRDA protocol requires that the receiver of data translates the data into it's format (i.e., the writer writes data in its own format). Data has to be converted from the writer format to the local format.

Scheduling

The scheduling algorithm used is first in first out. When a client session connects to the server, the server checks to see if there are any DRDAConnThreads which are free to handle the session. If there are, it notifies the thread. If there are no available threads and we haven't reached the maximum number of connection threads we can have, the server creates a new thread with the session information. If we have already reached the maximum number of connection threads, the server places the session on a run queue for the next available thread.

How long a thread works on a particular session depends on the value of the timeslice. If timeslice is 0, the thread works on the session until the session ends. If the timeslice is greater than 0, the thread checks the amount of time it has spent on the session after each complete communication once the session has been initiated. A complete communication consists of a packet from the client and the return from the server. For example, for an execute immediate of a create table command, the packet from the client would include the create table command and a commit. The return from the server would be information about the result of the command. For a cursor, each fetch would represent a separate communication.

A timeout of the timeslice is set on the client socket so that the connection thread won't be blocked for more than the timeslice by an idle client.

Coordinating information between Server and Connection Threads

Several commands change information needed by the connection threads. For example, timeslice can be changed. This is handled by keeping a copy of the value in the connection thread. If the value is changed, the command changing the value is responsible for changing the value in the thread's copy. The result of this is that instead of one synchronization point in the server which all threads will block on to read, each thread has a copy which it can separately sync on.

Command Protocol

The command protocol is used to send commands such as shutdown, turn tracing on, etc. to a running network server. The client sends:

4 bytes - String CMD:

2 bytes - Protocol version

1 byte - command

n bytes - parameters for the command

The server returns:

1 byte - command result, 0 - OK, 1 - error

1 byte - number of messages

2 bytes - length of message (or message key)

n bytes - message or message key

1 byte - number of parameters to message

{2 bytes - length of parameter

n bytes - parameter} for each parameter

Note, the 3rd byte of the command header must not be 'D0' to distinquish it from DRDA DSS structures.

The protocol for the parameters for each command is in the javadoc for NetworkServerControlImpl.

The processing 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.



DRDA Protocol

The DRDA protocol is described at great length in the DRDA Reference manuals. DRDA Protocol is divided into three layers corresponding to the DDM three-tier architecture. For each layer, their is a DSS (Data Stream Structure) defined.

Layer A Communications management services

Layer B Agent services

Layer C Data management services

At layer A are request, reply and data correlation, structure chaining, continuation or termination of chains when errors are detected, interleaving and multi-leaving request, reply, and data DSSs for multitasking environments. For TCP/IP, the format of the DDM envelope is

2 bytes Length of the data

1 byte 'D0' - indicates DDM data

1 byte DDM format byte(DSSFMT) - type of DSS(RQSDSS,RPYDSS), whether it is chained, information about the next chained DSS

2 bytes request correlation identifier

The correlation identifier ties together a request, the request data and the reply. In a chained DSS, each request has a correlation identifier which is higher than the previous request (all correlation identifiers must be greater than 0).

At layer B are object mapping, object validation and command routing. Layer B objects with data 5 bytes less than 32K bytes consist of

2 bytes Length

2 bytes Type of the object (code point)

Object data

Object data is either SCALAR or COLLECTION data.

Scalar data consists of a string of bytes formatted as the class description of the object required. Collections consist of a set of objects in which the entries in the collection are nested within the length/ code point of the collection.

Layer B objects with data >=32763 bytes long format is

2 bytes Length - length of class, length, and extended total length fields (high order bit set, indicating >=32763)

2 bytes Type of the object (code point)

n bytes Extended total length - length of the object (n = Length – 4)

Object data

Some of the objects in the collections are required and some are optional. To handle this, a required array is created for each command with optional objects with the required codepoints and each element is zeroed as the required objects are found. A check is done to see if there are any required objects missing and an error message is produced indicating the missing codepoints if some have not been sent.

Packages

In DRDA, dynamic SQL is bound to predefined packages. Since Derby doesn't support packages, PACKAGE messages will be handled entirely in the network server.The network server will just validate the protocol and "pretend" to execute the bind command.

*This document was based in large part on a design document written by Judy Peachey when Network Server was first implemented.

Java Source File NameTypeComment
AppRequester.javaClass AppRequester stores information about the application requester.
CcsidManager.javaClass
CharacterEncodings.javaClass
ClientThread.javaClass
CodePoint.javaClass
CodePointNameTable.javaClass This class has a hashtable of CodePoint values.
ConsistencyToken.javaClass Class which represents an RDB Package Consistency Token.
Database.javaClass
DDMReader.javaClass The DDMReader is used to read DRDA protocol.
DDMWriter.javaClass The DDMWriter is used to write DRDA protocol.
DecryptionManager.javaClass This class is used to decrypt password and/or userid. It uses Diffie_Hellman algorithm to get the publick key and secret key, and then DES encryption is done using certain token (based on security mechanism) and this side's own public key.
DRDAConnThread.javaClass
DRDAProtocolException.javaClass
DRDAProtocolExceptionInfo.javaClass
DRDAResultSet.javaClass
DRDAStatement.javaClass
DRDAString.javaClass This class provides functionality for reusing buffers and strings when parsing DRDA packets.
DRDAXAProtocol.javaClass
DRDAXid.javaClass
DssConstants.javaClass This class defines DSS constants that are shared in the classes implementing the DRDA protocol.
DssTrace.javaClass
EbcdicCcsidManager.javaClass A concrete implementation of a CcsidMgr used to convert between Java UCS2 and Ebcdic as needed to handle character DDM Parameters.
EXTDTAInputStream.javaClass
author:
   marsden
author:
   EXTDTAObjectHolder provides Externalized Large Object representation that
author:
   does not hold locks until the end of the transaction (DERBY-255)
author:
   It serves as a holder for lob data and is only valid as long as the original
author:
   result set from which it came is on the same row.
EXTDTAReaderInputStream.javaClass Implementation of InputStream which get EXTDTA from the DDMReader.
FdocaConstants.javaClass
memCheck.javaClass
NetworkServerControlImpl.javaClass
Pkgnamcsn.javaClass Class representing a PKGNAMCSN object (RDB Package Name, Consistency Token, and Section Number).
ReEncodedInputStream.javaClass ReEncodedInputStream passes stream from Reader, which is stream of decoded style, to user of this subclass of InputStream, which is stream of encoded style.
Session.javaClass Session stores information about the current session It is used so that a DRDAConnThread can work on any session.
SignedBinary.javaClass Converters from signed binary bytes to Java short, int, or long.
SQLTypes.javaClass
TestFile.javaClass
TestProto.javaClass This class is used to test error conditions in the protocol.
XADatabase.javaClass
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.