[CJ-dev] commonjava-projects/commonjava-bgthreads/src/java/org/commonjava/bgthreads/config BGService
Brought to you by:
johnqueso
From: <joh...@co...> - 2004-02-16 06:42:33
|
Update of /cvsroot/commonjava/commonjava-projects/commonjava-bgthreads/src/java/org/commonjava/bgthreads/config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27538/src/java/org/commonjava/bgthreads/config Added Files: BGServiceMgrConfigParser.java BGServiceMgrConfig.java Log Message: added OPL configuration support, and renamed the project to simply be Background Threads. --- NEW FILE: BGServiceMgrConfigParser.java --- /* Created on Feb 16, 2004 */ package org.commonjava.bgthreads.config; import org.commonjava.config.snapin.SnapInContainer; import org.commonjava.opl.ElementInfo; import org.commonjava.opl.NodeParser; import org.commonjava.opl.OPLContext; import org.commonjava.opl.ParseException; import org.commonjava.util.Strings; /** Parser to instantiate a background service manager's configuration. * @author John Casey */ public class BGServiceMgrConfigParser extends NodeParser { private static final String WAIT_MILLIS = "waitMillis"; private static final String JOIN_MILLIS = "joinMillis"; private static final String MAX_RUNNING = "maxRunning"; private static final String MAX_PENDING = "maxPending"; private BGServiceMgrConfig config = new BGServiceMgrConfig(); /** Create a new background service manager configuration parser * @param context the parse context * @param parent the parent parser */ public BGServiceMgrConfigParser(OPLContext context, NodeParser parent) { super(context, parent); } /** Create a new background service manager configuration parser * @param context the parse context */ public BGServiceMgrConfigParser(OPLContext context) { super(context); } /** Extract wait and join millis, along with max running and pending, and set each if it is not * null on the embedded configuration object. Then, retrieve the ancestor SnapInContainer impl, * and add the embedded configuration object as a new snap-in. * * @param element The element representation from which to extract attribute values. * @param bodyText the text of this element's body. * @see org.commonjava.opl.NodeParser#doAfterChildren(org.commonjava.opl.ElementInfo, java.lang.String) */ protected void doAfterChildren(ElementInfo element, String bodyText) throws ParseException { Long wait = Strings.toLong(getAttribute(WAIT_MILLIS, element, true)); if(wait != null){config.setWaitMillis(wait.longValue());} Long join = Strings.toLong(getAttribute(JOIN_MILLIS, element, true)); if(join != null){config.setJoinMillis(join.longValue());} Integer run = Strings.toInteger(getAttribute(MAX_RUNNING, element, true)); if(run != null){config.setMaxRunning(run.intValue());} Integer pend = Strings.toInteger(getAttribute(MAX_PENDING, element, true)); if(pend != null){config.setMaxPending(pend.intValue());} SnapInContainer container = (SnapInContainer)findAncestorOfType(SnapInContainer.class); container.addSnapIn(config); } } --- NEW FILE: BGServiceMgrConfig.java --- /* Created on Feb 16, 2004 */ package org.commonjava.bgthreads.config; import org.commonjava.config.snapin.ConfigSnapIn; /** Configuration class for the background service manager. * @author John Casey */ public class BGServiceMgrConfig implements ConfigSnapIn { public static final String SNAP_IN_ID = BGServiceMgrConfig.class.getName(); public static final long DEFAULT_WAIT_MILLIS = 100; public static final long DEFAULT_JOIN_MILLIS = 1000; public static final int DEFAULT_MAX_PENDING = 10; public static final int DEFAULT_MAX_RUNNING = 5; private long waitMillis = DEFAULT_WAIT_MILLIS; private long joinMillis = DEFAULT_JOIN_MILLIS; private int maxPending = DEFAULT_MAX_PENDING; private int maxRunning = DEFAULT_MAX_RUNNING; /** Create a new configuration object. */ public BGServiceMgrConfig() { } /** Retrieve the snap-in unique id for this configuration class. */ public String getSnapInId() { return SNAP_IN_ID; } /** Return the duration in millis to wait for a join to complete */ public long getJoinMillis() { return joinMillis; } /** Return the maximum of pending threads in the thread throttle controlled by the * background service manager. */ public int getMaxPending() { return maxPending; } /** Return the maximum of pending threads in the thread throttle controlled by the * background service manager. */ public int getMaxRunning() { return maxRunning; } /** Return the duration in millis to wait for a thread to free up in the thread throttle */ public long getWaitMillis() { return waitMillis; } /** Set the duration in millis to wait for a join to complete */ public void setJoinMillis(long l) { joinMillis = l; } /** Set the maximum of pending threads in the thread throttle controlled by the * background service manager. */ public void setMaxPending(int i) { maxPending = i; } /** Set the maximum of pending threads in the thread throttle controlled by the * background service manager. */ public void setMaxRunning(int i) { maxRunning = i; } /** Return the duration in millis to wait for a thread to free up in the thread throttle */ public void setWaitMillis(long l) { waitMillis = l; } } |