<commit_before>package com.hazelcast.wm.test;

import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.ContextConfig;
import org.apache.catalina.startup.Tomcat;

import java.io.File;

public class TomcatServer implements ServletContainer {

    Tomcat tomcat;
    String serverXml;
    String sourceDir;
    volatile boolean running;

    public TomcatServer(int port, String sourceDir, String serverXml) throws Exception {
        this.serverXml = serverXml;
        this.sourceDir = sourceDir;
        buildTomcat(port,sourceDir,serverXml);
    }

    @Override
    public void stop() throws LifecycleException {
        tomcat.stop();
        running = false;
    }

    @Override
    public void start() throws Exception {
        tomcat.start();
        running = true;
    }

    @Override
    public void restart() throws LifecycleException, InterruptedException {
        int port = tomcat.getConnector().getLocalPort();
        tomcat.stop();
        running = false;
        tomcat.destroy();
        Thread.sleep(5000);
        buildTomcat(port, sourceDir, serverXml);
        Thread.sleep(5000);
        running = true;
    }

    public void buildTomcat(int port, String sourceDir, String serverXml) throws LifecycleException {
        tomcat = new Tomcat();
        File baseDir = new File(System.getProperty("java.io.tmpdir"));
        tomcat.setPort(port);
        tomcat.setBaseDir(baseDir.getAbsolutePath());
        Context context = tomcat.addContext("/", sourceDir);
        context.getServletContext().setAttribute(Globals.ALT_DD_ATTR, sourceDir + "/WEB-INF/" + serverXml);
        ContextConfig contextConfig = new ContextConfig();
        context.addLifecycleListener(contextConfig);
        context.setCookies(true);
        context.setBackgroundProcessorDelay(1);
        context.setReloadable(true);
        tomcat.getEngine().setJvmRoute("tomcat" + port);
        tomcat.getEngine().setName("tomcat-test" + port);
        tomcat.start();
        running = true;
    }

    @Override
    public boolean isRunning() {
        return running;
    }
}<commit_msg>tomcat server start fix for issue #3458<commit_after>package com.hazelcast.wm.test;

import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.ContextConfig;
import org.apache.catalina.startup.Tomcat;

import java.io.File;

public class TomcatServer implements ServletContainer {

    Tomcat tomcat;
    String serverXml;
    String sourceDir;
    int port;
    volatile boolean running;

    public TomcatServer(int port, String sourceDir, String serverXml) throws Exception {
        this.port = port;
        this.serverXml = serverXml;
        this.sourceDir = sourceDir;
        buildTomcat(sourceDir, serverXml);
    }

    @Override
    public void stop() throws Exception {
        tomcat.stop();
        tomcat.destroy();
        running = false;
    }

    @Override
    public void start() throws Exception {
        buildTomcat(sourceDir, serverXml);
        running = true;
    }

    @Override
    public void restart() throws Exception {
        stop();
        Thread.sleep(5000);
        start();
    }

    public void buildTomcat(String sourceDir, String serverXml) throws LifecycleException {
        tomcat = new Tomcat();
        File baseDir = new File(System.getProperty("java.io.tmpdir"));
        tomcat.setPort(port);
        tomcat.setBaseDir(baseDir.getAbsolutePath());
        Context context = tomcat.addContext("/", sourceDir);
        context.getServletContext().setAttribute(Globals.ALT_DD_ATTR, sourceDir + "/WEB-INF/" + serverXml);
        ContextConfig contextConfig = new ContextConfig();
        context.addLifecycleListener(contextConfig);
        context.setCookies(true);
        context.setBackgroundProcessorDelay(1);
        context.setReloadable(true);
        tomcat.getEngine().setJvmRoute("tomcat" + port);
        tomcat.getEngine().setName("tomcat-test" + port);
        tomcat.start();
        running = true;
    }

    @Override
    public boolean isRunning() {
        return running;
    }
}
{'fraction_non_alphanumeric': 0.10288552507095554, 'fraction_numerical': 0.004257332071901609, 'mean_word_length': 2.9230055658627085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '258025', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1166, 'n_words': 257}