com.sun.nio.sctp.Association Java Examples

The following examples show how to use com.sun.nio.sctp.Association. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SctpMultiChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #2
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public HandlerResult handleNotification(
        AssociationChangeNotification not, Object unused) {
    AssociationChange sac = (AssociationChange) not;

    /* Update map to reflect change in association */
    switch (not.event()) {
        case COMM_UP :
            Association newAssociation = new AssociationImpl
               (sac.assocId(), sac.maxInStreams(), sac.maxOutStreams());
            addAssociation(newAssociation);
            break;
        case SHUTDOWN :
        case COMM_LOST :
        //case RESTART: ???
            /* mark association for removal after user handler invoked*/
            associationToRemove.set(lookupAssociation(sac.assocId()));
    }
    return HandlerResult.CONTINUE;
}
 
Example #3
Source File: SctpMultiChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpMultiChannel setOption(SctpSocketOption<T> name,
                                      T value,
                                      Association association)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!(supportedOptions().contains(name)))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (association != null && (name.equals(SCTP_PRIMARY_ADDR) ||
                name.equals(SCTP_SET_PEER_PRIMARY_ADDR))) {
            checkAssociation(association);
        }
        if (!isOpen())
            throw new ClosedChannelException();

        int assocId = association == null ? 0 : association.associationID();
        SctpNet.setSocketOption(fdVal, name, value, assocId);
    }
    return this;
}
 
Example #4
Source File: SctpChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #5
Source File: SctpMultiChannelImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T getOption(SctpSocketOption<T> name, Association association)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (association != null && (name.equals(SCTP_PRIMARY_ADDR) ||
                name.equals(SCTP_SET_PEER_PRIMARY_ADDR))) {
            checkAssociation(association);
        }
        if (!isOpen())
            throw new ClosedChannelException();

        int assocId = association == null ? 0 : association.associationID();
        return (T)SctpNet.getSocketOption(fdVal, name, assocId);
    }
}
 
Example #6
Source File: SctpMultiChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #7
Source File: SctpMultiChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #8
Source File: SctpMultiChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Set<SocketAddress> getRemoteAddresses(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        try {
            return SctpNet.getRemoteAddresses(fdVal, association.associationID());
        } catch (SocketException se) {
            /* a valid association should always have remote addresses */
            Set<SocketAddress> addrs = associationMap.get(association);
            return addrs != null ? addrs : Collections.<SocketAddress>emptySet();
        }
    }
}
 
Example #9
Source File: Send.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public HandlerResult handleNotification(
        AssociationChangeNotification notification, Void attachment) {
    AssocChangeEvent event = notification.event();
    Association association = notification.association();
    debug("AssociationChangeNotification");
    debug("  Association: " + notification.association());
    debug("  Event: " + event);

    if (event.equals(AssocChangeEvent.COMM_UP))
        receivedCommUp = true;

    this.maxInStreams = association.maxInboundStreams();
    this.maxOutStreams = association.maxOutboundStreams();

    return HandlerResult.RETURN;
}
 
Example #10
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Set<SocketAddress> getRemoteAddresses(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        try {
            return SctpNet.getRemoteAddresses(fdVal, association.associationID());
        } catch (SocketException se) {
            /* a valid association should always have remote addresses */
            Set<SocketAddress> addrs = associationMap.get(association);
            return addrs != null ? addrs : Collections.<SocketAddress>emptySet();
        }
    }
}
 
Example #11
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpMultiChannel setOption(SctpSocketOption<T> name,
                                      T value,
                                      Association association)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!(supportedOptions().contains(name)))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (association != null && (name.equals(SCTP_PRIMARY_ADDR) ||
                name.equals(SCTP_SET_PEER_PRIMARY_ADDR))) {
            checkAssociation(association);
        }
        if (!isOpen())
            throw new ClosedChannelException();

        int assocId = association == null ? 0 : association.associationID();
        SctpNet.setSocketOption(fdVal, name, value, assocId);
    }
    return this;
}
 
Example #12
Source File: SctpMultiChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpMultiChannel setOption(SctpSocketOption<T> name,
                                      T value,
                                      Association association)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!(supportedOptions().contains(name)))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (association != null && (name.equals(SCTP_PRIMARY_ADDR) ||
                name.equals(SCTP_SET_PEER_PRIMARY_ADDR))) {
            checkAssociation(association);
        }
        if (!isOpen())
            throw new ClosedChannelException();

        int assocId = association == null ? 0 : association.associationID();
        SctpNet.setSocketOption(fdVal, name, value, assocId);
    }
    return this;
}
 
Example #13
Source File: SctpMultiChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #14
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #15
Source File: SctpMultiChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T getOption(SctpSocketOption<T> name, Association association)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (association != null && (name.equals(SCTP_PRIMARY_ADDR) ||
                name.equals(SCTP_SET_PEER_PRIMARY_ADDR))) {
            checkAssociation(association);
        }
        if (!isOpen())
            throw new ClosedChannelException();

        int assocId = association == null ? 0 : association.associationID();
        return (T)SctpNet.getSocketOption(fdVal, name, assocId);
    }
}
 
Example #16
Source File: SctpMultiChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Set<SocketAddress> getRemoteAddresses(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        try {
            return SctpNet.getRemoteAddresses(fdVal, association.associationID());
        } catch (SocketException se) {
            /* a valid association should always have remote addresses */
            Set<SocketAddress> addrs = associationMap.get(association);
            return addrs != null ? addrs : Collections.<SocketAddress>emptySet();
        }
    }
}
 
Example #17
Source File: SctpMultiChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SctpMultiChannel shutdown(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.shutdown(fdVal, association.associationID());
    }
    return this;
}
 
Example #18
Source File: SctpMultiChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void removeAssociation(Association association) {
    synchronized (stateLock) {
        int assocId = association.associationID();
        Set<SocketAddress> addresses = null;

         try {
            addresses = SctpNet.getRemoteAddresses(fdVal, assocId);
        } catch (IOException unused) {
            /* OK, determining connected addresses may not be possible
             * shutdown, connection lost, etc */
        }

        Set<Association> assocs = associationMap.keySet();
        for (Association a : assocs) {
            if (a.associationID() == assocId) {
                associationMap.remove(a);
                break;
            }
        }
        if (addresses != null) {
            for (SocketAddress addr : addresses)
                addressMap.remove(addr);
        } else {
            /* We cannot determine the connected addresses */
            Set<java.util.Map.Entry<SocketAddress, Association>> addrAssocs =
                    addressMap.entrySet();
            Iterator<Entry<SocketAddress, Association>> iterator = addrAssocs.iterator();
            while (iterator.hasNext()) {
                Entry<SocketAddress, Association> entry = iterator.next();
                if (entry.getValue().equals(association)) {
                    iterator.remove();
                }
            }
        }
    }
}
 
Example #19
Source File: OioSctpChannel.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public Association association() {
    try {
        return ch.association();
    } catch (IOException ignored) {
        return null;
    }
}
 
Example #20
Source File: SctpChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Association association() throws ClosedChannelException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (!isConnected())
            return null;

        return association;
    }
}
 
Example #21
Source File: SctpMultiChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SctpMultiChannel shutdown(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.shutdown(fdVal, association.associationID());
    }
    return this;
}
 
Example #22
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void checkAssociation(Association sendAssociation) {
    synchronized (stateLock) {
        if (sendAssociation != null && !sendAssociation.equals(association)) {
            throw new IllegalArgumentException(
                    "Cannot send to another association");
        }
    }
}
 
Example #23
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Set<Association> associations()
        throws ClosedChannelException, NotYetBoundException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (!isBound())
            throw new NotYetBoundException();

        return Collections.unmodifiableSet(associationMap.keySet());
    }
}
 
Example #24
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void checkAssociation(Association sendAssociation) {
    synchronized (stateLock) {
        if (sendAssociation != null && !sendAssociation.equals(association)) {
            throw new IllegalArgumentException(
                    "Cannot send to another association");
        }
    }
}
 
Example #25
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void removeAssociation(Association association) {
    synchronized (stateLock) {
        int assocId = association.associationID();
        Set<SocketAddress> addresses = null;

         try {
            addresses = SctpNet.getRemoteAddresses(fdVal, assocId);
        } catch (IOException unused) {
            /* OK, determining connected addresses may not be possible
             * shutdown, connection lost, etc */
        }

        Set<Association> assocs = associationMap.keySet();
        for (Association a : assocs) {
            if (a.associationID() == assocId) {
                associationMap.remove(a);
                break;
            }
        }
        if (addresses != null) {
            for (SocketAddress addr : addresses)
                addressMap.remove(addr);
        } else {
            /* We cannot determine the connected addresses */
            Set<java.util.Map.Entry<SocketAddress, Association>> addrAssocs =
                    addressMap.entrySet();
            Iterator<Entry<SocketAddress, Association>> iterator = addrAssocs.iterator();
            while (iterator.hasNext()) {
                Entry<SocketAddress, Association> entry = iterator.next();
                if (entry.getValue().equals(association)) {
                    iterator.remove();
                }
            }
        }
    }
}
 
Example #26
Source File: SctpChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Association association() throws ClosedChannelException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (!isConnected())
            return null;

        return association;
    }
}
 
Example #27
Source File: SctpMultiChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Set<SocketAddress> getRemoteAddresses
        (Association association) throws IOException {
    throw new UnsupportedOperationException(message);
}
 
Example #28
Source File: SctpMultiChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Set<SocketAddress> getRemoteAddresses
        (Association association) throws IOException {
    throw new UnsupportedOperationException(message);
}
 
Example #29
Source File: SendFailed.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Association association() {
    /* may be null */
    return association;
}
 
Example #30
Source File: Shutdown.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setAssociation(Association association) {
    this.association = association;
}