This closes #879
This commit is contained in:
commit
3066690055
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.utils;
|
package org.apache.activemq.artemis.utils;
|
||||||
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
@ -72,4 +73,20 @@ public final class TimeUtils {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean waitOnBoolean(boolean expected, long timeout, CheckMethod check) {
|
||||||
|
long timeLeft = timeout;
|
||||||
|
long interval = 10;
|
||||||
|
while (check.check() != expected && timeLeft > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(interval);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
timeLeft -= interval;
|
||||||
|
}
|
||||||
|
return check.check() == expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface CheckMethod {
|
||||||
|
boolean check();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.activemq.artemis.utils;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class TimeUnitsTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWaitOnBoolean() throws IOException {
|
||||||
|
File tmpFile = folder.newFile("myfile.txt");
|
||||||
|
assertTrue(tmpFile.exists());
|
||||||
|
long begin = System.currentTimeMillis();
|
||||||
|
boolean result = TimeUtils.waitOnBoolean(false, 100, tmpFile::exists);
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
assertFalse(result);
|
||||||
|
assertTrue(tmpFile.exists());
|
||||||
|
//ideally the sleep time should > 2000.
|
||||||
|
assertTrue((end - begin) >= 100);
|
||||||
|
tmpFile.delete();
|
||||||
|
begin = System.currentTimeMillis();
|
||||||
|
result = TimeUtils.waitOnBoolean(false, 5000, tmpFile::exists);
|
||||||
|
end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
assertTrue(result);
|
||||||
|
assertFalse(tmpFile.exists());
|
||||||
|
|
||||||
|
assertTrue((end - begin) < 5000);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,8 @@ import org.jboss.logging.annotations.LogMessage;
|
||||||
import org.jboss.logging.annotations.Message;
|
import org.jboss.logging.annotations.Message;
|
||||||
import org.jboss.logging.annotations.MessageLogger;
|
import org.jboss.logging.annotations.MessageLogger;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger Code 24
|
* Logger Code 24
|
||||||
*
|
*
|
||||||
|
@ -52,4 +54,7 @@ public interface ActiveMQWebLogger extends BasicLogger {
|
||||||
@Message(id = 241002, value = "Artemis Jolokia REST API available at {0}", format = Message.Format.MESSAGE_FORMAT)
|
@Message(id = 241002, value = "Artemis Jolokia REST API available at {0}", format = Message.Format.MESSAGE_FORMAT)
|
||||||
void jolokiaAvailable(String bind);
|
void jolokiaAvailable(String bind);
|
||||||
|
|
||||||
|
@LogMessage(level = Logger.Level.WARN)
|
||||||
|
@Message(id = 244003, value = "Temporary file not deleted on shutdown: {0}", format = Message.Format.MESSAGE_FORMAT)
|
||||||
|
void tmpFileNotDeleted(File tmpdir);
|
||||||
}
|
}
|
|
@ -16,16 +16,20 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.component;
|
package org.apache.activemq.artemis.component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.ActiveMQWebLogger;
|
import org.apache.activemq.artemis.ActiveMQWebLogger;
|
||||||
import org.apache.activemq.artemis.components.ExternalComponent;
|
import org.apache.activemq.artemis.components.ExternalComponent;
|
||||||
import org.apache.activemq.artemis.dto.AppDTO;
|
import org.apache.activemq.artemis.dto.AppDTO;
|
||||||
import org.apache.activemq.artemis.dto.ComponentDTO;
|
import org.apache.activemq.artemis.dto.ComponentDTO;
|
||||||
import org.apache.activemq.artemis.dto.WebServerDTO;
|
import org.apache.activemq.artemis.dto.WebServerDTO;
|
||||||
|
import org.apache.activemq.artemis.utils.TimeUtils;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.HttpConfiguration;
|
import org.eclipse.jetty.server.HttpConfiguration;
|
||||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||||
|
@ -46,6 +50,7 @@ public class WebServerComponent implements ExternalComponent {
|
||||||
private WebServerDTO webServerConfig;
|
private WebServerDTO webServerConfig;
|
||||||
private URI uri;
|
private URI uri;
|
||||||
private String jolokiaUrl;
|
private String jolokiaUrl;
|
||||||
|
private List<WebAppContext> webContexts;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
|
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
|
||||||
|
@ -87,9 +92,11 @@ public class WebServerComponent implements ExternalComponent {
|
||||||
|
|
||||||
Path warDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
|
Path warDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
|
||||||
|
|
||||||
if (webServerConfig.apps != null) {
|
if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
|
||||||
|
webContexts = new ArrayList<>();
|
||||||
for (AppDTO app : webServerConfig.apps) {
|
for (AppDTO app : webServerConfig.apps) {
|
||||||
deployWar(app.url, app.war, warDir);
|
WebAppContext webContext = deployWar(app.url, app.war, warDir);
|
||||||
|
webContexts.add(webContext);
|
||||||
if (app.war.startsWith("jolokia")) {
|
if (app.war.startsWith("jolokia")) {
|
||||||
jolokiaUrl = webServerConfig.bind + "/" + app.url;
|
jolokiaUrl = webServerConfig.bind + "/" + app.url;
|
||||||
}
|
}
|
||||||
|
@ -121,6 +128,23 @@ public class WebServerComponent implements ExternalComponent {
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
server.stop();
|
server.stop();
|
||||||
|
if (webContexts != null) {
|
||||||
|
File tmpdir = null;
|
||||||
|
for (WebAppContext context : webContexts) {
|
||||||
|
tmpdir = context.getTempDirectory();
|
||||||
|
|
||||||
|
if (tmpdir != null && !context.isPersistTempDirectory()) {
|
||||||
|
//tmpdir will be removed by deleteOnExit()
|
||||||
|
//somehow when broker is stopped and restarted quickly
|
||||||
|
//this tmpdir won't get deleted sometimes
|
||||||
|
boolean fileDeleted = TimeUtils.waitOnBoolean(false, 10000, tmpdir::exists);
|
||||||
|
if (!fileDeleted) {
|
||||||
|
ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webContexts.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,7 +152,7 @@ public class WebServerComponent implements ExternalComponent {
|
||||||
return server != null && server.isStarted();
|
return server != null && server.isStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deployWar(String url, String warFile, Path warDirectory) throws IOException {
|
private WebAppContext deployWar(String url, String warFile, Path warDirectory) throws IOException {
|
||||||
WebAppContext webapp = new WebAppContext();
|
WebAppContext webapp = new WebAppContext();
|
||||||
if (url.startsWith("/")) {
|
if (url.startsWith("/")) {
|
||||||
webapp.setContextPath(url);
|
webapp.setContextPath(url);
|
||||||
|
@ -138,5 +162,6 @@ public class WebServerComponent implements ExternalComponent {
|
||||||
|
|
||||||
webapp.setWar(warDirectory.resolve(warFile).toString());
|
webapp.setWar(warDirectory.resolve(warFile).toString());
|
||||||
handlers.addHandler(webapp);
|
handlers.addHandler(webapp);
|
||||||
|
return webapp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue