EMMA Coverage Report (generated Tue May 01 18:46:53 CEST 2007)
[all classes][dk.deepthought.sidious.goalhandler]

COVERAGE SUMMARY FOR SOURCE FILE [GoalHandlerEngine.java]

nameclass, %method, %block, %line, %
GoalHandlerEngine.java100% (1/1)100% (6/6)56%  (54/97)78%  (18/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GoalHandlerEngine100% (1/1)100% (6/6)56%  (54/97)78%  (18/23)
getTopPriorityGoal (SuperLinkID): Goal 100% (1/1)35%  (23/66)58%  (7/12)
<static initializer> 100% (1/1)100% (8/8)100% (2/2)
GoalHandlerEngine (): void 100% (1/1)100% (5/5)100% (2/2)
getInstance (): GoalHandler 100% (1/1)100% (2/2)100% (1/1)
process (SuperLinkID): void 100% (1/1)100% (12/12)100% (4/4)
request (SuperLinkID): void 100% (1/1)100% (4/4)100% (2/2)

1package dk.deepthought.sidious.goalhandler;
2 
3import java.util.PriorityQueue;
4 
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7 
8import dk.deepthought.sidious.ruleengine.RuleEngine;
9import dk.deepthought.sidious.supportsystem.Repository;
10import dk.deepthought.sidious.supportsystem.SuperLinkID;
11import dk.deepthought.sidious.supportsystem.SystemSettings;
12import dk.deepthought.sidious.util.SidiousQueue;
13 
14/**
15 * This class prioritizes goals and chooses which are to be sent to the
16 * <code>BlackBoard</code>.
17 * <p>
18 * The class extends the sidious queue and process goals asynchronously.
19 * 
20 * @author Deepthought
21 * 
22 */
23public class GoalHandlerEngine extends SidiousQueue<SuperLinkID> implements
24                GoalHandler {
25        /**
26         * Logger for this class
27         */
28        private static final Log logger = LogFactory
29                        .getLog(GoalHandlerEngine.class);
30 
31        /**
32         * Private Singleton instance.
33         */
34        private static final GoalHandler INSTANCE = new GoalHandlerEngine();
35 
36        /**
37         * Private constructor to facilitate singleton property.
38         */
39        private GoalHandlerEngine() {
40                super(GoalHandlerEngine.class.getSimpleName());
41        }
42 
43        /*
44         * (non-Javadoc)
45         * 
46         * @see dk.deepthought.sidious.goalhandler.GoalHandler#getTopPriorityGoal(dk.deepthought.sidious.supportsystem.SuperLinkID)
47         */
48        public Goal getTopPriorityGoal(SuperLinkID id) {
49                if (logger.isDebugEnabled()) {
50                        logger.debug("getTopPriorityGoal(SuperLinkID id=" + id
51                                        + ") - start");
52                }
53                RuleEngine ruleEngine = Repository.getRuleEngine();
54                PriorityQueue<Goal> queue = new PriorityQueue<Goal>(ruleEngine
55                                .extractGoals(id));
56                if (queue == null) {
57                        if (logger.isDebugEnabled()) {
58                                logger.debug("getTopPriorityGoal(SuperLinkID id=" + id
59                                                + ") - end - return value=null");
60                        }
61                        return null;
62                }
63                Goal returnGoal = queue.peek();
64                if (logger.isDebugEnabled()) {
65                        logger.debug("getTopPriorityGoal(SuperLinkID id=" + id
66                                        + ") - end - return value=" + returnGoal);
67                }
68                return returnGoal;
69        }
70 
71        /**
72         * Returns the singleton instance of this goal handler.
73         * 
74         * @return the singleton instance
75         */
76        public static GoalHandler getInstance() {
77                return INSTANCE;
78        }
79 
80        /*
81         * (non-Javadoc)
82         * 
83         * @see dk.deepthought.sidious.goalhandler.GoalHandler#request(dk.deepthought.sidious.supportsystem.SuperLinkID)
84         */
85        public final void request(SuperLinkID id) {
86                enqueue(id);
87        }
88 
89        /*
90         * (non-Javadoc)
91         * 
92         * @see dk.deepthought.sidious.util.SidiousQueue#process(java.lang.Object)
93         */
94        @Override
95        protected void process(SuperLinkID item) {
96                Goal goal = getTopPriorityGoal(item);
97                if (goal != null && !SystemSettings.isTestMode()) {
98                        Repository.getBlackboard().deliverResult(goal);
99                }
100        }
101 
102}

[all classes][dk.deepthought.sidious.goalhandler]
EMMA 2.0.5312 (C) Vladimir Roubtsov