import java import jacomma from jacomma.platform.core import Agent, MessagePattern from jacomma.icm.type import Symbol ## a print handler class print_handler( Agent.MessageHandler ): def onMessage( self, ag, msg ): print msg def register_print_handler( agent ) : agent.registerHandler( MessagePattern.anyPattern(), print_handler() ) class echo_handler( Agent.MessageHandler ): def onMessage( self, ag, msg ): print msg ag.send( msg.replyto(), msg.getContent() ) def register_echo_handler( agent ) : agent.registerHandler( MessagePattern.anyPattern(), echo_handler() ) ## a handler that displays frames class frame_handler( Agent.MessageHandler ): def onMessage( self, ag, msg ): msg.getContent().get( 1 ).show() ## The pattern test object class frame_test( java.lang.Object ) : def equals( self, msg ) : l = msg.getContent() return java.util.List.isInstance( l ) \ and l.size() == 2 \ and l.get( 0 ).equals( Symbol( "show" ) ) \ and java.awt.Frame.isInstance( l.get( 1 ) ) def make_frame_pattern() : return MessagePattern.createPattern( java.util.List, frame_test() ) def register_frame_handler( agent ) : agent.registerHandler( make_frame_pattern(), frame_handler() )