Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Bruch2016-03-04 11:15:20 +0000
committerMarcel Bruch2016-03-04 11:16:19 +0000
commitc6ce9f27af44ffd8a28e1153140a61a7d15d3f32 (patch)
treecc0785638118811831d04da8af98cd40f5739252
parentea0843665351e53533333647764ddb8a54f03329 (diff)
downloadorg.eclipse.epp.logging-c6ce9f27af44ffd8a28e1153140a61a7d15d3f32.tar.gz
org.eclipse.epp.logging-c6ce9f27af44ffd8a28e1153140a61a7d15d3f32.tar.xz
org.eclipse.epp.logging-c6ce9f27af44ffd8a28e1153140a61a7d15d3f32.zip
Disable AERI on EclipseContext Disposals on shutdown
Bug: 488868 Change-Id: I851fac22b02adeabecec83efc4c3b96e7e47533a Signed-off-by: Marcel Bruch <marcel.bruch@codetrails.com>
-rw-r--r--bundles/org.eclipse.epp.logging.aeri.core/src/org/eclipse/epp/logging/aeri/core/SystemControl.java64
1 files changed, 45 insertions, 19 deletions
diff --git a/bundles/org.eclipse.epp.logging.aeri.core/src/org/eclipse/epp/logging/aeri/core/SystemControl.java b/bundles/org.eclipse.epp.logging.aeri.core/src/org/eclipse/epp/logging/aeri/core/SystemControl.java
index 389a73706..7f6beffc2 100644
--- a/bundles/org.eclipse.epp.logging.aeri.core/src/org/eclipse/epp/logging/aeri/core/SystemControl.java
+++ b/bundles/org.eclipse.epp.logging.aeri.core/src/org/eclipse/epp/logging/aeri/core/SystemControl.java
@@ -8,6 +8,7 @@
package org.eclipse.epp.logging.aeri.core;
import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.ImmutableList.of;
import static org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke;
import static org.eclipse.epp.logging.aeri.core.Constants.*;
import static org.eclipse.epp.logging.aeri.core.l10n.LogMessages.WARN_AERI_FAILURE;
@@ -16,14 +17,40 @@ import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.internal.contexts.EclipseContext;
+import org.eclipse.e4.core.internal.contexts.IContextDisposalListener;
import org.eclipse.epp.logging.aeri.core.handlers.ResetSendModeHandler;
import org.eclipse.epp.logging.aeri.core.handlers.SetSendModeHandler;
import org.eclipse.epp.logging.aeri.core.util.Logs;
import org.eclipse.jdt.annotation.Nullable;
+@SuppressWarnings("restriction")
public class SystemControl {
- private static IEclipseContext SYSTEM_CONTEXT;
+ private static final IEclipseContext SYSTEM_CONTEXT = init();
+ private static volatile boolean DISPOSED;
+
+ private static EclipseContext init() {
+ EclipseContext local = new EclipseContext(null);
+ local.set(EclipseContext.DEBUG_STRING, "AERI System Context");
+ local.set(ISystemSettings.class, IModelFactory.eINSTANCE.createSystemSettings());
+
+ // register the default handlers
+ for (Class<?> clazz : of(SetSendModeHandler.class, ResetSendModeHandler.class)) {
+ Object handler = ContextInjectionFactory.make(clazz, local);
+ local.declareModifiable(clazz);
+ local.set(clazz.getName(), handler);
+ }
+
+ // respond to disposal events:
+ local.notifyOnDisposal(new IContextDisposalListener() {
+
+ @Override
+ public void disposed(IEclipseContext context) {
+ setDisposed(true);
+ }
+ });
+ return local;
+ }
/**
* Returns the DI context used by the error reporting system. Applications may set the parent context of the returned
@@ -32,13 +59,6 @@ public class SystemControl {
* @see IEclipseContext#setParent(IEclipseContext)
*/
public static IEclipseContext getSystemContext() {
- if (SYSTEM_CONTEXT == null) {
- // do a default initialization
- SYSTEM_CONTEXT = new EclipseContext(null);
- SYSTEM_CONTEXT.set(EclipseContext.DEBUG_STRING, "AERI System Context");
- SYSTEM_CONTEXT.set(ISystemSettings.class, IModelFactory.eINSTANCE.createSystemSettings());
- registerHandlers(SetSendModeHandler.class, ResetSendModeHandler.class);
- }
return SYSTEM_CONTEXT;
}
@@ -49,17 +69,17 @@ public class SystemControl {
@SuppressWarnings("unchecked")
@Nullable
public static <T> T get(String key) {
- return (T) getSystemContext().get(key);
+ return (T) SYSTEM_CONTEXT.get(key);
}
@Nullable
public static <T> T get(Class<T> key) {
- return getSystemContext().get(key);
+ return SYSTEM_CONTEXT.get(key);
}
public static boolean isActive() {
try {
- if (Boolean.getBoolean(SYSPROP_DISABLE_AERI) || Boolean.getBoolean(SYSPROP_DISABLE_AERI_V1)) {
+ if (Boolean.getBoolean(SYSPROP_DISABLE_AERI) || Boolean.getBoolean(SYSPROP_DISABLE_AERI_V1) || isDisposed()) {
return false;
}
SendMode mode = (SendMode) executeHandler(ResetSendModeHandler.class);
@@ -83,9 +103,9 @@ public class SystemControl {
public static void registerHandlers(Class<?>... handlers) {
for (Class<?> clazz : handlers) {
- Object handler = ContextInjectionFactory.make(clazz, getSystemContext());
- getSystemContext().declareModifiable(clazz);
- getSystemContext().set(clazz.getName(), handler);
+ Object handler = ContextInjectionFactory.make(clazz, SYSTEM_CONTEXT);
+ SYSTEM_CONTEXT.declareModifiable(clazz);
+ SYSTEM_CONTEXT.set(clazz.getName(), handler);
}
}
@@ -98,15 +118,21 @@ public class SystemControl {
*/
@Nullable
public static Object executeHandler(Class<?> clazz) {
- IEclipseContext context = getSystemContext();
- Object handler = context.get(clazz);
- return ContextInjectionFactory.invoke(handler, Execute.class, context);
+ Object handler = SYSTEM_CONTEXT.get(clazz);
+ return ContextInjectionFactory.invoke(handler, Execute.class, SYSTEM_CONTEXT);
}
@Nullable
public static Object executeHandler(Class<?> clazz, IEclipseContext localContext) {
- Object handler = getSystemContext().get(clazz);
- return invoke(handler, Execute.class, getSystemContext(), localContext, null);
+ Object handler = SYSTEM_CONTEXT.get(clazz);
+ return invoke(handler, Execute.class, SYSTEM_CONTEXT, localContext, null);
}
+ private static void setDisposed(boolean value) {
+ DISPOSED = value;
+ }
+
+ private static boolean isDisposed() {
+ return DISPOSED;
+ }
}

Back to the top