[关闭]
@aloxc 2017-12-05T06:25:25.000000Z 字数 2379 阅读 455

我们一起学ignite之GridNioServer及build

一起学 ignite 源码分析


转载请注明本文作者:aloxc,邮箱leerohwa#gmail.com[#更换为@]

如题,ignite还支持memcache协议,具体就是ignite启动的时候启动了一个绑定到11211--11310这100个端口中的一个的nio服务。

这100个端口是这样选择的,初始是从11211端口起一个nio服务,如果起的这个nio服务没启动成功起来就往之前的端口加1后再次起nio服务,至到成功的起了一个nio服务。
相关代码(org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestProtocol中)如下

  1. public void start(final GridRestProtocolHandler hnd) throws IgniteCheckedException {
  2. assert hnd != null;
  3. ConnectorConfiguration cfg = ctx.config().getConnectorConfiguration();
  4. assert cfg != null;
  5. lsnr = new GridTcpRestNioListener(log, this, hnd, ctx);
  6. GridNioParser parser = new GridTcpRestParser(false);
  7. try {
  8. host = resolveRestTcpHost(ctx.config());
  9. SSLContext sslCtx = null;
  10. if (cfg.isSslEnabled()) {
  11. Factory<SSLContext> igniteFactory = ctx.config().getSslContextFactory();
  12. Factory<SSLContext> factory = cfg.getSslFactory();
  13. // This factory deprecated and will be removed.
  14. GridSslContextFactory depFactory = cfg.getSslContextFactory();
  15. if (factory == null && depFactory == null && igniteFactory == null)
  16. // Thrown SSL exception instead of IgniteCheckedException for writing correct warning message into log.
  17. throw new SSLException("SSL is enabled, but SSL context factory is not specified.");
  18. if (factory != null)
  19. sslCtx = factory.create();
  20. else if (depFactory != null)
  21. sslCtx = depFactory.createSslContext();
  22. else
  23. sslCtx = igniteFactory.create();
  24. }
  25. int startPort = cfg.getPort();
  26. int portRange = cfg.getPortRange();
  27. int lastPort = portRange == 0 ? startPort : startPort + portRange - 1;
  28. for (int port0 = startPort; port0 <= lastPort; port0++) {
  29. if (startTcpServer(host, port0, lsnr, parser, sslCtx, cfg)) {
  30. port = port0;
  31. if (log.isInfoEnabled())
  32. log.info(startInfo());
  33. return;
  34. }
  35. }
  36. IgniteUtils.warn(log, "Failed to start TCP binary REST server (possibly all ports in range are in use) " +
  37. "[firstPort=" + cfg.getPort() + ", lastPort=" + lastPort + ", host=" + host + ']');
  38. }
  39. catch (SSLException e) {
  40. IgniteUtils.warn(log, "Failed to start " + name() + " protocol on port " + port + ": " + e.getMessage(),
  41. "Failed to start " + name() + " protocol on port " + port + ". Check if SSL context factory is " +
  42. "properly configured.");
  43. }
  44. catch (IOException e) {
  45. IgniteUtils.warn(log, "Failed to start " + name() + " protocol on port " + port + ": " + e.getMessage(),
  46. "Failed to start " + name() + " protocol on port " + port + ". " +
  47. "Check restTcpHost configuration property.");
  48. }
  49. }

如果说我们线上服务器,不希望ignite启动后还兼容memcache命令,可以把这个方法中行lsnr = new GridTcpRestNioListener(log, this, hnd, ctx);后面的代码注释掉。其实本人认为ignite这么做兼容别的命令有点画蛇添足,虽然有很多公司在使用memcache,并且也愿意使用ignite的情况下也不会简单的更换到ignite并且还用memcache命令连接ignite,虽然直接替换下memcache地址,接着使用memcache命令连接ignite这样成本较小。我个人不希望ignite这么做,

x

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注