KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > engine > FilterProxyConsumerTask


1 package org.jacorb.notification.engine;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import org.omg.CORBA.AnyHolder JavaDoc;
25 import org.omg.CosNotifyFilter.UnsupportedFilterableData;
26
27 /**
28  * @author Alphonse Bendt
29  * @version $Id: FilterProxyConsumerTask.java,v 1.15 2005/04/27 10:48:40 alphonse.bendt Exp $
30  */

31
32 public class FilterProxyConsumerTask extends AbstractFilterTask
33 {
34     private static int sCount = 0;
35     private int id_ = ++sCount;
36
37     private boolean orSemantic_ = false;
38
39     ////////////////////
40

41     public FilterProxyConsumerTask(TaskFactory factory, TaskExecutor executor) {
42         super(factory, executor);
43     }
44
45     ////////////////////
46

47     public String JavaDoc toString()
48     {
49         return "[FilterProxyConsumerTask#" + id_ + "]";
50     }
51
52
53     public void reset()
54     {
55         super.reset();
56
57         orSemantic_ = false;
58     }
59
60
61     /**
62      * access the Filter hint for next Stage. if the current
63      * FilterStage has InterFilterGroupOperator.OR_OP enabled and a
64      * filter matched the
65      * evaluation of the SupplierAdmin Filters can be skipped.
66      */

67     public boolean getSkip()
68     {
69         return orSemantic_;
70     }
71
72
73     /**
74      * match the attached Priority MappingFilter.
75      * the current Message is matched to the MappingFilter attached to
76      * the current FilterStage. In case of successful match
77      * operation the priority of the Messages is updated accordingly.
78      */

79     private void updatePriority()
80     {
81         try
82         {
83             AnyHolder JavaDoc newPriority = new AnyHolder JavaDoc();
84
85             boolean priorityMatch =
86                 getMessage().match( arrayCurrentFilterStage_[ 0 ].getPriorityFilter(),
87                                 newPriority );
88
89             if ( priorityMatch )
90             {
91                 getMessage().setPriority( newPriority.value.extract_long() );
92             }
93         }
94         catch ( UnsupportedFilterableData e )
95         {
96             logger_.error( "Error evaluating PriorityFilter", e );
97         }
98     }
99
100
101     /**
102      * match the attached Lifetime MappingFilter.
103      * the current Message is matched to the MappingFilter attached to
104      * the current FilterStage. In case of successful match
105      * operation the lifetime of the Messages is updated accordingly.
106      */

107     private void updateLifetime()
108     {
109         try
110         {
111             AnyHolder JavaDoc newLifetime = new AnyHolder JavaDoc();
112
113             boolean lifetimeMatch =
114                 getMessage().match( arrayCurrentFilterStage_[ 0 ].getLifetimeFilter(),
115                                 newLifetime );
116
117             if ( lifetimeMatch )
118             {
119                 getMessage().setTimeout( newLifetime.value.extract_long() );
120             }
121         }
122         catch ( UnsupportedFilterableData e )
123         {
124             logger_.error( "Error evaluating LifetimeFilter", e );
125         }
126     }
127
128
129     public void doFilter() throws InterruptedException JavaDoc
130     {
131         if ( arrayCurrentFilterStage_[ 0 ].hasPriorityFilter() )
132         {
133             updatePriority();
134         }
135
136         if ( arrayCurrentFilterStage_[ 0 ].hasLifetimeFilter() )
137         {
138             updateLifetime();
139         }
140
141         boolean _filterMatch = filter();
142
143         if ( !_filterMatch && arrayCurrentFilterStage_[ 0 ].hasInterFilterGroupOperatorOR() )
144         {
145             if ( logger_.isDebugEnabled() )
146             {
147                 logger_.debug( "filter failed, but the ProxyConsumer"
148                                + arrayCurrentFilterStage_[ 0 ]
149                                + " has InterFilterGroupOperator OR_OP Enabled" );
150             }
151
152             // no filter attached to the current ProxyConsumer
153
// matched. However the ProxyConsumer has
154
// InterFilterGroupOperator.OR_OP enabled. Therefor we
155
// have to continue processing because the Filters
156
// attached to the SupplierAdmin still may match.
157

158             addFilterStage( arrayCurrentFilterStage_[ 0 ].getSubsequentFilterStages() );
159         }
160
161         if ( !isFilterStageListEmpty() )
162         {
163             getTaskFactory().newFilterSupplierAdminTask( this ).schedule();
164         }
165     }
166
167     private boolean filter()
168     {
169         boolean _forward = false;
170
171         // eval attached filters
172
// as an Event passes only 1 ProxyConsumer we can assume
173
// constant array size here
174

175         _forward = getMessage().match( arrayCurrentFilterStage_[ 0 ] );
176
177         if ( _forward )
178         {
179             addFilterStage( arrayCurrentFilterStage_[ 0 ].getSubsequentFilterStages() );
180         }
181
182         // check if this destination has OR enabled
183
// if this is the case the filtering in the next run can be skipped
184
if ( arrayCurrentFilterStage_[ 0 ].hasInterFilterGroupOperatorOR() )
185         {
186             orSemantic_ = true;
187         }
188
189         return _forward;
190     }
191
192     public void schedule() throws InterruptedException JavaDoc {
193         // directRunAllowed is false here
194
// cause the calling thread is usually created by the ORB.
195
// exceptions are PullSuppliers.
196
schedule(false);
197     }
198 }
199
Popular Tags