package org.openlcb.implementations; import org.openlcb.*; /** * Example of connecting a number of nodes. *

* Messages that the nodes send are sent to all other nodes, * but not the originating node. * *

* The sequence is *

* * @author Bob Jacobsen Copyright 2009 * @version $Revision: 2175 $ */ public class ScatterGather { /** * Provide a connection object for use by * a Node */ public Connection getConnection() { SingleConnection c = new SingleConnection(); issuedConnections.add(c); return c; } class SingleConnection extends AbstractConnection { public void put(Message msg, Connection sender) { // forward to all but the sender boolean match = false; for (Connection e : registeredConnections) { if (e.equals(sender)) match = true; else e.put(msg, sender); } if (!match) throw new AssertionError("Sender not registered"); } } java.util.ArrayList issuedConnections = new java.util.ArrayList(); java.util.ArrayList registeredConnections = new java.util.ArrayList(); public void register(Connection c) { registeredConnections.add(c); } }