KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.jacorb.notification.interfaces.FilterStage;
29
30 /**
31  * @author Alphonse Bendt
32  * @version $Id: FilterConsumerAdminTask.java,v 1.18 2005/04/27 10:48:40 alphonse.bendt Exp $
33  */

34
35 public class FilterConsumerAdminTask extends AbstractFilterTask
36 {
37     private static int sCount = 0;
38
39     private int id_ = ++sCount;
40
41     /**
42      * this List contains FilterStages (ProxySuppliers) which have a MessageConsumer associated.
43      */

44     private final List JavaDoc listOfFilterStageWithMessageConsumer_ = new ArrayList JavaDoc();
45
46     ////////////////////////////////////////
47

48     public FilterConsumerAdminTask(TaskFactory taskFactory, TaskExecutor taskExecutor)
49     {
50         super(taskFactory, taskExecutor);
51     }
52
53     ////////////////////////////////////////
54

55     public String JavaDoc toString()
56     {
57         return "[FilterConsumerAdminTask#" + id_ + "]";
58     }
59
60     /**
61      * access the FilterStages that have a Event Consumer associated.
62      */

63     public FilterStage[] getFilterStagesWithMessageConsumer()
64     {
65         return (FilterStage[]) listOfFilterStageWithMessageConsumer_.toArray(EMPTY_FILTERSTAGE);
66     }
67
68     private void clearFilterStagesWithMessageConsumer()
69     {
70         listOfFilterStageWithMessageConsumer_.clear();
71     }
72
73     public void reset()
74     {
75         super.reset();
76
77         clearFilterStagesWithMessageConsumer();
78         arrayCurrentFilterStage_ = EMPTY_FILTERSTAGE;
79     }
80
81     public void doFilter() throws InterruptedException JavaDoc
82     {
83         filter();
84
85         pushToConsumers();
86     }
87
88     private void pushToConsumers() throws InterruptedException JavaDoc
89     {
90         // if we are filtering Outgoing events its
91
// possible that deliveries can be made as soon as
92
// the ConsumerAdmin Filters are eval'd
93
// (if InterFilterGroupOperator.OR_OP is set !)
94

95         FilterStage[] _filterStagesWithMessageConsumer = getFilterStagesWithMessageConsumer();
96
97         if (_filterStagesWithMessageConsumer.length > 0)
98         {
99             getTaskFactory()
100                     .enqueueMessage(_filterStagesWithMessageConsumer, getMessage());
101         }
102
103         Schedulable _filterTaskToBeScheduled = _filterTaskToBeScheduled = getTaskFactory()
104                 .newFilterProxySupplierTask(this);
105
106         _filterTaskToBeScheduled.schedule();
107     }
108
109     private void filter() throws InterruptedException JavaDoc
110     {
111         for (int x = 0; x < arrayCurrentFilterStage_.length; ++x)
112         {
113             checkInterrupt();
114
115             boolean _filterForCurrentFilterStageMatched = false;
116
117             if (!arrayCurrentFilterStage_[x].isDisposed())
118             {
119                 _filterForCurrentFilterStageMatched = getMessage().match(arrayCurrentFilterStage_[x]);
120             }
121
122             if (_filterForCurrentFilterStageMatched)
123             {
124                 if (arrayCurrentFilterStage_[x].hasInterFilterGroupOperatorOR())
125                 {
126                     // if the destinations
127
// InterFilterGroupOperator equals OR_OP
128
// we can add it to
129
// listOfFilterStageWithMessageConsumer_ as the
130
// corresponding filters dont need to be eval'd
131

132                     listOfFilterStageWithMessageConsumer_.addAll(arrayCurrentFilterStage_[x]
133                             .getSubsequentFilterStages());
134                 }
135                 else
136                 {
137                     // the Filters of the ProxySupplier need to be
138
// eval'd
139

140                     addFilterStage(arrayCurrentFilterStage_[x].getSubsequentFilterStages());
141                 }
142             }
143             else
144             {
145                 // no filter matched at all. we have to check all subsequent
146
// destinations if one of them has
147
// InterFilterGroupOperator.OR_OP enabled. In this
148
// Case add it to the list of ProxySupplier to be
149
// eval'd by the next task.
150

151                 Iterator JavaDoc _i = arrayCurrentFilterStage_[x].getSubsequentFilterStages().iterator();
152
153                 while (_i.hasNext())
154                 {
155                     FilterStage _filterStage = (FilterStage) _i.next();
156
157                     if (_filterStage.hasInterFilterGroupOperatorOR())
158                     {
159                         addFilterStage(_filterStage);
160                     }
161                 }
162             }
163         }
164     }
165 }
Popular Tags