use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.
the class NettyClientTest method testServerClose.
@Test
public void testServerClose() throws Exception {
for (int i = 0; i < 100; i++) {
RemotingServer aServer = Exchangers.bind(URL.valueOf("exchange://localhost:" + NetUtils.getAvailablePort(6000) + "?server=netty3"), new TelnetServerHandler());
aServer.close();
}
}
use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.
the class WebServiceProtocol method doExport.
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
transportFactory = new SoapTransportFactory();
destinationRegistry = new DestinationRegistryImpl();
String addr = getAddr(url);
ProtocolServer protocolServer = serverMap.get(addr);
if (protocolServer == null) {
RemotingServer remotingServer = httpBinder.bind(url, new WebServiceHandler());
serverMap.put(addr, new ProxyProtocolServer(remotingServer));
}
serverFactoryBean = new ServerFactoryBean();
serverFactoryBean.setAddress(url.getAbsolutePath());
serverFactoryBean.setServiceClass(type);
serverFactoryBean.setServiceBean(impl);
serverFactoryBean.setBus(bus);
serverFactoryBean.setDestinationFactory(transportFactory);
serverFactoryBean.getServiceFactory().getConfigurations().add(new URLHashMethodNameSoapActionServiceConfiguration());
server = serverFactoryBean.create();
return new Runnable() {
@Override
public void run() {
if (serverFactoryBean.getServer() != null) {
serverFactoryBean.getServer().destroy();
}
if (serverFactoryBean.getBus() != null) {
serverFactoryBean.getBus().shutdown(true);
}
ProtocolServer httpServer = serverMap.get(addr);
if (httpServer != null) {
httpServer.close();
serverMap.remove(addr);
}
}
};
}
use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.
the class XmlRpcProtocol method doExport.
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
final URL httpUrl = url.setProtocol("http");
String addr = httpUrl.getIp() + ":" + httpUrl.getPort();
ProtocolServer protocolServer = serverMap.get(addr);
if (protocolServer == null) {
RemotingServer remotingServer = httpBinder.bind(httpUrl, new InternalHandler(httpUrl.getParameter("cors", false)));
serverMap.put(addr, new ProxyProtocolServer(remotingServer));
}
final String path = httpUrl.getAbsolutePath();
XmlRpcServletServer xmlRpcServer = new XmlRpcServletServer();
PropertyHandlerMapping propertyHandlerMapping = new PropertyHandlerMapping();
try {
propertyHandlerMapping.setRequestProcessorFactoryFactory(new RequestProcessorFactoryFactory() {
@Override
public RequestProcessorFactory getRequestProcessorFactory(Class pClass) throws XmlRpcException {
return new RequestProcessorFactory() {
@Override
public Object getRequestProcessor(XmlRpcRequest pRequest) throws XmlRpcException {
return impl;
}
};
}
});
propertyHandlerMapping.addHandler(XmlRpcProxyFactoryBean.replace(type.getName()), type);
} catch (Exception e) {
throw new RpcException(e);
}
xmlRpcServer.setHandlerMapping(propertyHandlerMapping);
XmlRpcServerConfigImpl xmlRpcServerConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
xmlRpcServerConfig.setEnabledForExceptions(true);
xmlRpcServerConfig.setContentLengthOptional(false);
skeletonMap.put(path, xmlRpcServer);
return new Runnable() {
@Override
public void run() {
skeletonMap.remove(path);
}
};
}
use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.
the class ServerStatusChecker method check.
@Override
public Status check() {
List<ProtocolServer> servers = DubboProtocol.getDubboProtocol().getServers();
if (servers == null || servers.isEmpty()) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (ProtocolServer protocolServer : servers) {
RemotingServer server = protocolServer.getRemotingServer();
if (!server.isBound()) {
level = Status.Level.ERROR;
buf.setLength(0);
buf.append(server.getLocalAddress());
break;
}
if (buf.length() > 0) {
buf.append(",");
}
buf.append(server.getLocalAddress());
buf.append("(clients:");
buf.append(server.getChannels().size());
buf.append(")");
}
return new Status(level, buf.toString());
}
use of org.apache.dubbo.remoting.RemotingServer in project dubbo by alibaba.
the class NettyTransporterTest method shouldAbleToBindNetty4.
@Test
public void shouldAbleToBindNetty4() throws Exception {
int port = NetUtils.getAvailablePort();
URL url = new URL("telnet", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) });
RemotingServer server = new NettyTransporter().bind(url, new ChannelHandlerAdapter());
assertThat(server.isBound(), is(true));
}
Aggregations