src/java.base/share/classes/sun/nio/ch/MembershipKeyImpl.java
author igerasim
Wed, 21 Aug 2019 13:49:16 -0700
changeset 57826 bf4c808a4488
parent 49001 ce06058197a4
permissions -rw-r--r--
8211360: Change #if DEF to #if defined(DEF) Reviewed-by: bpb, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     1
/*
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 47216
diff changeset
     2
 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     4
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    10
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    15
 * accompanied this code).
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    16
 *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    23
 * questions.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    24
 */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    25
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    26
package sun.nio.ch;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    27
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    28
import java.net.InetAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    29
import java.net.NetworkInterface;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    30
import java.io.IOException;
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 47216
diff changeset
    31
import java.nio.channels.MembershipKey;
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 47216
diff changeset
    32
import java.nio.channels.MulticastChannel;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    33
import java.util.HashSet;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    34
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    35
/**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    36
 * MembershipKey implementation.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    37
 */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    38
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    39
class MembershipKeyImpl
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    40
    extends MembershipKey
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    41
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    42
    private final MulticastChannel ch;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    43
    private final InetAddress group;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    44
    private final NetworkInterface interf;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    45
    private final InetAddress source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    46
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 29986
diff changeset
    47
    private volatile boolean invalid;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    48
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    49
    // lock used when creating or accessing blockedSet
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 47216
diff changeset
    50
    private final Object stateLock = new Object();
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    51
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    52
    // set of source addresses that are blocked
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    53
    private HashSet<InetAddress> blockedSet;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    54
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    55
    private MembershipKeyImpl(MulticastChannel ch,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    56
                              InetAddress group,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    57
                              NetworkInterface interf,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    58
                              InetAddress source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    59
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    60
        this.ch = ch;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    61
        this.group = group;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    62
        this.interf = interf;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    63
        this.source = source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    64
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    65
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    66
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    67
     * MembershipKey will additional context for IPv4 membership
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    68
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    69
    static class Type4 extends MembershipKeyImpl {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    70
        private final int groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    71
        private final int interfAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    72
        private final int sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    73
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    74
        Type4(MulticastChannel ch,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    75
              InetAddress group,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    76
              NetworkInterface interf,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    77
              InetAddress source,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    78
              int groupAddress,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    79
              int interfAddress,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    80
              int sourceAddress)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    81
        {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    82
            super(ch, group, interf, source);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    83
            this.groupAddress = groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    84
            this.interfAddress = interfAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    85
            this.sourceAddress = sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    86
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    87
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
    88
        int groupAddress() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    89
            return groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    90
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    91
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    92
        int interfaceAddress() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    93
            return interfAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    94
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    95
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    96
        int source() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    97
            return sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    98
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
    99
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   100
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   101
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   102
     * MembershipKey will additional context for IPv6 membership
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   103
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   104
    static class Type6 extends MembershipKeyImpl {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   105
        private final byte[] groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   106
        private final int index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   107
        private final byte[] sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   108
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   109
        Type6(MulticastChannel ch,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   110
              InetAddress group,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   111
              NetworkInterface interf,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   112
              InetAddress source,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   113
              byte[] groupAddress,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   114
              int index,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   115
              byte[] sourceAddress)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   116
        {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   117
            super(ch, group, interf, source);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   118
            this.groupAddress = groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   119
            this.index = index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   120
            this.sourceAddress = sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   121
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   122
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   123
        byte[] groupAddress() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   124
            return groupAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   125
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   126
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   127
        int index() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   128
            return index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   129
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   130
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   131
        byte[] source() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   132
            return sourceAddress;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   133
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   134
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   135
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   136
    public boolean isValid() {
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 29986
diff changeset
   137
        return !invalid;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   138
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   139
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   140
    // package-private
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   141
    void invalidate() {
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 29986
diff changeset
   142
        invalid = true;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   143
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   144
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   145
    public void drop() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   146
        // delegate to channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   147
        ((DatagramChannelImpl)ch).drop(this);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   148
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   149
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   150
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   151
    public MulticastChannel channel() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   152
        return ch;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   153
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   154
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   155
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   156
    public InetAddress group() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   157
        return group;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   158
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   159
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   160
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   161
    public NetworkInterface networkInterface() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   162
        return interf;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   163
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   164
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   165
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   166
    public InetAddress sourceAddress() {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   167
        return source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   168
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   169
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   170
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   171
    public MembershipKey block(InetAddress toBlock)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   172
        throws IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   173
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   174
        if (source != null)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   175
            throw new IllegalStateException("key is source-specific");
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   176
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   177
        synchronized (stateLock) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   178
            if ((blockedSet != null) && blockedSet.contains(toBlock)) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   179
                // already blocked, nothing to do
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   180
                return this;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   181
            }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   182
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   183
            ((DatagramChannelImpl)ch).block(this, toBlock);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   184
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   185
            // created blocked set if required and add source address
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   186
            if (blockedSet == null)
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   187
                blockedSet = new HashSet<>();
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   188
            blockedSet.add(toBlock);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   189
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   190
        return this;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   191
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   192
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   193
    @Override
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1152
diff changeset
   194
    public MembershipKey unblock(InetAddress toUnblock) {
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   195
        synchronized (stateLock) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   196
            if ((blockedSet == null) || !blockedSet.contains(toUnblock))
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   197
                throw new IllegalStateException("not blocked");
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   198
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   199
            ((DatagramChannelImpl)ch).unblock(this, toUnblock);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   200
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   201
            blockedSet.remove(toUnblock);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   202
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   203
        return this;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   204
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   205
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   206
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   207
    public String toString() {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   208
        StringBuilder sb = new StringBuilder(64);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   209
        sb.append('<');
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   210
        sb.append(group.getHostAddress());
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   211
        sb.append(',');
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   212
        sb.append(interf.getName());
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   213
        if (source != null) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   214
            sb.append(',');
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   215
            sb.append(source.getHostAddress());
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   216
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   217
        sb.append('>');
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   218
        return sb.toString();
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   219
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents:
diff changeset
   220
}