As detailed on the Getting Started page, the main method in AnvilJ's output projects instantiate the AnvilJ Object Manager as below:
anvilj.Settings _anviljsettings = new anvilj.Settings(true, false, false);
 
anvilj.refactored.Globals.om = new anvilj.ObjectManager(
    anviljsettings,
    0,
    new anvilj.socketcomms.SocketComms(0, anvilj.refactored.HostnameMapFactory.getMap()),
    new anvilj.refactored.Architecture(),
    new anvilj.refactored.ThreadCreator(),
    new anvilj.refactored.SharedMessages(),
    new anvilj.refactored.Routing(),
    new anvilj.sharedmessagehandlers.FullSerialization(null),
    new anvilj.Port());
 
anvilj.refactored.Globals.omThread =
    new Thread(anvilj.refactored.Globals.om);
 
anvilj.refactored.Globals.omThread.start();
In the instantiation of anvilj.ObjectManager, an instance of anvilj.socketcomms.SocketComms is created and passed. SocketComms is the default implementation of the communications drivers which makes use of TCP sockets to convey messages between nodes. This will work on most operating systems and is useful for testing the refactored projects. In an embedded system this will likely be needed to be replaced with a set of hardware drivers. This page describes how to do this.

The IComms interface

The Object Manager's constructor takes an instance of the anvilj.interfaces.IComms interface. By default, the refactoring engine creates an instance of SocketComms, but on an embedded system this will need to be replaced with a class that implements the communications of the target node. The methods of the IComms interface are as follows:
  • public void sendMessage(ISerializationHandler sh, Message message);
    • Sends a message to another Object Manager in the system. May block if send queues (if used) are full. The Message instance contains information about its target node, and methods to serialise the message into a byte stream.
  • public int recvQueueCount();
    • The number of messages in the receive queue.
  • public UnparsedMessage getNextMessage() throws NoSuchElementException;
    • Get the least recently received message from the internal message queue. Will not block if the queue is empty.
  • public UnparsedMessage getNextMessageWait() throws InterruptedException;
    • Get the least recently received message from the internal message queue. Will block the calling thread if the queue is empty until a message arrives. On some embedded systems this may be implemented as a busy loop; on compliant JVMs wait and notify should be used.