diff --git a/nucleus/core/logging/pom.xml b/nucleus/core/logging/pom.xml
index a8972f2c294..29bc99d71c4 100755
--- a/nucleus/core/logging/pom.xml
+++ b/nucleus/core/logging/pom.xml
@@ -93,12 +93,6 @@
jakarta.json-api
${jsonp.version}
-
- fish.payara.server.internal.payara-modules
- payara-executor-service
- ${project.version}
- jar
-
org.mockito
mockito-core
@@ -108,6 +102,13 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ false
+
+
org.apache.felix
maven-bundle-plugin
diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/GFFileHandler.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/GFFileHandler.java
index 82abd029212..1b290f830b0 100644
--- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/GFFileHandler.java
+++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/GFFileHandler.java
@@ -51,8 +51,7 @@
import com.sun.enterprise.util.io.FileUtils;
import com.sun.enterprise.v3.logging.AgentFormatterDelegate;
import fish.payara.enterprise.server.logging.JSONLogFormatter;
-import fish.payara.enterprise.server.logging.PayaraNotificationLogRotationTimer;
-import fish.payara.nucleus.executorservice.PayaraExecutorService;
+import fish.payara.enterprise.server.logging.PayaraNotificationLogRotationTimer;;
import java.io.*;
import java.security.PrivilegedAction;
import java.text.FieldPosition;
@@ -120,9 +119,6 @@ public class GFFileHandler extends StreamHandler implements
@Inject
private ServiceLocator habitat;
- @Inject
- private PayaraExecutorService payaraExecutorService;
-
// This is a OutputStream to keep track of number of bytes
// written out to the stream
private MeteredStream meter;
@@ -175,12 +171,12 @@ public class GFFileHandler extends StreamHandler implements
public static final int MINIMUM_ROTATION_LIMIT_VALUE = 500*1000;
private BooleanLatch done = new BooleanLatch();
-
+
private boolean dayBasedFileRotation = false;
private List logEventListeners = new ArrayList<>();
- private Future> pumpFuture;
+ private Thread pump;
protected String logFileProperty = "";
private final LogManager manager = LogManager.getLogManager();
@@ -188,10 +184,6 @@ public class GFFileHandler extends StreamHandler implements
private static final String GF_FILE_HANDLER = GFFileHandler.class.getCanonicalName() ;
private LogRecord logRecord = new LogRecord(Level.INFO, LogFacade.GF_VERSION_INFO);
- void setPayaraExecutorService(PayaraExecutorService payaraExecutorService) {
- this.payaraExecutorService = payaraExecutorService;
- }
-
@Override
public void postConstruct() {
@@ -433,12 +425,10 @@ private void rotationOnDateChange() {
if (className.equals(GF_FILE_HANDLER)) {
LogRotationTimer.getInstance().startTimer(
- payaraExecutorService.getUnderlyingScheduledExecutorService(),
new LogRotationTimerTask(rotationTask,
rotationTimeLimitValue / 60000));
} else {
PayaraNotificationLogRotationTimer.getInstance().startTimer(
- payaraExecutorService.getUnderlyingScheduledExecutorService(),
new LogRotationTimerTask(rotationTask,
rotationTimeLimitValue / 60000));
}
@@ -453,17 +443,15 @@ private void rotationOnTimeLimit() {
if (className.equals(GF_FILE_HANDLER)) {
LogRotationTimer.getInstance().startTimer(
- payaraExecutorService.getUnderlyingScheduledExecutorService(),
new LogRotationTimerTask(rotationTask,
rotationTimeLimitValue));
} else {
PayaraNotificationLogRotationTimer.getInstance().startTimer(
- payaraExecutorService.getUnderlyingScheduledExecutorService(),
new LogRotationTimerTask(rotationTask,
rotationTimeLimitValue));
}
}
-}
+ }
private void rotationOnFileSizeLimit(String propertyValue) {
try {
@@ -585,14 +573,10 @@ private void configureUniformLogFormatter(String excludeFields, boolean multiLin
}
void initializePump() {
- if (pumpFuture != null) {
- pumpFuture.cancel(true);
- pumpFuture = null;
- }
- if (logToFile) {
- pumpFuture = payaraExecutorService.submit(
- () -> {
- while (!done.isSignalled() && logToFile) {
+ pump = new Thread() {
+ @Override
+ public void run() {
+ while (!done.isSignalled()) {
try {
log();
} catch (Exception e) {
@@ -601,11 +585,10 @@ void initializePump() {
}
}
}
- );
- } else {
- drainAllPendingRecords();
- flush();
- }
+ };
+ pump.setName("GFFileHandler log pump");
+ pump.setDaemon(true);
+ pump.start();
}
@Override
@@ -631,8 +614,8 @@ public void preDestroy() {
}
done.tryReleaseShared(1);
- if (pumpFuture != null) {
- pumpFuture.cancel(true);
+ if (pump != null) {
+ pump.interrupt();
}
// drain and return all
@@ -934,18 +917,18 @@ private void restartTimeBasedLogRotation() {
if (dayBasedFileRotation) {
if (className.equals(GF_FILE_HANDLER)) {
LogRotationTimer.getInstance()
- .restartTimerForDayBasedRotation(payaraExecutorService.getUnderlyingScheduledExecutorService());
+ .restartTimerForDayBasedRotation();
} else {
PayaraNotificationLogRotationTimer.getInstance()
- .restartTimerForDayBasedRotation(payaraExecutorService.getUnderlyingScheduledExecutorService());
+ .restartTimerForDayBasedRotation();
}
} else {
if (className.equals(GF_FILE_HANDLER)) {
LogRotationTimer.getInstance()
- .restartTimer(payaraExecutorService.getUnderlyingScheduledExecutorService());
+ .restartTimer();
} else {
PayaraNotificationLogRotationTimer.getInstance()
- .restartTimer(payaraExecutorService.getUnderlyingScheduledExecutorService());
+ .restartTimer();
}
}
diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimer.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimer.java
index b976fa071ba..2855dfc3618 100644
--- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimer.java
+++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimer.java
@@ -37,13 +37,12 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
-// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
+// Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.server.logging;
-import java.util.concurrent.ScheduledExecutorService;
+import java.util.Timer;
import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
public class LogRotationTimer {
@@ -51,61 +50,51 @@ public class LogRotationTimer {
private ScheduledFuture> logRotationFuture;
private static LogRotationTimer instance = new LogRotationTimer();
+ private Timer rotationTimer;
- private LogRotationTimer() {}
+ private LogRotationTimer() {
+ rotationTimer = new Timer("log-rotation-timer");
+ }
public static LogRotationTimer getInstance() {
return instance;
}
- public void startTimer(ScheduledExecutorService scheduledExecutorService, LogRotationTimerTask timerTask) {
+ public void startTimer(LogRotationTimerTask timerTask) {
rotationTimerTask = timerTask;
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- timerTask.getRotationTimerValue(),
- TimeUnit.MILLISECONDS
- );
+ rotationTimer.schedule(rotationTimerTask, timerTask.getRotationTimerValue());
}
public void stopTimer() {
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
- }
+ rotationTimer.cancel();
}
- public void restartTimer(ScheduledExecutorService scheduledExecutorService) {
+ public void restartTimer() {
// We will restart the timer only if the timerTask is set which
// means user has set a value for LogRotation based on Time
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
+ if (rotationTimerTask != null) {
+ rotationTimerTask.cancel();
rotationTimerTask = new LogRotationTimerTask(
// This is wierd, We need to have a fresh TimerTask object
// to reschedule the work.
rotationTimerTask.task,
rotationTimerTask.getRotationTimerValueInMinutes());
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- rotationTimerTask.getRotationTimerValue(),
- TimeUnit.MILLISECONDS);
+ rotationTimer.schedule(rotationTimerTask, rotationTimerTask.getRotationTimerValue());
}
}
- public void restartTimerForDayBasedRotation(ScheduledExecutorService scheduledExecutorService) {
+ public void restartTimerForDayBasedRotation() {
// We will restart the timer only if the timerTask is set which
// means user has set a value for LogRotation based on Time
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
+ if (rotationTimerTask != null) {
+ rotationTimerTask.cancel();
rotationTimerTask = new LogRotationTimerTask(
// This is wierd, We need to have a fresh TimerTask object
// to reschedule the work.
rotationTimerTask.task,
60 * 24
);
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- 1000 * 60 * 60 * 24,
- TimeUnit.MILLISECONDS
- );
+ rotationTimer.schedule(rotationTimerTask, 1000 * 60 * 60 * 24);
}
}
diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimerTask.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimerTask.java
index edd76b3041e..68e32d515b8 100644
--- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimerTask.java
+++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogRotationTimerTask.java
@@ -37,13 +37,14 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
-// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
+// Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.server.logging;
+import java.util.TimerTask;
import org.glassfish.api.logging.Task;
-public class LogRotationTimerTask implements Runnable {
+public class LogRotationTimerTask extends TimerTask {
private long timerValue;
public Task task;
diff --git a/nucleus/core/logging/src/main/java/fish/payara/enterprise/server/logging/PayaraNotificationLogRotationTimer.java b/nucleus/core/logging/src/main/java/fish/payara/enterprise/server/logging/PayaraNotificationLogRotationTimer.java
index f8e7383fbd6..b70ddd8f3b6 100644
--- a/nucleus/core/logging/src/main/java/fish/payara/enterprise/server/logging/PayaraNotificationLogRotationTimer.java
+++ b/nucleus/core/logging/src/main/java/fish/payara/enterprise/server/logging/PayaraNotificationLogRotationTimer.java
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright (c) [2018] Payara Foundation and/or its affiliates. All rights reserved.
+ * Copyright (c) [2018-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
@@ -41,10 +41,9 @@
package fish.payara.enterprise.server.logging;
import com.sun.enterprise.server.logging.LogRotationTimerTask;
+import java.util.Timer;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
/**
*
@@ -54,59 +53,48 @@ public class PayaraNotificationLogRotationTimer {
private LogRotationTimerTask rotationTimerTask;
private ScheduledFuture> logRotationFuture;
+ private Timer rotationTimer;
private static PayaraNotificationLogRotationTimer instance = new PayaraNotificationLogRotationTimer();
private PayaraNotificationLogRotationTimer() {
+ rotationTimer = new Timer("payara-log-rotation-timer");
}
public static PayaraNotificationLogRotationTimer getInstance() {
return instance;
}
- public void startTimer(ScheduledExecutorService scheduledExecutorService, LogRotationTimerTask timerTask) {
+ public void startTimer(LogRotationTimerTask timerTask) {
rotationTimerTask = timerTask;
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- timerTask.getRotationTimerValue(),
- TimeUnit.MILLISECONDS
- );
+ rotationTimer.schedule(rotationTimerTask, timerTask.getRotationTimerValue());
}
public void stopTimer() {
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
- }
+ rotationTimer.cancel();
}
- public void restartTimer(ScheduledExecutorService scheduledExecutorService) {
+ public void restartTimer() {
// We will restart the timer only if the timerTask is set which
// means user has set a value for LogRotation based on Time
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
+ if (rotationTimerTask != null) {
+ rotationTimerTask.cancel();
rotationTimerTask = new LogRotationTimerTask(
rotationTimerTask.task,
rotationTimerTask.getRotationTimerValueInMinutes());
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- rotationTimerTask.getRotationTimerValue(),
- TimeUnit.MILLISECONDS
- );
+ rotationTimer.schedule(rotationTimerTask, rotationTimerTask.getRotationTimerValue());
}
}
- public void restartTimerForDayBasedRotation(ScheduledExecutorService scheduledExecutorService) {
+ public void restartTimerForDayBasedRotation() {
// We will restart the timer only if the timerTask is set which
// means user has set a value for LogRotation based on Time
- if (logRotationFuture != null) {
- logRotationFuture.cancel(false);
+ if (rotationTimerTask != null) {
+ rotationTimerTask.cancel();
rotationTimerTask = new LogRotationTimerTask(
rotationTimerTask.task,
60 * 24);
- logRotationFuture = scheduledExecutorService.schedule(
- rotationTimerTask,
- 1000 * 60 * 60 * 24, TimeUnit.MILLISECONDS
- );
+ rotationTimer.schedule(rotationTimerTask, 1000 * 60 * 60 * 24);
}
}
}
\ No newline at end of file
diff --git a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
index 2b9663c77c1..b5028dd595b 100644
--- a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
+++ b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
@@ -37,11 +37,10 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
-// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
+// Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.server.logging;
-import fish.payara.nucleus.executorservice.PayaraExecutorService;
import java.io.File;
import java.util.concurrent.*;
import java.util.logging.Level;
@@ -79,9 +78,7 @@ public static void initializeLoggingAnnotationsTest() throws Exception {
File testLog = new File(TEST_EVENTS_LOG);
// Add a file handler with UniformLogFormatter
- PayaraExecutorService payaraExecutorService = new TestPayaraExecutorService();
gfFileHandler = new GFFileHandler();
- gfFileHandler.setPayaraExecutorService(payaraExecutorService);
gfFileHandler.changeFileName(testLog);
UniformLogFormatter formatter = new UniformLogFormatter();
formatter.setLogEventBroadcaster(gfFileHandler);
@@ -117,29 +114,6 @@ public static void cleanupLoggingAnnotationsTest() throws Exception {
gfFileHandler.preDestroy();
}
- private static class TestPayaraExecutorService extends PayaraExecutorService {
-
- private ScheduledExecutorService scheduledExecutorService;
- private ExecutorService executorService;
-
- TestPayaraExecutorService() {
- super();
- this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
- this.executorService = Executors.newSingleThreadExecutor();
- }
-
- @Override
- public ScheduledExecutorService getUnderlyingScheduledExecutorService() {
- return this.scheduledExecutorService;
- }
-
- @Override
- public Future> submit(Runnable task) {
- return this.executorService.submit(task);
- }
-
- }
-
private static class TestLogEventListener implements LogEventListener {
private BlockingQueue logEvents = new ArrayBlockingQueue<>(100);