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


Java IllegalBlockingModeException类代码示例

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


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

示例1: implAccept

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * This protected method is used to help subclasses override
 * <code>ServerSocket.accept()</code>.  The passed in socket will be
 * connected when this method returns.
 *
 * @param socket The socket that is used for the accepted connection
 *
 * @exception IOException If an error occurs
 * @exception IllegalBlockingModeException If this socket has an associated
 * channel, and the channel is in non-blocking mode
 *
 * @since 1.1
 */
protected final void implAccept(Socket socket) throws IOException
{
  if (isClosed())
    throw new SocketException("ServerSocket is closed");

  // The Sun spec says that if we have an associated channel and
  // it is in non-blocking mode, we throw an IllegalBlockingModeException.
  // However, in our implementation if the channel itself initiated this
  // operation, then we must honor it regardless of its blocking mode.
  if (getChannel() != null && ! getChannel().isBlocking()
      && ! ((PlainSocketImpl) getImpl()).isInChannelOperation())
    throw new IllegalBlockingModeException();

  impl.accept(socket.impl);
  socket.bound = true;
  socket.implCreated = true;

  SecurityManager sm = System.getSecurityManager();
  if (sm != null)
    sm.checkAccept(socket.getInetAddress().getHostAddress(),
                   socket.getPort());
}
 
开发者ID:vilie,项目名称:javify,代码行数:36,代码来源:ServerSocket.java

示例2: receive

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * Reads a datagram packet from the socket.  Note that this method
 * will block until a packet is received from the network.  On return,
 * the passed in <code>DatagramPacket</code> is populated with the data
 * received and all the other information about the packet.
 *
 * @param p A <code>DatagramPacket</code> for storing the data
 *
 * @exception IOException If an error occurs.
 * @exception SocketTimeoutException If setSoTimeout was previously called
 * and the timeout has expired.
 * @exception PortUnreachableException If the socket is connected to a
 * currently unreachable destination. Note, there is no guarantee that the
 * exception will be thrown.
 * @exception IllegalBlockingModeException If this socket has an associated
 * channel, and the channel is in non-blocking mode.
 * @exception SecurityException If a security manager exists and its
 * checkAccept method doesn't allow the receive.
 */
public synchronized void receive(DatagramPacket p) throws IOException
{
  if (isClosed())
    throw new SocketException("socket is closed");

  if (remoteAddress != null && remoteAddress.isMulticastAddress())
    throw new IOException
      ("Socket connected to a multicast address my not receive");

  if (getChannel() != null && ! getChannel().isBlocking()
      && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
    throw new IllegalBlockingModeException();

  DatagramPacket p2 = new DatagramPacket(p.getData(), p.getOffset(), p.maxlen);
  getImpl().receive(p2);
  p.length = p2.length;
  if (p2.getAddress() != null)
    p.setAddress(p2.getAddress());
  if (p2.getPort() != -1)
    p.setPort(p2.getPort());

  SecurityManager s = System.getSecurityManager();
  if (s != null && isConnected())
    s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
}
 
开发者ID:vilie,项目名称:javify,代码行数:45,代码来源:DatagramSocket.java

示例3: read

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
public int read() throws IOException
{
  if (ch instanceof SelectableChannel
      && (! ((SelectableChannel) ch).isBlocking()))
    throw new IllegalBlockingModeException();

  ByteBuffer buffer = ByteBuffer.allocate(1);
  int result = ch.read(buffer);

  if (result == -1)
    return -1;

  if (result == 0)
    throw new IOException("Could not read from channel");

  return buffer.get(0) & 0xff;
}
 
开发者ID:vilie,项目名称:javify,代码行数:18,代码来源:ChannelInputStream.java

示例4: implAccept

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * This protected method is used to help subclasses override
 * <code>ServerSocket.accept()</code>.  The passed in socket will be
 * connected when this method returns.
 *
 * @param socket The socket that is used for the accepted connection
 *
 * @exception IOException If an error occurs
 * @exception IllegalBlockingModeException If this socket has an associated
 * channel, and the channel is in non-blocking mode
 *
 * @since 1.1
 */
protected final void implAccept(Socket socket) throws IOException
{
  if (isClosed())
    throw new SocketException("ServerSocket is closed");

  // The Sun spec says that if we have an associated channel and
  // it is in non-blocking mode, we throw an IllegalBlockingModeException.
  // However, in our implementation if the channel itself initiated this
  // operation, then we must honor it regardless of its blocking mode.
  if (getChannel() != null && ! getChannel().isBlocking()
      && ! ((PlainSocketImpl) getImpl()).isInChannelOperation())
    throw new IllegalBlockingModeException();

  impl.accept(socket.impl);
  socket.bound = true;
  socket.implCreated = true;

  SecurityManager sm = System.getSecurityManager();
  if (sm != null)
    sm.checkAccept(socket.getInetAddress().getHostAddress(),
     socket.getPort());
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:36,代码来源:ServerSocket.java

示例5: receive

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
  * Reads a datagram packet from the socket.  Note that this method
  * will block until a packet is received from the network.  On return,
  * the passed in <code>DatagramPacket</code> is populated with the data
  * received and all the other information about the packet.
  *
  * @param p A <code>DatagramPacket</code> for storing the data
  *
  * @exception IOException If an error occurs.
  * @exception SocketTimeoutException If setSoTimeout was previously called
  * and the timeout has expired.
  * @exception PortUnreachableException If the socket is connected to a
  * currently unreachable destination. Note, there is no guarantee that the
  * exception will be thrown.
  * @exception IllegalBlockingModeException If this socket has an associated
  * channel, and the channel is in non-blocking mode.
  * @exception SecurityException If a security manager exists and its
  * checkAccept method doesn't allow the receive.
  */
 public synchronized void receive(DatagramPacket p) throws IOException
 {
   if (isClosed())
     throw new SocketException("socket is closed");

   if (remoteAddress != null && remoteAddress.isMulticastAddress())
     throw new IOException
("Socket connected to a multicast address my not receive");

   if (getChannel() != null && ! getChannel().isBlocking()
       && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
     throw new IllegalBlockingModeException();

   DatagramPacket p2 = new DatagramPacket(p.getData(), p.getOffset(), p.maxlen);
   getImpl().receive(p2);
   p.length = p2.length;
   if (p2.getAddress() != null)
     p.setAddress(p2.getAddress());
   if (p2.getPort() != -1)
     p.setPort(p2.getPort());

   SecurityManager s = System.getSecurityManager();
   if (s != null && isConnected())
     s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:45,代码来源:DatagramSocket.java

示例6: connect

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * Connects the socket with a remote address. A timeout of zero is
 * interpreted as an infinite timeout. The connection will then block
 * until established or an error occurs.
 *
 * @param endpoint The address to connect to
 * @param timeout The length of the timeout in milliseconds, or
 * 0 to indicate no timeout.
 *
 * @exception IOException If an error occurs
 * @exception IllegalArgumentException If the address type is not supported
 * @exception IllegalBlockingModeException If this socket has an associated
 * channel, and the channel is in non-blocking mode
 * @exception SocketTimeoutException If the timeout is reached
 *
 * @since 1.4
 */
public void connect(SocketAddress endpoint, int timeout)
  throws IOException
{
  if (isClosed())
    throw new SocketException("socket is closed");

  if (! (endpoint instanceof InetSocketAddress))
    throw new IllegalArgumentException("unsupported address type");

  // The Sun spec says that if we have an associated channel and
  // it is in non-blocking mode, we throw an IllegalBlockingModeException.
  // However, in our implementation if the channel itself initiated this
  // operation, then we must honor it regardless of its blocking mode.
  if (getChannel() != null && ! getChannel().isBlocking()
      && ! ((PlainSocketImpl) getImpl()).isInChannelOperation())
    throw new IllegalBlockingModeException();

  if (! isBound())
    bind(null);

  getImpl().connect(endpoint, timeout);
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:40,代码来源:Socket.java

示例7: read

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
public int read() throws IOException
 {
   if (ch instanceof SelectableChannel
&& (! ((SelectableChannel) ch).isBlocking()))
     throw new IllegalBlockingModeException();
     
   ByteBuffer buffer = ByteBuffer.allocate(1);
   int result = ch.read(buffer);

   if (result == -1)
     return -1;

   if (result == 0)
     throw new IOException("Could not read from channel");

   return buffer.get(0) & 0xff;
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:18,代码来源:ChannelInputStream.java

示例8: send

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
@Override
public void send(DatagramPacket packet) throws IOException {
    if (!channelImpl.isBlocking()) {
        throw new IllegalBlockingModeException();
    }

    // DatagramSocket.send() will implicitly bind if it hasn't been done explicitly. Force
    // bind() here so that the channel state stays in sync with the socket.
    boolean wasBound = isBound();
    super.send(packet);
    if (!wasBound) {
        // DatagramSocket.send() will implicitly bind if it hasn't been done explicitly.
        // Sync the channel state with the socket.
        channelImpl.onBind(false /* updateSocketState */);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:17,代码来源:DatagramChannelImpl.java

示例9: connect

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
@Override
public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.onBind(false);
    if (super.isConnected()) {
        InetSocketAddress remoteInetAddress = (InetSocketAddress) remoteAddr;
        channel.onConnectStatusChanged(
                remoteInetAddress, SOCKET_STATUS_CONNECTED, false /* updateSocketState */);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:17,代码来源:SocketChannelImpl.java

示例10: testSerializationSelf

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * @tests serialization/deserialization compatibility.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationSelf",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "IllegalBlockingModeException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new IllegalBlockingModeException());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:IllegalBlockingModeExceptionTest.java

示例11: testSerializationCompatibility

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * @tests serialization/deserialization compatibility with RI.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationGolden",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "IllegalBlockingModeException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest
            .verifyGolden(this, new IllegalBlockingModeException());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:IllegalBlockingModeExceptionTest.java

示例12: test_configureBlocking_Z_IllegalBlockingMode

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * @tests AbstractSelectableChannel#configureBlocking(boolean)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "configureBlocking",
    args = {boolean.class}
)
public void test_configureBlocking_Z_IllegalBlockingMode() throws Exception {
    SocketChannel sc = SocketChannel.open();
    sc.configureBlocking(false);
    Selector acceptSelector = SelectorProvider.provider().openSelector();
    SelectionKey acceptKey = sc.register(acceptSelector,
            SelectionKey.OP_READ, null);
    assertEquals(sc.keyFor(acceptSelector), acceptKey);
    SelectableChannel getChannel = sc.configureBlocking(false);
    assertEquals(getChannel, sc);
    try {
        sc.configureBlocking(true);
        fail("Should throw IllegalBlockingModeException");
    } catch (IllegalBlockingModeException e) {
        // expected
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:AbstractSelectableChannelTest.java

示例13: test_accept

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
public void test_accept() throws IOException {
    int portNumber = Support_PortManager.getNextPort();

    ServerSocket newSocket = new ServerSocket(portNumber);
    newSocket.setSoTimeout(500);
    try {
        Socket accepted = newSocket.accept();
        fail("SocketTimeoutException was not thrown: " + accepted);
    } catch(SocketTimeoutException expected) {
    }
    newSocket.close();

    ServerSocketChannel ssc = ServerSocketChannel.open();
    ServerSocket ss = ssc.socket();

    try {
        ss.accept();
        fail("IllegalBlockingModeException was not thrown.");
    } catch(IllegalBlockingModeException ibme) {
        //expected
    } finally {
        ss.close();
        ssc.close();
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:OldServerSocketTest.java

示例14: connect

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
/**
 * @see java.net.Socket#connect(java.net.SocketAddress, int)
 */
@Override
public void connect(SocketAddress remoteAddr, int timeout)
        throws IOException {
    if (!channel.isBlocking()) {
        throw new IllegalBlockingModeException();
    }
    if (isConnected()) {
        throw new AlreadyConnectedException();
    }
    super.connect(remoteAddr, timeout);
    channel.localAddress = networkSystem.getSocketLocalAddress(
            channel.fd, false);
    if (super.isConnected()) {
        channel.setConnected();
        channel.isBound = super.isBound();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SocketChannelImpl.java

示例15: testSocket_configureblocking

import java.nio.channels.IllegalBlockingModeException; //导入依赖的package包/类
public void testSocket_configureblocking() throws IOException {
    byte[] serverWBuf = new byte[CAPACITY_NORMAL];
    for (int i = 0; i < serverWBuf.length; i++) {
        serverWBuf[i] = (byte) i;
    }
    java.nio.ByteBuffer buf = java.nio.ByteBuffer
            .allocate(CAPACITY_NORMAL + 1);
    channel1.connect(localAddr1);
    server1.accept();
    Socket sock = this.channel1.socket();
    channel1.configureBlocking(false);
    assertFalse(channel1.isBlocking());
    OutputStream channelSocketOut = sock.getOutputStream();
    try {
        // write operation is not allowed in non-blocking mode
        channelSocketOut.write(buf.array());
        fail("Non-Blocking mode should cause IllegalBlockingModeException");
    } catch (IllegalBlockingModeException e) {
        // correct
    }
    channel1.configureBlocking(true);
    assertTrue(channel1.isBlocking());
    // write operation is allowed in blocking mode
    channelSocketOut.write(buf.array());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:SocketChannelTest.java


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