1 package org.jacorb.notification.servant; 2 3 23 24 import java.util.List ; 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 ; 35 import org.omg.CORBA.ORB ; 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 ; 45 import org.omg.PortableServer.Servant ; 46 47 51 52 public class SequenceProxyPullSupplierImpl extends StructuredProxyPullSupplierImpl implements 53 SequenceProxyPullSupplierOperations 54 { 55 private static final StructuredEvent[] UNDEFINED_SEQUENCE; 56 57 59 static 60 { 61 UNDEFINED_SEQUENCE = new StructuredEvent[] { UNDEFINED_STRUCTURED_EVENT }; 62 } 63 64 66 private SequencePullConsumer sequencePullConsumer_; 67 68 70 public SequenceProxyPullSupplierImpl(IAdmin admin, ORB orb, POA 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 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 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 getServant() 166 { 167 if (thisServant_ == null) 168 { 169 thisServant_ = new SequenceProxyPullSupplierPOATie(this); 170 } 171 172 return thisServant_; 173 } 174 } | Popular Tags |