View Javadoc
1 /* ====================================================================
2 * License:
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. The end-user documentation included with the redistribution,
17 * if any, must include the following acknowledgment:
18 * "This product includes software developed by
19 * Robert Half International (http://www.rhi.com/)."
20 * Alternately, this acknowledgment may appear in the software itself,
21 * if and wherever such third-party acknowledgments normally appear.
22 *
23 * 4. The names "Parc", "RHI", and "Robert Half International" must
24 * not be used to endorse or promote products derived from this
25 * software without prior written permission. For written
26 * permission, please contact pete.mckinstry@rhi.com.
27 *
28 * 5. Products derived from this software may not be called "PARC",
29 * nor may "PARC" appear in their name, without prior written
30 * permission of Robert Half International.
31 *
32 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
33 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
36 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
42 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 * ====================================================================
45 *
46 */
47 package com.rhi.architecture.parc;
48
49 import java.util.Collection;
50
51 /***
52 * The AbstractFilter provides a partially implemented
53 * Filter allowing simpler concrete Filter objects. It
54 * deals w/ thread safe exit logic, and idle cycle
55 * detection as well as providing the required hooks for
56 * pre & post channel hookup. All concrete filter
57 * processing is deferred to a doWork() abstract method.
58 * <p/>
59 * Note: a simple run() method is provided to support
60 * the Runnable Interface.
61 *
62 * @deprecated Use one of the filters in the parc.filter sub-package.
63 *
64 * @author Pete McKinstry
65 * @copyright 2002, Robert Half Int'l., Inc. All rights reserved.
66 *
67 * @since 1.0
68 */
69 public abstract class AbstractFilter
70 extends com.rhi.architecture.parc.filter.AbstractFilter {
71
72 /***
73 * Push a collection of records through the filter.
74 * <br />
75 * Details: The AbstractFilter processes records w/in
76 * a dependent loop. The exit criteria for the loop
77 * is the markForDeath() flag which should be set by
78 * the pipeline, _and_ an empty processing cycle. This
79 * allows the Strategy to flush the Pipeline w/o knowing
80 * much about the inner workings of the Filter. While
81 * this criteria is false, the Filter does this:
82 * (pseudo-code)
83 * <code>
84 * InboundChannel.pull();
85 * doWork() <abstract>
86 * OutboundChannel.push();
87 * </code>
88 * <p/>
89 * This method must be threadsafe as it is the
90 * fundamental multi-processing hook in the framework.
91 *
92 * @throws ProcessingException
93 * @since 1.0
94 */
95 public void process() throws ProcessingException {
96 int record_count = 0;
97 long totalTime = 0;
98 while (true) {
99 Collection in = getInbound().pull(getMaxRecords());
100 int size = in.size();
101 if (size > 0) {
102 if (log().isDebugEnabled()) {
103 log().debug(
104 "filer::process() cycle detected for "
105 + "Filter: <"
106 + getName()
107 + ">, "
108 + "thread = "
109 + Thread.currentThread().getName());
110 }
111 record_count += in.size();
112 long startTime = System.currentTimeMillis();
113 Collection out = doWork(in);
114 long endTime = System.currentTimeMillis();
115 totalTime = totalTime + endTime - startTime;
116 getOutbound().push(out);
117 }
118 else {
119 log().debug(
120 "filter::process() idle cycle for "
121 + "Filter: <"
122 + getName()
123 + ">, "
124 + "thread="
125 + Thread.currentThread().getName());
126 // Marked for death _&_ hit an idle cycle, quit.
127 if (isShutdown()) { // volatile, therefore threadsafe.
128 break;
129 }
130 // rest if you were just idle & let the busy threads work.
131 try {
132 Thread.sleep(1000);
133 // Thread.yield();
134 }
135 catch (InterruptedException ie) {
136 // continue
137 }
138
139 } // else
140
141 // if another thread has detected a fatal error, exit immediately.
142 if (getExceptionHandler().hasError()) {
143 break;
144 }
145
146 } // while loop
147
148 if (stats().isInfoEnabled()) {
149 stats().info(
150 "Filter <"
151 + getName()
152 + "> processed "
153 + record_count
154 + " records in "
155 + totalTime
156 + " milliseconds");
157 }
158 return;
159 }
160
161 }
This page was automatically generated by Maven