Introduction

In the previous part of this custom adapter development series, we have walked through the steps to clone the sample JCA adapter and deploy it into the PI system.

In this part, we will be having a closer look at the Java source codes that form the custom adapter. We will only be looking at some of the key classes and their methods, in order to have a better understanding on the behavior of the adapter during the different stages in its life cycle.

This part will be a bit “drier” compared to the previous part as it will not have as much hands-on steps. However, it is crucial to have an understanding of these key elements as the basis for subsequent modification of the adapter according to specific requirements.

Deployment and Adapter Registration

During deployment of the adapter, it will perform registration of itself with the adapter framework. Following are some of the key aspects of the registration process.

SPIManagedConnectionFactory (SMCF) is one of the central classes for the adapter. Below are the description of the class as taken from the comments section of the class:-

An object of the class SPIManagedConnectionFactory (MCF) is a factory of both,

ManagedConnection and CCIConnectionFactory instances.

This class supports connection pooling by defining methods for matching and creating connections.

When an object of SMCF is created, it will perform a JNDI Lookup to retrieve an object of SAPAdapterResources.

/wp-content/uploads/2016/05/smcf_constructor_943636.png

Subsequently, SMCF is started by the AS Java server which calls its start() method. This in turn calls the startMCF() method. Within the startMCF() method, the above SAPAdapterResources object will execute its startRunnable() method using the SMCF object as a reference. This is to enable the SMCF to run in its own thread which is used to handle inbound processing.

/wp-content/uploads/2016/05/smcf_startrunnable_943649.png

As SMCF implements the Runnable interface, its run() method will subsequently be executed in its on thread.

/wp-content/uploads/2016/05/runnable_943843.png

Within the run() method, the adapter type and namespace are set. As mentioned in the first part of the series, it is important that the combination of the type and namespace forms a unique pair as this combination will be used during the registration of the adapter. This unique pair also has to match the name used for the Adapter Metadata in ESR.

/wp-content/uploads/2016/05/smcf_run1_943650.png

The above combination is used as input values during construction of an XIConfiguration object. This class manages all the channel information.

/wp-content/uploads/2016/05/smcf_run2_943651.png

Within the init() method of the XIConfiguration object, an execution of the registerAdapter() method of AdapterRegistry is performed to register the adapter with the adapter framework.

/wp-content/uploads/2016/05/init_register_943652.png

Successful registration of the adapter with the framework is crucial to ensure proper behavior and processing of the associated channels.

If the registration was not successful, channels created for this adapter will have the error “No adapter registered for this channel” when viewed in the Communication Channel Monitor.

/wp-content/uploads/2016/05/not_registered_943653.png

Side Note: Although the SMCF class implements the Runnable interface, it is not mandatory for it to do so. Implementation of the Runnable interface (to handle threads for inbound processing) can be delegated to a separate/new class as long as an object of the class is passed as an input value to the startRunnable() method.

Channel Management

During the lifecycle of a deployed adapter, channels can be created, changed and deleted for the adapter type. The XIConfiguration class is responsible for managing the details of channels for an adapter.

Following are some of the methods executed when actions for channels of an adapter are taken.

/wp-content/uploads/2016/05/add_channel_943654.png

Following is an example of the one of the methods, channelAdded().

The class maintains private attributes that contain lists of both inbound (sender) and outbound (receiver) channels that belongs to the adapter.

/wp-content/uploads/2016/05/channel_list_945319.png

During the execution of the method, the newly created channel will be added to the list. Note that this logic is executed within a synchronized block to ensure that the contents of the list is consistent in multi-threaded executions.

/wp-content/uploads/2016/05/add_channel_943654.png

Runtime Processing

Following are some of the key aspects during runtime execution of channels for the adapter.

A) Receiver Channel Processing

For receiver channel processing, the message is processed by the execute() method of class CCIInteraction. Within this method, it determines whether it is an asynchronous (Send) or synchronous (Call) execution and calls the corresponding method accordingly.

/wp-content/uploads/2016/05/receiver_processing_943655.png

As an example, for an asynchronous message, the send() method is called. In the sample JCA adapter, it will create an output file (according to the directory and filename configured in the receiver channel) in the file system of the PI server.

/wp-content/uploads/2016/05/receiver_async1_943661.png

The following logic section in the method constructs the target output file.

/wp-content/uploads/2016/05/receiver_async2_943662.png

An below is an example output generated by a sample message processed by the receiver JCA adapter.

/wp-content/uploads/2016/05/payload_945442.png

B) Sender Channel Processing

The sample JCA adapter provides a polling mechanism for the sender channel to poll files from the file system of the PI server.

The logic is implemented within the run() method of the SPIManagedConnectionFactory class.

/wp-content/uploads/2016/05/poll_943656.png

After the wait time is completed for each polling interval, method sendMessageFromFile() is executed to pick up file(s) from the configured directory and generate an message in the Messaging System.

/wp-content/uploads/2016/05/sendfile_943657.png

Refactoring Hard-coded Adapter Constant Values

Now that we have examined some of the key aspects of the adapter logic, we will have some hands-on to prepare the adapter project for modifications that will be introduced in the later parts of this series.

The source code for the sample JCA adapter contains many hard-coded values across the different classes. In this section, we will consolidate all these hard-coded values in a separate class as static final attributes. This is an optional yet recommended step in order to allow for ease of change in the future.

Below is the new class AdapterConstants that contains these constant values. Subsequently, the various classes are updated to reference these constants instead of hard-coding them within the classes themselves.

/wp-content/uploads/2016/05/constants_943663.png

i) CCIConnectionMetaData

/wp-content/uploads/2016/05/adapt1_943718.png

ii) CCIResourceAdapterMetaData

/wp-content/uploads/2016/05/adapt2_943719.png

iii) SPIManagedConnection

/wp-content/uploads/2016/05/adapt_3_943720.png

iv) SPIManagedConnectionFactory

/wp-content/uploads/2016/05/adapt_4_1_943722.png

/wp-content/uploads/2016/05/adapt_4_2_943723.png

v) SPIManagedConnectionMetaData

/wp-content/uploads/2016/05/adapt_5_943721.png

vi) XIAdapterCategories

/wp-content/uploads/2016/05/adapt_6_943724.png

vii) XIConfiguration

/wp-content/uploads/2016/05/adapt_7_943725.png

Conclusion

Phew! Finally, we have come to the end of this part and hopefully gained a better understanding on some of the internal behavior of the custom adapter. This will provide the foundation needed when we introduce modifications to the adapter later on in this series. In the next post, we will be looking at the deployment descriptor, manifest and adapter metadata files.

Other Parts of this Series

Demystifying Custom Adapter Development: Part 1a – Cloning the Sample JCA Adapter

Demystifying Custom Adapter Development: Part 1b – Cloning the Sample JCA Adapter

Demystifying Custom Adapter Development: Part 3 – Examining the Deployment and Metadata Files

Demystifying Custom Adapter Development: Part 4 – Modifying the Adapter’s Functionality

Demystifying Custom Adapter Development: Part 5 – Creating an HTTP Poller with OAuth 2.0 authentication

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Daniel Graversen

    Great post again making it easy to understand the not documented part.

    (0) 

Leave a Reply