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;
}
}
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");
}
Aggregations