本文整理汇总了Java中com.alibaba.dubbo.remoting.Channel类的典型用法代码示例。如果您正苦于以下问题:Java Channel类的具体用法?Java Channel怎么用?Java Channel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Channel类属于com.alibaba.dubbo.remoting包,在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_received_request_oneway
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@Test
public void test_received_request_oneway() throws RemotingException{
final Channel mchannel = new MockedChannel();
final Person requestdata = new Person("charles");
Request request = new Request();
request.setTwoWay(false);
request.setData(requestdata);
ExchangeHandler exhandler = new MockedExchangeHandler(){
public void received(Channel channel, Object message) throws RemotingException {
Assert.assertEquals(requestdata, message);
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
hexhandler.received(mchannel, request);
}
示例2: test_received_request_twoway_error_reqeustBroken
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@Test
public void test_received_request_twoway_error_reqeustBroken() throws RemotingException{
final Request request = new Request();
request.setTwoWay(true);
request.setData(new BizException());
request.setBroken(true);
final AtomicInteger count = new AtomicInteger(0);
final Channel mchannel = new MockedChannel(){
@Override
public void send(Object message) throws RemotingException {
Response res = (Response)message;
Assert.assertEquals(request.getId(), res.getId());
Assert.assertEquals(request.getVersion(), res.getVersion());
Assert.assertEquals(Response.BAD_REQUEST, res.getStatus());
Assert.assertNull(res.getResult());
Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
count.incrementAndGet();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
hexhandler.received(mchannel, request);
Assert.assertEquals(1, count.get());
}
示例3: caught
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public void caught(Channel channel, Throwable exception) throws RemotingException {
if (exception instanceof ExecutionException) {
ExecutionException e = (ExecutionException) exception;
Object msg = e.getRequest();
if (msg instanceof Request) {
Request req = (Request) msg;
if (req.isTwoWay() && ! req.isHeartbeat()) {
Response res = new Response(req.getId(), req.getVersion());
res.setStatus(Response.SERVER_ERROR);
res.setErrorMessage(StringUtils.toString(e));
channel.send(res);
return;
}
}
}
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.caught(exchangeChannel, exception);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
示例4: decode
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
int save = buffer.readerIndex();
MultiMessage result = MultiMessage.create();
do {
Object obj = codec.decode(channel, buffer);
if (Codec2.DecodeResult.NEED_MORE_INPUT == obj) {
buffer.readerIndex(save);
break;
} else {
result.addMessage(obj);
logMessageLength(obj, buffer.readerIndex() - save);
save = buffer.readerIndex();
}
} while (true);
if (result.isEmpty()) {
return Codec2.DecodeResult.NEED_MORE_INPUT;
}
if (result.size() == 1) {
return result.get(0);
}
return result;
}
示例5: telnet
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
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();
}
示例6: getChannel
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@Override
protected Channel getChannel() {
Connection<?> c = connection;
if (c == null || ! c.isOpen())
return null;
return GrizzlyChannel.getOrAddChannel(c, getUrl(), this);
}
示例7: received
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@Override
public void received( Channel channel, Object message ) throws RemotingException {
if ( message instanceof Request ) {
Request req = ( Request ) message;
if ( req.isHeartbeat() ) {
heartBeatCounter.incrementAndGet();
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
Response res = new Response( req.getId(), req.getVersion() );
res.setEvent( req.getData() == null ? null : req.getData().toString() );
channel.send( res );
}
} else {
super.received( channel, message );
}
}
示例8: ChannelWrappedInvoker
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public ChannelWrappedInvoker(Class<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;
}
示例9: test_Decode_Error_Length
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@Test
public void test_Decode_Error_Length() throws IOException{
byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, 0x20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Person person = new Person();
byte[] request = getRequestBytes(person, header);
Channel channel = getServerSideChannel(url);
byte[] baddata = new byte[]{1,2};
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(join(request, baddata));
Response obj = (Response)codec.decode(channel, buffer);
Assert.assertEquals(person, obj.getResult());
//only decode necessary bytes
Assert.assertEquals(request.length, buffer.readerIndex());
}
示例10: received
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void received(Channel channel, Object message) throws RemotingException {
if (message instanceof MultiMessage) {
MultiMessage list = (MultiMessage)message;
for(Object obj : list) {
handler.received(channel, obj);
}
} else {
handler.received(channel, message);
}
}
示例11: DecodeableRpcInvocation
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public DecodeableRpcInvocation(Channel channel, Request request, InputStream is, byte id) {
Assert.notNull(channel, "channel == null");
Assert.notNull(request, "request == null");
Assert.notNull(is, "inputStream == null");
this.channel = channel;
this.request = request;
this.inputStream = is;
this.serializationType = id;
}
示例12: disconnected
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public void disconnected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.disconnected(exchangeChannel);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
示例13: received
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
public void received(Channel channel, Object message) {
for (ChannelHandler listener : channelHandlers) {
try {
listener.received(channel, message);
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
}
}
示例14: testDecode_assertEquals
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
protected void testDecode_assertEquals(byte[] request,Object ret, boolean isServerside) throws IOException{
//init channel
Channel channel = isServerside? getServerSideChannel(url) : getCliendSideChannel(url);
//init request string
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);
//decode
Object obj = codec.decode(channel, buffer);
Assert.assertEquals(ret, obj);
}
示例15: isClientSide
import com.alibaba.dubbo.remoting.Channel; //导入依赖的package包/类
private static boolean isClientSide(Channel channel) {
InetSocketAddress address = channel.getRemoteAddress();
URL url = channel.getUrl();
return url.getPort() == address.getPort() &&
NetUtils.filterLocalHost(url.getIp())
.equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}