001: package org.drools.common;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.drools.reteoo.ReteTuple;
020: import org.drools.rule.Rule;
021: import org.drools.spi.Activation;
022: import org.drools.spi.PropagationContext;
023: import org.drools.util.ObjectHashMap;
024: import org.drools.util.TupleHashTable;
025:
026: public class PropagationContextImpl implements PropagationContext {
027: private final int type;
028:
029: private Rule rule;
030:
031: private Activation activation;
032:
033: private final long propagationNumber;
034:
035: public final int activeActivations;
036:
037: public final int dormantActivations;
038:
039: public ObjectHashMap retracted;
040:
041: public PropagationContextImpl(final long number, final int type,
042: final Rule rule, final Activation activation) {
043: this .type = type;
044: this .rule = rule;
045: this .activation = activation;
046: this .propagationNumber = number;
047: this .activeActivations = 0;
048: this .dormantActivations = 0;
049: }
050:
051: public PropagationContextImpl(final long number, final int type,
052: final Rule rule, final Activation activation,
053: final int activeActivations, final int dormantActivations) {
054: this .type = type;
055: this .rule = rule;
056: this .activation = activation;
057: this .propagationNumber = number;
058: this .activeActivations = activeActivations;
059: this .dormantActivations = dormantActivations;
060: }
061:
062: public long getPropagationNumber() {
063: return this .propagationNumber;
064: }
065:
066: /*
067: * (non-Javadoc)
068: *
069: * @see org.drools.reteoo.PropagationContext#getRuleOrigin()
070: */
071: public Rule getRuleOrigin() {
072: return this .rule;
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.drools.reteoo.PropagationContext#getActivationOrigin()
079: */
080: public Activation getActivationOrigin() {
081: return this .activation;
082: }
083:
084: /*
085: * (non-Javadoc)
086: *
087: * @see org.drools.reteoo.PropagationContext#getType()
088: */
089: public int getType() {
090: return this .type;
091: }
092:
093: public int getActiveActivations() {
094: return this .activeActivations;
095: }
096:
097: public int getDormantActivations() {
098: return this .dormantActivations;
099: }
100:
101: public void addRetractedTuple(final Rule rule,
102: final Activation activation) {
103: if (this .retracted == null) {
104: this .retracted = new ObjectHashMap();
105: }
106:
107: ReteTuple tuple = (ReteTuple) activation.getTuple();
108:
109: ObjectHashMap tuples = (ObjectHashMap) this .retracted.get(rule);
110: if (tuples == null) {
111: tuples = new ObjectHashMap();
112: this .retracted.put(rule, tuples);
113: }
114: tuples.put(tuple, activation);
115: }
116:
117: public Activation removeRetractedTuple(final Rule rule,
118: final ReteTuple tuple) {
119: if (this .retracted == null) {
120: return null;
121: }
122:
123: final ObjectHashMap tuples = (ObjectHashMap) this .retracted
124: .get(rule);
125: if (tuples != null) {
126: return (Activation) tuples.remove(tuple);
127: } else {
128: return null;
129: }
130: }
131:
132: public void clearRetractedTuples() {
133: this .retracted = null;
134: }
135:
136: public void releaseResources() {
137: this.activation = null;
138: this.retracted = null;
139: this.rule = null;
140: }
141: }
|