Here are the examples of the java api com.alibaba.dubbo.remoting.Channel taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
457 Examples
19
Source : ThriftCodecTest.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* @author <a href="mailto:[email protected]">gang.lvg</a>
*/
public clreplaced ThriftCodecTest {
private ThriftCodec codec = new ThriftCodec();
private Channel channel = new MockedChannel(URL.valueOf("thrift://127.0.0.1"));
@Test
public void testEncodeRequest() throws Exception {
Request request = createRequest();
ChannelBuffer output = ChannelBuffers.dynamicBuffer(1024);
codec.encode(channel, output, request);
byte[] bytes = new byte[output.readableBytes()];
output.readBytes(bytes);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
TTransport transport = new TIOStreamTransport(bis);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
// frame
byte[] length = new byte[4];
transport.read(length, 0, 4);
if (bis.markSupported()) {
bis.mark(0);
}
// magic
replacedert.replacedertEquals(ThriftCodec.MAGIC, protocol.readI16());
// message length
int messageLength = protocol.readI32();
replacedert.replacedertEquals(messageLength + 4, bytes.length);
// header length
short headerLength = protocol.readI16();
// version
replacedert.replacedertEquals(ThriftCodec.VERSION, protocol.readByte());
// service name
replacedert.replacedertEquals(Demo.Iface.clreplaced.getName(), protocol.readString());
// dubbo request id
replacedert.replacedertEquals(request.getId(), protocol.readI64());
// test message header length
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
Demo.echoString_args args = new Demo.echoString_args();
args.read(protocol);
protocol.readMessageEnd();
replacedert.replacedertEquals("echoString", message.name);
replacedert.replacedertEquals(TMessageType.CALL, message.type);
replacedert.replacedertEquals("Hello, World!", args.getArg());
}
@Test
public void testDecodeReplyResponse() throws Exception {
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.clreplaced.getName());
Channel channel = new MockedChannel(url);
RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(128);
Request request = createRequest();
DefaultFuture future = new DefaultFuture(channel, request, 10);
TMessage message = new TMessage("echoString", TMessageType.REPLY, ThriftCodec.getSeqId());
Demo.echoString_result methodResult = new Demo.echoString_result();
methodResult.success = "Hello, World!";
TTransport transport = new TIOStreamTransport(bos);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
int messageLength, headerLength;
// prepare
protocol.writeI16(ThriftCodec.MAGIC);
protocol.writeI32(Integer.MAX_VALUE);
protocol.writeI16(Short.MAX_VALUE);
protocol.writeByte(ThriftCodec.VERSION);
protocol.writeString(Demo.Iface.clreplaced.getName());
protocol.writeI64(request.getId());
protocol.getTransport().flush();
headerLength = bos.size();
protocol.writeMessageBegin(message);
methodResult.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex(ThriftCodec.MESSAGE_LENGTH_INDEX);
protocol.writeI32(messageLength);
bos.setWriteIndex(ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX);
protocol.writeI16((short) (0xffff & headerLength));
} finally {
bos.setWriteIndex(oldIndex);
}
// prepare
byte[] buf = new byte[4 + bos.size()];
System.arraycopy(bos.toByteArray(), 0, buf, 4, bos.size());
ChannelBuffer bis = ChannelBuffers.wrappedBuffer(buf);
Object obj = codec.decode((Channel) null, bis);
replacedert.replacedertNotNull(obj);
replacedert.replacedertEquals(true, obj instanceof Response);
Response response = (Response) obj;
replacedert.replacedertEquals(request.getId(), response.getId());
replacedert.replacedertTrue(response.getResult() instanceof RpcResult);
RpcResult result = (RpcResult) response.getResult();
replacedert.replacedertTrue(result.getResult() instanceof String);
replacedert.replacedertEquals(methodResult.success, result.getResult());
}
@Test
public void testDecodeExceptionResponse() throws Exception {
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.clreplaced.getName());
Channel channel = new MockedChannel(url);
RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(128);
Request request = createRequest();
DefaultFuture future = new DefaultFuture(channel, request, 10);
TMessage message = new TMessage("echoString", TMessageType.EXCEPTION, ThriftCodec.getSeqId());
TTransport transport = new TIOStreamTransport(bos);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TApplicationException exception = new TApplicationException();
int messageLength, headerLength;
// prepare
protocol.writeI16(ThriftCodec.MAGIC);
protocol.writeI32(Integer.MAX_VALUE);
protocol.writeI16(Short.MAX_VALUE);
protocol.writeByte(ThriftCodec.VERSION);
protocol.writeString(Demo.clreplaced.getName());
protocol.writeI64(request.getId());
protocol.getTransport().flush();
headerLength = bos.size();
protocol.writeMessageBegin(message);
exception.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex(ThriftCodec.MESSAGE_LENGTH_INDEX);
protocol.writeI32(messageLength);
bos.setWriteIndex(ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX);
protocol.writeI16((short) (0xffff & headerLength));
} finally {
bos.setWriteIndex(oldIndex);
}
// prepare
ChannelBuffer bis = ChannelBuffers.wrappedBuffer(encodeFrame(bos.toByteArray()));
Object obj = codec.decode((Channel) null, bis);
replacedert.replacedertNotNull(obj);
replacedert.replacedertTrue(obj instanceof Response);
Response response = (Response) obj;
replacedert.replacedertTrue(response.getResult() instanceof RpcResult);
RpcResult result = (RpcResult) response.getResult();
replacedert.replacedertTrue(result.hasException());
replacedert.replacedertTrue(result.getException() instanceof RpcException);
}
@Test
public void testEncodeReplyResponse() throws Exception {
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.clreplaced.getName());
Channel channel = new MockedChannel(url);
Request request = createRequest();
RpcResult rpcResult = new RpcResult();
rpcResult.setResult("Hello, World!");
Response response = new Response();
response.setResult(rpcResult);
response.setId(request.getId());
ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);
ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(ThriftCodec.getSeqId(), Demo.Iface.clreplaced.getName(), "echoString");
ThriftCodec.cachedRequest.putIfAbsent(request.getId(), rd);
codec.encode(channel, bos, response);
byte[] buf = new byte[bos.writerIndex() - 4];
System.arraycopy(bos.array(), 4, buf, 0, bos.writerIndex() - 4);
ByteArrayInputStream bis = new ByteArrayInputStream(buf);
if (bis.markSupported()) {
bis.mark(0);
}
TIOStreamTransport transport = new TIOStreamTransport(bis);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
replacedert.replacedertEquals(ThriftCodec.MAGIC, protocol.readI16());
replacedert.replacedertEquals(protocol.readI32() + 4, bos.writerIndex());
int headerLength = protocol.readI16();
replacedert.replacedertEquals(ThriftCodec.VERSION, protocol.readByte());
replacedert.replacedertEquals(Demo.Iface.clreplaced.getName(), protocol.readString());
replacedert.replacedertEquals(request.getId(), protocol.readI64());
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
replacedert.replacedertEquals("echoString", message.name);
replacedert.replacedertEquals(TMessageType.REPLY, message.type);
replacedert.replacedertEquals(ThriftCodec.getSeqId(), message.seqid);
Demo.echoString_result result = new Demo.echoString_result();
result.read(protocol);
protocol.readMessageEnd();
replacedert.replacedertEquals(rpcResult.getValue(), result.getSuccess());
}
@Test
public void testEncodeExceptionResponse() throws Exception {
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.clreplaced.getName());
Channel channel = new MockedChannel(url);
Request request = createRequest();
RpcResult rpcResult = new RpcResult();
String exceptionMessage = "failed";
rpcResult.setException(new RuntimeException(exceptionMessage));
Response response = new Response();
response.setResult(rpcResult);
response.setId(request.getId());
ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);
ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(ThriftCodec.getSeqId(), Demo.Iface.clreplaced.getName(), "echoString");
ThriftCodec.cachedRequest.put(request.getId(), rd);
codec.encode(channel, bos, response);
byte[] buf = new byte[bos.writerIndex() - 4];
System.arraycopy(bos.array(), 4, buf, 0, bos.writerIndex() - 4);
ByteArrayInputStream bis = new ByteArrayInputStream(buf);
if (bis.markSupported()) {
bis.mark(0);
}
TIOStreamTransport transport = new TIOStreamTransport(bis);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
replacedert.replacedertEquals(ThriftCodec.MAGIC, protocol.readI16());
replacedert.replacedertEquals(protocol.readI32() + 4, bos.writerIndex());
int headerLength = protocol.readI16();
replacedert.replacedertEquals(ThriftCodec.VERSION, protocol.readByte());
replacedert.replacedertEquals(Demo.Iface.clreplaced.getName(), protocol.readString());
replacedert.replacedertEquals(request.getId(), protocol.readI64());
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
replacedert.replacedertEquals("echoString", message.name);
replacedert.replacedertEquals(TMessageType.EXCEPTION, message.type);
replacedert.replacedertEquals(ThriftCodec.getSeqId(), message.seqid);
TApplicationException exception = TApplicationException.read(protocol);
protocol.readMessageEnd();
replacedert.replacedertEquals(exceptionMessage, exception.getMessage());
}
@Test
public void testDecodeRequest() throws Exception {
Request request = createRequest();
// encode
RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024);
TIOStreamTransport transport = new TIOStreamTransport(bos);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
int messageLength, headerLength;
protocol.writeI16(ThriftCodec.MAGIC);
protocol.writeI32(Integer.MAX_VALUE);
protocol.writeI16(Short.MAX_VALUE);
protocol.writeByte(ThriftCodec.VERSION);
protocol.writeString(((RpcInvocation) request.getData()).getAttachment(Constants.INTERFACE_KEY));
protocol.writeI64(request.getId());
protocol.getTransport().flush();
headerLength = bos.size();
Demo.echoString_args args = new Demo.echoString_args();
args.setArg("Hell, World!");
TMessage message = new TMessage("echoString", TMessageType.CALL, ThriftCodec.getSeqId());
protocol.writeMessageBegin(message);
args.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex(ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX);
protocol.writeI16((short) (0xffff & headerLength));
bos.setWriteIndex(ThriftCodec.MESSAGE_LENGTH_INDEX);
protocol.writeI32(messageLength);
} finally {
bos.setWriteIndex(oldIndex);
}
Object obj = codec.decode((Channel) null, ChannelBuffers.wrappedBuffer(encodeFrame(bos.toByteArray())));
replacedert.replacedertTrue(obj instanceof Request);
obj = ((Request) obj).getData();
replacedert.replacedertTrue(obj instanceof RpcInvocation);
RpcInvocation invocation = (RpcInvocation) obj;
replacedert.replacedertEquals("echoString", invocation.getMethodName());
replacedert.replacedertArrayEquals(new Clreplaced[] { String.clreplaced }, invocation.getParameterTypes());
replacedert.replacedertArrayEquals(new Object[] { args.getArg() }, invocation.getArguments());
}
private Request createRequest() {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("echoString");
invocation.setArguments(new Object[] { "Hello, World!" });
invocation.setParameterTypes(new Clreplaced<?>[] { String.clreplaced });
invocation.setAttachment(Constants.INTERFACE_KEY, Demo.Iface.clreplaced.getName());
Request request = new Request(1L);
request.setData(invocation);
return request;
}
static byte[] encodeFrame(byte[] content) {
byte[] result = new byte[4 + content.length];
TFramedTransport.encodeFrameSize(content.length, result);
System.arraycopy(content, 0, result, 4, content.length);
return result;
}
}
19
Source : ThriftNativeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
return null;
}
19
Source : ThriftNativeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void encode(Channel channel, ChannelBuffer buffer, Object message) throws IOException {
if (message instanceof Request) {
encodeRequest(channel, buffer, (Request) message);
} else if (message instanceof Response) {
encodeResponse(channel, buffer, (Response) message);
} else {
throw new IOException("Unsupported message type " + message.getClreplaced().getName());
}
}
19
Source : CurrentTelnetHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public String telnet(Channel channel, String message) {
if (message.length() > 0) {
return "Unsupported parameter " + message + " for pwd.";
}
String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY);
StringBuilder buf = new StringBuilder();
if (service == null || service.length() == 0) {
buf.append("/");
} else {
buf.append(service);
}
return buf.toString();
}
19
Source : DubboCountCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void encode(Channel channel, ChannelBuffer buffer, Object msg) throws IOException {
codec.encode(channel, buffer, msg);
}
19
Source : ChannelWrappedInvoker.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* 基于已有channel的invoker.
*
* @author chao.liuc
*/
clreplaced ChannelWrappedInvoker<T> extends AbstractInvoker<T> {
private final Channel channel;
private final String serviceKey;
public ChannelWrappedInvoker(Clreplaced<T> serviceType, Channel channel, URL url, String serviceKey) {
super(serviceType, url, new String[] { Constants.GROUP_KEY, Constants.TOKEN_KEY, Constants.TIMEOUT_KEY });
this.channel = channel;
this.serviceKey = serviceKey;
}
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
RpcInvocation inv = (RpcInvocation) invocation;
// 拿不到client端export 的service path.约定为interface的名称.
inv.setAttachment(Constants.PATH_KEY, getInterface().getName());
inv.setAttachment(Constants.CALLBACK_SERVICE_KEY, serviceKey);
ExchangeClient currentClient = new HeaderExchangeClient(new ChannelWrapper(this.channel));
try {
if (getUrl().getMethodParameter(invocation.getMethodName(), Constants.ASYNC_KEY, false)) {
// 不可靠异步
currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), Constants.SENT_KEY, false));
return new RpcResult();
}
int timeout = getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
if (timeout > 0) {
return (Result) currentClient.request(inv, timeout).get();
} else {
return (Result) currentClient.request(inv).get();
}
} catch (RpcException e) {
throw e;
} catch (TimeoutException e) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
} catch (RemotingException e) {
throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
} catch (Throwable e) {
// here is non-biz exception, wrap it.
throw new RpcException(e.getMessage(), e);
}
}
public static clreplaced ChannelWrapper extends ClientDelegate {
private final Channel channel;
private final URL url;
public ChannelWrapper(Channel channel) {
this.channel = channel;
this.url = channel.getUrl().addParameter("codec", DubboCodec.NAME);
}
public URL getUrl() {
return url;
}
public ChannelHandler getChannelHandler() {
return channel.getChannelHandler();
}
public InetSocketAddress getLocalAddress() {
return channel.getLocalAddress();
}
public void close() {
channel.close();
}
public boolean isClosed() {
return channel == null ? true : channel.isClosed();
}
public void reset(URL url) {
throw new RpcException("ChannelInvoker can not reset.");
}
public InetSocketAddress getRemoteAddress() {
return channel.getLocalAddress();
}
public boolean isConnected() {
return channel == null ? false : channel.isConnected();
}
public boolean hasAttribute(String key) {
return channel.hasAttribute(key);
}
public Object getAttribute(String key) {
return channel.getAttribute(key);
}
public void setAttribute(String key, Object value) {
channel.setAttribute(key, value);
}
public void removeAttribute(String key) {
channel.removeAttribute(key);
}
public void reconnect() throws RemotingException {
}
public void send(Object message) throws RemotingException {
channel.send(message);
}
public void send(Object message, boolean sent) throws RemotingException {
channel.send(message, sent);
}
}
public void destroy() {
// channel资源的清空由channel创建者清除.
// super.destroy();
// try {
// channel.close();
// } catch (Throwable t) {
// logger.warn(t.getMessage(), t);
// }
}
}
19
Source : CallbackServiceCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private static String getServerSideCallbackServiceCacheKey(Channel channel, String interfaceClreplaced, int instid) {
return Constants.CALLBACK_SERVICE_PROXY_KEY + "." + System.idenreplacedyHashCode(channel) + "." + interfaceClreplaced + "." + instid;
}
19
Source : CallbackServiceCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private static boolean isInstancesOverLimit(Channel channel, URL url, String interfaceClreplaced, int instid, boolean isServer) {
Integer count = (Integer) channel.getAttribute(isServer ? getServerSideCountKey(channel, interfaceClreplaced) : getClientSideCountKey(interfaceClreplaced));
int limit = url.getParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, Constants.DEFAULT_CALLBACK_INSTANCES);
if (count != null && count >= limit) {
// client side error
throw new IllegalStateException("interface " + interfaceClreplaced + " `s callback instances num exceed providers limit :" + limit + " ,current num: " + (count + 1) + ". The new callback service will not work !!! you can cancle the callback service which exported before. channel :" + channel);
} else {
return false;
}
}
19
Source : CallbackServiceCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private static String getServerSideCallbackInvokerCacheKey(Channel channel, String interfaceClreplaced, int instid) {
return getServerSideCallbackServiceCacheKey(channel, interfaceClreplaced, instid) + "." + "invoker";
}
19
Source : CallbackServiceCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private static String getServerSideCountKey(Channel channel, String interfaceClreplaced) {
return Constants.CALLBACK_SERVICE_PROXY_KEY + "." + System.idenreplacedyHashCode(channel) + "." + interfaceClreplaced + ".COUNT";
}
19
Source : DeprecatedTelnetCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Object decode(Channel channel, InputStream is) throws IOException {
int readable = is.available();
byte[] message = new byte[readable];
is.read(message);
return decode(channel, is, readable, message);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected Object decodeData(Channel channel, ObjectInput in) throws IOException {
return decodeRequestData(channel, in);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void encode(Channel channel, OutputStream os, Object msg) throws IOException {
if (msg instanceof Request) {
encodeRequest(channel, os, (Request) msg);
} else if (msg instanceof Response) {
encodeResponse(channel, os, (Response) msg);
} else {
super.encode(channel, os, msg);
}
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected Object decodeResponseData(Channel channel, ObjectInput in, Object requestData) throws IOException {
return decodeResponseData(channel, in);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected void encodeRequestData(Channel channel, ObjectOutput out, Object data) throws IOException {
encodeRequestData(out, data);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
private void encodeEventData(Channel channel, ObjectOutput out, Object data) throws IOException {
encodeEventData(out, data);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Object decode(Channel channel, InputStream is) throws IOException {
int readable = is.available();
byte[] header = new byte[Math.min(readable, HEADER_LENGTH)];
is.read(header);
return decode(channel, is, readable, header);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException {
encodeResponseData(out, data);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected void encodeData(Channel channel, ObjectOutput out, Object data) throws IOException {
encodeRequestData(channel, out, data);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected Object decodeEventData(Channel channel, ObjectInput in) throws IOException {
try {
return in.readObject();
} catch (ClreplacedNotFoundException e) {
throw new IOException(StringUtils.toString("Read object failed.", e));
}
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected Object decodeRequestData(Channel channel, ObjectInput in) throws IOException {
return decodeRequestData(in);
}
19
Source : DeprecatedExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected Object decodeResponseData(Channel channel, ObjectInput in) throws IOException {
return decodeResponseData(in);
}
19
Source : MockedChannelHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void caught(Channel channel, Throwable exception) throws RemotingException {
throw new RemotingException(channel, exception);
}
19
Source : ExecutionChannelHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void caught(Channel channel, Throwable exception) throws RemotingException {
executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CAUGHT, exception));
}
19
Source : ExecutionChannelHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void connected(Channel channel) throws RemotingException {
executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.CONNECTED));
}
19
Source : ExecutionChannelHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void disconnected(Channel channel) throws RemotingException {
executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.DISCONNECTED));
}
19
Source : ExecutionChannelHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void received(Channel channel, Object message) throws RemotingException {
executor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message));
}
19
Source : DecodeHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void received(Channel channel, Object message) throws RemotingException {
if (message instanceof Decodeable) {
decode(message);
}
if (message instanceof Request) {
decode(((Request) message).getData());
}
if (message instanceof Response) {
decode(((Response) message).getResult());
}
handler.received(channel, message);
}
19
Source : ChannelHandlerAdapter.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void connected(Channel channel) throws RemotingException {
}
19
Source : ChannelHandlerAdapter.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void disconnected(Channel channel) throws RemotingException {
}
19
Source : ChannelHandlerAdapter.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void received(Channel channel, Object message) throws RemotingException {
}
19
Source : ChannelHandlerAdapter.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void sent(Channel channel, Object message) throws RemotingException {
}
19
Source : ChannelHandlerAdapter.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void caught(Channel channel, Throwable exception) throws RemotingException {
}
19
Source : ChannelDelegate.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
/**
* ChannelDelegate
*
* @author william.liangf
*/
public clreplaced ChannelDelegate implements Channel {
private transient Channel channel;
public ChannelDelegate() {
}
public ChannelDelegate(Channel channel) {
setChannel(channel);
}
public Channel getChannel() {
return channel;
}
public void setChannel(Channel channel) {
if (channel == null) {
throw new IllegalArgumentException("channel == null");
}
this.channel = channel;
}
public URL getUrl() {
return channel.getUrl();
}
public InetSocketAddress getRemoteAddress() {
return channel.getRemoteAddress();
}
public ChannelHandler getChannelHandler() {
return channel.getChannelHandler();
}
public boolean isConnected() {
return channel.isConnected();
}
public InetSocketAddress getLocalAddress() {
return channel.getLocalAddress();
}
public boolean hasAttribute(String key) {
return channel.hasAttribute(key);
}
public void send(Object message) throws RemotingException {
channel.send(message);
}
public Object getAttribute(String key) {
return channel.getAttribute(key);
}
public void setAttribute(String key, Object value) {
channel.setAttribute(key, value);
}
public void send(Object message, boolean sent) throws RemotingException {
channel.send(message, sent);
}
public void removeAttribute(String key) {
channel.removeAttribute(key);
}
public void close() {
channel.close();
}
public void close(int timeout) {
channel.close(timeout);
}
public boolean isClosed() {
return channel.isClosed();
}
}
19
Source : ChannelDelegate.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void setChannel(Channel channel) {
if (channel == null) {
throw new IllegalArgumentException("channel == null");
}
this.channel = channel;
}
19
Source : AbstractCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
protected boolean isServerSide(Channel channel) {
return !isClientSide(channel);
}
19
Source : AbstractClient.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void removeAttribute(String key) {
Channel channel = getChannel();
if (channel == null)
return;
channel.removeAttribute(key);
}
19
Source : AbstractClient.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Object getAttribute(String key) {
Channel channel = getChannel();
if (channel == null)
return null;
return channel.getAttribute(key);
}
19
Source : ClearTelnetHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public String telnet(Channel channel, String message) {
int lines = 100;
if (message.length() > 0) {
if (!StringUtils.isInteger(message)) {
return "Illegal lines " + message + ", must be integer.";
}
lines = Integer.parseInt(message);
}
StringBuilder buf = new StringBuilder();
for (int i = 0; i < lines; i++) {
buf.append("\r\n");
}
return buf.toString();
}
19
Source : HeartbeatHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void sent(Channel channel, Object message) throws RemotingException {
setWriteTimestamp(channel);
handler.sent(channel, message);
}
19
Source : HeartbeatHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void disconnected(Channel channel) throws RemotingException {
clearReadTimestamp(channel);
clearWriteTimestamp(channel);
handler.disconnected(channel);
}
19
Source : HeartbeatHandler.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void connected(Channel channel) throws RemotingException {
setReadTimestamp(channel);
setWriteTimestamp(channel);
handler.connected(channel);
}
19
Source : HeaderExchangeChannel.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
static void removeChannelIfDisconnected(Channel ch) {
if (ch != null && !ch.isConnected()) {
ch.removeAttribute(CHANNEL_KEY);
}
}
19
Source : ExchangeHandlerDispatcher.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public void received(Channel channel, Object message) {
handlerDispatcher.received(channel, message);
}
19
Source : DefaultFuture.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public static void sent(Channel channel, Request request) {
DefaultFuture future = FUTURES.get(request.getId());
if (future != null) {
future.doSent();
}
}
19
Source : ExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
int readable = buffer.readableBytes();
byte[] header = new byte[Math.min(readable, HEADER_LENGTH)];
buffer.readBytes(header);
return decode(channel, buffer, readable, header);
}
19
Source : ExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Override
protected Object decodeData(Channel channel, ObjectInput in) throws IOException {
return decodeRequestData(channel, in);
}
19
Source : ExchangeCodec.java
with Apache License 2.0
from yunhaibin
with Apache License 2.0
from yunhaibin
@Override
protected void encodeData(Channel channel, ObjectOutput out, Object data) throws IOException {
encodeRequestData(channel, out, data);
}
19
Source : DataSizeCodecWrapper.java
with Apache License 2.0
from sofastack
with Apache License 2.0
from sofastack
/**
* @param channel a long connection
* @param buffer buffer
* @param message the original Request object
* @param invocation Invocation in Request
* @throws IOException serialization exception
*/
protected void encodeRequestWithTracer(Channel channel, ChannelBuffer buffer, Object message, RpcInvocation invocation) throws IOException {
long startTime = System.currentTimeMillis();
int index = buffer.writerIndex();
// serialization
codec.encode(channel, buffer, message);
int reqSize = buffer.writerIndex() - index;
long elapsed = System.currentTimeMillis() - startTime;
invocation.setAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_SIZE, String.valueOf(reqSize));
invocation.setAttachment(AttachmentKeyConstants.CLIENT_SERIALIZE_TIME, String.valueOf(elapsed));
}
19
Source : DataSizeCodecWrapper.java
with Apache License 2.0
from sofastack
with Apache License 2.0
from sofastack
@Override
public void encode(Channel channel, ChannelBuffer buffer, Object message) throws IOException {
if (message instanceof Request) {
Object data = ((Request) message).getData();
if (data instanceof RpcInvocation) {
RpcInvocation invocation = (RpcInvocation) data;
encodeRequestWithTracer(channel, buffer, message, invocation);
return;
}
} else if (message instanceof Response) {
Object response = ((Response) message).getResult();
if (response instanceof RpcResult) {
encodeResultWithTracer(channel, buffer, message);
return;
}
}
codec.encode(channel, buffer, message);
}
See More Examples