1 22 package org.jboss.net.sockets; 23 24 import java.io.IOException ; 25 import java.rmi.server.RMIClientSocketFactory ; 26 import java.net.Socket ; 27 import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore; 28 33 public class QueuedClientSocketFactory 34 implements RMIClientSocketFactory , java.io.Externalizable 35 { 36 private transient FIFOSemaphore permits; 37 private long numPermits; 38 public QueuedClientSocketFactory() 39 { 40 } 41 42 public QueuedClientSocketFactory(long nPermits) 43 { 44 permits = new FIFOSemaphore(nPermits); 45 numPermits = nPermits; 46 } 47 56 public Socket createSocket(String host, int port) throws IOException 57 { 58 try 59 { 60 permits.acquire(); 61 return new Socket (host, port); 62 } 63 catch (InterruptedException ex) 64 { 65 throw new IOException ("Failed to acquire FIFOSemaphore for ClientSocketFactory"); 66 } 67 finally 68 { 69 permits.release(); 70 } 71 } 72 73 public boolean equals(Object obj) 74 { 75 return obj instanceof QueuedClientSocketFactory; 76 } 77 public int hashCode() 78 { 79 return getClass().getName().hashCode(); 80 } 81 82 public void writeExternal(java.io.ObjectOutput out) 83 throws IOException 84 { 85 out.writeLong(numPermits); 86 } 87 public void readExternal(java.io.ObjectInput in) 88 throws IOException , ClassNotFoundException 89 { 90 numPermits = in.readLong(); 91 permits = new FIFOSemaphore(numPermits); 92 } 93 } 94 | Popular Tags |