Search in sources :

Example 1 with HeartbeatFactory

use of com.weibo.api.motan.transport.HeartbeatFactory in project motan by weibocom.

the class AbstractEndpointFactory method createServer.

@Override
public Server createServer(URL url, MessageHandler messageHandler) {
    HeartbeatFactory heartbeatFactory = getHeartbeatFactory(url);
    messageHandler = heartbeatFactory.wrapMessageHandler(messageHandler);
    synchronized (ipPort2ServerShareChannel) {
        String ipPort = url.getServerPortStr();
        String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
        boolean shareChannel = url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
        if (!shareChannel) {
            // 独享一个端口
            LoggerUtil.info(this.getClass().getSimpleName() + " create no_share_channel server: url={}", url);
            // 如果端口已经被使用了,使用该server bind 会有异常
            return innerCreateServer(url, messageHandler);
        }
        LoggerUtil.info(this.getClass().getSimpleName() + " create share_channel server: url={}", url);
        Server server = ipPort2ServerShareChannel.get(ipPort);
        if (server != null) {
            // can't share service channel
            if (!MotanFrameworkUtil.checkIfCanShallServiceChannel(server.getUrl(), url)) {
                throw new MotanFrameworkException("Service export Error: share channel but some config param is different, protocol or codec or serialize or maxContentLength or maxServerConnection or maxWorkerThread or heartbeatFactory, source=" + server.getUrl() + " target=" + url, MotanErrorMsgConstant.FRAMEWORK_EXPORT_ERROR);
            }
            saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
            return server;
        }
        url = url.createCopy();
        // 共享server端口,由于有多个interfaces存在,所以把path设置为空
        url.setPath("");
        server = innerCreateServer(url, messageHandler);
        ipPort2ServerShareChannel.put(ipPort, server);
        saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
        return server;
    }
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Server(com.weibo.api.motan.transport.Server) HeartbeatFactory(com.weibo.api.motan.transport.HeartbeatFactory)

Example 2 with HeartbeatFactory

use of com.weibo.api.motan.transport.HeartbeatFactory in project motan by weibocom.

the class AbstractEndpointFactory method getHeartbeatFactory.

private HeartbeatFactory getHeartbeatFactory(URL url) {
    String heartbeatFactoryName = url.getParameter(URLParamType.heartbeatFactory.getName(), URLParamType.heartbeatFactory.getValue());
    HeartbeatFactory heartbeatFactory = ExtensionLoader.getExtensionLoader(HeartbeatFactory.class).getExtension(heartbeatFactoryName);
    if (heartbeatFactory == null) {
        throw new MotanFrameworkException("HeartbeatFactory not exist: " + heartbeatFactoryName);
    }
    return heartbeatFactory;
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) HeartbeatFactory(com.weibo.api.motan.transport.HeartbeatFactory)

Example 3 with HeartbeatFactory

use of com.weibo.api.motan.transport.HeartbeatFactory in project motan by weibocom.

the class HeartbeatClientEndpointManager method addEndpoint.

@Override
public void addEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof Client)) {
        throw new MotanFrameworkException("HeartbeatClientEndpointManager addEndpoint Error: class not support " + endpoint.getClass());
    }
    Client client = (Client) endpoint;
    URL url = endpoint.getUrl();
    String heartbeatFactoryName = url.getParameter(URLParamType.heartbeatFactory.getName(), URLParamType.heartbeatFactory.getValue());
    HeartbeatFactory heartbeatFactory = ExtensionLoader.getExtensionLoader(HeartbeatFactory.class).getExtension(heartbeatFactoryName);
    if (heartbeatFactory == null) {
        throw new MotanFrameworkException("HeartbeatFactory not exist: " + heartbeatFactoryName);
    }
    endpoints.put(client, heartbeatFactory);
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) HeartbeatFactory(com.weibo.api.motan.transport.HeartbeatFactory) Client(com.weibo.api.motan.transport.Client) URL(com.weibo.api.motan.rpc.URL)

Aggregations

MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)3 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)3 URL (com.weibo.api.motan.rpc.URL)1 Client (com.weibo.api.motan.transport.Client)1 Server (com.weibo.api.motan.transport.Server)1