[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl ...
Ben Wang
bwang at jboss.com
Sat Jan 13 10:55:06 EST 2007
User: bwang
Date: 07/01/13 10:55:06
Added: tests/functional/org/jboss/cache/pojo/test/propagation/impl
PropagationRuleFactory.java StateItemImpl.java
PropagationManagerImpl.java NodeImpl.java
AbstractPropagtionRule.java ORSummaryRule.java
Log:
JBCACHE-922 Merged src-50 and tests-50 into src and tests, respectively.
Revision Changes Path
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/PropagationRuleFactory.java
Index: PropagationRuleFactory.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.PropagationRule;
public class PropagationRuleFactory
{
public static PropagationRule getPropagationRule()
{
return new ORSummaryRule();
}
}
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/StateItemImpl.java
Index: StateItemImpl.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.PropagationRule;
import org.jboss.cache.pojo.test.propagation.StateItem;
public class StateItemImpl implements StateItem
{
private long itemId_;
private long state_;
public StateItemImpl()
{
}
public StateItemImpl(long itemId)
{
this.itemId_ = itemId;
this.state_ = PropagationRule.STATE_CLEAR;
}
public long getState()
{
return this.state_;
}
public boolean setState(long state)
{
if (this.state_ != state)
{
state_ = state;
return STATE_CHANGED;
} else
{
return STATE_NOT_CHANGED;
}
}
public long getItemId()
{
return this.itemId_;
}
public String toString()
{
return "Id: " + itemId_ + " state: " + state_ + "\n";
}
}
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/PropagationManagerImpl.java
Index: PropagationManagerImpl.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.Node;
import org.jboss.cache.pojo.test.propagation.PropagationManager;
import org.jboss.cache.pojo.test.propagation.PropagationRule;
import org.jboss.cache.pojo.test.propagation.StateItem;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PropagationManagerImpl implements PropagationManager
{
private Node rootNode_;
private Map nodeMap_ = new HashMap();
private transient PropagationRule orRule_;
public PropagationManagerImpl()
{
orRule_ = PropagationRuleFactory.getPropagationRule();
}
public void setRootNode(String rdn)
{
this.rootNode_ = new NodeImpl();
rootNode_.setNodeFDN(rdn);
rootNode_.setNodeRDN(rdn);
rootNode_.setPropagationRule(orRule_);
StateItem summary = new StateItemImpl(0);
summary.setState(PropagationRule.STATE_CLEAR);
rootNode_.setSummaryStateItem(summary);
registMap(rootNode_);
}
public void addNode(String parentFdn, String rdn)
{
Node parent = findNode(parentFdn);
if (parent != null)
{
Node node = new NodeImpl();
node.setNodeFDN(parentFdn + "." + rdn);
node.setNodeRDN(rdn);
node.setPropagationRule(orRule_);
node.setParentNode(parent);
parent.addChildNode(node);
StateItem summary = new StateItemImpl(0);
summary.setState(PropagationRule.STATE_CLEAR);
node.setSummaryStateItem(summary);
registMap(node);
PropagationRule rule = node.getPropagationRule();
rule.summaryUpperPropagate(node);
}
}
public void addStateItem(String parentFdn, long itemId, long defaultState)
{
Node node = findNode(parentFdn);
if (node != null)
{
StateItem item = new StateItemImpl(itemId);
item.setState(defaultState);
node.addStateItem(item);
PropagationRule rule = node.getPropagationRule();
rule.summaryUpperPropagate(node);
}
}
public void stateChange(String parentFdn, long itemId, long newState)
{
Node node = findNode(parentFdn);
if (node != null)
{
PropagationRule rule = node.getPropagationRule();
rule.changeState(node, itemId, newState);
}
}
public Node findNode(String fdn)
{
return (Node) nodeMap_.get(fdn);
}
private void registMap(Node node)
{
this.nodeMap_.put(node.getNodeFDN(), node);
}
public void printNodes()
{
printNode(rootNode_, "");
}
private void printNode(Node node, String prefix)
{
System.out.println(prefix + node.getNodeRDN() + " (Summary : "
+ node.getSummaryStateItem().getState() + ")");
String itemPrefix = prefix + " | ";
List items = node.getStateItems();
int size = items.size();
for (int idx = 0; idx < size; idx++)
{
StateItem item = (StateItem) items.get(idx);
printStateItem(item, itemPrefix);
}
String childPrefix = prefix + " + ";
List children = node.getChildren();
size = children.size();
for (int idx = 0; idx < size; idx++)
{
Node child = (Node) children.get(idx);
printNode(child, childPrefix);
}
}
private void printStateItem(StateItem item, String prefix)
{
System.out.println(prefix + "(" + item.getItemId() + " : "
+ item.getState() + ")");
}
private String toNodeString(Node node, String prefix)
{
StringBuffer buf = new StringBuffer();
buf.append(prefix + node.getNodeRDN() + " (Summary : "
+ node.getSummaryStateItem().getState() + ")");
String itemPrefix = prefix + " | ";
List items = node.getStateItems();
int size = items.size();
for (int idx = 0; idx < size; idx++)
{
StateItem item = (StateItem) items.get(idx);
buf.append(toStateItemString(item, itemPrefix));
}
String childPrefix = prefix + " + ";
List children = node.getChildren();
size = children.size();
for (int idx = 0; idx < size; idx++)
{
Node child = (Node) children.get(idx);
buf.append(toNodeString(child, childPrefix));
}
return buf.toString();
}
private String toStateItemString(StateItem item, String prefix)
{
return (prefix + "(" + item.getItemId() + " : "
+ item.getState() + ")");
}
public String toString()
{
return toNodeString(rootNode_, "+");
}
}
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/NodeImpl.java
Index: NodeImpl.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.Node;
import org.jboss.cache.pojo.test.propagation.PropagationRule;
import org.jboss.cache.pojo.test.propagation.StateItem;
import java.util.ArrayList;
import java.util.List;
public class NodeImpl implements Node
{
private String rdn_;
private String fdn_;
private List childNodes_ = new ArrayList();
private Node parentNode_;
private List stateItems_ = new ArrayList();
private StateItem summaryItem_;
private transient PropagationRule rule_;
public NodeImpl()
{
rule_ = PropagationRuleFactory.getPropagationRule();
}
public void setNodeRDN(String rdn)
{
this.rdn_ = rdn;
}
public String getNodeRDN()
{
return this.rdn_;
}
public void setNodeFDN(String fdn)
{
this.fdn_ = fdn;
}
public String getNodeFDN()
{
return this.fdn_;
}
public void addChildNode(Node child)
{
childNodes_.add(child);
}
public List getChildren()
{
return childNodes_;
}
public void setParentNode(Node parent)
{
parentNode_ = parent;
}
public Node getParentNode()
{
return this.parentNode_;
}
public void addStateItem(StateItem stateItem)
{
stateItems_.add(stateItem);
}
public void setSummaryStateItem(StateItem stateItem)
{
this.summaryItem_ = stateItem;
}
public StateItem getSummaryStateItem()
{
return this.summaryItem_;
}
public void setPropagationRule(PropagationRule rule)
{
this.rule_ = rule;
}
public PropagationRule getPropagationRule()
{
return rule_;
}
public List getStateItems()
{
return this.stateItems_;
}
public StateItem findStateItem(long itemId)
{
StateItem retItem = null;
int size = stateItems_.size();
for (int idx = 0; idx < size; idx++)
{
StateItem stateItem = (StateItem) stateItems_.get(idx);
if (stateItem.getItemId() == itemId)
{
retItem = stateItem;
break;
}
}
return retItem;
}
public String toString()
{
return getNodeFDN();
}
}
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/AbstractPropagtionRule.java
Index: AbstractPropagtionRule.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.Node;
import org.jboss.cache.pojo.test.propagation.PropagationRule;
import org.jboss.cache.pojo.test.propagation.StateItem;
public abstract class AbstractPropagtionRule implements PropagationRule
{
public void changeState(Node node, long itemId, long state)
{
StateItem target = node.findStateItem(itemId);
if (target == null)
{
System.out.println("[Error] StateItem not found. : " + node + ":"
+ itemId);
return;
}
if (StateItem.STATE_CHANGED == target.setState(state))
{
summaryUpperPropagate(node);
}
}
protected void upperPropagate(Node node)
{
Node parentNode = (Node) node.getParentNode();
if (parentNode != null)
{
PropagationRule parentRule = parentNode.getPropagationRule();
parentRule.summaryUpperPropagate(parentNode);
}
}
protected boolean isClear(StateItem item)
{
long state = item.getState();
if ((state % 10) == 0)
{
return true;
} else
{
return false;
}
}
protected long getSeverity(StateItem item)
{
long state = item.getState();
long severity = 0;
if (isSummaryItem(item))
{
severity = state % 1000;
} else
{
severity = (state % 1000) / 10;
}
return severity;
}
protected boolean isSummaryItem(StateItem item)
{
long state = item.getState();
long summaryDigit = (state / 1000) % 10;
if (summaryDigit == 2)
{
return true;
} else
{
return false;
}
}
protected long updateMaxSeverity(long maxSeverity, StateItem stateItem)
{
if (!isClear(stateItem))
{
long severity = getSeverity(stateItem);
if (severity > maxSeverity)
{
maxSeverity = severity;
}
}
return maxSeverity;
}
}
1.1 date: 2007/01/13 15:55:06; author: bwang; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/propagation/impl/ORSummaryRule.java
Index: ORSummaryRule.java
===================================================================
package org.jboss.cache.pojo.test.propagation.impl;
import org.jboss.cache.pojo.test.propagation.Node;
import org.jboss.cache.pojo.test.propagation.StateItem;
import java.util.List;
public class ORSummaryRule extends AbstractPropagtionRule
{
private static final String RULE_NAME = "OR-Rule";
public void summaryUpperPropagate(Node node)
{
long maxSeverity = 0;
List stateItems = node.getStateItems();
int size = stateItems.size();
for (int idx = 0; idx < size; idx++)
{
StateItem stateItem = (StateItem) stateItems.get(idx);
maxSeverity = updateMaxSeverity(maxSeverity, stateItem);
}
List childNodes = node.getChildren();
size = childNodes.size();
for (int idx = 0; idx < size; idx++)
{
Node child = (Node) childNodes.get(idx);
StateItem childSummary = child.getSummaryStateItem();
maxSeverity = updateMaxSeverity(maxSeverity, childSummary);
}
long summaryState = STATE_CLEAR + maxSeverity;
StateItem summaryItem = node.getSummaryStateItem();
boolean isSummaryChanged = summaryItem.setState(summaryState);
if (StateItem.STATE_CHANGED == isSummaryChanged)
{
upperPropagate(node);
}
}
public String toString()
{
return RULE_NAME;
}
}
More information about the jboss-cvs-commits
mailing list