当前位置: 首页>>代码示例>>Java>>正文


Java ClosedChannelException类代码示例

本文整理汇总了Java中java.nio.channels.ClosedChannelException的典型用法代码示例。如果您正苦于以下问题:Java ClosedChannelException类的具体用法?Java ClosedChannelException怎么用?Java ClosedChannelException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClosedChannelException类属于java.nio.channels包,在下文中一共展示了ClosedChannelException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Client

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
public Client(Selector selector, SocketChannel clientChannel, CloseListener<Client> closeListener) throws ClosedChannelException {
    id = nextId++;
    this.clientChannel = clientChannel;
    router = new Router(this, selector);
    pendingIdBuffer = createIntBuffer(id);

    SelectionHandler selectionHandler = (selectionKey) -> {
        if (selectionKey.isValid() && selectionKey.isWritable()) {
            processSend();
        }
        if (selectionKey.isValid() && selectionKey.isReadable()) {
            processReceive();
        }
        if (selectionKey.isValid()) {
            updateInterests();
        }
    };
    // on start, we are interested only in writing (we must first send the client id)
    interests = SelectionKey.OP_WRITE;
    selectionKey = clientChannel.register(selector, interests, selectionHandler);

    this.closeListener = closeListener;
}
 
开发者ID:Genymobile,项目名称:gnirehtet,代码行数:24,代码来源:Client.java

示例2: setOption

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@Override
public <T> SctpServerChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
        return this;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:SctpServerChannelImpl.java

示例3: getRemoteAddresses

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@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();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:SctpMultiChannelImpl.java

示例4: setBytes

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
    ByteBuffer buf = ByteBuffer.wrap(array, index, length);
    int readBytes = 0;

    do {
        int localReadBytes;
        try {
            localReadBytes = in.read(buf);
        } catch (ClosedChannelException e) {
            localReadBytes = -1;
        }
        if (localReadBytes < 0) {
            if (readBytes == 0) {
                return -1;
            } else {
                break;
            }
        } else if (localReadBytes == 0) {
            break;
        }
        readBytes += localReadBytes;
    } while (readBytes < length);

    return readBytes;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:26,代码来源:HeapChannelBuffer.java

示例5: transferTo

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:FileChannelImpl.java

示例6: exceptionCaught

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:ShuffleHandler.java

示例7: setOption

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@Override
public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
    }
    return this;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:SctpChannelImpl.java

示例8: branch

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:SctpMultiChannelImpl.java

示例9: handleWriteTimeout

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
private void handleWriteTimeout(final long ret) throws IOException {
    if (!connection.isOpen()) {
        return;
    }
    if (ret == 0 && handle != null) {
        return;
    }
    Integer timeout = getTimeout();
    if (timeout == null || timeout <= 0) {
        return;
    }
    long currentTime = System.currentTimeMillis();
    long expireTimeVar = expireTime;
    if (expireTimeVar != -1 && currentTime > expireTimeVar) {
        IoUtils.safeClose(connection);
        throw new ClosedChannelException();
    }
    expireTime = currentTime + timeout;
    XnioExecutor.Key key = handle;
    if (key == null) {
        handle = connection.getIoThread().executeAfter(timeoutCommand, timeout, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:WriteTimeoutStreamSinkConduit.java

示例10: exceptionCaught

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{
    // Stop the epic channel closed spam at close
    if (!(cause instanceof ClosedChannelException))
    {
        // Mute the reset by peer exception - it's disconnection noise
        if (cause.getMessage().contains("Connection reset by peer"))
        {
            FMLLog.log(Level.DEBUG, cause, "Muted NetworkDispatcher exception");
        }
        else
        {
            FMLLog.log(Level.ERROR, cause, "NetworkDispatcher exception");
        }
    }
    super.exceptionCaught(ctx, cause);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:19,代码来源:NetworkDispatcher.java

示例11: handleIdleTimeout

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
private void handleIdleTimeout() throws ClosedChannelException {
    if(timedOut) {
        return;
    }
    long idleTimeout = this.idleTimeout;
    if(idleTimeout <= 0) {
        return;
    }
    long currentTime = System.currentTimeMillis();
    long expireTimeVar = expireTime;
    if(expireTimeVar != -1 && currentTime > expireTimeVar) {
        timedOut = true;
        doClose();
        throw new ClosedChannelException();
    }
    expireTime = currentTime + idleTimeout;
    XnioExecutor.Key key = handle;
    if (key == null) {
        handle = sink.getWriteThread().executeAfter(timeoutCommand, idleTimeout, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:IdleTimeoutConduit.java

示例12: write

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@Override
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException {
    if (anyAreSet(state, SHUTDOWN | CLOSED) || currentBuffer == null) {
        throw new ClosedChannelException();
    }
    try {
        int total = 0;
        for (int i = offset; i < offset + length; ++i) {
            if (srcs[i].hasRemaining()) {
                int ret = write(srcs[i]);
                total += ret;
                if (ret == 0) {
                    return total;
                }
            }
        }
        return total;
    } catch (IOException e) {
        freeBuffer();
        throw e;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:DeflatingStreamSinkConduit.java

示例13: getOption

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:SctpMultiChannelImpl.java

示例14: transferFrom

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
    if (count == 0L) return 0L;
    long val = state;
    if (allAreSet(val, FLAG_CLOSE_REQUESTED)) {
        throw new ClosedChannelException();
    }
    if (allAreClear(val, MASK_COUNT)) {
        throw new FixedLengthOverflowException();
    }
    long res = 0L;
    try {
        return res = next.transferFrom(src, position, min(count, (val & MASK_COUNT)));
    } catch (IOException e) {
        broken = true;
        throw e;
    } finally {
        exitWrite(val, res);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AbstractFixedLengthStreamSinkConduit.java

示例15: transferFrom

import java.nio.channels.ClosedChannelException; //导入依赖的package包/类
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:FileChannelImpl.java


注:本文中的java.nio.channels.ClosedChannelException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。