Ping Pong - Sample Xholon App

What is it

Ping Pong is a sample Xholon application. Two active objects of the same class collaborate to count from 0 to 19. They coordinate their behaviors by writing directly into each others public variables, through ports. Compare this with the Hello World tutorial in which two active objects collaborate by passing messages through ports.

How to use it

Run it:

  1. Run the Java application through the Xhn GUI (, and select File --> Open --> PingPong --> PingPong_xhn.xml.
  2. Expand the Controller node in the tree.
  3. Press the Start node.
  4. You should see pairs of messages on the console from pingPongEntity_1: 0 to pingPongEntity_2: 19

Things to notice

pingPongEntity_1 and pingPongEntity_2 are both instances of the PingPongEntity xholon class. Each has a single port through which it directly accesses the sum variable in the other instance (see the act() function in

The first instance outputs the even numbers, and the second instance the odd numbers.

Things to try

The maximum count can be controlled by varying the MaxProcessLoops parameter in PingPong_xhn.xml. Each instance of PingPongEntity is invoked once per process loop (time step).

You can run (src/...samples) directly without using the Xhn GUI.

Extending the model

Instead of directly accessing the sum variable, the two PingPongEntity xholons could implement the function public void incVal(double incAmount) from the IXholon interface. For example:

public void incVal(double incAmount)
	sum += (int)incAmount;

Xholon features

How xholons can directly access public variables through ports.

How to set default attribute values for Xholon instances using the XML attribute tag. See CompositeStructureHierarchy.xml .

A Xholon can be both an active object and a passive object at the same time. A XholonClass can have the XhtypeBehFgsxxx xhType, specifying that it can both act on other Xholons and be passively acted upon by other ones. Beh means that it has active behavior, and the Fgs means that it has passive fine-grained structure (attributes) that can be acted upon. See ClassDetails.xml .

These are useful features to have in complex biological simulations, one of the reasons for the Xholon project. Cells and small biochemical entities typically interact directly with each other through binding sites, and are better modeled by directly interacting with each other's attributes (or calling simple get(), set(), increment() and decrement() methods to accomplish the same thing), rather than sending asynchronous messages.

Credits and references

This application only demonstrates internal features of Xholon.