/[classpath]/classpath/gnu/CORBA/SocketRepository.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/SocketRepository.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2.2.3 by gnu_andrew, Wed Nov 2 00:43:23 2005 UTC revision 1.2.2.4 by gnu_andrew, Sun Nov 27 21:00:36 2005 UTC
# Line 40  package gnu.CORBA; Line 40  package gnu.CORBA;
40    
41  import java.net.Socket;  import java.net.Socket;
42  import java.net.SocketException;  import java.net.SocketException;
43  import java.util.Hashtable;  import java.util.HashMap;
44  import java.util.Iterator;  import java.util.Iterator;
45  import java.util.Map;  import java.util.Map;
46    
# Line 56  public class SocketRepository Line 56  public class SocketRepository
56    /**    /**
57     * The socket map.     * The socket map.
58     */     */
59    private static Hashtable sockets = new Hashtable();    private static HashMap sockets = new HashMap();
60        
61    /**    /**
62     * Put a socket. This method also discards all not reusable sockets from     * Put a socket. This method also discards all not reusable sockets from
# Line 68  public class SocketRepository Line 68  public class SocketRepository
68     */     */
69    public static void put_socket(Object key, Socket s)    public static void put_socket(Object key, Socket s)
70    {    {
71      sockets.put(key, s);      synchronized (sockets)
72      gc();        {
73            sockets.put(key, s);
74            gc();
75          }
76    }    }
77        
78    /**    /**
79     * Removes all non reusable sockets.     * Removes all non reusable sockets. As it is private,
80       * we know we call from the synchronized code already.
81     */     */
82    public static void gc()    private static void gc()
83    {    {
84      Iterator iter = sockets.entrySet().iterator();      Iterator iter = sockets.entrySet().iterator();
85            
# Line 107  public class SocketRepository Line 111  public class SocketRepository
111     * @param key a socket key.     * @param key a socket key.
112     *     *
113     * @return an opened socket for reuse, null if no such available or it is     * @return an opened socket for reuse, null if no such available or it is
114     * closed, its input or output has been shutown or otherwise the socket     * closed, its input or output has been shutown or otherwise the socket is not
115     * is not reuseable.     * reuseable.
116     */     */
117    public static Socket get_socket(Object key)    public static Socket get_socket(Object key)
118    {    {
119      if (true)      if (true)
120        return null;        return null;
121        
122      Socket s = (Socket) sockets.get(key);      synchronized (sockets)
     if (s == null)  
       return null;  
       
     // Ensure that the socket is fully reusable.  
     else if (not_reusable(s))  
       {  
         sockets.remove(key);  
         return null;  
       }  
     else  
123        {        {
124          try          Socket s = (Socket) sockets.get(key);
125            if (s == null)
126              return null;
127    
128            // Ensure that the socket is fully reusable.
129            else if (not_reusable(s))
130            {            {
131              // Set one minute time out that will be changed later.              sockets.remove(key);
132              s.setSoTimeout(60*1000);              return null;
133            }            }
134          catch (SocketException e)          else
135            {            {
136              s = null;              try
137                  {
138                    // Set one minute time out that will be changed later.
139                    s.setSoTimeout(60 * 1000);
140                  }
141                catch (SocketException e)
142                  {
143                    s = null;
144                  }
145    
146                sockets.remove(key);
147                return s;
148            }            }
           
         sockets.remove(key);  
         return s;  
149        }        }
150    }    }
151  }  }

Legend:
Removed from v.1.2.2.3  
changed lines
  Added in v.1.2.2.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26