From 7438671cfcf65bc3e969a61ed8cdd700c1d7907d Mon Sep 17 00:00:00 2001 From: Cousjava Date: Mon, 5 Jun 2017 09:30:46 +0100 Subject: [PATCH] PAYARA-1696 stop previous thread when notifier is configured (#1640) Only a single thread will now exist for each notifer. --- .../datadog/DatadogNotifierService.java | 4 ---- .../email/EmailNotifierService.java | 6 +----- .../hipchat/HipchatNotifierService.java | 6 +----- .../notification/jms/JmsNotifierService.java | 7 +------ .../newrelic/NewRelicNotifierService.java | 6 +----- .../slack/SlackNotifierService.java | 6 +----- .../snmp/SnmpNotifierService.java | 2 +- .../xmpp/XmppNotifierService.java | 4 ++-- .../service/BaseNotifierService.java | 5 +++++ .../service/QueueBasedNotifierService.java | 19 +++++++++++++++++-- .../core/EventbusNotifierService.java | 4 ---- 11 files changed, 30 insertions(+), 39 deletions(-) diff --git a/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java b/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java index d1b03a3b737..93ebc5d314d 100644 --- a/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java +++ b/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java @@ -81,8 +81,4 @@ public void bootstrap() { scheduleExecutor(new DatadogNotificationRunnable(queue, executionOptions)); } - @Override - public void shutdown() { - super.reset(); - } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/notification-email-core/src/main/java/fish/payara/notification/email/EmailNotifierService.java b/appserver/payara-appserver-modules/notification-email-core/src/main/java/fish/payara/notification/email/EmailNotifierService.java index 7ad4aba42f6..3a9d6415b77 100644 --- a/appserver/payara-appserver-modules/notification-email-core/src/main/java/fish/payara/notification/email/EmailNotifierService.java +++ b/appserver/payara-appserver-modules/notification-email-core/src/main/java/fish/payara/notification/email/EmailNotifierService.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-2017 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 @@ -101,8 +101,4 @@ public void bootstrap() { } } - @Override - public void shutdown() { - super.reset(); - } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/notification-hipchat-core/src/main/java/fish/payara/notification/hipchat/HipchatNotifierService.java b/appserver/payara-appserver-modules/notification-hipchat-core/src/main/java/fish/payara/notification/hipchat/HipchatNotifierService.java index 6a66e568554..d40db04e07b 100644 --- a/appserver/payara-appserver-modules/notification-hipchat-core/src/main/java/fish/payara/notification/hipchat/HipchatNotifierService.java +++ b/appserver/payara-appserver-modules/notification-hipchat-core/src/main/java/fish/payara/notification/hipchat/HipchatNotifierService.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-2017 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 @@ -81,8 +81,4 @@ public void bootstrap() { scheduleExecutor(new HipchatNotificationRunnable(queue, executionOptions)); } - @Override - public void shutdown() { - super.reset(); - } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/notification-jms-core/src/main/java/fish/payara/notification/jms/JmsNotifierService.java b/appserver/payara-appserver-modules/notification-jms-core/src/main/java/fish/payara/notification/jms/JmsNotifierService.java index 26d824194f7..7d91eecb620 100644 --- a/appserver/payara-appserver-modules/notification-jms-core/src/main/java/fish/payara/notification/jms/JmsNotifierService.java +++ b/appserver/payara-appserver-modules/notification-jms-core/src/main/java/fish/payara/notification/jms/JmsNotifierService.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2017 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 @@ -123,11 +123,6 @@ public void bootstrap() { } } - @Override - public void shutdown() { - super.reset(); - } - @Override @Subscribe public void handleNotification(JmsNotificationEvent event) { diff --git a/appserver/payara-appserver-modules/notification-newrelic-core/src/main/java/fish/payara/notification/newrelic/NewRelicNotifierService.java b/appserver/payara-appserver-modules/notification-newrelic-core/src/main/java/fish/payara/notification/newrelic/NewRelicNotifierService.java index e529f5fcc18..e3321173e7f 100644 --- a/appserver/payara-appserver-modules/notification-newrelic-core/src/main/java/fish/payara/notification/newrelic/NewRelicNotifierService.java +++ b/appserver/payara-appserver-modules/notification-newrelic-core/src/main/java/fish/payara/notification/newrelic/NewRelicNotifierService.java @@ -80,9 +80,5 @@ public void bootstrap() { executionOptions = (NewRelicNotifierConfigurationExecutionOptions) getNotifierConfigurationExecutionOptions(); scheduleExecutor(new NewRelicNotificationRunnable(queue, executionOptions)); } - - @Override - public void shutdown() { - super.reset(); - } + } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/notification-slack-core/src/main/java/fish/payara/notification/slack/SlackNotifierService.java b/appserver/payara-appserver-modules/notification-slack-core/src/main/java/fish/payara/notification/slack/SlackNotifierService.java index 5a7164fca3c..00337302077 100644 --- a/appserver/payara-appserver-modules/notification-slack-core/src/main/java/fish/payara/notification/slack/SlackNotifierService.java +++ b/appserver/payara-appserver-modules/notification-slack-core/src/main/java/fish/payara/notification/slack/SlackNotifierService.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-2017 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 @@ -82,8 +82,4 @@ public void bootstrap() { scheduleExecutor(new SlackNotificationRunnable(queue, executionOptions)); } - @Override - public void shutdown() { - super.reset(); - } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/notification-snmp-core/src/main/java/fish/payara/notification/snmp/SnmpNotifierService.java b/appserver/payara-appserver-modules/notification-snmp-core/src/main/java/fish/payara/notification/snmp/SnmpNotifierService.java index f52e790e97c..1c2c30530bb 100644 --- a/appserver/payara-appserver-modules/notification-snmp-core/src/main/java/fish/payara/notification/snmp/SnmpNotifierService.java +++ b/appserver/payara-appserver-modules/notification-snmp-core/src/main/java/fish/payara/notification/snmp/SnmpNotifierService.java @@ -123,7 +123,7 @@ public void bootstrap() { @Override public void shutdown() { - super.reset(); + super.shutdown(); if (snmp != null) { try { snmp.close(); diff --git a/appserver/payara-appserver-modules/notification-xmpp-core/src/main/java/fish/payara/notification/xmpp/XmppNotifierService.java b/appserver/payara-appserver-modules/notification-xmpp-core/src/main/java/fish/payara/notification/xmpp/XmppNotifierService.java index 2e0600ba47d..fc24d9486e2 100644 --- a/appserver/payara-appserver-modules/notification-xmpp-core/src/main/java/fish/payara/notification/xmpp/XmppNotifierService.java +++ b/appserver/payara-appserver-modules/notification-xmpp-core/src/main/java/fish/payara/notification/xmpp/XmppNotifierService.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-2017 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 @@ -116,7 +116,7 @@ public void bootstrap() { @Override public void shutdown() { - super.reset(); + super.shutdown(); if (connection != null) { connection.disconnect(); } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/BaseNotifierService.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/BaseNotifierService.java index 8429c004a7c..368848928c3 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/BaseNotifierService.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/BaseNotifierService.java @@ -124,6 +124,11 @@ public NotifierConfigurationExecutionOptions getNotifierConfigurationExecutionOp return null; } + /** + * Unregisters a service and cleans up any information stored in it + * This function does NOT restart the service. + * @param service + */ protected void reset(BaseNotifierService service) { eventBus.unregister(service); } diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/QueueBasedNotifierService.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/QueueBasedNotifierService.java index 8f64f6628e2..0358a77f621 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/QueueBasedNotifierService.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/service/QueueBasedNotifierService.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2017 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 @@ -85,12 +85,27 @@ protected ScheduledFuture scheduleExecutor(NotificationRunnable notificationRunn TimeUnit.MILLISECONDS); } + /** + * Unregisters the service and cleans up any information stored in it + * This function does NOT restart the service. + */ protected void reset() { super.reset(this); queue.resetQueue(); if (scheduledFuture != null) { scheduledFuture.cancel(true); } - initializeExecutor(); + //initializeExecutor(); + } + + /** + * Shuts down the service + */ + @Override + public void shutdown(){ + if (executor != null){ + executor.shutdown(); + } + reset(); } } \ No newline at end of file diff --git a/nucleus/payara-modules/notification-eventbus-core/src/main/java/fish/payara/notification/eventbus/core/EventbusNotifierService.java b/nucleus/payara-modules/notification-eventbus-core/src/main/java/fish/payara/notification/eventbus/core/EventbusNotifierService.java index db510924df1..f55cc7d1862 100644 --- a/nucleus/payara-modules/notification-eventbus-core/src/main/java/fish/payara/notification/eventbus/core/EventbusNotifierService.java +++ b/nucleus/payara-modules/notification-eventbus-core/src/main/java/fish/payara/notification/eventbus/core/EventbusNotifierService.java @@ -86,8 +86,4 @@ public void bootstrap() { executionOptions = (EventbusNotifierConfigurationExecutionOptions) getNotifierConfigurationExecutionOptions(); } - @Override - public void shutdown() { - super.reset(); - } } \ No newline at end of file