001: package org.xdev.base.xssl.manage;
002:
003: import java.util.HashMap;
004: import java.util.ArrayList;
005:
006: import org.xdev.base.xssl.XSSLAction;
007: import org.xdev.base.xssl.XSSLActionIterator;
008:
009: /**
010: * @author hneiper
011: *
012: * To change the template for this generated type comment go to
013: * Window - Preferences - Java - Code Generation - Code and Comments
014: */
015: public class TransactionThreadGroup extends XSSLActionIterator {
016: public static final int ALL = 0;
017: public static final int ID = 1;
018: public static final int INDEX = 2;
019:
020: private ArrayList group = new ArrayList();
021:
022: private HashMap indexedGroup = new HashMap();
023:
024: /**
025: * @param id
026: */
027: public TransactionThreadGroup(String id) {
028: super (id);
029: // TODO Auto-generated constructor stub
030: }
031:
032: /**
033: * @param id
034: * @param properties
035: */
036: public TransactionThreadGroup(String id, HashMap properties) {
037: super (id, properties);
038: // TODO Auto-generated constructor stub
039: }
040:
041: /* (non-Javadoc)
042: * @see org.xdev.base.xssl.XSSLActionIterator#invoke(org.xdev.base.xssl.XSSLAction)
043: */
044: protected void invoke(XSSLAction component) throws Exception {
045:
046: if (component instanceof ITransactionInterruptable) {
047:
048: this .group.add(component.getProperty("thread-name"));
049:
050: this .indexedGroup.put(component.getProperty("thread-name"),
051: component);
052: }
053: }
054:
055: protected Object executeIteratingElement(XSSLAction c,
056: boolean lastElement) throws Exception {
057: c.start();
058:
059: return null;
060: }
061:
062: /* (non-Javadoc)
063: * @see org.xdev.base.xssl.XSSLAction#set()
064: */
065: protected void set() throws Exception {
066: if (this .getBooleanProperty("interrupt")) {
067:
068: TransactionThreadGroup thGroup = (TransactionThreadGroup) this
069: .getReference();
070:
071: switch (this .getIntegerProperty("interrupt-scope")) {
072: case TransactionThreadGroup.ALL:
073:
074: thGroup.interruptAll();
075:
076: break;
077: case TransactionThreadGroup.ID:
078:
079: thGroup.interruptSingleById(this
080: .getProperty("thread-name"));
081:
082: break;
083: case TransactionThreadGroup.INDEX:
084:
085: thGroup.interruptSingleByIndex(this
086: .getIntegerProperty("thread-index"));
087:
088: break;
089: }
090: }
091: }
092:
093: public void interruptAll() throws Exception {
094: while (!this .group.isEmpty()) {
095: this .interruptSingleByIndex(0);
096: }
097: }
098:
099: public void interruptSingleById(String id) throws Exception {
100: ITransactionInterruptable iTx = (ITransactionInterruptable) this .indexedGroup
101: .remove(id);
102:
103: iTx.interrupt();
104: }
105:
106: public void interruptSingleByIndex(int index) throws Exception {
107: this .interruptSingleById((String) this.group.remove(index));
108: }
109: }
|