1 21 package org.jacorb.orb.etf; 22 23 import java.util.*; 24 25 import org.omg.ETF.*; 26 27 import org.apache.avalon.framework.logger.*; 28 import org.apache.avalon.framework.configuration.*; 29 30 import org.jacorb.orb.*; 31 32 36 public abstract class ListenerBase 37 extends _ListenerLocalBase 38 implements Configurable 39 { 40 43 protected ORB orb = null; 44 45 48 protected Profile endpoint = null; 49 50 53 protected Acceptor acceptor = null; 54 55 58 protected org.jacorb.config.Configuration configuration = null; 59 60 63 protected Logger logger = null; 64 65 69 protected org.omg.ETF.Handle up = null; 70 71 77 protected List incoming_connections = new ArrayList(); 78 79 protected boolean terminated = false; 80 81 public ListenerBase() 82 { 83 } 84 85 88 public ListenerBase(ORB orb) 89 { 90 this.orb = orb; 91 } 92 93 public void configure(Configuration configuration) 94 throws ConfigurationException 95 { 96 this.configuration = (org.jacorb.config.Configuration)configuration; 97 98 if (orb == null) 99 { 100 this.orb = this.configuration.getORB(); 102 } 103 104 logger = this.configuration.getNamedLogger(this.configuration.getLoggerName(this.getClass())); 105 } 106 107 112 public void set_handle(Handle up) 113 { 114 this.up = up; 115 } 116 117 128 public void listen() 129 { 130 if (acceptor != null) 131 acceptor.start(); 132 } 133 134 138 protected void deliverConnection(Connection connection) 139 { 140 if (up != null) 141 { 142 up.add_input(connection); 143 } 144 else 145 { 146 synchronized (incoming_connections) 147 { 148 incoming_connections.add(connection); 149 incoming_connections.notifyAll(); 150 } 151 } 152 } 153 154 164 public Connection accept() 165 { 166 if (up != null) 167 throw new org.omg.CORBA.BAD_INV_ORDER 168 ("Must not call accept() when a Handle has been set"); 169 else 170 { 171 synchronized (incoming_connections) 172 { 173 while (!terminated && 174 incoming_connections.isEmpty()) 175 { 176 try 177 { 178 incoming_connections.wait(); 179 } 180 catch (InterruptedException ex) 181 { 182 } 184 } 185 if (!terminated) 186 return (Connection)incoming_connections.remove (0); 187 else 188 return null; 189 } 190 } 191 } 192 193 197 public void completed_data (Connection conn) 198 { 199 throw new org.omg.CORBA.NO_IMPLEMENT (); 200 } 201 202 207 public void destroy() 208 { 209 if (acceptor != null) 210 acceptor.terminate(); 211 212 this.terminated = true; 213 if (up == null) 214 incoming_connections.notifyAll(); 215 } 216 217 218 222 public Profile endpoint() 223 { 224 return endpoint.copy(); 225 } 226 227 protected abstract class Acceptor 228 extends Thread 229 { 230 protected abstract void init(); 231 232 public abstract void run(); 233 234 public abstract void terminate(); 235 } 236 } 237 | Popular Tags |