1 package org.jacorb.events; 2 3 22 23 import org.omg.CosEventComm.*; 24 import org.jacorb.orb.*; 25 import java.util.*; 26 27 28 48 public class ProxyPullSupplierImpl 49 extends org.omg.CosEventChannelAdmin.ProxyPullSupplierPOA 50 { 51 private EventChannelImpl myEventChannel = null; 52 private PullConsumer myPullConsumer = null; 53 private org.omg.PortableServer.POA myPoa = null; 54 private boolean connected = false; 55 private LinkedList pendingEvents = new LinkedList(); 56 private final int maxListSize = 200; 57 private static org.omg.CORBA.Any undefinedAny = null; 58 59 62 protected ProxyPullSupplierImpl ( EventChannelImpl ec, 63 org.omg.CORBA.ORB orb, 64 org.omg.PortableServer.POA poa ) 65 { 66 myEventChannel = ec; 67 myPoa = poa; 68 connected = false; 69 _this_object(orb); 70 undefinedAny = org.omg.CORBA.ORB.init().create_any(); 71 } 72 73 82 83 public void connect_pull_consumer ( PullConsumer pullConsumer ) 84 throws org.omg.CosEventChannelAdmin.AlreadyConnected 85 { 86 if ( connected ) { throw new org.omg.CosEventChannelAdmin.AlreadyConnected(); } 87 myPullConsumer = pullConsumer; 88 connected = true; 89 } 90 91 106 107 public void disconnect_pull_supplier() 108 { 109 if ( connected ) 110 { 111 if ( myPullConsumer != null ) 112 { 113 myPullConsumer.disconnect_pull_consumer(); 114 myPullConsumer = null; 115 } 116 connected = false; 117 } 118 else 119 { 120 throw new org.omg.CORBA.OBJECT_NOT_EXIST (); 121 } 122 } 123 124 130 131 public org.omg.CORBA.Any pull () 132 throws org.omg.CosEventComm.Disconnected 133 { 134 org.omg.CORBA.Any event = null; 135 org.omg.CORBA.BooleanHolder hasEvent = new org.omg.CORBA.BooleanHolder (); 136 while ( true ) 137 { 138 event = try_pull( hasEvent ); 139 if ( hasEvent.value ) 140 { 141 return event; 142 } 143 Thread.yield(); 144 } 145 } 146 147 160 161 public org.omg.CORBA.Any try_pull ( org.omg.CORBA.BooleanHolder hasEvent ) 162 throws org.omg.CosEventComm.Disconnected 163 { 164 if ( !connected ) { throw new org.omg.CosEventComm.Disconnected(); } 165 166 org.omg.CORBA.Any event = null; 167 168 synchronized( pendingEvents ) 169 { 170 int listSize = pendingEvents.size(); 171 if ( listSize > 0 ) 172 { 173 event = (org.omg.CORBA.Any )pendingEvents.getFirst(); 174 pendingEvents.remove( event ); 175 hasEvent.value = true; 176 return event; 177 } 178 else 179 { 180 hasEvent.value = false; 181 return undefinedAny; 182 } 183 } 184 } 185 186 193 194 public void push_to_supplier( org.omg.CORBA.Any event) 195 { 196 synchronized( pendingEvents ) 197 { 198 if ( pendingEvents.size() > maxListSize ) 199 { 200 pendingEvents.remove( pendingEvents.getFirst() ); 201 } 202 pendingEvents.add( event ); 203 } 204 } 205 206 212 213 public org.omg.PortableServer.POA _default_POA() 214 { 215 return myPoa; 216 } 217 } 218 | Popular Tags |