001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.thread;
028:
029: import java.util.Comparator;
030:
031: import org.cougaar.core.service.ThreadControlService;
032: import org.cougaar.util.UnaryPredicate;
033:
034: /**
035: * The implementation of {@link ThreadControlService}. Most of the
036: * real work happens in the {@link TreeNode} or the {@link Schedulable}
037: * for the corresponding {@link ThreadService}.
038: */
039: class ThreadControlServiceProxy implements ThreadControlService {
040: private TreeNode node;
041:
042: ThreadControlServiceProxy(TreeNode node) {
043: this .node = node;
044: }
045:
046: public int getDefaultLane() {
047: return node.getDefaultLane();
048: }
049:
050: public void setDefaultLane(int lane) {
051: node.setDefaultLane(lane);
052: }
053:
054: private void validateLane(int lane) {
055: if (lane < 0 || lane >= node.getLaneCount())
056: throw new RuntimeException("Lane is out of range: " + lane);
057: }
058:
059: public void setMaxRunningThreadCount(int count, int lane) {
060: validateLane(lane);
061: node.getScheduler(lane).setMaxRunningThreadCount(count);
062: }
063:
064: public void setQueueComparator(Comparator<Schedulable> comparator,
065: int lane) {
066: validateLane(lane);
067: node.getScheduler(lane).setQueueComparator(comparator);
068: }
069:
070: public void setRightsSelector(RightsSelector selector, int lane) {
071: validateLane(lane);
072: node.getScheduler(lane).setRightsSelector(selector);
073: }
074:
075: public boolean setQualifier(UnaryPredicate predicate, int lane) {
076: validateLane(lane);
077: return node.getScheduler(lane).setQualifier(predicate);
078: }
079:
080: public boolean setChildQualifier(UnaryPredicate predicate, int lane) {
081: validateLane(lane);
082: return node.getScheduler(lane).setChildQualifier(predicate);
083: }
084:
085: public int runningThreadCount(int lane) {
086: validateLane(lane);
087: return node.getScheduler(lane).runningThreadCount();
088: }
089:
090: public int pendingThreadCount(int lane) {
091: validateLane(lane);
092: return node.getScheduler(lane).pendingThreadCount();
093: }
094:
095: public int activeThreadCount(int lane) {
096: validateLane(lane);
097: return node.getScheduler(lane).activeThreadCount();
098: }
099:
100: public int maxRunningThreadCount(int lane) {
101: validateLane(lane);
102: return node.getScheduler(lane).maxRunningThreadCount();
103: }
104:
105: public void setMaxRunningThreadCount(int count) {
106: setMaxRunningThreadCount(count, node.getDefaultLane());
107: }
108:
109: public void setQueueComparator(Comparator<Schedulable> comparator) {
110: setQueueComparator(comparator, node.getDefaultLane());
111: }
112:
113: public void setRightsSelector(RightsSelector selector) {
114: setRightsSelector(selector, node.getDefaultLane());
115: }
116:
117: public boolean setQualifier(UnaryPredicate predicate) {
118: return setQualifier(predicate, node.getDefaultLane());
119: }
120:
121: public boolean setChildQualifier(UnaryPredicate predicate) {
122: return setChildQualifier(predicate, node.getDefaultLane());
123: }
124:
125: public int runningThreadCount() {
126: return runningThreadCount(node.getDefaultLane());
127: }
128:
129: public int pendingThreadCount() {
130: return pendingThreadCount(node.getDefaultLane());
131: }
132:
133: public int activeThreadCount() {
134: return activeThreadCount(node.getDefaultLane());
135: }
136:
137: public int maxRunningThreadCount() {
138: return maxRunningThreadCount(node.getDefaultLane());
139: }
140:
141: }
|