Java applications that comply with OSGi
CICS® includes the Equinox implementation of the OSGi framework to run Java™ applications that comply with the OSGi specification in a JVM server.
The OSGi Service Platform specification, as described in The OSGi Service Platform, provides a framework for running and managing modular and dynamic Java applications. The default configuration of a JVM server includes the Equinox implementation of an OSGi framework. Java applications that are deployed on the OSGi framework of a JVM server benefit from the advantages of using OSGi and the qualities of service that are inherent in running applications in CICS.
You might want to use Java applications for any of the following reasons:
- You want to create Java workloads that can run on a zAAP to reduce the cost of transactions.
- You have experience of writing Java applications that use OSGi on other platforms and want to create Java applications in CICS.
- You want to provide Java applications as a set of modular components that can be reused and updated independently, without affecting the availability of applications and the JVM in which they are running.
To effectively develop, deploy, and manage Java applications that comply with OSGi, you must use the CICS Explorer® SDK and CICS Explorer:
- The CICS Explorer SDK enhances an existing Eclipse Integrated Development Environment (IDE) to provide the tools and support to help Java developers create and deploy Java applications in CICS. Use this tool to convert existing Java applications to OSGi bundles.
- CICS Explorer is an Eclipse-based systems management tool that provides system administrators with views for OSGi bundles, OSGi services, and the JVM servers in which they run. Use this tool to enable and disable Java applications, check the status of OSGi bundles and services in the framework, and get some preliminary statistics on the performance of the JVM server.
Any Java developer or systems administrator who wants to work with OSGi requires access to these freely available tools.
The following examples describe how you can run Java applications that use OSGi in CICS.
Run multiple Java applications in the same JVM server
The JVM server can handle multiple requests in the same JVM concurrently. Therefore, you can call the same application multiple times concurrently or run more than one application in the same JVM server.
When you decide how to split your applications between JVM servers, you can plan how to use the OSGi model to componentize your applications into a set of OSGi bundles. You must also decide what supporting OSGi bundles are required in the framework to provide services to your applications. The OSGi framework can contain different types of OSGi bundle, as shown in the following diagram:
- Application bundles
- An application bundle is an OSGi bundle that contains application code. OSGi bundles can be self-contained or have dependencies on other bundles in the framework. These dependencies are managed by the framework, so that an OSGi bundle that has an unresolved dependency cannot run in the framework. In order for the application to be accessible outside the framework in CICS, an OSGi bundle must declare a CICS main class as its OSGi service. If a PROGRAM resource points to the CICS main class, other applications outside the OSGi framework can access the Java application. If you have an OSGi bundle that contains common libraries for one or more applications, a Java developer might decide not to declare a CICS main class. This OSGi bundle is available only to other OSGi bundles in the framework.
- Middleware bundles
- A middleware bundle is an OSGi bundle that contains classes to implement system services, such as connecting to WebSphere® MQ. Another example might be an OSGi bundle that contains native code and must be loaded only once in the OSGi framework. A middleware bundle is managed with the lifecycle of the JVM server, rather than the applications that use its classes. Middleware bundles are specified in the JVM profile of the JVM server and are loaded by CICS when the JVM server starts up.
- System bundles
- A system bundle is an OSGi bundle that manages the interaction between CICS and the OSGi framework to provide key services to the applications. The primary example is the JCICS OSGi bundles, which provide access to CICS services and resources.
To simplify the management of your Java applications, follow these best practices:
- Deploy tightly coupled OSGi bundles that comprise an application in the same CICS bundle. Tightly coupled bundles export classes directly from each other without using OSGi services. Deploy these OSGi bundles together in a CICS bundle to update and manage them together.
- Avoid creating dependencies between applications. Instead, create a common library in a separate OSGi bundle and manage it in its own CICS bundle. You can update the library separately from the applications.
- Follow OSGi best practices by using versions when you are creating dependencies between bundles. Using a range of versions mean that an application can tolerate compatible updates to bundles that it depends on.
- You should always explicitly declare the packages that your OSGi bundle uses, even if the tooling does not indicate an error. You can do this by adding or updating the Import-Package bundle header in your OSGi bundle manifest. Tools such as Eclipse make assumptions about the availability of javax.* packages that might not be correct for a runtime environment where an explicit Import is necessary.
- Set up a naming convention for the JVM servers and agree the convention between the system programmers and Java developers.
- Avoid the use of singleton OSGi bundles. Discarding a singleton bundle that other bundles depend on can cause the dependent bundles to fail.
Run multiple versions of the same Java application in a JVM server
The OSGi framework supports running multiple versions of an OSGi bundle in a framework, so you can phase in updates to the application without interrupting its availability. While you can install multiple implementations of the same OSGi service into the framework, the service with the highest version property is used when that service is called. In CICS the version property is inferred from the underlying OSGi bundle. So if you want to run multiple versions of the same Java application in a JVM server at the same time and the different versions of the OSGi bundle have the same CICS main class, you must use an alias on one definition of the CICS main class. The alias is specified with the declaration of the CICS main class and registered in the OSGi framework as the OSGi service for a specific version of the application. Specify the alias on another PROGRAM resource to make that version of the application available.
For more information about defining aliases, see Updating the plug-in project manifest file in the CICS Java Developer Guide in the CICS Explorer product help.