001: /*
002: * Created on Dec 30, 2003
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl.manage;
008:
009: import java.util.*;
010:
011: import org.xdev.base.xssl.XSSLAction;
012: import org.xdev.base.xssl.XSSLReference;
013: import org.xdev.base.xssl.XSSLReturn;
014: import org.xdev.base.core.BASE;
015: import org.xdev.base.util.GuidGenerator;
016:
017: /**
018: * @author AYegorov
019: *
020: * To change the template for this generated type comment go to
021: * Window>Preferences>Java>Code Generation>Code and Comments
022: */
023: public class TransactionManager extends XSSLReference {
024: public static final String NAME = "name";
025: public static final String START_COMPONENT = "start";
026: public static final String STOP_COMPONENT = "stop";
027: public static final String MIN_INSTANCES = "min-instances";
028: public static final String MAX_INSTANCES = "max-instances";
029: public static final String AUTO_START = "auto-start";
030:
031: public static final int MIN_DEFAULT = 0;
032: public static final int MAX_DEFAULT = 1;
033:
034: protected static HashMap managers = new HashMap();
035:
036: protected boolean started = false;
037: protected boolean initialized = false;
038:
039: protected String name = null;
040:
041: protected String initMessage = null;
042: protected String startMessage = null;
043: protected String stopMessage = null;
044:
045: protected String guid = null;
046:
047: protected int min = 0;
048: protected int max = 1;
049:
050: protected ArrayList jobs = new ArrayList();
051:
052: /**
053: * @param id
054: */
055: public TransactionManager(String id) {
056: super (id);
057: // XXX Auto-generated constructor stub
058: }
059:
060: /**
061: * @param id
062: * @param properties
063: */
064: public TransactionManager(String id, HashMap properties) {
065: super (id, properties);
066: // XXX Auto-generated constructor stub
067: }
068:
069: /* (non-Javadoc)
070: * @see org.xdev.base.xssl.XSSLReference#processReference(java.lang.Object)
071: */
072: protected Object processReference(Object reference)
073: throws Exception {
074: Object obj = null;
075:
076: if (reference == null) {
077: this .min = this .setThreshold(
078: TransactionManager.MIN_INSTANCES,
079: TransactionManager.MIN_DEFAULT);
080: this .max = this .setThreshold(
081: TransactionManager.MAX_INSTANCES,
082: TransactionManager.MAX_DEFAULT);
083:
084: this .setReference(this );
085:
086: reference = this ;
087: }
088:
089: if (this .getCount() > 0) {
090: obj = this .getElement(0);
091:
092: ((TransactionManager) reference).addJob((XSSLAction) obj);
093: }
094:
095: return obj;
096: }
097:
098: protected void addJob(XSSLAction job) throws Exception {
099: if ((this .jobs.size() < this .max) && job.execute(this )) {
100: this .jobs.add(job);
101: } else {
102: throw new Exception("Job manager " + this .name
103: + " has exceeded its maximum job instance limit.");
104: }
105: }
106:
107: protected int setThreshold(String val, int def) {
108: int thresh = -1;
109:
110: try {
111: thresh = this .getIntegerProperty(val);
112: } catch (Exception ex) {
113: thresh = def;
114: }
115:
116: return thresh;
117: }
118: }
|