|
From: <to...@us...> - 2008-01-17 21:03:27
|
Revision: 103
http://xoperator.svn.sourceforge.net/xoperator/?rev=103&view=rev
Author: tomatop
Date: 2008-01-17 13:03:32 -0800 (Thu, 17 Jan 2008)
Log Message:
-----------
Modified Paths:
--------------
trunk/xOperator/src/net/sf/xoperator/blackboard/NoPlanBlackBoardControl.java
trunk/xOperator/src/net/sf/xoperator/blackboard/ThreadsafeTransientMemory.java
trunk/xOperator/src/net/sf/xoperator/rdfxmpp/SPARQLQuery.java
trunk/xOperator/src/net/sf/xoperator/startup/CommandLineMain.java
trunk/xOperator/src/net/sf/xoperator/ui/aiml/TemplateExectutionContext.java
trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java
Modified: trunk/xOperator/src/net/sf/xoperator/blackboard/NoPlanBlackBoardControl.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/blackboard/NoPlanBlackBoardControl.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/blackboard/NoPlanBlackBoardControl.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -26,183 +26,216 @@
import org.openbbs.blackboard.filter.KindOfFilter;
import org.openbbs.blackboard.ks.KSExecutionContext;
import org.openbbs.blackboard.ks.KnowledgeSource;
+
/**
- * The all-in-one no plan all you need approach. everything to make the blackbaord run is in this class.
- * Just implement some Knowledgesources, instantiate this class with them and you'll be fine. As long as
- * every Knowledge source can determine just from the content of the zone what if is should perform its task or not.
- * And also it has to know if already has performed. Easy.
+ * The all-in-one no plan all you need approach. everything to make the
+ * blackbaord run is in this class. Just implement some Knowledgesources,
+ * instantiate this class with them and you'll be fine. As long as every
+ * Knowledge source can determine just from the content of the zone what if is
+ * should perform its task or not. And also it has to know if already has
+ * performed. Easy.
+ *
* @author joerg
- *
+ *
*/
public class NoPlanBlackBoardControl implements BlackboardObserver {
-
+
private Log log = LogFactory.getLog(NoPlanBlackBoardControl.class);
-
-
+
private Blackboard bboard;
+
private List<KnowledgeSource> ksources = new ArrayList<KnowledgeSource>();
-
-
- public KSExecutionContext newZonedAccess(){
+ public KSExecutionContext newZonedAccess() {
final Zone nz = openRandomNamedZone();
- return new KSExecutionContext(){
+ return new KSExecutionContext() {
public BlackboardAccess blackboard() {
-
- return new ZonedBlackboardAccess(NoPlanBlackBoardControl.this.bboard,nz);
+
+ return new ZonedBlackboardAccess(
+ NoPlanBlackBoardControl.this.bboard, nz);
}
public BlackboardAccess blackboard(Zone zone) {
-
- return new ZonedBlackboardAccess(NoPlanBlackBoardControl.this.bboard,zone);
+
+ return new ZonedBlackboardAccess(
+ NoPlanBlackBoardControl.this.bboard, zone);
}
-
+
};
}
-
private Zone openRandomNamedZone() {
- final NamedZone nz = new NamedZone(System.currentTimeMillis()+RandomStringUtils.randomAlphanumeric(8));
+ final NamedZone nz = new NamedZone(System.currentTimeMillis()
+ + RandomStringUtils.randomAlphanumeric(8));
this.bboard.openZone(nz);
this.log.debug("opened a new zone on the blackboard: " + nz.name());
return nz;
}
-
+
/**
- * a special zone on the blackboard dedicated for keeping track of the configuration. Changes made to this context will not notify any of the knowledgesource, use <code>propagateConfiguration</code> instead. Updating this zone is done in the yoperator application by the <code>SErializingPersonalDAtastore</code> Knowledgesource
+ * a special zone on the blackboard dedicated for keeping track of the
+ * configuration. Changes made to this context will not notify any of the
+ * knowledgesource, use <code>propagateConfiguration</code> instead.
+ * Updating this zone is done in the yoperator application by the
+ * <code>SErializingPersonalDAtastore</code> Knowledgesource
+ *
* @return
*/
- public KSExecutionContext getConfigurationContext(){
- return new KSExecutionContext(){
+ public KSExecutionContext getConfigurationContext() {
+ return new KSExecutionContext() {
public BlackboardAccess blackboard() {
-
- return new ZonedBlackboardAccess(NoPlanBlackBoardControl.this.bboard,Constants.CONFIGURATION_ZONE);
+
+ return new ZonedBlackboardAccess(
+ NoPlanBlackBoardControl.this.bboard,
+ Constants.CONFIGURATION_ZONE);
}
public BlackboardAccess blackboard(Zone zone) {
-
- return new ZonedBlackboardAccess(NoPlanBlackBoardControl.this.bboard,zone);
+
+ return new ZonedBlackboardAccess(
+ NoPlanBlackBoardControl.this.bboard, zone);
}
-
+
};
}
-
-
-
-
public NoPlanBlackBoardControl(Blackboard bboard) {
super();
this.bboard = bboard;
bboard.openZone(Constants.CONFIGURATION_ZONE);
-
- bboard.registerInterest(new ZoneSelector(){
+ bboard.registerInterest(new ZoneSelector() {
public boolean selects(Zone zone) {
- if(zone.equals(Constants.CONFIGURATION_ZONE)){
+ if (zone.equals(Constants.CONFIGURATION_ZONE)) {
return false;
- }else{
+ } else {
return true;
}
-
+
}
}, this);
}
-
- public void registerKnowledgeSource(KnowledgeSource ks){
+
+ public void registerKnowledgeSource(KnowledgeSource ks) {
this.ksources.add(ks);
}
-
-
-
- public void blackboardDidAddEntry(final Blackboard blackboard, final Zone zone, final Object entry) {
+
+ public void blackboardDidAddEntry(final Blackboard blackboard,
+ final Zone zone, final Object entry) {
this.log.debug("New Entry on Blackboard: " + entry.toString());
- KSExecutionContext context = new KSExecutionContext(){
+ KSExecutionContext context = new KSExecutionContext() {
public BlackboardAccess blackboard() {
-
- return new ZonedBlackboardAccess(blackboard,zone);
+
+ return new ZonedBlackboardAccess(blackboard, zone);
}
+
public BlackboardAccess blackboard(Zone zo) {
// TODO Auto-generated method stub
- return new ZonedBlackboardAccess(blackboard,zo);
+ return new ZonedBlackboardAccess(blackboard, zo);
}
};
-
- for (KnowledgeSource source : this.ksources) {
- if(source.isEnabled(context)){
- source.execute(context);
+
+
+ for (KnowledgeSource source : this.ksources) {
+ if (source.isEnabled(context)) {
+ source.execute(context);
+ }
+
}
-
- }
-
+
}
- public void blackboardDidRemoveEntry(Blackboard blackboard, Zone zone, Object entry) {
-
+
+ public void blackboardDidRemoveEntry(Blackboard blackboard, Zone zone,
+ Object entry) {
+
}
+
/**
- * puts a message into the blackboard and registers the messages in the appropriate chat zone
+ * puts a message into the blackboard and registers the messages in the
+ * appropriate chat zone
+ *
* @param message
* @param chat
*/
- public void registerMessage(Message message, Chat chat){
+ public void registerMessage(Message message, Chat chat) {
Zone chatzone = new NamedZone(chat.getThreadID());
-
- if(!this.bboard.exists(new ExactZoneSelector(chatzone), new KindOfFilter(List.class))){
- //create a zone for the chat
+
+ if (!this.bboard.exists(new ExactZoneSelector(chatzone),
+ new KindOfFilter(List.class))) {
+ // create a zone for the chat
this.bboard.openZone(chatzone);
- this.bboard.write(chatzone, Collections.synchronizedList(new ArrayList<Zone>()));
+ this.bboard.write(chatzone, Collections
+ .synchronizedList(new ArrayList<Zone>()));
}
-
- List<Zone> messagesOfChat = (List<Zone>) this.bboard.take(new ExactZoneSelector(chatzone), new KindOfFilter(List.class));
+
+ List<Zone> messagesOfChat = (List<Zone>) this.bboard.take(
+ new ExactZoneSelector(chatzone), new KindOfFilter(List.class));
Zone newMessageZone = openRandomNamedZone();
messagesOfChat.add(newMessageZone);
- //the chat to which this message belongs is written to the blackboard, to allow later referencing
+ // the chat to which this message belongs is written to the blackboard,
+ // to allow later referencing
this.bboard.write(newMessageZone, chat);
- //and finally we write the message to the zone
+ // and finally we write the message to the zone
this.bboard.write(newMessageZone, message);
-
+
}
-
+
public Blackboard getBboard() {
return this.bboard;
}
-
+
/**
- * writes a configuration element to the blackboard on a new zone and deletes it afterwards. Thus
- * @param conf
+ * writes a configuration element to the blackboard on a new zone and
+ * deletes it afterwards. Thus
+ *
+ * @param conf
*/
- public void propagateConfiguration(KSConfiguration conf){
+ public void propagateConfiguration(KSConfiguration conf) {
Zone tmpzone = openRandomNamedZone();
this.bboard.write(tmpzone, conf);
this.bboard.closeZone(tmpzone);
}
-
-
- public Set<SPARQLResult> executeQuery(SPARQLQuery query, KSExecutionContext context){
+
+ public Set<SPARQLResult> executeQuery(SPARQLQuery query,
+ KSExecutionContext context) {
+
+ return executeQuery(query, context, 0);
+ }
+
+ public Set<SPARQLResult> executeQuery(SPARQLQuery query,
+ KSExecutionContext context, int waitForCollection) {
Zone tmpzone = openRandomNamedZone();
- this.bboard.write(tmpzone, context.blackboard().read(new KindOfFilter(Chat.class)));
+ this.bboard.write(tmpzone, context.blackboard().read(
+ new KindOfFilter(Chat.class)));
this.bboard.write(tmpzone, query);
-
-
- Set resultset = this.bboard.readAll(new ExactZoneSelector(tmpzone), new KindOfFilter(SPARQLResult.class));
+ if (waitForCollection > 0) {
+ try {
+ Thread.sleep(waitForCollection);
+ } catch (InterruptedException e) {
+ log.error("Error: cant sleep");
+ }
+ }
- this.bboard.closeZone(tmpzone);
-
- return resultset;
+ Set resultset = this.bboard.readAll(new ExactZoneSelector(tmpzone),
+ new KindOfFilter(SPARQLResult.class));
+
+ this.bboard.closeZone(tmpzone);
+
+ return resultset;
}
- public Set<SPARQLResult> executeQuery(SPARQLQuery query){
+
+ public Set<SPARQLResult> executeQuery(SPARQLQuery query) {
Zone tmpzone = openRandomNamedZone();
this.bboard.write(tmpzone, query);
-
-
- Set resultset = this.bboard.readAll(new ExactZoneSelector(tmpzone), new KindOfFilter(SPARQLResult.class));
-
- this.bboard.closeZone(tmpzone);
-
- return resultset;
+ Set resultset = this.bboard.readAll(new ExactZoneSelector(tmpzone),
+ new KindOfFilter(SPARQLResult.class));
+
+ this.bboard.closeZone(tmpzone);
+
+ return resultset;
}
}
Modified: trunk/xOperator/src/net/sf/xoperator/blackboard/ThreadsafeTransientMemory.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/blackboard/ThreadsafeTransientMemory.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/blackboard/ThreadsafeTransientMemory.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -2,6 +2,7 @@
import java.io.Serializable;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -20,8 +21,8 @@
public class ThreadsafeTransientMemory implements BlackboardMemory,
SnapshottableMemory, Serializable {
- private Map<Zone, Set<Object>> zones = new ConcurrentHashMap<Zone, Set<Object>>();
-
+ //private Map<Zone, Set<Object>> zones = new ConcurrentHashMap<Zone, Set<Object>>();
+ private Map<Zone, Set<Object>> zones = Collections.synchronizedMap(new HashMap<Zone, Set<Object>>());
//private Map<Object, Zone> entries = new ConcurrentHashMap<Object, Zone>();
private Log log = LogFactory.getLog(ThreadsafeTransientMemory.class);
Modified: trunk/xOperator/src/net/sf/xoperator/rdfxmpp/SPARQLQuery.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/rdfxmpp/SPARQLQuery.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/rdfxmpp/SPARQLQuery.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -53,6 +53,8 @@
public final static String TXT_OUTPUT = "TXT";
public final static String P2P = "P2P";
+
+ private boolean localAsked = false;
private int htl = 1;
@@ -67,6 +69,12 @@
public List<String> getAgentsToAsk() {
return agentsToAsk;
}
+ public boolean isLocalAsked() {
+ return localAsked;
+ }
+ public void setLocalAsked(boolean localAsked) {
+ this.localAsked = localAsked;
+ }
private SPARQLResult result = null;
Modified: trunk/xOperator/src/net/sf/xoperator/startup/CommandLineMain.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/startup/CommandLineMain.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/startup/CommandLineMain.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -235,16 +235,29 @@
CommandLineMain main = new CommandLineMain();
main.startUp(args);
- int exit = 0;
+ Object obj = new Object();
try {
- while (exit!=-1) {
- exit = System.in.read();
+ synchronized (obj) {
+ obj.wait();
}
-
- } catch (IOException e) {
+
+ } catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+
+
+// int exit = 0;
+// try {
+// while (exit!=-1) {
+// //exit = System.in.read();
+//
+// }
+//
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
}
}
Modified: trunk/xOperator/src/net/sf/xoperator/ui/aiml/TemplateExectutionContext.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/ui/aiml/TemplateExectutionContext.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/ui/aiml/TemplateExectutionContext.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -51,12 +51,14 @@
List<SPARQLResultTableWrapper> results = new ArrayList<SPARQLResultTableWrapper>();
SPARQLQuery squery = new SPARQLQuery(query);
squery.setOutputType(SPARQLQuery.XML_OUTPUT);
- if (stores != null && !stores.isEmpty()) {
- squery.setStoresToAsk(stores);
- }
- if (agents != null && !agents.isEmpty()) {
- squery.setAgentsToAsk(agents);
- }
+// if (stores != null && !stores.isEmpty()) {
+// squery.setStoresToAsk(stores);
+// }
+// if (agents != null && !agents.isEmpty()) {
+// squery.setAgentsToAsk(agents);
+// }
+ squery.setStoresToAsk(stores);
+ squery.setAgentsToAsk(agents);
for (Object oresult : control.executeQuery(squery,context)) {
SPARQLResultTableWrapper wrappedResult = new SPARQLResultTableWrapper(
Modified: trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java
===================================================================
--- trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java 2008-01-17 20:28:15 UTC (rev 102)
+++ trunk/xOperator/src/net/sf/xoperator/xmpp/XMPPManager.java 2008-01-17 21:03:32 UTC (rev 103)
@@ -176,8 +176,14 @@
new KindOfFilter(Chat.class));
if (chat != null) {
- Set messages = context.blackboard().readAll(
+ Set mess = context.blackboard().readAll(
new KindOfFilter(MessageToUser.class));
+ List messages = new ArrayList<MessageToUser>();
+
+ for (Object object : mess) {
+ messages.add(object);
+ }
+
Set sendMsgNote = context.blackboard().readAll(
new KindOfFilter(MessageSend.class));
if (messages.size() > sendMsgNote.size()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|