当前位置: 首页>>代码示例>>Java>>正文


Java ExchangeChannel类代码示例

本文整理汇总了Java中com.alibaba.dubbo.remoting.exchange.ExchangeChannel的典型用法代码示例。如果您正苦于以下问题:Java ExchangeChannel类的具体用法?Java ExchangeChannel怎么用?Java ExchangeChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExchangeChannel类属于com.alibaba.dubbo.remoting.exchange包,在下文中一共展示了ExchangeChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
private static void test(int port) throws Exception
{
    ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	MockResult result = (MockResult)client.request(new RpcMessage(DemoService.class.getName(),"plus",new Class<?>[]{int.class, int.class},new Object[]{55,25})).get();
	System.out.println("55+25="+result.getResult());

	for(int i=0;i<100;i++)
		client.request(new RpcMessage(DemoService.class.getName(),"sayHello", new Class<?>[]{String.class},new Object[]{"qianlei"+i}));

	for(int i=0;i<100;i++)
		client.request(new Main.Data());

	System.out.println("=====test invoke=====");
	for(int i=0;i<100;i++){
		ResponseFuture future = client.request(new Main.Data());
		System.out.println("invoke and get");
		System.out.println("invoke result:" + future.get());
	}
	System.out.println("=====the end=====");
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:Main.java

示例2: caught

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的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);
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:23,代码来源:HeaderExchangeHandler.java

示例3: received

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
    channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
    ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
    try {
        if (message instanceof Request) {
            // handle request.
            Request request = (Request) message;
            if (request.isEvent()) {
                handlerEvent(channel, request);
            } else {
                if (request.isTwoWay()) {
                    Response response = handleRequest(exchangeChannel, request);
                    channel.send(response);
                } else {
                    handler.received(exchangeChannel, request.getData());
                }
            }
        } else if (message instanceof Response) {
            handleResponse(channel, (Response) message);
        } else if (message instanceof String) {
            if (isClientSide(channel)) {
                Exception e = new Exception("Dubbo client can not supported string message: " + message + " in channel: " + channel + ", url: " + channel.getUrl());
                logger.error(e.getMessage(), e);
            } else {
                String echo = handler.telnet(channel, (String) message);
                if (echo != null && echo.length() > 0) {
                    channel.send(echo);
                }
            }
        } else {
            handler.received(exchangeChannel, message);
        }
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:37,代码来源:HeaderExchangeHandler.java

示例4: getExchangeChannels

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public Collection<ExchangeChannel> getExchangeChannels() {
    Collection<ExchangeChannel> exchangeChannels  = new ArrayList<ExchangeChannel>();
    Collection<Channel> channels = server.getChannels();
    if (channels != null && channels.size() > 0) {
        for (Channel channel : channels) {
            exchangeChannels.add(HeaderExchangeChannel.getOrAddChannel(channel));
        }
    }
    return exchangeChannels;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:11,代码来源:HeaderExchangeServer.java

示例5: getExchangeChannels

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
@Override
public Collection<ExchangeChannel> getExchangeChannels() {
    Collection<ExchangeChannel> channels = super.getExchangeChannels();
    if (clients.size() > 0) {
        channels = channels == null ? new ArrayList<ExchangeChannel>() : new ArrayList<ExchangeChannel>(channels);
        channels.addAll(clients.values());
    }
    return channels;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:ExchangeServerPeer.java

示例6: getExchangeChannel

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
@Override
public ExchangeChannel getExchangeChannel(InetSocketAddress remoteAddress) {
    String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
    int port = remoteAddress.getPort();
    ExchangeChannel channel = super.getExchangeChannel(remoteAddress);
    if (channel == null) {
        for (Map.Entry<URL, ExchangeClient> entry : clients.entrySet()) {
            URL url = entry.getKey();
            if (url.getIp().equals(host) && url.getPort() == port) {
                return entry.getValue();
            }
        }
    }
    return channel;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:ExchangeServerPeer.java

示例7: connected

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public void connected(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.connected(exchangeChannel);
    } finally {
        HeaderExchangeChannel.removeChannelIfDisconnected(channel);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:HeaderExchangeHandler.java

示例8: sent

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public void sent(Channel channel, Object message) throws RemotingException {
    Throwable exception = null;
    try {
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.sent(exchangeChannel, message);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
    } catch (Throwable t) {
        exception = t;
    }
    if (message instanceof Request) {
        Request request = (Request) message;
        DefaultFuture.sent(channel, request);
    }
    if (exception != null) {
        if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else if (exception instanceof RemotingException) {
            throw (RemotingException) exception;
        } else {
            throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(),
                                        exception.getMessage(), exception);
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:29,代码来源:HeaderExchangeHandler.java

示例9: dataPackageTest

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
static void dataPackageTest(int port) throws Exception
{
	ExchangeChannel client = Exchangers.connect(URL.valueOf("dubbo://localhost:" + port));
	Random random = new Random();
	for(int i=5;i<100;i++)
	{
		StringBuilder sb = new StringBuilder();
		for(int j=0;j<i*100;j++)
			sb.append("("+random.nextLong()+")");
		Main.Data d = new Main.Data();
		d.setData(sb.toString());
		client.request(d).get();
	}
	System.out.println("send finished.");
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:Main.java

示例10: reply

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
    if (message instanceof Invocation) {
        Invocation inv = (Invocation) message;
        Invoker<?> invoker = getInvoker(channel, inv);
        //如果是callback 需要处理高版本调用低版本的问题
        if (Boolean.TRUE.toString().equals(inv.getAttachments().get(IS_CALLBACK_SERVICE_INVOKE))){
            String methodsStr = invoker.getUrl().getParameters().get("methods");
            boolean hasMethod = false;
            if (methodsStr == null || methodsStr.indexOf(",") == -1){
                hasMethod = inv.getMethodName().equals(methodsStr);
            } else {
                String[] methods = methodsStr.split(",");
                for (String method : methods){
                    if (inv.getMethodName().equals(method)){
                        hasMethod = true;
                        break;
                    }
                }
            }
            if (!hasMethod){
                logger.warn(new IllegalStateException("The methodName "+inv.getMethodName()+" not found in callback service interface ,invoke will be ignored. please update the api interface. url is:" + invoker.getUrl()) +" ,invocation is :"+inv );
                return null;
            }
        }
        RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
        return invoker.invoke(inv);
    }
    throw new RemotingException(channel, "Unsupported request: " + message == null ? null : (message.getClass().getName() + ": " + message) + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:30,代码来源:DubboProtocol.java

示例11: received

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
@Override
public void received( Channel channel, Object message ) throws RemotingException {
    if ( message instanceof Invocation ) {
        reply( ( ExchangeChannel ) channel, message );
    } else {
        super.received( channel, message );
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:9,代码来源:ThriftProtocol.java

示例12: run

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
public void run(String[] args) throws Exception {
    if (args == null || args.length != 5) {
        throw new IllegalArgumentException(
                                           "must give three args: listenPort | maxThreads | responseSize | transporter | serialization");
    }
    int listenPort = Integer.parseInt(args[0]);
    int maxThreads = Integer.parseInt(args[1]);
    final int responseSize = Integer.parseInt(args[2]);
    String transporter = args[3];
    String serialization = args[4];
    System.out.println(dateFormat.format(new Date()) + " ready to start server,listenPort is: " + listenPort
                       + ",maxThreads is:" + maxThreads + ",responseSize is:" + responseSize
                       + " bytes,transporter is:" + transporter + ",serialization is:" + serialization);
    StringBuilder url = new StringBuilder();
    url.append("exchange://0.0.0.0:");
    url.append(listenPort);
    url.append("?transporter=");
    url.append(transporter);
    url.append("&serialization=");
    url.append(serialization);
    url.append("&threads=");
    url.append(maxThreads);
    Exchangers.bind(url.toString(), new ExchangeHandlerAdapter() {

        public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
            return new ResponseObject(responseSize); // 发送响应
        }
    });
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:30,代码来源:AbstractBenchmarkServer.java

示例13: disconnected

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的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);
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:11,代码来源:HeaderExchangeHandler.java

示例14: received

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
@Override
public void received(Channel channel, Object message) throws RemotingException {
    if (message instanceof Invocation) {
        reply((ExchangeChannel) channel, message);
    } else {
        super.received(channel, message);
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:9,代码来源:DubboProtocol.java

示例15: startServer

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入依赖的package包/类
private static void startServer(int port) throws Exception
{
    ReplierDispatcher dispatcher = new ReplierDispatcher();
    dispatcher.addReplier(RpcMessage.class, new RpcMessageHandler());
    dispatcher.addReplier(Object.class, new Replier<Object>() {
		public Object reply(ExchangeChannel channel, Object msg)
		{
			for(int i=0;i<10000;i++)
				System.currentTimeMillis();
			System.out.println("handle:"+msg+";thread:"+Thread.currentThread().getName());
			return new StringMessage("hello world");
		}
	});
	Exchangers.bind(URL.valueOf("dubbo://localhost:" + port), dispatcher);
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:16,代码来源:Main.java


注:本文中的com.alibaba.dubbo.remoting.exchange.ExchangeChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。