/[classpath]/classpath/java/nio/channels/spi/AbstractSelectableChannel.java
ViewVC logotype

Diff of /classpath/java/nio/channels/spi/AbstractSelectableChannel.java

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

revision 1.9 by mkoch, Sat Dec 21 11:42:37 2002 UTC revision 1.10 by mkoch, Sun Oct 12 16:56:00 2003 UTC
# Line 1  Line 1 
1  /* AbstractSelectableChannel.java  /* AbstractSelectableChannel.java
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 48  import java.util.ListIterator; Line 48  import java.util.ListIterator;
48    
49  public abstract class AbstractSelectableChannel extends SelectableChannel  public abstract class AbstractSelectableChannel extends SelectableChannel
50  {  {
51    int registered;    private int registered;
52    boolean blocking = true;    private boolean blocking = true;
53    Object LOCK = new Object ();    private Object LOCK = new Object();
54    SelectorProvider provider;    private SelectorProvider provider;
55    List keys;    private LinkedList keys;
56    
57    /**    /**
58     * Initializes the channel     * Initializes the channel
# Line 60  public abstract class AbstractSelectable Line 60  public abstract class AbstractSelectable
60    protected AbstractSelectableChannel (SelectorProvider provider)    protected AbstractSelectableChannel (SelectorProvider provider)
61    {    {
62      this.provider = provider;      this.provider = provider;
63        this.keys = new LinkedList();
64    }    }
65    
66    /**    /**
# Line 122  public abstract class AbstractSelectable Line 123  public abstract class AbstractSelectable
123     */     */
124    public final boolean isRegistered()    public final boolean isRegistered()
125    {    {
126      return registered > 0;      return !keys.isEmpty();
127    }    }
128    
129    /**    /**
# Line 154  public abstract class AbstractSelectable Line 155  public abstract class AbstractSelectable
155      if (keys == null)      if (keys == null)
156        return null;        return null;
157            
     SelectionKey k = null;  
158      ListIterator it = keys.listIterator ();      ListIterator it = keys.listIterator ();
159            
160      while (it.hasNext ())      while (it.hasNext ())
161        {        {
162          k = (SelectionKey) it.next ();          SelectionKey key = (SelectionKey) it.next();
163          if (k.selector () == selector)          
164            {          if (key.selector() == selector)
165              return k;            return key;
           }  
166        }        }
167            
168      return k;      return null;
169    }    }
170    
171    private void add (SelectionKey key)    private void add (SelectionKey key)
172    {    {
     if (keys == null)  
       {  
         keys = new LinkedList ();  
       }  
       
173      keys.add (key);      keys.add (key);
174    }    }
175    
# Line 190  public abstract class AbstractSelectable Line 184  public abstract class AbstractSelectable
184      if (!isOpen ())      if (!isOpen ())
185        throw new ClosedChannelException();        throw new ClosedChannelException();
186    
187      SelectionKey k = null;      SelectionKey key = null;
188      AbstractSelector selector = (AbstractSelector) selin;      AbstractSelector selector = (AbstractSelector) selin;
189    
190      synchronized (LOCK)      synchronized (LOCK)
191        {        {
192          k = locate (selector);          key = locate (selector);
193    
194          if (k != null)          if (key != null)
195            {            {
196              k.attach (att);              key.attach (att);
197            }            }
198          else          else
199            {            {
200              k = selector.register (this, ops, att);              key = selector.register (this, ops, att);
201                                    
202              if (k != null)              if (key != null)
203                add (k);                add (key);
204            }            }
205        }        }
206    
207      return k;      return key;
208    }    }
209  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

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