1 Star 3 Fork 1

jannal / rabbitmq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SocketFrameHandlerFactory.java 2.73 KB
一键复制 编辑 原始数据 按行查看 历史
jannal 提交于 2018-02-21 17:08 . rabbitmq源码分析
// Copyright (c) 2007-Present Pivotal Software, Inc. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// info@rabbitmq.com.
package com.rabbitmq.client.impl;
import com.rabbitmq.client.Address;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.SocketConfigurator;
import javax.net.SocketFactory;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
public class SocketFrameHandlerFactory extends AbstractFrameHandlerFactory {
private final SocketFactory factory;
//用于关闭socket的线程池
private final ExecutorService shutdownExecutor;
public SocketFrameHandlerFactory(int connectionTimeout, SocketFactory factory, SocketConfigurator configurator, boolean ssl) {
this(connectionTimeout, factory, configurator, ssl, null);
}
public SocketFrameHandlerFactory(int connectionTimeout, SocketFactory factory, SocketConfigurator configurator, boolean ssl, ExecutorService shutdownExecutor) {
super(connectionTimeout, configurator, ssl);
this.factory = factory;
this.shutdownExecutor = shutdownExecutor;
}
public FrameHandler create(Address addr) throws IOException {
String hostName = addr.getHost();
int portNumber = ConnectionFactory.portOrDefault(addr.getPort(), ssl);
Socket socket = null;
try {
//通过socketFactory创建Socket
socket = factory.createSocket();
//设置socket选项
configurator.configure(socket);
//开启连接
socket.connect(new InetSocketAddress(hostName, portNumber),
connectionTimeout);
return create(socket);
} catch (IOException ioe) {
quietTrySocketClose(socket);
throw ioe;
}
}
public FrameHandler create(Socket sock) throws IOException
{
return new SocketFrameHandler(sock, this.shutdownExecutor);
}
private static void quietTrySocketClose(Socket socket) {
if (socket != null)
try { socket.close(); } catch (Exception _e) {/*ignore exceptions*/}
}
}
Java
1
https://gitee.com/jannal/rabbitmq.git
git@gitee.com:jannal/rabbitmq.git
jannal
rabbitmq
rabbitmq
master

搜索帮助