/[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.2 by gnu_andrew, Sat Sep 10 15:31:35 2005 UTC revision 1.2.2.3 by gnu_andrew, Wed Nov 2 00:43:23 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;
44  import java.util.HashMap;  import java.util.Iterator;
45    import java.util.Map;
46    
47  /**  /**
48   * This class caches the opened sockets that are reused during the   * This class caches the opened sockets that are reused during the
# Line 55  public class SocketRepository Line 56  public class SocketRepository
56    /**    /**
57     * The socket map.     * The socket map.
58     */     */
59    private static HashMap sockets = new HashMap();    private static Hashtable sockets = new Hashtable();
60      
61    /**    /**
62     * Put a socket.     * Put a socket. This method also discards all not reusable sockets from
63       * the map.
64     *     *
65     * @param key as socket key.     * @param key as socket key.
66     *     *
# Line 67  public class SocketRepository Line 69  public class SocketRepository
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);      sockets.put(key, s);
72        gc();
73      }
74      
75      /**
76       * Removes all non reusable sockets.
77       */
78      public static void gc()
79      {
80        Iterator iter = sockets.entrySet().iterator();
81        
82        Map.Entry e;
83        Socket sx;
84        
85        while (iter.hasNext())
86          {
87            e = (Map.Entry) iter.next();
88            sx = (Socket) e.getValue();
89            
90            if (not_reusable(sx))
91              iter.remove();
92          }
93      }
94      
95      /**
96       * Return true if the socket is no longer reusable.
97       */
98      static boolean not_reusable(Socket s)
99      {
100        return (s.isClosed() || !s.isBound() || !s.isConnected() ||
101            s.isInputShutdown() || s.isOutputShutdown());
102    }    }
103    
104    /**    /**
# Line 75  public class SocketRepository Line 107  public class SocketRepository
107     * @param key a socket key.     * @param key a socket key.
108     *     *
109     * @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
110     * closed.     * closed, its input or output has been shutown or otherwise the socket
111       * is not reuseable.
112     */     */
113    public static Socket get_socket(Object key)    public static Socket get_socket(Object key)
114    {    {
115        if (true)
116          return null;
117        
118      Socket s = (Socket) sockets.get(key);      Socket s = (Socket) sockets.get(key);
119      if (s == null)      if (s == null)
120        return null;        return null;
121      else if (s.isClosed())      
122        // Ensure that the socket is fully reusable.
123        else if (not_reusable(s))
124        {        {
125          sockets.remove(key);          sockets.remove(key);
126          return null;          return null;
127        }        }
128      else      else
129        {        {
         sockets.remove(key);  
130          try          try
131            {            {
132              // Set one minute time out that will be changed later.              // Set one minute time out that will be changed later.
# Line 99  public class SocketRepository Line 136  public class SocketRepository
136            {            {
137              s = null;              s = null;
138            }            }
139            
140            sockets.remove(key);
141          return s;          return s;
142        }        }
143    }    }

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

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