middleware a guide to middleware construction (roughly) based on Boris (roughly) geared towards Java Simon Lynch s.c.lynch@tees.ac.uk
what is middleware? a substrate to support system components / subsystems an interface between subsystems an additional level of abstraction
what does middleware do? handles data/message passing between subsystems provides clean subsystem interfacing allowing greater encapsulation & interoperability adding a new level of abstraction “glues (sub)systems together”
what may it also do? facilitate easier concurrency for subsystems allow distribution provide system diagnostics allow dynamic reconfiguration manage resources
building middleware NB: these notes based on Boris philosophy meta-agents / meta-actors building blocks blocking queue (spooler) meta-agent Portal agent, socket agent, interface agent PS: assume (here) all messages are Strings
messages & threads see example… message sending message receiving clones non-clones
a meta-agent subsystem
the blocking queue eg: class LinkedBlockingQueue<E> extends AbstractQueue<E> implements BlockingQueue<E>, Serializable void put(E e) Inserts element at the tail of queue, waiting if necessary for space to become available. E take() Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
meta-agent meta-agent extends blocking-queue variables: name, portal constructor method( args... ) | super.constructor( args... ) | thread{ loop-forever | msgHandler ( dequeue() )} void msgHandler( String msg ) | ... msg processing code goes here...
msgs via portals (i) agents sharing a portal (ii) agents with their own portal
portal portal extends meta-agent variables: routing-table void msg-handler(msg) | routing-table.get( | recipient-of(msg)).enqueue(msg) void add-agent( name, agent ) | routing-table.set( name, agent ) so... meta-agent.send-message(recipient, msg) | portal.enqueue( | wrap(name, recipient, msg)
comms with sockets
name mapping #1 P1 : { A1 | A1| , A2 | A2| }
name mapping #2 P1 : { A1 | A1| , A2 | P2| } P2 : { A1 | P1| , A2 | A2| }
name mapping #3 P1 : { A1 | A1| , A2 | S1| } P2 : { A1 | S2| , A2 | A2| }
usr-agent #1 usr-agent variables: metaAgent, msgHandler constructor method( args... ) | metaAgent = new MetaAgent( args... ) | ...other stuff... void sendMessage( String to, String msg) | ... add who from & send ... ...other methods...
usr-agent #2 usr-agent variables: metaAgent, msgHandler constructor method( args... ) | metaAgent = new MetaAgent( args... ) | ...other stuff... void msg-handler(msg) | if msgHandler != null | msgHandler.processMsg( ...un-wrapped msg...) void addMsgHandler( MsgHandler m )... NB: MsgHandler is an Interface with a method... void processMsg( String )