From d1d0b8e3838e6bacc3feb3512453992755db0091 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Thu, 7 Feb 2019 15:13:03 +0100 Subject: [PATCH 1/4] added grace period system property to server and micro --- .../micro/boot/runtime/MicroGlassFish.java | 8 +++++--- .../glassfish/bootstrap/GlassFishImpl.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java index 4a67e9a9fb1..169d21ac8ef 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java @@ -39,6 +39,7 @@ */ package fish.payara.micro.boot.runtime; +import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl; import com.sun.enterprise.module.bootstrap.ModuleStartup; import java.util.Properties; import org.glassfish.embeddable.CommandRunner; @@ -74,19 +75,20 @@ public void start() throws GlassFishException { } @Override - public void stop() throws GlassFishException { + public synchronized void stop() throws GlassFishException { if (status == Status.STOPPED || status == Status.STOPPING || status == Status.DISPOSED) { throw new IllegalStateException("Already in " + status + " state."); } - + status = Status.STOPPING; + GlassFishImpl.sleepShutdownGracePeriod(); kernel.stop(); habitat.shutdown(); status = Status.STOPPED; } @Override - public void dispose() throws GlassFishException { + public synchronized void dispose() throws GlassFishException { if (status == Status.DISPOSED) { throw new IllegalStateException("Already disposed."); } else if (status != Status.STOPPED) { diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java index ef53cd6d630..03520b1c968 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java @@ -47,10 +47,13 @@ import org.glassfish.embeddable.Deployer; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; +import org.glassfish.grizzly.threadpool.Threads; import org.glassfish.hk2.api.ServiceLocator; import java.util.Properties; +import javax.swing.plaf.SliderUI; + /** * @author Sanjeeb.Sahoo@Sun.COM */ @@ -87,10 +90,24 @@ public synchronized void stop() throws GlassFishException { throw new IllegalStateException("Already in " + status + " state."); } status = Status.STOPPING; + sleepShutdownGracePeriod(); gfKernel.stop(); status = Status.STOPPED; } + public static void sleepShutdownGracePeriod() { + String shutdowngrace = System.getProperty("fish.payara.shutdowngrace"); + if (shutdowngrace != null) { + try { + Thread.sleep(Integer.parseInt(shutdowngrace)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (NumberFormatException e) { + // no sleep, continue shutdown + } + } + } + public synchronized void dispose() throws GlassFishException { if (status == Status.DISPOSED) { throw new IllegalStateException("Already disposed."); From 1e87e824f734ba3d3aed4a7552e8331e0ec53836 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Thu, 7 Feb 2019 16:15:09 +0100 Subject: [PATCH 2/4] updated copyright header --- .../java/fish/payara/micro/boot/runtime/MicroGlassFish.java | 2 +- .../com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java index 169d21ac8ef..f8ba3956df5 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/boot/runtime/MicroGlassFish.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java index 03520b1c968..7a74adbd0eb 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2017] Payara Foundation and/or affiliates + * Portions Copyright [2017-2019] Payara Foundation and/or affiliates */ package com.sun.enterprise.glassfish.bootstrap; From d03ad8cebaf2492ce31d80f29b15d3c0db6f4406 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Thu, 7 Feb 2019 17:51:28 +0100 Subject: [PATCH 3/4] removed unused imports --- .../com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java index 7a74adbd0eb..a6bcbf81bbe 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java @@ -47,13 +47,10 @@ import org.glassfish.embeddable.Deployer; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; -import org.glassfish.grizzly.threadpool.Threads; import org.glassfish.hk2.api.ServiceLocator; import java.util.Properties; -import javax.swing.plaf.SliderUI; - /** * @author Sanjeeb.Sahoo@Sun.COM */ From 287cd1ff0274df053ce8c802894b633fe2131011 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Fri, 8 Feb 2019 11:19:47 +0100 Subject: [PATCH 4/4] extracted constant for grace property, added command line option for micro --- .../java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java | 3 ++- .../src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java | 4 ++++ .../com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java index 5fd5233b2b8..cfb1ff823e1 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java @@ -103,7 +103,8 @@ public enum RUNTIME_OPTION { sslcert(true), help(false), enablesni(false), - hzpublicaddress(true); + hzpublicaddress(true), + shutdowngrace(true, new IntegerValidator(1, Integer.MAX_VALUE)); private RUNTIME_OPTION(boolean hasValue) { this(hasValue, new Validator()); diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java index 40475ce0b78..e5c61fbcc8f 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java @@ -77,6 +77,7 @@ import org.glassfish.embeddable.GlassFishRuntime; import com.sun.appserv.server.util.Version; import com.sun.enterprise.glassfish.bootstrap.Constants; +import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl; import com.sun.enterprise.server.logging.ODLLogFormatter; import fish.payara.micro.PayaraMicroRuntime; import fish.payara.micro.boot.PayaraMicroBoot; @@ -1382,6 +1383,9 @@ else if (requestTracing[0].matches("\\D+")) { case hzpublicaddress: publicAddress = value; break; + case shutdowngrace: + System.setProperty(GlassFishImpl.PAYARA_SHUTDOWNGRACE_PROPERTY, value); + break; default: break; } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java index a6bcbf81bbe..6c7f59536a2 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java @@ -57,6 +57,8 @@ public class GlassFishImpl implements GlassFish { + public static final String PAYARA_SHUTDOWNGRACE_PROPERTY = "fish.payara.shutdowngrace"; + private ModuleStartup gfKernel; private ServiceLocator habitat; volatile Status status = Status.INIT; @@ -93,7 +95,7 @@ public synchronized void stop() throws GlassFishException { } public static void sleepShutdownGracePeriod() { - String shutdowngrace = System.getProperty("fish.payara.shutdowngrace"); + String shutdowngrace = System.getProperty(PAYARA_SHUTDOWNGRACE_PROPERTY); if (shutdowngrace != null) { try { Thread.sleep(Integer.parseInt(shutdowngrace));