< prev index next >

src/java.base/share/classes/sun/nio/ch/MembershipKeyImpl.java

Print this page




 167         return source;
 168     }
 169 
 170     @Override
 171     public MembershipKey block(InetAddress toBlock)
 172         throws IOException
 173     {
 174         if (source != null)
 175             throw new IllegalStateException("key is source-specific");
 176 
 177         synchronized (stateLock) {
 178             if ((blockedSet != null) && blockedSet.contains(toBlock)) {
 179                 // already blocked, nothing to do
 180                 return this;
 181             }
 182 
 183             ((DatagramChannelImpl)ch).block(this, toBlock);
 184 
 185             // created blocked set if required and add source address
 186             if (blockedSet == null)
 187                 blockedSet = new HashSet<InetAddress>();
 188             blockedSet.add(toBlock);
 189         }
 190         return this;
 191     }
 192 
 193     @Override
 194     public MembershipKey unblock(InetAddress toUnblock) {
 195         synchronized (stateLock) {
 196             if ((blockedSet == null) || !blockedSet.contains(toUnblock))
 197                 throw new IllegalStateException("not blocked");
 198 
 199             ((DatagramChannelImpl)ch).unblock(this, toUnblock);
 200 
 201             blockedSet.remove(toUnblock);
 202         }
 203         return this;
 204     }
 205 
 206     @Override
 207     public String toString() {


 167         return source;
 168     }
 169 
 170     @Override
 171     public MembershipKey block(InetAddress toBlock)
 172         throws IOException
 173     {
 174         if (source != null)
 175             throw new IllegalStateException("key is source-specific");
 176 
 177         synchronized (stateLock) {
 178             if ((blockedSet != null) && blockedSet.contains(toBlock)) {
 179                 // already blocked, nothing to do
 180                 return this;
 181             }
 182 
 183             ((DatagramChannelImpl)ch).block(this, toBlock);
 184 
 185             // created blocked set if required and add source address
 186             if (blockedSet == null)
 187                 blockedSet = new HashSet<>();
 188             blockedSet.add(toBlock);
 189         }
 190         return this;
 191     }
 192 
 193     @Override
 194     public MembershipKey unblock(InetAddress toUnblock) {
 195         synchronized (stateLock) {
 196             if ((blockedSet == null) || !blockedSet.contains(toUnblock))
 197                 throw new IllegalStateException("not blocked");
 198 
 199             ((DatagramChannelImpl)ch).unblock(this, toUnblock);
 200 
 201             blockedSet.remove(toUnblock);
 202         }
 203         return this;
 204     }
 205 
 206     @Override
 207     public String toString() {
< prev index next >