KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > servant > SequenceProxyPullSupplierImpl


1 package org.jacorb.notification.servant;
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.List JavaDoc;
25
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.apache.avalon.framework.configuration.ConfigurationException;
28 import org.jacorb.notification.OfferManager;
29 import org.jacorb.notification.SubscriptionManager;
30 import org.jacorb.notification.engine.TaskProcessor;
31 import org.jacorb.notification.interfaces.Message;
32 import org.jacorb.notification.interfaces.MessageConsumer;
33 import org.jacorb.notification.util.CollectionsWrapper;
34 import org.omg.CORBA.BooleanHolder JavaDoc;
35 import org.omg.CORBA.ORB JavaDoc;
36 import org.omg.CosEventChannelAdmin.AlreadyConnected;
37 import org.omg.CosEventComm.Disconnected;
38 import org.omg.CosNotification.StructuredEvent;
39 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
40 import org.omg.CosNotifyChannelAdmin.ProxyType;
41 import org.omg.CosNotifyChannelAdmin.SequenceProxyPullSupplierOperations;
42 import org.omg.CosNotifyChannelAdmin.SequenceProxyPullSupplierPOATie;
43 import org.omg.CosNotifyComm.SequencePullConsumer;
44 import org.omg.PortableServer.POA JavaDoc;
45 import org.omg.PortableServer.Servant JavaDoc;
46
47 /**
48  * @author Alphonse Bendt
49  * @version $Id: SequenceProxyPullSupplierImpl.java,v 1.12 2005/04/27 10:45:46 alphonse.bendt Exp $
50  */

51
52 public class SequenceProxyPullSupplierImpl extends StructuredProxyPullSupplierImpl implements
53         SequenceProxyPullSupplierOperations
54 {
55     private static final StructuredEvent[] UNDEFINED_SEQUENCE;
56
57     ////////////////////////////////////////
58

59     static
60     {
61         UNDEFINED_SEQUENCE = new StructuredEvent[] { UNDEFINED_STRUCTURED_EVENT };
62     }
63
64     ////////////////////////////////////////
65

66     private SequencePullConsumer sequencePullConsumer_;
67
68     ////////////////////////////////////////
69

70     public SequenceProxyPullSupplierImpl(IAdmin admin, ORB JavaDoc orb, POA JavaDoc poa, Configuration conf,
71             TaskProcessor taskProcessor, OfferManager offerManager, SubscriptionManager subscriptionManager, ConsumerAdmin consumerAdmin) throws ConfigurationException
72     {
73         super(admin, orb, poa, conf, taskProcessor, offerManager, subscriptionManager, consumerAdmin);
74     }
75
76     public ProxyType MyType()
77     {
78         return ProxyType.PULL_SEQUENCE;
79     }
80
81     public void connect_sequence_pull_consumer(SequencePullConsumer consumer)
82             throws AlreadyConnected
83     {
84         checkIsNotConnected();
85
86         connectClient(consumer);
87
88         sequencePullConsumer_ = consumer;
89
90         logger_.info("connect sequence_pull_consumer");
91     }
92
93     public StructuredEvent[] pull_structured_events(int number) throws Disconnected
94     {
95         checkStillConnected();
96
97         StructuredEvent _structuredEvents[] = UNDEFINED_SEQUENCE;
98
99         Message[] _messages = getUpToMessages(number);
100
101         if (_messages != null && _messages.length > 0)
102         {
103             _structuredEvents = new StructuredEvent[_messages.length];
104
105             for (int x = 0; x < _messages.length; ++x)
106             {
107                 _structuredEvents[x] = _messages[x].toStructuredEvent();
108                 _messages[x].dispose();
109             }
110         }
111
112         return _structuredEvents;
113     }
114
115     public StructuredEvent[] try_pull_structured_events(int number, BooleanHolder JavaDoc success)
116             throws Disconnected
117     {
118         checkStillConnected();
119
120         Message[] _messages = getUpToMessages(number);
121
122         if (_messages != null && _messages.length > 0)
123         {
124             StructuredEvent[] _ret = new StructuredEvent[_messages.length];
125
126             for (int x = 0; x < _messages.length; ++x)
127             {
128                 _ret[x] = _messages[x].toStructuredEvent();
129
130                 _messages[x].dispose();
131             }
132             success.value = true;
133
134             return _ret;
135         }
136         success.value = false;
137
138         return UNDEFINED_SEQUENCE;
139     }
140
141     public List JavaDoc getSubsequentFilterStages()
142     {
143         return CollectionsWrapper.singletonList(this);
144     }
145
146     public MessageConsumer getMessageConsumer()
147     {
148         return this;
149     }
150
151     protected void disconnectClient()
152     {
153         sequencePullConsumer_.disconnect_sequence_pull_consumer();
154
155         sequencePullConsumer_ = null;
156
157         logger_.info("disconnect sequence_pull_consumer");
158     }
159
160     public void disconnect_sequence_pull_supplier()
161     {
162         destroy();
163     }
164
165     public synchronized Servant JavaDoc getServant()
166     {
167         if (thisServant_ == null)
168         {
169             thisServant_ = new SequenceProxyPullSupplierPOATie(this);
170         }
171
172         return thisServant_;
173     }
174 }
Popular Tags