Skip to content

Commit

Permalink
Fix for #293 (Tomcat)
Browse files Browse the repository at this point in the history
  • Loading branch information
decebals committed Jun 29, 2016
1 parent 6a26b00 commit 225013d
Showing 1 changed file with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import ro.pippo.core.AbstractWebServer;
import ro.pippo.core.Application;
import ro.pippo.core.PippoFilter;

import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoServlet;
import ro.pippo.core.WebServer;
import ro.pippo.core.util.StringUtils;

import java.io.File;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* @author Daniel Jipa
Expand All @@ -45,6 +47,31 @@ public class TomcatServer extends AbstractWebServer<TomcatSettings> {
private Application application;
private Tomcat tomcat;

private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final CountDownLatch startLatch = new CountDownLatch(1);

@Override
public void start() {
executor.submit(this::internalStart);
try {
startLatch.await();
} catch (InterruptedException e) {
log.info(e.getMessage());
}
}

@Override
public void stop() {
if (tomcat != null) {
try {
tomcat.stop();
executor.shutdownNow();
} catch (Exception e) {
throw new PippoRuntimeException(e, "Cannot stop Tomcat Server");
}
}
}

@Override
public void setPippoFilter(PippoFilter pippoFilter) {
super.setPippoFilter(pippoFilter);
Expand All @@ -53,7 +80,11 @@ public void setPippoFilter(PippoFilter pippoFilter) {
}

@Override
public void start() {
protected TomcatSettings createDefaultSettings() {
return new TomcatSettings(pippoSettings);
}

protected void internalStart() {
if (StringUtils.isNullOrEmpty(pippoFilterPath)) {
pippoFilterPath = "/*";
}
Expand Down Expand Up @@ -89,9 +120,9 @@ public void start() {
} catch (LifecycleException e) {
throw new PippoRuntimeException(e);
}
if (!pippoSettings.isTest()) {
tomcat.getServer().await();
}

startLatch.countDown();
tomcat.getServer().await();
}

private void enablePlainConnector(Tomcat tomcat) {
Expand Down Expand Up @@ -121,20 +152,4 @@ private void enableSSLConnector(Tomcat tomcat) {
connector.setAttribute("SSLEnabled", true);
}

@Override
public void stop() {
if (tomcat != null) {
try {
tomcat.stop();
} catch (Exception e) {
throw new PippoRuntimeException(e, "Cannot stop Tomcat Server");
}
}
}

@Override
protected TomcatSettings createDefaultSettings() {
return new TomcatSettings(pippoSettings);
}

}

0 comments on commit 225013d

Please sign in to comment.