/** {@inheritDoc} */ @Override protected void body() throws InterruptedException { try { while (!Thread.interrupted()) { ShmemWorker e = new ShmemWorker(srv.accept(), true); shmemWorkers.add(e); new IgniteThread(e).start(); } } catch (IgniteCheckedException e) { if (!isCancelled()) U.error(log, "Shmem server failed.", e); } finally { srv.close(); } }
/** * Create server IPC endpoint. * * @param endpointCfg Endpoint configuration. * @param mgmt Management flag. * @return Server endpoint. * @throws IgniteCheckedException If failed. */ private IpcServerEndpoint createEndpoint(IgfsIpcEndpointConfiguration endpointCfg, boolean mgmt) throws IgniteCheckedException { A.notNull(endpointCfg, "endpointCfg"); IgfsIpcEndpointType typ = endpointCfg.getType(); if (typ == null) throw new IgniteCheckedException("Failed to create server endpoint (type is not specified)"); switch (typ) { case SHMEM: { IpcSharedMemoryServerEndpoint endpoint = new IpcSharedMemoryServerEndpoint( igfsCtx.kernalContext().config().getWorkDirectory()); endpoint.setPort(endpointCfg.getPort()); endpoint.setSize(endpointCfg.getMemorySize()); endpoint.setTokenDirectoryPath(endpointCfg.getTokenDirectoryPath()); return endpoint; } case TCP: { IpcServerTcpEndpoint endpoint = new IpcServerTcpEndpoint(); endpoint.setHost(endpointCfg.getHost()); endpoint.setPort(endpointCfg.getPort()); endpoint.setManagement(mgmt); return endpoint; } default: throw new IgniteCheckedException( "Failed to create server endpoint (type is unknown): " + typ); } }
/** * Creates new shared memory communication server. * * @return Server. * @throws IgniteCheckedException If failed. */ @Nullable private IpcSharedMemoryServerEndpoint resetShmemServer() throws IgniteCheckedException { if (boundTcpShmemPort >= 0) throw new IgniteCheckedException( "Shared memory server was already created on port " + boundTcpShmemPort); if (shmemPort == -1 || U.isWindows()) return null; IgniteCheckedException lastEx = null; // If configured TCP port is busy, find first available in range. for (int port = shmemPort; port < shmemPort + locPortRange; port++) { try { IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint( log.getLogger(IpcSharedMemoryServerEndpoint.class), locProcDesc.processId(), gridName); srv.setPort(port); srv.omitOutOfResourcesWarning(true); srv.start(); boundTcpShmemPort = port; // Ack Port the TCP server was bound to. if (log.isInfoEnabled()) log.info( "Successfully bound shared memory communication to TCP port [port=" + boundTcpShmemPort + ", locHost=" + locHost + ']'); return srv; } catch (IgniteCheckedException e) { lastEx = e; if (log.isDebugEnabled()) log.debug( "Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + locHost + ']'); } } // If free port wasn't found. throw new IgniteCheckedException( "Failed to bind shared memory communication to any port within range [startPort=" + locPort + ", portRange=" + locPortRange + ", locHost=" + locHost + ']', lastEx); }
/** {@inheritDoc} */ @Override public void cancel() { super.cancel(); srv.close(); }