The lightweight and speedy integration framework.

Home

Download

Javadoc

Examples

Project Page

Example:

 

Here are all the methods you need to implement in order to create a base adapter

package net.sourceforge.ipony.examples;

import net.sourceforge.ipony.adapter.AdapterBase;

public class ConsoleAdapter extends AdapterBase {

  public void init() {
    
  }

  public void startup() {
    
  }

  public void shutdown() {
    
  }
}

Obviously this does nothing to interact with anything, but we do get our failover capability. If you start another instance of this adapter on another machine (or on this one for that matter), the first one started will be in control and its init and startup methods will be called. The second instance will have not have the init and start called until the first instance shuts down or dies an untimely death.

So here is a little more concrete stuff. This adapter is a simple adapter that accepts input from the console and publishes the string on a channel and subject that is defined in the config file. This adapter also subscribes to subjects defined in the config file. We just happen to subscribe to what we are publishing. Run this adapter on another machine and change the failover.channel in the config file to a unique name and you will see the messages comming through from one adapter to the other.

package net.sourceforge.ipony.examples;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import net.sourceforge.ipony.adapter.AdapterBase;
import net.sourceforge.ipony.message.Message;
public class ConsoleAdapter extends AdapterBase {
  /*
   */
  public String getDescription() {
    return "A description that will show up in the JMX console.";
  }
  /*
   */
  public void init() {
  }
  /*
   */
  public void startup() {

  /*
   * We will accept input from the console in another thread
 
   */
    Thread t = new Thread(new Runnable() {
      public void run() {
        try {
          while (true) {
            BufferedReader in = new BufferedReader(
                new InputStreamReader(System.in));
            String line = in.readLine();
            if ("exit".equalsIgnoreCase(line))
              break;
            publish(getConfig().getAttributes().getProperty(
                "pubChannel"), getConfig().getAttributes()
                .getProperty("pubSubject"), line);
          }
        catch (Exception e) {
          e.printStackTrace();
        }
        System.out.println("Exiting.....");
        stop();
        System.exit(0);
      }
    });
    t.start();
  }
  /*
   * Clean up 
   */
  public void shutdown() {
    System.out.println("Shutting down the adapter");
  }
  /*
   * Implementing this method allows you to subscribe to subjects that are
   * defined in the config file
   */
  public void onMessage(Message msg) {
    System.out.println("*****Received Message : " + msg);
  }
}

Pretty simple. To run it all you need to do is type

 
			java -Dconfig.file=consoleAdapter.xml net.sourceforge.ipony.examples.ConsoleAdapter
			
So here is the config file we used
<properties>
  <category name="attributes">
    <property name="pubSubject" value="test.subject"></property>
    <property name="pubChannel" value="MyChannel"></property>
  </category>
  <category name="subscription.1">
    <property name="subject" value="test.>"></property>
    <property name="channel" value="MyChannel"></property>
  </category>
  <category name="db.persistance">
    <property name="user" value="sa"></property>
    <property name="password" value=""></property>
    <property name="url" value="jdbc:hsqldb:test"></property>
    <property name="driver" value="org.hsqldb.jdbcDriver"></property>
    <property name="DatabaseName" value="adapter"></property>
  </category>
  <category name="general">
    <property name="recovery.channel" value="testrecoverychannel"></property>
    <property name="peristance.factory" value="net.sourceforge.ipony.message.persistance.db.DbMessagePersistanceFactory"></property>
    <property name="failover.channel" value="failover"></property>
    <property name="jmx.port" value="8080"></property>
    <property name="class.name" value="net.sourceforge.ipony.examples.ConsoleAdapter"></property>
  </category>
</properties>

More to come.....
SourceForge.net Logo