Search in sources :

Example 1 with Ender

use of es.bsc.compss.nio.master.handlers.Ender in project compss by bsc-wdc.

the class WorkerStarter method startWorker.

/**
 * Starts the current worker
 *
 * @return
 * @throws InitNodeException
 */
public NIONode startWorker() throws InitNodeException {
    String name = this.nw.getName();
    String user = this.nw.getUser();
    int minPort = this.nw.getConfiguration().getMinPort();
    int maxPort = this.nw.getConfiguration().getMaxPort();
    int port = minPort;
    // Solves exit error 143
    synchronized (addressToWorkerStarter) {
        addressToWorkerStarter.put(name, this);
        LOGGER.debug("[WorkerStarter] Worker starter for " + name + " registers in the hashmap");
    }
    NIONode n = null;
    int pid = -1;
    while (port <= maxPort && !this.toStop) {
        // Kill previous worker processes if any
        killPreviousWorker(user, name, pid);
        // Instantiate the node
        n = new NIONode(name, port);
        // Start the worker
        pid = startWorker(user, name, port);
        // Check worker status
        LOGGER.info("[WorkerStarter] Worker process started. Checking connectivity...");
        checkWorker(n, name);
        // Check received ack
        LOGGER.debug("[WorkerStarter] Retries for " + name + " have finished.");
        if (!this.workerIsReady) {
            // Try next port
            ++port;
        } else {
            // Success, return node
            try {
                Runtime.getRuntime().addShutdownHook(new Ender(this, this.nw, pid));
            } catch (IllegalStateException e) {
                LOGGER.warn("Tried to shutdown vm while it was already being shutdown", e);
            }
            return n;
        }
    }
    // This can be because node is stopping or because we reached the maximum available ports
    if (this.toStop) {
        String msg = "[STOP]: Worker " + name + " stopped during creation because application is stopped";
        LOGGER.warn(msg);
        throw new InitNodeException(msg);
    } else if (!this.workerIsReady) {
        String msg = "[TIMEOUT]: Could not start the NIO worker on resource " + name + " through user " + user + ".";
        LOGGER.warn(msg);
        throw new InitNodeException(msg);
    } else {
        String msg = "[UNKNOWN]: Could not start the NIO worker on resource " + name + " through user " + user + ".";
        LOGGER.warn(msg);
        throw new InitNodeException(msg);
    }
}
Also used : NIONode(es.bsc.comm.nio.NIONode) InitNodeException(es.bsc.compss.exceptions.InitNodeException) Ender(es.bsc.compss.nio.master.handlers.Ender)

Aggregations

NIONode (es.bsc.comm.nio.NIONode)1 InitNodeException (es.bsc.compss.exceptions.InitNodeException)1 Ender (es.bsc.compss.nio.master.handlers.Ender)1