Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 10 Getting Started: Hello World Adapter : The Adapter Program

The Adapter Program
After the configuration is completed, the code can access the configuration file. This section lists the code for the Hello World Adapter in C++ and Java.
Hello World Code in C++
Sample code for the Hello World program is included as part of the SDK installation. To view the code, open the project file SDK_HOME\examples\helloWorld\helloWorld.dsp on Microsoft Windows platforms or the helloWorld.cpp file on UNIX platforms.
The adapter application manager class is defined as follows:

 
#include <Maverick.h>
 
#include <iostream.h>
class HelloWorldApp : public MApp
{
public:
HelloWorldApp( MAppProperties* pMAppProperties)    //constructor
:MApp(pMAppProperties, NULL) {}
 
virtual ~HelloWorldApp() {}                        //destructor
 
 
void onInitialization() throw (MException)         //you must define this method
                                                    //it is called by MApp::start()
{
cout << " Hello World Adapter " << endl ;
}
void onTermination() throw (MException) {}      //you must define this method
                                                    //it is called by MApp::stop()
 
};

 
main() is defined as follows:
1.
It first creates an MAppPropterties instance to specify application properties.

 
int main(int argc, char* argv[])
{
 
MAppProperties appProperties;
 
   appProperties.set(MAppProperties::APPVERSION, "1.0");
appProperties.set(MAppProperties::APPINFO, "TIBCO Adapter Hello World Example");
appProperties.set(MAppProperties::APPNAME, "helloWorld");
 
// set the repository location
appProperties.set(MAppProperties::REPOURL, "HelloWorldRepo.dat");
appProperties.set(MAppProperties::CONFIGURL,
                       "/tibco/private/adapter/HelloWorldAdapter/defaultInstance");
 
// store the command line args with MApp
   appProperties.setCommandLine(argc, argv);

 
2.
The program then creates the MApp application manager, passing in the properties just defined.

 
 
try {
HelloWorldApp* pHelloWorldApp =
new HelloWorldApp(&appProperties);

 
3.
Next comes a call to the start() method, which starts the event loop by default. For this example, there is no need to start the event loop, so pass in false.
4.
The stop() method is invoked right after that. While the application did not enter the event loop, the stop() method must be called because it performs any internal cleanup and will then call onTermination() to perform developer-defined cleanup.

 
 
pHelloWorldApp->start(Mfalse);
pHelloWorldApp->stop();
 
delete pHelloWorldApp;
}
catch(MException& e )
{
cout << "Exception caught in main:
                           "<< e.getType() << ":" << e.getDescription() << endl;
}
 
return 0;
 
} // main
 

 
 
You can compile and link the program using:
make on Unix platforms
Hello World Code in Java
The helloWorld example file is included in the installation media as: SDK_HOME\examples\helloWorld\helloWorld.java
The MAppProperties class is defined as follows:

 
Define the helloWorld class as follows:
public class helloWorld
{
MApp app;
 
public helloWorld( String[] args ) throws Exception
   {
// Create the Mapp
// you can also try to pass in parameter as -system:configurl and       //-system:repourl
MAppProperties p = new MAppProperties(
"helloWorld",
"1.0",
"Hello World Adapter",
"/tibco/private/adapter/HelloWorldAdapter/defaultInstance",
"HelloWorldRepo.dat",
args);
System.out.println ("repo = "+p.getRepoURL());
System.out.println ("config = "+p.getConfigURL());
 
app = new helloWorldApp( p );
app.start(false);
app.stop();
   }
 

 
import java.util.*;
import com.tibco.sdk.*;
 
class helloWorldApp extends MApp                   //create application manager
 
{
public helloWorldApp( MAppProperties p )
{
super( p );
}
 
/** Hook to perform application-specific behavior during
* initialization
*/
protected void onInitialization() throws MException          //required
{
System.out.println (" Hello World Adapter ");
}
 
/** Hook to perform application-specific behavior during
* shut-down
*/
protected void onTermination() throws MException
{
}
 
} // end of class helloWorldApp
 
 
 
public static void main( String[] args ) {
try {
new helloWorld( args );
}
catch( Exception fatal ) { fatal.printStackTrace(); }
}
} // end of class helloWorld

 
1.
2.
javac helloWorld.java
3.
Run the helloWorld adapter using the following command.
java helloWorld

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved