Codemesh Runtime v3 C++ API Reference
3.9.205
|
Classes | |
class | xmog_jvm_options |
A class abstracting the maintenance and initialization of JVM configuration options. More... | |
class | xmog_options |
This class wraps around options that govern the overall behavior of the runtime library with respect to logging, tracing, errorhandling, etc. More... | |
class | xmog_remote_client_options |
A class that represents the settings that a remote client uses to connect to a shared JVM. More... | |
class | xmog_jvm_loader |
The class that acts as a factory for xmog_jvm_loaders and thereby for our JVM abstraction. More... | |
Typedefs | |
typedef void(XMOG_CALLING_CONVENTION * | xmog_jvm_loader::XMOG_CONFIG_HOOK) (void *pLoader, int when) |
A typedef for registration hooks. More... | |
Enumerations | |
enum | xmog_jvm_verbosity { VerbosityUndefined = -1, VerbosityNone = 0, VerbosityClass =1, VerbosityGC =2, VerbosityJNI =4, VerbosityAll =7 } |
Verbosity levels for the JVM. More... | |
enum | xmog_bytecode_verification { VerifyUndefined = -1, VerifyNone = 0, VerifyRemote = 1, VerifyAll = 2 } |
Bytecode verification levels for JDK 1.1. More... | |
When you're using Java from a different programming language, you need to configure the Java runtime options as well as the framework options. Java options include such items as the classpath and are configured by class xmog_jvm_options; general framework options include such items as the error handling strategy and are configured by class xmog_options; shared JVM framework options include such items as the connection string and are configured by class xmog_remote_client_options.
The main class responsible for configuring all these options is the xmog_jvm_loader class. It aggregates the above groups of options via inheritance. You typically access all of the options through a singleton instance of type xmog_jvm_loader. You acquire the singleton instance through one of several different factory methods called get_jvm_loader
. Each of the methods takes different arguments and selects a different method for initializing the returned instance. The methods include such mechanisms as an old-style JunC++ion configuration file, a .NET style config file, the Windows registry, or environment variables.
Once you have an instance of an xmog_jvm_loader, you can further modify its settings and thereby affect how the JVM is being loaded. Please note that most options can only be set meaningfully before a JVM has been loaded into the native process. This means that you have to be careful to avoid unintentional JVM loading before you have fully configured your runtime environment.
A JVM is loaded automatically for you the very first time that one of the runtime types needs to access the Java side. This can for example happen because you create a wrapper instance of type String
or any other proxy type. You can rely on this behavior and everything will work as expected as long as you have your application correctly deployed and configured.
If at all possible though, you should try to explicitly load the JVM in a well-defined place in your application where you perform initialization tasks. This can help a lot by centralizing error handling and receiving an error that is due to a misconfiguration early rather than halfway through the application. Even if you rely on configuration files or the registry for supplying the configuration information, you might wish to have a block of code like this in your application's main()
or in whichever method performs initialization for your use case:
Depending on the factory method that you are using to create your xmog_jvm_loader instance, and on what kind of proxy classes are in your process, different activities might take place during the determination of your initialization options.
Most proxy classes will have been generated with a named configuration embedded in them. When these classes are loaded into the process, they will register their named configuration with the runtime framework. When the time comes to load a JVM into the process, all registered named configurations will be inspected and their collective options will be used to initialize the JVM. The 3.0 version of the runtime library is the first version that supports both the consolidation of settings from more than one named configuration and the total absence of named configurations. In the absence of named configuration information, you have to initialize your application using one of the following mechanisms:
When you have proxy types residing in a library that might be used as a native library in a Java application or when the loading of the JVM is outside of your control, you need to take special care about the configuration of the runtime.
First of all, you need to understand that any JVM configuration that you might be performing is almost totally useless because it only gets taken into account when the JVM is loaded. If the JVM is already loaded whatever classpath and -D or -X options you're configuring via the configuration API will simply be ignored. Nevertheless, you might need to configure the interoperability, non-JVM-related aspects of the runtime, for example the error handling policy, the trace level, the native string encoding, etc.
These framework configuration aspects could for example be configured in a configuration hook that is built into your shared library and gets called when the xmog_jvm_loader singleton is created.
Here's a checklist for this kind of usecase:
JvmPath
to the one that you're running with? On Windows, we use a platform API to check for an already loaded jvm.dll
and use that one. On other platforms, you need to make sure that the configured JvmPath corresponds with the Jvm that is used to execute the Java parts of the application.Configuration hooks allow you to register a function that will be called before and after the instance of xmog_jvm_loader has been configured as specified by the user. This is a very useful feature when you're using a proxy frmaework or a third-party proxy library that requires certain configuration settings regardless of what else the user might wish to configure. A proxy library might for example always have to add a certain jarfile to the classpath, irrespective of what other classpath roots the user has configured.
While you can register the configuration hook manually if you so desire, it is most useful if it gets registered automatically, for example when a proxy library is being loaded into a process. This is easy to achieve by declaring a static variable whose initializer registers the configuration callback. The following code snippet which would be part of a proxy library illustrates this approach:
We also support the aliases XMOG_BEFORE
for XMOG_BEFORE_INITIALIZATION
and XMOG_AFTER
for XMOG_AFTER_INITIALIZATION
.
Don't assume that your library is going to be the only library that attempts to configure the runtime environment. In particular, is is generally a good practice to do the following in your configuration hook:
You hopefully have a pretty good idea now of what you can do with this feature if you're shipping libraries to your users.
typedef void(XMOG_CALLING_CONVENTION * xmog_jvm_loader::XMOG_CONFIG_HOOK) (void *pLoader, int when) |
A typedef for registration hooks.
Once a registration hook has been registered via the registerConfigHook method, it is called when the xmog_jvm_loader instance is being created. It is called at least three times with different values for when:
XMOG_AFTER_INITIALIZATION
XMOG_BEFORE_LOADING
XMOG_AFTER_LOADING
This allows you to perform your configuration customizations in a way that makes them the default values (to be overwritten by the user) or in a way that makes them priority values (potentially overriding your user's settings).
pLoader | a pointer to the xmog_jvm_loader instance. |
when | one of XMOG_AFTER_INITIALIZATION , XMOG_BEFORE_LOADING or XMOG_AFTER_LOADING . Every installed hook is called multiple times with different values of when . Other calling times might be added later, so please code defensively and always test when for the proper value before executing your configuration task. |
XMOG_BEFORE
is an alias for XMOG_AFTER_INITIALIZATION
; XMOG_AFTER
is an alias for XMOG_BEFORE_LOADING
.
enum xmog_jvm_verbosity |
Verbosity levels for the JVM.
The different levels of verbosity can be ORed to create custom verbosity levels.