15-2 Programming JMS for Oracle WebLogic Server
15.2 System Requirements
The following section provides information on the system requirements needed to use the WebLogic JMS C API in your environment:
■
A list of supported operating systems for the WebLogic JMS C API is available from the Oracle Fusion Middleware Supported System Configurations page at
http:www.oracle.comtechnologysoftwareproductsiasfiles fusion_certification.html
.
■
A supported JVM for your operating system.
■
An ANSI C compiler for your operating system.
■
Use one of the following WebLogic clients to connect your C client applications to your JMS applications:
– The WebLogic Thin T3 Client jar wlthint3client.jar. See Developing a
WebLogic Thin T3 Client in Programming Stand-alone Clients for Oracle WebLogic Server.
– The WebLogic application client wlfullclient.jar file. See Using the
WebLogic JarBuilder Tool in Programming Stand-alone Clients for Oracle WebLogic Server.
– The WebLogic JMS thin client wljmsclient.jar file. See the WebLogic
JMS Thin Client in Programming Stand-alone Clients for Oracle WebLogic Server.
15.3 Design Principles
The following sections discuss guiding principals for porting or developing applications for the WebLogic JMS C API:
■
Section 15.3.1, Java Objects Map to Handles
■
Section 15.3.2, Thread Utilization
■
Section 15.3.3, Exception Handling
■
Section 15.3.4, Type Conversions
■
Section 15.3.5, Memory Allocation and Garbage Collection
■
Section 15.3.6, Closing Connections
■
Section 15.3.7, Helper Functions
15.3.1 Java Objects Map to Handles
The WebLogic JMS C API is handle-based to promote modular code implementation. This means that in your application, you implement Java objects as handles in C code.
The details of how a JMS object is implemented is hidden inside a handle. However, unlike in Java, when you are done with a handle, you must explicitly free it by calling
the corresponding Close or Destroy methods. See
Section 15.3.5, Memory Allocation and Garbage Collection.
15.3.2 Thread Utilization
The handles returned from the WebLogic JMS C API are as thread safe as their Java counterparts. For example:
■
javax.jms.Session objects are not thread safe, and the corresponding WebLogic JMS C API handle, JmsSession, is not thread safe.
WebLogic JMS C API 15-3
■
java.jms.Connection objects are thread safe, and the corresponding WebLogic JMS C API handle, JmsConnection, is thread safe.
As long as concurrency control is managed by the C client application, all objects returned by the WebLogic JMS C API may be used in any thread.
15.3.3 Exception Handling
Exceptions in the WebLogic JMS C API are local to a thread of execution. The WebLogic JMS C API has the following exception types:
■
JavaThrowable represents the class java.lang.Throwable.
■
JavaException represents the class java.lang.Exception.
■
JmsException represents the class javax.jms.JMSException. All standard subclasses of JMSException are determined by bits in the type descriptor of the
exception. The type descriptor is returned with a call to JmsGetLastException.
15.3.4 Type Conversions
When you interoperate between Java code and C code, typically one of the main tasks is converting a C type to a Java type. For example, a short type is a two-byte entity in
Java as well as in C. The following type conversions that require special handling:
15.3.4.1 Integer int
Integer int converts to JMS32I 4-byte signed value.
15.3.4.2 Long long
Long long converts to JMS64I 8-byte signed value.
15.3.4.3 Character char
Character char converts to short 2-byte java character.
15.3.4.4 String
String converts to JmsString. Java strings are arrays of two-byte characters. In C, strings are generally arrays of
one-byte UTF-8 encoded characters. Pure ASCII strings fit into the UTF-8 specification as well. For more information on UTF-8 string, see
http:www.unicode.org . It is
inconvenient for C programmers to translate all strings into the two-byte Java encoding. The JmsString structure allows C clients to use native strings or Java
strings, depending on the requirements of the application.
JmsString supports two kinds of string:
■
Native C string CSTRING
■
JavaString UNISTRING A union of the UNISTRING and CSTRING called uniOrC has a character pointer called
string that can be used for a NULL terminated UTF-8 encoded C string. The uniOrC union provides a structure called uniString, which contains a void pointer for the
string data and an integer length bytes.
Note: The WebLogic JMS C API uses integer return codes.
15-4 Programming JMS for Oracle WebLogic Server
When the stringType element of JmsString is used as input, you should set it to CSTRING or UNISTRING, depending on the type of string input. The corresponding
data field contains the string used as input.
The UNISTRING encoding encodes every two bytes as a single Java character. The two-byte sequence is big-endian. Unicode calls this encoding UTF-16BE as opposed to
UTF-16LE, which is a two-byte sequence that is little-endian. The CSTRING encoding expects a UTF-8 encoded string.
When the stringType element of JmsString is used as output, the caller has the option to let the API allocate enough space for output using malloc, or you can
supply the space and have the system copy the returned string into the provided bytes. If the appropriate field in the union either string or data is NULL, then the API
allocates enough space for the output using malloc. It is the callers responsibility to free this allocated space using free when the memory is no longer in use. If the
appropriate field in the union string or data is not NULL, then the allocatedSize field of JmsString must contain the number of bytes available to be written.
If there is not enough space in the string to contain the entire output, then allocatedSize sets to the amount of space needed and the API called returns JMS_
NEED_SPACE. The appropriate field in the JmsString either string or data contains as much data as could be stored up to the allocatedSize bytes. In this case, the
NULL character may or may not have been written at the end of the C string data returned. Example:
To allocate one hundred bytes for the string output from a text message, you would set the data pointer and the allocatedSize field to one hundred. The
JmsMessageGetTextMessage API returns JMS_NEED_SPACE with allocatedSize set to two hundred. Call realloc on the original string to reset the
data pointer and call the function again. Now the call succeeds and you are able to extract the string from the message handle. Alternatively, you can free the original
buffer and allocate a new buffer of the correct size.
15.3.5 Memory Allocation and Garbage Collection
All resources that you allocate must also be disposed of it properly. In Java, garbage collection cleans up all objects that are no longer referenced. However, in C, all objects
must be explicitly cleaned up. All WebLogic JMS C API handles given to the user must be explicitly destroyed. Notice that some handles have a verb that ends in Close
while others end in Destroy. This convention distinguishes between Java objects that have a close method and those that do not. Example:
■
The javax.jms.Session object has a close method so the WebLogic JMS C API has a JmsSessionClose function.
■
The javax.jms.ConnectionFactory object does not have a close method so the WebLogic JMS C API has a JmsConnectionFactoryDestroy function.
15.3.6 Closing Connections