use of org.apache.ignite.spi.systemview.view.ClientConnectionView in project ignite by apache.
the class SystemViewSelfTest method testClientsConnections.
/**
*/
@Test
public void testClientsConnections() throws Exception {
try (IgniteEx g0 = startGrid(0)) {
String host = g0.configuration().getClientConnectorConfiguration().getHost();
if (host == null)
host = g0.configuration().getLocalHost();
int port = g0.configuration().getClientConnectorConfiguration().getPort();
SystemView<ClientConnectionView> conns = g0.context().systemView().view(CLI_CONN_VIEW);
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
assertEquals(1, conns.size());
ClientConnectionView cliConn = conns.iterator().next();
assertEquals("THIN", cliConn.type());
assertEquals(cliConn.localAddress().getHostName(), cliConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), cliConn.localAddress().getPort());
assertEquals(cliConn.version(), ProtocolVersion.LATEST_VER.toString());
try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
assertEquals(2, conns.size());
assertEquals(1, F.size(jdbcConnectionsIterator(conns)));
ClientConnectionView jdbcConn = jdbcConnectionsIterator(conns).next();
assertEquals("JDBC", jdbcConn.type());
assertEquals(jdbcConn.localAddress().getHostName(), jdbcConn.remoteAddress().getHostName());
assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), jdbcConn.localAddress().getPort());
assertEquals(jdbcConn.version(), JdbcConnectionContext.CURRENT_VER.asString());
}
}
boolean res = GridTestUtils.waitForCondition(() -> conns.size() == 0, 5_000);
assertTrue(res);
}
}
use of org.apache.ignite.spi.systemview.view.ClientConnectionView in project ignite by apache.
the class ClientListenerProcessor method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
IgniteConfiguration cfg = ctx.config();
// Daemon node should not open client port
if (cfg.isDaemon()) {
if (log.isDebugEnabled())
log.debug("Client connection configuration ignored for daemon node.");
return;
}
ClientConnectorConfiguration cliConnCfg = prepareConfiguration(cfg);
if (cliConnCfg != null) {
try {
validateConfiguration(cliConnCfg);
// Resolve host.
String host = cliConnCfg.getHost();
if (host == null)
host = cfg.getLocalHost();
InetAddress hostAddr;
try {
hostAddr = U.resolveLocalHost(host);
} catch (Exception e) {
throw new IgniteCheckedException("Failed to resolve client connector host: " + host, e);
}
execSvc = ctx.pools().getThinClientExecutorService();
Exception lastErr = null;
int portTo = cliConnCfg.getPort() + cliConnCfg.getPortRange();
if (// Handle int overflow.
portTo <= 0)
portTo = Integer.MAX_VALUE;
GridNioFilter[] filters = makeFilters(cliConnCfg);
long idleTimeout = cliConnCfg.getIdleTimeout();
int selectorCnt = cliConnCfg.getSelectorCount();
ctx.metric().registry(CLIENT_CONNECTOR_METRICS);
for (int port = cliConnCfg.getPort(); port <= portTo && port <= 65535; port++) {
try {
srv = GridNioServer.<ClientMessage>builder().address(hostAddr).port(port).listener(new ClientListenerNioListener(ctx, busyLock, cliConnCfg)).logger(log).selectorCount(selectorCnt).igniteInstanceName(ctx.igniteInstanceName()).serverName("client-listener").tcpNoDelay(cliConnCfg.isTcpNoDelay()).directBuffer(DFLT_TCP_DIRECT_BUF).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(cliConnCfg.getSocketSendBufferSize()).socketReceiveBufferSize(cliConnCfg.getSocketReceiveBufferSize()).filters(filters).directMode(true).idleTimeout(idleTimeout > 0 ? idleTimeout : Long.MAX_VALUE).metricRegistry(ctx.metric().registry(CLIENT_CONNECTOR_METRICS)).build();
ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
if (log.isInfoEnabled())
log.info("Client connector processor has started on TCP port " + port);
lastErr = null;
ctx.addNodeAttribute(CLIENT_LISTENER_PORT, port);
break;
} catch (Exception e) {
lastErr = e;
}
}
assert (srv != null && lastErr == null) || (srv == null && lastErr != null);
if (lastErr != null)
throw new IgniteCheckedException("Failed to bind to any [host:port] from the range [" + "host=" + host + ", portFrom=" + cliConnCfg.getPort() + ", portTo=" + portTo + ", lastErr=" + lastErr + ']', lastErr);
if (!U.IGNITE_MBEANS_DISABLED)
registerMBean();
ctx.systemView().registerView(CLI_CONN_VIEW, CLI_CONN_VIEW_DESC, new ClientConnectionViewWalker(), srv.sessions(), ClientConnectionView::new);
distrThinCfg = new DistributedThinClientConfiguration(ctx);
} catch (Exception e) {
throw new IgniteCheckedException("Failed to start client connector processor.", e);
}
}
}
Aggregations