![]() |
Copyright © TIBCO Software Inc. All Rights Reserved |
At the center of each running adapter instance is the application manager, an instance of a subclass of MApp. All adapters need to create a subclass of MApp and define its methods.The MApp instance handles the following tasks:
• Initialization and shutdown of an adapter. Loading the configuration data (such as sessions, endpoints) and metadata into memory as part of initialization.
• Connecting to the project repository and processing configuration and metadata information found there.The SDK MApp class and its application-defined subclass implement these tasks together.Figure 4 Adapter Control Flow (C++)Figure 4 illustrates how a C++ program proceeds in single-threaded mode. In general, custom adapters run most efficiently in single-threaded mode, which is also the default mode. If a custom adapter requires multithreading, see Multithreaded Adapters.
1.
2.
a. Checks to see if MApp is already started; if it is, just returns.
b. Reads the information in project repository and creates objects as appropriate. This includes session, endpoint, and trace objects, as well as metadata description objects.
3. MApp calls the method onInitialization(), which performs application-specific initialization and must be defined for each custom adapter.
4. The SDK executes onInitialization().
5.
− If start() was called with bStartEventLoop set to true (default behavior), MApp enters a loop to dispatch events.
− If start() was called with bStartEventLoop set to false, MApp returns execution control to the custom adapter, which can then call MApp::nextEvent() to dispatch any incoming event, or MRvSession::nextEvent() to dispatch events for this session.See Event Model for information on the event model in use.
6. To exit the event loop, the custom adapter must send a message that invokes the stop() method, which leads to a shutdown operation.
Also, call stop() if the program never entered the event loop.
7. When MApp receives the call to stop(), it calls onTermination()—defined by the custom adapter—which performs application-specific cleanup.
8. The custom adapter executes onTermination() and returns control to the SDK.
10.
11. MApp is destroyed and control returns once more to the adapter.The control flow for Java differs slightly from that in C++. The SDK and the custom adapter interact as follows:
1.
2.
− Checks to see if MApp is already started; if it is, just returns.
− Reads the information in project repository and creates objects as appropriate. This includes session, endpoint, and trace objects, as well as metadata description objects.
3. After MApp has performed internal initialization, it calls onInitialization(). This method performs application-specific initialization and must be defined for each custom adapter.Components and metadata objects are already available; the custom adapter can therefore register listeners with subscribers and activate the subscribers.
4. The SDK executes onInitialization(), then activates all components, if so specified. For some components, additional criteria must be met. For example, a subscriber must have at least one listener attached to get activated.
5. See Event Model for information on the event model in use.
6.
7. When MApp receives the call to stop(), it first checks whether MApp is already stopped; if so, it just returns. If not, it calls onTermination().
8. The adapter executes onTermination() and returns control to the SDK.Custom adapters set up MApp as follows:
1. Use the TIBCO Designer software to set the adapter name, version, banner information, and other information, and save the configuration to the project repository.
2. Programmatically create an MAppProperties instance that points to the project repository.See MAppProperties in the online API Reference documentation.
3. Call the constructor for MApp, passing in the MAppProperties instance, which allows access to the configuration information.MApp is an abstract class. All custom adapters must create a subclass and implement, at a minimum, the onInitialization() and onTermination() methods. In addition, MApp offers methods to allow command-line arguments, to retrieve the current adapter name and version, and so on. See the online API documentation for MApp for details.Example 1 onInitialization()The following code fragment illustrates the use of onInitialization().MComponentRegistry componentRegistry = getComponentRegistry();MSubscriber sub = componentRegistry.getSubscriber( "DiscoveryListener" );MHawkMicroAgent hma = hawkRegistry.getHawkMicroAgent( "GetStatistics" );Example 2 onTermination()The following code fragment illustrates the use of onTermination().MPublisher publisher = getComponentRegistry().getPublisher( "Alert-sender" );Minstance message = getClassRegistry().getDataFactory().newInstance( “Alert” );
![]() |
Copyright © TIBCO Software Inc. All Rights Reserved |