Event-Based Components

Ken Webb 2010-03-27T22:21:31Z

Ralf Westphal is working on an idea that he calls event-based components (EBC). There is at least some resemblance between Xholon and EBC, and Ralf and I have just started to correspond about this. Ralf sent me a description of a simple example he has developed using C#. My name for this application is ClientService. In the Xholon application section of the Xholon wiki I have included a simple self-contained Xholon version of this, without using the full Xholon framework and without using XML.

On this page, I am providing the XML and Java code for the same ClientService application, but making use of the full framework and XML.

Typically the first step in creating a Xholon application is to define classes in a InheritanceHierarchy.xml file. There are three classes in this application - Board, Client, and PrintService. Only Client really needs to be defined here, so the other two classes are commented out.

<?xml version="1.0" encoding="UTF-8"?>
<XholonClass xmlns:xi="http://www.w3.org/2001/XInclude">

  <!--<Board/>-->
  <Client/>
  <!--<PrintService/>-->

</XholonClass>

The next step is to define the hierarchical structure in a CompositeStructureHierarchy.xml file. There are three objects in this tree. The root is an instance Board. The Board object has two children - and instance of Client, and an instance of PrintService.

<?xml version="1.0" encoding="UTF-8"?>
<Board>
  <Client/>
  <PrintService/>
</Board>

Typically some of the nodes in a Xholon application have ports that connect them to other nodes in the tree. Ports are defined at the class level in a ClassDetails.xml file. Again, Board and PrintService don't really need to be defined, so they are commented out. The Xholon framework automatically associates the Xholon class Board with the Java class org.primordion.user.app.ClientService.Board, but the current implementation requires this to be explicitly stated when a port is being defined. Client has a port called outPin, which is the name of a variable in Client.java. The Xholon framework will connect this port to whatever node in the tree matches the XPath expression ../PrintService.

<?xml version="1.0" encoding="UTF-8"?>
<xholonClassDetails>

  <!--<Board implName="org.primordion.user.app.ClientService.Board"/>-->
  <Client implName="org.primordion.user.app.ClientService.Client">
    <port name="outPin" connector="#xpointer(../PrintService)"/>
  </Client>
  <!--<PrintService implName="org.primordion.user.app.ClientService.PrintService"/>-->

  <XholonClass xhType="XhtypePureContainer"/>
</xholonClassDetails>

The Java behavior of these three Xholon classes is defined in the three Java classes - Board.java, Client.java, and PrintService.java.

Board

package org.primordion.user.app.ClientService;

/**
 * Board
 */
public class Board extends XhClientService {

  public void act()
  {
    processMessageQ();
    super.act();
  }

}

Client

package org.primordion.user.app.ClientService;

import org.primordion.xholon.base.IXholon;

/**
 * Client
 */
public class Client extends XhClientService {

  /**
   * a Xholon port
   */
  private IXholon outPin = null;

  /*
   * @see org.primordion.user.app.ClientService.Xholon#act()
   */
  public void act()
  {
    /**
     * Send an asynchronous message through the outPin port.
     *  '''101''' is an arbitrary message signal identifier
     *  "hello" is the message data
     *  '''this''' is the sender of the message
     */
    outPin.sendMessage(101, "hello", this);
  }

  public IXholon getOutPin() {
    return outPin;
  }

  public void setOutPin(IXholon outPin) {
    this.outPin = outPin;
  }

}

PrintService

package org.primordion.user.app.ClientService;

import org.primordion.xholon.base.IMessage;

/**
 * Service
 */
public class PrintService extends XhClientService {

  /*
   * @see org.primordion.xholon.base.Xholon#processReceivedMessage(org.primordion.xholon.base.IMessage)
   */
  public void processReceivedMessage(IMessage msg)
  {
    System.out.println(msg.getData());
  }

}

When the full Xholon framework is used, a simple GUI is available to load, control, and interact with the application.

The GUI can also invoke various viewers and can write the application out in a variety of formats. For example, the application can generate a sequence diagram at runtime and display it using an external tool such as the Quick Sequence Diagram Editor.

return to main page