MockAgent
A very simple agent which performs useful tests during development, and exercises the APIs
All agents which plug into the SolrAgentFramework must implement the IPluggableAgent interface:

public interface IPluggableAgent {

/**
* Initialize the agent by accepting an instance of
* {@link SolrEnvironment}, performing initializations,
* and returning error messages, if any.
* @param env
* @return
*/
IResult init(SolrEnvironment env);
/**
* Necessary for any services the agents might need
*/
void shutDown();
}

A built in agent for development is MockInterface. It is booted by adding it to the config-props.xml file, as follows:

<!-- 
provide a list of agents, which must be in the classpath, for booting.
Each agent implements the org.topicquests.solr.api.IPluggableAgent interface.
MockAgent is for testing.
used in SolrEnvironment; they are the last to boot since they
go right to work
-->
<list name="Agents">
<parameter name="mock" value="org.topicquests.agent.mock.MockAgent" />
</list>

Each agent thus booted is kept in a Map<String,IPluggableAgent> structure for later calls to shutDown().

The MockAgent, as it is presently coded  is this:

public class MockAgent implements IPluggableAgent {
private LoggingPlatform log;
private Tracer tracer;
private AgentEnvironment agentEnvironment;
private SolrEnvironment solrEnvironment;
private ISemiSpace blackboard;
private Worker thread;
private TupleFactory factory; // not actually used here
/**
* <code>agentName</code> is used both in the internal blackboard,
* and the remote one
*/
private String agentName;

/* (non-Javadoc)
* @see org.topicquests.solr.api.IPluggableAgent#init(org.topicquests.solr.SolrEnvironment)
*/
@Override
public IResult init(AgentEnvironment env, String agentName) {
this.agentName = agentName;
agentEnvironment = env;
solrEnvironment = env.getSolrEnvironment();
blackboard = agentEnvironment.getTupleSpaceEnvironment().getTupleSpace();
factory = new TupleFactory(agentEnvironment.getTupleSpaceEnvironment());
log  = LoggingPlatform.getInstance();
tracer = log.getTracer(agentName);
IResult result = new ResultPojo();
thread = new Worker();
return result;
}
class Worker extends Thread {
private boolean isRunning = true;
private Object synchObject = new Object();
private ISemiSpaceTuple template;
public void shutDown() {
synchronized(synchObject) {
isRunning = false;
synchObject.notify();
}
}
Worker() {
template = new Tuple(1, ITupleTags.NEW_SOLR_DOC);
template.set(ITupleFields.AGENT_NAME, agentName);
this.start();
}
public void run() {
log.logDebug( "MockAgent.Worker started");
ISemiSpaceTuple t=null;
String cargo;
while(isRunning) {
t = blackboard.read(template, 1000); // leave up to a second
System.out.println("MockAgent read "+t+" "+isRunning);
if (t == null) {
synchronized(synchObject) {
try {
synchObject.wait(1000);
} catch (Exception e) {}
}
}
if (isRunning && t != null) {
log.logDebug("MockAgent GOT"+ t.getJSON());
if (containsData(t)) {
cargo = (String)t.get(ITupleFields.CARGO);
tracer.trace(0, cargo);
System.out.println(cargo);
}
t = null;
}
}
}
}
/**
* {"id":1361127537959,"tag":"NewSolrDoc","cargo":"nodata"}
* is an example of a returned tuple with "no data"
* @param t
* @return
*/
boolean containsData(ISemiSpaceTuple t) {
String cargo = (String)t.get(ITupleFields.CARGO);
if (cargo.equals("nodata"))
return false;
return true;
}
@Override
public void shutDown() {
thread.shutDown();
tracer.shutDown();
log.shutDown();
}

}

The function of MockAgent is simply to monitor any new document sent to Solr. It's output is to send the document, in a JSON string format, to the Tracer.  A fragment of the trace, taken while importing the topic maps bootstrap typology is this:

{"locator":"TypeType","smallIcon":"cogwheel.png","details":"The TopicQuests typology root node type.","isPrivate":"false","creatorId":"SystemUser","label":"Type Type","lastEditDate":"2013-02-17T23:22:58.287Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:22:58.287Z"}
{"locator":"ClassType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology class node type.","isPrivate":"false","creatorId":"SystemUser","label":"Class Type","lastEditDate":"2013-02-17T23:22:59.982Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:22:59.982Z"}
{"locator":"NodeType","smallIcon":"cogwheel.png","subOf":"ClassType","details":"The TopicQuests typology node type.","isPrivate":"false","creatorId":"SystemUser","label":"Node Type","lastEditDate":"2013-02-17T23:23:00.628Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:00.628Z"}
{"locator":"GraphType","smallIcon":"cogwheel.png","subOf":"ClassType","details":"The TopicQuests typology graph type.","isPrivate":"false","creatorId":"SystemUser","label":"Graph Type","lastEditDate":"2013-02-17T23:23:01.351Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:01.351Z"}
{"locator":"VirtualNodeType","smallIcon":"cogwheel.png","subOf":"ClassType","details":"The TopicQuests typology virtual node type.","isPrivate":"false","creatorId":"SystemUser","label":"Virtual Node Type","lastEditDate":"2013-02-17T23:23:01.88Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:01.88Z"}
{"locator":"RelationType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology relation node type.","isPrivate":"false","creatorId":"SystemUser","label":"Relation Type","lastEditDate":"2013-02-17T23:23:02.54Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:02.54Z"}
{"locator":"MergeAssertionType","smallIcon":"cogwheel.png","subOf":"RelationType","details":"The TopicQuests typology merge assertion node type.","isPrivate":"false","creatorId":"SystemUser","label":"Merge Assertion Type","lastEditDate":"2013-02-17T23:23:03.57Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:03.57Z"}
{"locator":"OntologyType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology ontology node type.","isPrivate":"false","creatorId":"SystemUser","label":"Ontology Type","lastEditDate":"2013-02-17T23:23:06.086Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:06.086Z"}
{"locator":"PropertyType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology property node type.","isPrivate":"false","creatorId":"SystemUser","label":"Property Type","lastEditDate":"2013-02-17T23:23:06.529Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:06.529Z"}
{"locator":"RuleType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology rule node type.","isPrivate":"false","creatorId":"SystemUser","label":"Rule Type","lastEditDate":"2013-02-17T23:23:07.498Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:07.498Z"}
{"locator":"MergeRuleType","smallIcon":"cogwheel.png","subOf":"RuleType","details":"The TopicQuests typology merge rule node type.","isPrivate":"false","creatorId":"SystemUser","label":"Merge Rule Type","lastEditDate":"2013-02-17T23:23:08.079Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:08.079Z"}
{"locator":"RoleType","smallIcon":"cogwheel.png","subOf":"TypeType","details":"The TopicQuests typology role node type.","isPrivate":"false","creatorId":"SystemUser","label":"Role Type","lastEditDate":"2013-02-17T23:23:08.735Z","largeIcon":"cogwheel.png","createdDate":"2013-02-17T23:23:08.735Z"}

}
Immediately related elementsHow this works
-
OpenSherlock Project Â»OpenSherlock Project
Resources Â»Resources
SolrSherlock Code Â»SolrSherlock Code
Agent Architecture Â»Agent Architecture
SolrAgentFramework Â»SolrAgentFramework
MockAgent
+Kommentare (0)
+Verweise (0)
+About