001: package org.jacorb.notification.servant;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1999-2004 Gerald Brose
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: import org.apache.avalon.framework.configuration.Configuration;
025: import org.apache.avalon.framework.configuration.ConfigurationException;
026: import org.jacorb.notification.OfferManager;
027: import org.jacorb.notification.SubscriptionManager;
028: import org.jacorb.notification.engine.TaskProcessor;
029: import org.jacorb.notification.interfaces.Message;
030: import org.omg.CORBA.BooleanHolder;
031: import org.omg.CORBA.ORB;
032: import org.omg.CosEventChannelAdmin.AlreadyConnected;
033: import org.omg.CosEventComm.Disconnected;
034: import org.omg.CosNotification.StructuredEvent;
035: import org.omg.CosNotifyChannelAdmin.ConsumerAdmin;
036: import org.omg.CosNotifyChannelAdmin.ProxyType;
037: import org.omg.CosNotifyChannelAdmin.SequenceProxyPullSupplierOperations;
038: import org.omg.CosNotifyChannelAdmin.SequenceProxyPullSupplierPOATie;
039: import org.omg.CosNotifyComm.SequencePullConsumer;
040: import org.omg.PortableServer.POA;
041: import org.omg.PortableServer.Servant;
042:
043: /**
044: * @author Alphonse Bendt
045: * @version $Id: SequenceProxyPullSupplierImpl.java,v 1.16 2006/01/12 22:34:54 alphonse.bendt Exp $
046: */
047:
048: public class SequenceProxyPullSupplierImpl extends
049: AbstractProxySupplier implements
050: SequenceProxyPullSupplierOperations {
051: private static final StructuredEvent[] UNDEFINED_SEQUENCE;
052:
053: ////////////////////////////////////////
054:
055: static {
056: UNDEFINED_SEQUENCE = new StructuredEvent[] { StructuredProxyPullSupplierImpl.UNDEFINED_STRUCTURED_EVENT };
057: }
058:
059: ////////////////////////////////////////
060:
061: private SequencePullConsumer sequencePullConsumer_;
062:
063: ////////////////////////////////////////
064:
065: public SequenceProxyPullSupplierImpl(IAdmin admin, ORB orb,
066: POA poa, Configuration conf, TaskProcessor taskProcessor,
067: OfferManager offerManager,
068: SubscriptionManager subscriptionManager,
069: ConsumerAdmin consumerAdmin) throws ConfigurationException {
070: super (admin, orb, poa, conf, taskProcessor, offerManager,
071: subscriptionManager, consumerAdmin);
072: }
073:
074: public ProxyType MyType() {
075: return ProxyType.PULL_SEQUENCE;
076: }
077:
078: public void connect_sequence_pull_consumer(
079: SequencePullConsumer consumer) throws AlreadyConnected {
080: checkIsNotConnected();
081:
082: connectClient(consumer);
083:
084: sequencePullConsumer_ = consumer;
085:
086: logger_.info("connect sequence_pull_consumer");
087: }
088:
089: public StructuredEvent[] pull_structured_events(int number)
090: throws Disconnected {
091: checkStillConnected();
092:
093: StructuredEvent _structuredEvents[] = UNDEFINED_SEQUENCE;
094:
095: Message[] _messages = getUpToMessages(number);
096:
097: if (_messages != null && _messages.length > 0) {
098: _structuredEvents = new StructuredEvent[_messages.length];
099:
100: for (int x = 0; x < _messages.length; ++x) {
101: _structuredEvents[x] = _messages[x].toStructuredEvent();
102: _messages[x].dispose();
103: }
104: }
105:
106: return _structuredEvents;
107: }
108:
109: public StructuredEvent[] try_pull_structured_events(int number,
110: BooleanHolder success) throws Disconnected {
111: checkStillConnected();
112:
113: Message[] _messages = getUpToMessages(number);
114:
115: if (_messages != null && _messages.length > 0) {
116: StructuredEvent[] _ret = new StructuredEvent[_messages.length];
117:
118: for (int x = 0; x < _messages.length; ++x) {
119: _ret[x] = _messages[x].toStructuredEvent();
120:
121: _messages[x].dispose();
122: }
123: success.value = true;
124:
125: return _ret;
126: }
127: success.value = false;
128:
129: return UNDEFINED_SEQUENCE;
130: }
131:
132: protected void disconnectClient() {
133: sequencePullConsumer_.disconnect_sequence_pull_consumer();
134:
135: sequencePullConsumer_ = null;
136:
137: logger_.info("disconnect sequence_pull_consumer");
138: }
139:
140: public void disconnect_sequence_pull_supplier() {
141: destroy();
142: }
143:
144: public Servant newServant() {
145: return new SequenceProxyPullSupplierPOATie(this );
146: }
147:
148: protected long getCost() {
149: return 0;
150: }
151:
152: }
|