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


Java NotYetConnectedException类代码示例

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


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

示例1: sendNetworkEvent

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void sendNetworkEvent(BaseEvent event) throws IOException {
    if (this.getStatus() == Node.CLOSE) {
        return;
    }
    if (writeTarget == null) {
        throw new NotYetConnectedException();
    }
    if (this.status != Node.HANDSHAKE && !isHandShakeMessage(event)) {
        throw new NotYetConnectedException();
    }
    lock.lock();
    try {
        byte[] data = event.serialize();
        NulsMessage message = new NulsMessage(magicNumber, data);
        this.writeTarget.write(message.serialize());
    } finally {
        lock.unlock();
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:20,代码来源:Node.java

示例2: broadcastToGroup

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
private BroadcastResult broadcastToGroup(NulsMessage message, String groupName, String excludeNodeId) {
    List<Node> broadNodes = nodesManager.getGroupAvailableNodes(groupName, excludeNodeId);
    if (broadNodes.size() <= 1) {
        return new BroadcastResult(false, "no node can be broadcast");
    }

    int successCount = 0;
    for (Node node : broadNodes) {
        try {
            node.sendMessage(message);
            successCount++;
        } catch (NotYetConnectedException | IOException e) {
            Log.warn("broadcast message error , maybe the node closed ! node ip :{}, {}", node.getIp(), e.getMessage());
        }
    }

    if (successCount == 0) {
        new BroadcastResult(false, "broadcast fail", broadNodes);
    }
    Log.debug("成功广播给{}个节点,消息{}", successCount, message);
    return new BroadcastResult(true, "OK");
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:23,代码来源:BroadcasterImpl.java

示例3: sendMessage

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
/**
 * Sends the given message to the peer. Due to the asynchronousness of network programming, there is no guarantee
 * the peer will have received it. Throws NotYetConnectedException if we are not yet connected to the remote peer.
 * TODO: Maybe use something other than the unchecked NotYetConnectedException here
 */
public void sendMessage(Message message) throws NotYetConnectedException {
    lock.lock();
    try {
        if (writeTarget == null)
            throw new NotYetConnectedException();
    } finally {
        lock.unlock();
    }
    // TODO: Some round-tripping could be avoided here
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        serializer.serialize(message, out);
        writeTarget.writeBytes(out.toByteArray());
    } catch (IOException e) {
        exceptionCaught(e);
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:23,代码来源:PeerSocketHandler.java

示例4: invokeMethod

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void invokeMethod(String method, Object paramsObject,
                         @Nullable PendingRequestCallback callback)
    throws NotYetConnectedException {
  Util.throwIfNull(method);

  Long requestId = (callback != null) ? preparePendingRequest(callback) : null;

  // magic, can basically convert anything for some amount of runtime overhead...
  JSONObject params = mObjectMapper.convertValue(paramsObject, JSONObject.class);

  JsonRpcRequest message = new JsonRpcRequest(requestId, method, params);
  String requestString;
  JSONObject jsonObject = mObjectMapper.convertValue(message, JSONObject.class);
  requestString = jsonObject.toString();
  mPeer.sendText(requestString);
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:17,代码来源:JsonRpcPeer.java

示例5: invokeMethod

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void invokeMethod(String method, Object paramsObject,
    @Nullable PendingRequestCallback callback)
    throws NotYetConnectedException {
  Util.throwIfNull(method);

  Long requestId = (callback != null) ? preparePendingRequest(callback) : null;

  // magic, can basically convert anything for some amount of runtime overhead...
  JSONObject params = mObjectMapper.convertValue(paramsObject, JSONObject.class);

  JsonRpcRequest message = new JsonRpcRequest(requestId, method, params);
  String requestString;
  JSONObject jsonObject = mObjectMapper.convertValue(message, JSONObject.class);
  requestString = jsonObject.toString();
  mPeer.sendText(requestString);
}
 
开发者ID:Laisly,项目名称:weex,代码行数:17,代码来源:JsonRpcPeer.java

示例6: write

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public long write (ByteBuffer[] srcs, int offset, int length)
  throws IOException
{
  if (!isConnected())
    throw new NotYetConnectedException();

  if ((offset < 0)
      || (offset > srcs.length)
      || (length < 0)
      || (length > (srcs.length - offset)))
    throw new IndexOutOfBoundsException();

  /* We are connected, meaning we will write these bytes to
   * the host we connected to, so we don't need to explicitly
   * give the host. */
  return channel.writeGathering(srcs, offset, length);
}
 
开发者ID:vilie,项目名称:javify,代码行数:18,代码来源:DatagramChannelImpl.java

示例7: exceptionCaught

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable cause = e.getCause();

    // do not print exception if it is BindException.
    // we are trying to search available port below 1024. It is not good to
    // print a flood
    // of error logs during the searching.
    if (cause instanceof java.net.BindException) {
        return;
    }

    LOG.error("Exception on connection to " + getRemoteAddress(), e.getCause());

    // close the channel unless we are connecting and it is
    // NotYetConnectedException
    if (!((cause instanceof NotYetConnectedException)
            && _connection.getConnectionState().equals(Connection.State.CONNECTING))) {
        ctx.getChannel().close();
    }
}
 
开发者ID:EMCECS,项目名称:nfs-client-java,代码行数:21,代码来源:ClientIOHandler.java

示例8: doWriteFileRegion

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
@Override
protected void doWriteFileRegion(FileRegion region) throws Exception {
    OutputStream os = this.os;
    if (os == null) {
        throw new NotYetConnectedException();
    }
    if (outChannel == null) {
        outChannel = Channels.newChannel(os);
    }

    long written = 0;
    for (;;) {
        long localWritten = region.transferTo(outChannel, written);
        if (localWritten == -1) {
            checkEOF(region);
            return;
        }
        written += localWritten;

        if (written >= region.count()) {
            return;
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:25,代码来源:OioByteStreamChannel.java

示例9: testWriteByteBufferArray_Block

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Doesn't verify all exceptions according to specification.",
    method = "write",
    args = {java.nio.ByteBuffer[].class}
)
public void testWriteByteBufferArray_Block() throws IOException {
    ByteBuffer[] writeBuf = new ByteBuffer[2];
    writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    InetSocketAddress ipAddr = localAddr1;
    try {
        this.channel1.write(writeBuf);
        fail("Should throw NotYetConnectedException.");
    } catch (NotYetConnectedException e) {
        // correct
    }
    this.channel1.connect(ipAddr);
    assertTrue(this.channel1.isConnected());
    assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf));
    // cannot be buffered again!
    assertEquals(0, this.channel1.write(writeBuf));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:DatagramChannelTest.java

示例10: testSerializationSelf

import java.nio.channels.NotYetConnectedException; //导入依赖的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 = "NotYetConnectedException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

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

示例11: testSerializationCompatibility

import java.nio.channels.NotYetConnectedException; //导入依赖的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 = "NotYetConnectedException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

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

示例12: testOpen

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void testOpen() throws IOException {
    java.nio.ByteBuffer[] buf = new java.nio.ByteBuffer[1];
    buf[0] = java.nio.ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    MockSocketChannel testMSChannel = new MockSocketChannel(null);
    MockSocketChannel testMSChannelnotnull = new MockSocketChannel(
            SelectorProvider.provider());
    SocketChannel testSChannel = MockSocketChannel.open();
    assertTrue(testSChannel.isOpen());
    assertNull(testMSChannel.provider());
    assertNotNull(testSChannel.provider());
    assertEquals(SelectorProvider.provider(), testSChannel.provider());
    assertNotNull(testMSChannelnotnull.provider());
    assertEquals(this.channel1.provider(), testMSChannelnotnull.provider());
    try {
        this.channel1.write(buf);
        fail("Should throw NotYetConnectedException");
    } catch (NotYetConnectedException e) {
        // correct
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:OldSocketChannelTest.java

示例13: send

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
/**
 * Sends <var>text</var> to server
 *
 * @param text
 *            String to send to server
 */
@JavascriptInterface
public void send(final String text) {
	new Thread(new Runnable() {
		@Override
		public void run() {
			if (instance.readyState == WEBSOCKET_STATE_OPEN) {
				try {
					instance._send(text);
				} catch (Exception e) {
					instance.onError(e);
				}
			} else {
				instance.onError(new NotYetConnectedException());
			}
		}
	}).start();
}
 
开发者ID:hayksaakian,项目名称:wv_websocket,代码行数:24,代码来源:WebSocket.java

示例14: sendMessage

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
/**
 * Sends the given message to the peer. Due to the asynchronousness of network programming,
 * there is no guarantee
 * the peer will have received it. Throws NotYetConnectedException if we are not yet
 * connected to the remote peer.
 * TODO: Maybe use something other than the unchecked NotYetConnectedException here
 */
public void sendMessage(Message message) throws NotYetConnectedException {
    lock.lock();
    try {
        if (writeTarget == null) {
            throw new NotYetConnectedException();
        }
    } finally {
        lock.unlock();
    }
    // TODO: Some round-tripping could be avoided here
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        serializer.serialize(message, out);
        writeTarget.writeBytes(out.toByteArray());
    } catch (IOException e) {
        exceptionCaught(e);
    }
}
 
开发者ID:bither,项目名称:bitherj,代码行数:26,代码来源:PeerSocketHandler.java

示例15: testWriteByteBufferArrayIntInt_Block

import java.nio.channels.NotYetConnectedException; //导入依赖的package包/类
public void testWriteByteBufferArrayIntInt_Block() throws IOException {
    ByteBuffer[] writeBuf = new ByteBuffer[2];
    writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    InetSocketAddress ipAddr = localAddr1; 
    try {
        this.channel1.write(writeBuf, 0, 2);
        fail("Should throw NotYetConnectedException.");
    } catch (NotYetConnectedException e) {
        // correct
    }
    this.channel1.connect(ipAddr); 
    assertTrue(this.channel1.isConnected());
    assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
    // cannot be buffered again!
    assertEquals(0, this.channel1.write(writeBuf, 0, 1));

}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:DatagramChannelTest.java


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