Java 类java.nio.channels.NotYetConnectedException 实例源码

项目:nuls    文件:Node.java   
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();
    }
}
项目:nuls    文件:BroadcasterImpl.java   
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");
}
项目:creacoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:okwallet    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:cryptwallet    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:Dream-Catcher    文件:JsonRpcPeer.java   
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);
}
项目:weex    文件:JsonRpcPeer.java   
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);
}
项目:javify    文件:DatagramChannelImpl.java   
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);
}
项目:nfs-client-java    文件:ClientIOHandler.java   
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();
    }
}
项目:stetho    文件:JsonRpcPeer.java   
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);
}
项目:jvm-stm    文件:DatagramChannelImpl.java   
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);
}
项目:namecoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:netty4.0.27Learn    文件:OioByteStreamChannel.java   
@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;
        }
    }
}
项目:CoinJoin    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:digibytej-alice    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:In-the-Box-Fork    文件:DatagramChannelTest.java   
@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));
}
项目:In-the-Box-Fork    文件:NotYetConnectedExceptionTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:NotYetConnectedExceptionTest.java   
/**
 * @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());
}
项目:In-the-Box-Fork    文件:OldSocketChannelTest.java   
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
    }
}
项目:megacoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:My-Wallet-Android    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:netty4study    文件:OioByteStreamChannel.java   
@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;
        }
    }
}
项目:cannabiscoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:sparkbit-bitcoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:wv_websocket    文件:WebSocket.java   
/**
 * 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();
}
项目:bitherj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:cn1    文件:DatagramChannelTest.java   
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));

}
项目:cn1    文件:DatagramChannelTest.java   
public void testWriteByteBufferArrayIntInt_NonBlock() throws IOException {
    ByteBuffer[] writeBuf = new ByteBuffer[2];
    writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
    InetSocketAddress ipAddr = localAddr1; 
    // non-block mode
    this.channel1.configureBlocking(false);
    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));

}
项目:JamVM-PH    文件:DatagramChannelImpl.java   
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);
}
项目:wowdoge.org    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:quarkcoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:templecoin-java    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:animecoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:betacoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:mintcoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:netty-netty-5.0.0.Alpha1    文件:OioByteStreamChannel.java   
@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;
        }
    }
}
项目:NuBitsj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:myriadcoinj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:dashj    文件:PeerSocketHandler.java   
/**
 * 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);
    }
}
项目:nuls    文件:Node.java   
public void sendMessage(NulsMessage message) throws IOException {
    if (this.getStatus() == Node.CLOSE) {
        return;
    }
    if (writeTarget == null || this.status != Node.HANDSHAKE) {
        throw new NotYetConnectedException();
    }
    lock.lock();
    try {
        System.out.println("---send message:" + Hex.encode(message.serialize()));
        this.writeTarget.write(message.serialize());
    } finally {
        lock.unlock();
    }
}