use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.
the class TcpClientConnection method writeToBufferQueue.
private boolean writeToBufferQueue(AbstractTcpClientPackage tcpClientPackage) {
// just optimize for main scenes
if (Status.WORKING.equals(status)) {
// encode in sender thread
try (TcpOutputStream os = tcpClientPackage.createStream()) {
write(os.getByteBuf());
tcpClientPackage.finishWriteToBuffer();
}
return true;
}
return false;
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.
the class TcpClientConnection method tryLogin.
protected void tryLogin() {
if (!localSupportLogin || !remoteSupportLogin) {
LOGGER.error("local or remote not support login, address={}, localSupportLogin={}, remoteSupportLogin={}.", socketAddress.toString(), localSupportLogin, remoteSupportLogin);
onLoginSuccess();
return;
}
this.status = Status.TRY_LOGIN;
LOGGER.info("try login to address {}", socketAddress.toString());
try (TcpOutputStream os = createLogin()) {
requestMap.put(os.getMsgId(), new TcpRequest(clientConfig.getMsLoginTimeout(), this::onLoginResponse));
netSocket.write(os.getBuffer());
}
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.
the class TcpClientConnection method writePackageInContext.
private void writePackageInContext() {
for (; ; ) {
AbstractTcpClientPackage pkg = packageQueue.poll();
if (pkg == null) {
break;
}
try (TcpOutputStream os = pkg.createStream()) {
Buffer buf = os.getBuffer();
netSocket.write(buf);
pkg.finishWriteToBuffer();
}
}
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TestTcpParser method test.
@Test
public void test() throws UnsupportedEncodingException {
TcpBufferHandler output = new TcpBufferHandler() {
@Override
public void handle(long _msgId, Buffer _headerBuffer, Buffer _bodyBuffer) {
msgId = _msgId;
headerBuffer = _headerBuffer;
bodyBuffer = _bodyBuffer;
}
};
byte[] header = new byte[] { 1, 2, 3 };
byte[] body = new byte[] { 1, 2, 3, 4 };
TcpOutputStream os = new TcpOutputStream(1);
os.writeInt(header.length + body.length);
os.writeInt(header.length);
os.write(header);
os.write(body);
TcpParser parser = new TcpParser(output);
parser.handle(os.getBuffer());
os.close();
Assert.assertEquals(1, msgId);
Assert.assertArrayEquals(header, headerBuffer.getBytes());
Assert.assertArrayEquals(body, bodyBuffer.getBytes());
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TcpClientConnection method writePackageInContext.
private void writePackageInContext() {
for (; ; ) {
AbstractTcpClientPackage pkg = packageQueue.poll();
if (pkg == null) {
break;
}
try (TcpOutputStream os = pkg.createStream()) {
Buffer buf = os.getBuffer();
netSocket.write(buf);
pkg.finishWriteToBuffer();
}
}
}
Aggregations