Search in sources :

Example 1 with Server

use of com.weibo.api.motan.transport.Server 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 Server

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

the class BaseTest method before.

@Before
public void before() {
    mockery = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    final Server mockServer = mockery.mock(Server.class);
    final Client mockClient = mockery.mock(Client.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockClient).open();
            will(returnValue(true));
            allowing(mockClient).close();
            will(returnValue(null));
            allowing(mockClient).isAvailable();
            will(returnValue(true));
            allowing(mockServer).open();
            will(returnValue(true));
            allowing(mockServer).close();
            will(returnValue(null));
            allowing(mockServer).isAvailable();
            will(returnValue(true));
        }
    });
    ExtensionLoader loader = ExtensionLoader.getExtensionLoader(EndpointFactory.class);
    endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint");
    if (endpointFactory == null) {
        loader.addExtensionClass(MockEndpointFactory.class);
        endpointFactory = (MockEndpointFactory) loader.getExtension("mockEndpoint");
    }
    loader = ExtensionLoader.getExtensionLoader(RegistryFactory.class);
    MockRegistryFactory registryFactory = (MockRegistryFactory) loader.getExtension("mockRegistry");
    if (registryFactory == null) {
        loader.addExtensionClass(MockRegistryFactory.class);
    }
    endpointFactory.setClient(mockClient);
    endpointFactory.setServer(mockServer);
    cp = new ClassPathXmlApplicationContext("classpath:schemaTestContext.xml");
}
Also used : Expectations(org.jmock.Expectations) RegistryFactory(com.weibo.api.motan.registry.RegistryFactory) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Server(com.weibo.api.motan.transport.Server) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Client(com.weibo.api.motan.transport.Client) ExtensionLoader(com.weibo.api.motan.core.extension.ExtensionLoader) Before(org.junit.Before)

Aggregations

Server (com.weibo.api.motan.transport.Server)2 ExtensionLoader (com.weibo.api.motan.core.extension.ExtensionLoader)1 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 RegistryFactory (com.weibo.api.motan.registry.RegistryFactory)1 Client (com.weibo.api.motan.transport.Client)1 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)1 Expectations (org.jmock.Expectations)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 Before (org.junit.Before)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1