use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Encode_Request.
@Test
public void test_Encode_Request() throws IOException {
ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(2014);
Channel channel = getCliendSideChannel(url);
Request request = new Request();
Person person = new Person();
request.setData(person);
codec.encode(channel, encodeBuffer, request);
// encode resault check need decode
byte[] data = new byte[encodeBuffer.writerIndex()];
encodeBuffer.readBytes(data);
ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
Request obj = (Request) codec.decode(channel, decodeBuffer);
Assertions.assertEquals(request.isBroken(), obj.isBroken());
Assertions.assertEquals(request.isHeartbeat(), obj.isHeartbeat());
Assertions.assertEquals(request.isTwoWay(), obj.isTwoWay());
Assertions.assertEquals(person, obj.getData());
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Request_Event_Object.
@Test
public void test_Decode_Return_Request_Event_Object() throws IOException {
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
System.setProperty("deserialization.event.size", "100");
Request obj = (Request) decode(request);
Assertions.assertEquals(person, obj.getData());
Assertions.assertTrue(obj.isTwoWay());
Assertions.assertTrue(obj.isEvent());
Assertions.assertEquals(Version.getProtocolVersion(), obj.getVersion());
System.out.println(obj);
System.clearProperty("deserialization.event.size");
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ExchangeCodecTest method test_Decode_Return_Request_Object.
@Test
public void test_Decode_Return_Request_Object() throws IOException {
// |10011111|20-stats=ok|id=0|length=0
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xc2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Request obj = (Request) decode(request);
Assertions.assertEquals(person, obj.getData());
Assertions.assertTrue(obj.isTwoWay());
Assertions.assertFalse(obj.isHeartbeat());
Assertions.assertEquals(Version.getProtocolVersion(), obj.getVersion());
System.out.println(obj);
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class AllChannelHandler2 method received.
@Override
public void received(Channel channel, Object message) throws RemotingException {
ExecutorService executor = getPreferredExecutorService(message);
try {
Future<?> future = executor.submit(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message));
long timeout = this.url.getParameter("timeout", 1000) + 90;
TIME_OUT_TIMER.newTimeout(t -> {
if (!future.isDone() && (!future.isCancelled())) {
try {
future.cancel(true);
} catch (Throwable ex) {
// ignore
}
}
}, timeout, TimeUnit.MILLISECONDS);
} catch (Throwable t) {
if (message instanceof Request && t instanceof RejectedExecutionException) {
sendFeedback(channel, (Request) message, t);
return;
}
throw new ExecutionException(message, channel, getClass() + " error when process received event .", t);
}
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class HeaderExchangeChannel method send.
@Override
public void send(Object message, boolean sent) throws RemotingException {
if (closed) {
throw new RemotingException(this.getLocalAddress(), null, "Failed to send message " + message + ", cause: The channel " + this + " is closed!");
}
if (message instanceof Request || message instanceof Response || message instanceof String) {
channel.send(message, sent);
} else {
Request request = new Request();
request.setVersion(Version.getProtocolVersion());
request.setTwoWay(false);
request.setData(message);
channel.send(request, sent);
}
}
Aggregations