2018-05-15 20:24:34 +02:00
|
|
|
/*
|
2025-01-10 13:46:57 +00:00
|
|
|
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
|
2018-05-15 20:24:34 +02:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package jdk.jfr.internal;
|
|
|
|
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2023-11-22 20:48:42 +00:00
|
|
|
import jdk.internal.module.Checks;
|
2018-05-15 20:24:34 +02:00
|
|
|
import jdk.internal.module.Modules;
|
|
|
|
import jdk.jfr.AnnotationElement;
|
|
|
|
import jdk.jfr.Enabled;
|
|
|
|
import jdk.jfr.Name;
|
|
|
|
import jdk.jfr.Period;
|
|
|
|
import jdk.jfr.SettingControl;
|
|
|
|
import jdk.jfr.SettingDefinition;
|
|
|
|
import jdk.jfr.StackTrace;
|
|
|
|
import jdk.jfr.Threshold;
|
2025-06-05 11:36:08 +00:00
|
|
|
import jdk.jfr.Throttle;
|
2018-05-15 20:24:34 +02:00
|
|
|
import jdk.jfr.events.ActiveSettingEvent;
|
2023-11-22 20:48:42 +00:00
|
|
|
import jdk.jfr.events.StackFilter;
|
2018-05-15 20:24:34 +02:00
|
|
|
import jdk.jfr.internal.settings.CutoffSetting;
|
|
|
|
import jdk.jfr.internal.settings.EnabledSetting;
|
2023-12-07 10:45:55 +00:00
|
|
|
import jdk.jfr.internal.settings.LevelSetting;
|
2025-05-29 08:31:17 +00:00
|
|
|
import jdk.jfr.internal.settings.MethodSetting;
|
2018-05-15 20:24:34 +02:00
|
|
|
import jdk.jfr.internal.settings.PeriodSetting;
|
2025-06-05 08:18:18 +00:00
|
|
|
import jdk.jfr.internal.settings.CPUThrottleSetting;
|
2018-05-15 20:24:34 +02:00
|
|
|
import jdk.jfr.internal.settings.StackTraceSetting;
|
|
|
|
import jdk.jfr.internal.settings.ThresholdSetting;
|
2020-12-10 12:33:48 +00:00
|
|
|
import jdk.jfr.internal.settings.ThrottleSetting;
|
2025-06-05 11:36:08 +00:00
|
|
|
import jdk.jfr.internal.settings.Throttler;
|
2025-05-29 08:31:17 +00:00
|
|
|
import jdk.jfr.internal.tracing.Modification;
|
2023-06-19 17:46:23 +00:00
|
|
|
import jdk.jfr.internal.util.Utils;
|
2018-05-15 20:24:34 +02:00
|
|
|
|
|
|
|
// This class can't have a hard reference from PlatformEventType, since it
|
|
|
|
// holds SettingControl instances that need to be released
|
|
|
|
// when a class is unloaded (to avoid memory leaks).
|
|
|
|
public final class EventControl {
|
2022-05-13 15:33:04 +00:00
|
|
|
record NamedControl(String name, Control control) {
|
2019-10-30 19:43:52 +01:00
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
static final String FIELD_SETTING_PREFIX = "setting";
|
|
|
|
private static final Type TYPE_ENABLED = TypeLibrary.createType(EnabledSetting.class);
|
|
|
|
private static final Type TYPE_THRESHOLD = TypeLibrary.createType(ThresholdSetting.class);
|
|
|
|
private static final Type TYPE_STACK_TRACE = TypeLibrary.createType(StackTraceSetting.class);
|
|
|
|
private static final Type TYPE_PERIOD = TypeLibrary.createType(PeriodSetting.class);
|
|
|
|
private static final Type TYPE_CUTOFF = TypeLibrary.createType(CutoffSetting.class);
|
2020-12-10 12:33:48 +00:00
|
|
|
private static final Type TYPE_THROTTLE = TypeLibrary.createType(ThrottleSetting.class);
|
2023-11-22 20:48:42 +00:00
|
|
|
private static final long STACK_FILTER_ID = Type.getTypeId(StackFilter.class);
|
2023-12-07 10:45:55 +00:00
|
|
|
private static final Type TYPE_LEVEL = TypeLibrary.createType(LevelSetting.class);
|
2025-05-29 08:31:17 +00:00
|
|
|
private static final Type TYPE_METHOD_FILTER = TypeLibrary.createType(MethodSetting.class);
|
2018-05-15 20:24:34 +02:00
|
|
|
|
2022-10-10 17:56:34 +00:00
|
|
|
private final ArrayList<SettingControl> settingControls = new ArrayList<>();
|
2019-10-30 19:43:52 +01:00
|
|
|
private final ArrayList<NamedControl> namedControls = new ArrayList<>(5);
|
2018-05-15 20:24:34 +02:00
|
|
|
private final PlatformEventType type;
|
|
|
|
private final String idName;
|
|
|
|
|
|
|
|
EventControl(PlatformEventType eventType) {
|
2023-10-31 15:36:12 +00:00
|
|
|
if (eventType.hasThreshold()) {
|
2019-10-30 19:43:52 +01:00
|
|
|
addControl(Threshold.NAME, defineThreshold(eventType));
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
if (eventType.hasStackTrace()) {
|
2019-10-30 19:43:52 +01:00
|
|
|
addControl(StackTrace.NAME, defineStackTrace(eventType));
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
if (eventType.hasPeriod()) {
|
2019-10-30 19:43:52 +01:00
|
|
|
addControl(Period.NAME, definePeriod(eventType));
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
if (eventType.hasCutoff()) {
|
2019-10-30 19:43:52 +01:00
|
|
|
addControl(Cutoff.NAME, defineCutoff(eventType));
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
2020-12-10 12:33:48 +00:00
|
|
|
if (eventType.hasThrottle()) {
|
|
|
|
addControl(Throttle.NAME, defineThrottle(eventType));
|
2025-06-05 11:36:08 +00:00
|
|
|
eventType.setThrottler(new Throttler(eventType));
|
2020-12-10 12:33:48 +00:00
|
|
|
}
|
2023-12-07 10:45:55 +00:00
|
|
|
if (eventType.hasLevel()) {
|
|
|
|
addControl(Level.NAME, defineLevel(eventType));
|
|
|
|
}
|
2025-05-29 08:31:17 +00:00
|
|
|
if (eventType.getModification() != Modification.NONE) {
|
|
|
|
addControl("filter", defineMethodFilter(eventType, eventType.getModification()));
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:33:48 +00:00
|
|
|
addControl(Enabled.NAME, defineEnabled(eventType));
|
2018-05-15 20:24:34 +02:00
|
|
|
|
2023-11-22 20:48:42 +00:00
|
|
|
addStackFilters(eventType);
|
2021-03-24 09:54:29 +00:00
|
|
|
List<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
|
2018-05-15 20:24:34 +02:00
|
|
|
remove(eventType, aes, Threshold.class);
|
|
|
|
remove(eventType, aes, Period.class);
|
|
|
|
remove(eventType, aes, Enabled.class);
|
|
|
|
remove(eventType, aes, StackTrace.class);
|
|
|
|
remove(eventType, aes, Cutoff.class);
|
2020-12-10 12:33:48 +00:00
|
|
|
remove(eventType, aes, Throttle.class);
|
2023-11-22 20:48:42 +00:00
|
|
|
remove(eventType, aes, StackFilter.class);
|
2018-05-15 20:24:34 +02:00
|
|
|
eventType.setAnnotations(aes);
|
|
|
|
this.type = eventType;
|
|
|
|
this.idName = String.valueOf(eventType.getId());
|
|
|
|
}
|
|
|
|
|
2023-11-22 20:48:42 +00:00
|
|
|
private void addStackFilters(PlatformEventType eventType) {
|
|
|
|
String[] filter = getStackFilter(eventType);
|
|
|
|
if (filter != null) {
|
|
|
|
int size = filter.length;
|
|
|
|
List<String> types = new ArrayList<>(size);
|
|
|
|
List<String> methods = new ArrayList<>(size);
|
|
|
|
for (String frame : filter) {
|
|
|
|
int index = frame.indexOf("::");
|
|
|
|
String clazz = null;
|
|
|
|
String method = null;
|
|
|
|
boolean valid = false;
|
|
|
|
if (index != -1) {
|
|
|
|
clazz = frame.substring(0, index);
|
|
|
|
method = frame.substring(index + 2);
|
|
|
|
if (clazz.isEmpty()) {
|
|
|
|
clazz = null;
|
|
|
|
valid = isValidMethod(method);
|
|
|
|
} else {
|
|
|
|
valid = isValidType(clazz) && isValidMethod(method);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clazz = frame;
|
|
|
|
valid = isValidType(frame);
|
|
|
|
}
|
|
|
|
if (valid) {
|
|
|
|
if (clazz == null) {
|
|
|
|
types.add(null);
|
|
|
|
} else {
|
|
|
|
types.add(clazz.replace(".", "/"));
|
|
|
|
}
|
|
|
|
// If unqualified class name equals method name, it's a constructor
|
|
|
|
String className = clazz.substring(clazz.lastIndexOf(".") + 1);
|
|
|
|
if (className.equals(method)) {
|
|
|
|
method = "<init>";
|
|
|
|
}
|
|
|
|
methods.add(method);
|
|
|
|
} else {
|
|
|
|
Logger.log(LogTag.JFR, LogLevel.WARN, "@StackFrameFilter element ignored, not a valid Java identifier.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!types.isEmpty()) {
|
|
|
|
String[] typeArray = types.toArray(new String[0]);
|
|
|
|
String[] methodArray = methods.toArray(new String[0]);
|
|
|
|
long id = MetadataRepository.getInstance().registerStackFilter(typeArray, methodArray);
|
|
|
|
eventType.setStackFilterId(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String[] getStackFilter(PlatformEventType eventType) {
|
|
|
|
for (var a : eventType.getAnnotationElements()) {
|
|
|
|
if (a.getTypeId() == STACK_FILTER_ID) {
|
|
|
|
return (String[])a.getValue("value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isValidType(String className) {
|
|
|
|
if (className.length() < 1 || className.length() > 65535) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Checks.isClassName(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isValidMethod(String method) {
|
|
|
|
if (method.length() < 1 || method.length() > 65535) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Checks.isJavaIdentifier(method);
|
|
|
|
}
|
|
|
|
|
2019-10-30 19:43:52 +01:00
|
|
|
private boolean hasControl(String name) {
|
|
|
|
for (NamedControl nc : namedControls) {
|
|
|
|
if (name.equals(nc.name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addControl(String name, Control control) {
|
|
|
|
namedControls.add(new NamedControl(name, control));
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:24:34 +02:00
|
|
|
static void remove(PlatformEventType type, List<AnnotationElement> aes, Class<? extends java.lang.annotation.Annotation> clazz) {
|
|
|
|
long id = Type.getTypeId(clazz);
|
|
|
|
for (AnnotationElement a : type.getAnnotationElements()) {
|
|
|
|
if (a.getTypeId() == id && a.getTypeName().equals(clazz.getName())) {
|
|
|
|
aes.remove(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 02:10:21 +01:00
|
|
|
EventControl(PlatformEventType es, Class<? extends jdk.internal.event.Event> eventClass) {
|
2018-05-15 20:24:34 +02:00
|
|
|
this(es);
|
|
|
|
defineSettings(eventClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void defineSettings(Class<?> eventClass) {
|
|
|
|
// Iterate up the class hierarchy and let
|
|
|
|
// subclasses shadow base classes.
|
|
|
|
boolean allowPrivateMethod = true;
|
|
|
|
while (eventClass != null) {
|
|
|
|
for (Method m : eventClass.getDeclaredMethods()) {
|
|
|
|
boolean isPrivate = Modifier.isPrivate(m.getModifiers());
|
|
|
|
if (m.getReturnType() == Boolean.TYPE && m.getParameterCount() == 1 && (!isPrivate || allowPrivateMethod)) {
|
|
|
|
SettingDefinition se = m.getDeclaredAnnotation(SettingDefinition.class);
|
|
|
|
if (se != null) {
|
|
|
|
Class<?> settingClass = m.getParameters()[0].getType();
|
|
|
|
if (!Modifier.isAbstract(settingClass.getModifiers()) && SettingControl.class.isAssignableFrom(settingClass)) {
|
|
|
|
String name = m.getName();
|
|
|
|
Name n = m.getAnnotation(Name.class);
|
|
|
|
if (n != null) {
|
2021-09-20 15:44:46 +00:00
|
|
|
name = Utils.validJavaIdentifier(n.value(), name);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
2019-10-30 19:43:52 +01:00
|
|
|
|
|
|
|
if (!hasControl(name)) {
|
2018-05-15 20:24:34 +02:00
|
|
|
defineSetting((Class<? extends SettingControl>) settingClass, m, type, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eventClass = eventClass.getSuperclass();
|
|
|
|
allowPrivateMethod = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void defineSetting(Class<? extends SettingControl> settingsClass, Method method, PlatformEventType eventType, String settingName) {
|
|
|
|
try {
|
|
|
|
Module settingModule = settingsClass.getModule();
|
|
|
|
Modules.addReads(settingModule, EventControl.class.getModule());
|
2022-05-10 16:14:07 +00:00
|
|
|
SettingControl settingControl = instantiateSettingControl(settingsClass);
|
|
|
|
Control c = new Control(settingControl, null);
|
2018-05-15 20:24:34 +02:00
|
|
|
c.setDefault();
|
2020-07-08 17:37:27 +02:00
|
|
|
String defaultValue = c.getValue();
|
2018-05-15 20:24:34 +02:00
|
|
|
if (defaultValue != null) {
|
|
|
|
Type settingType = TypeLibrary.createType(settingsClass);
|
|
|
|
ArrayList<AnnotationElement> aes = new ArrayList<>();
|
|
|
|
for (Annotation a : method.getDeclaredAnnotations()) {
|
|
|
|
AnnotationElement ae = TypeLibrary.createAnnotation(a);
|
|
|
|
if (ae != null) {
|
|
|
|
aes.add(ae);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aes.trimToSize();
|
2020-07-08 17:37:27 +02:00
|
|
|
addControl(settingName, c);
|
2018-05-15 20:24:34 +02:00
|
|
|
eventType.add(PrivateAccess.getInstance().newSettingDescriptor(settingType, settingName, defaultValue, aes));
|
2022-10-10 17:56:34 +00:00
|
|
|
settingControls.add(settingControl);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
} catch (InstantiationException e) {
|
|
|
|
// Programming error by user, fail fast
|
|
|
|
throw new InstantiationError("Could not instantiate setting " + settingsClass.getName() + " for event " + eventType.getLogName() + ". " + e.getMessage());
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
// Programming error by user, fail fast
|
|
|
|
throw new IllegalAccessError("Could not access setting " + settingsClass.getName() + " for event " + eventType.getLogName() + ". " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private SettingControl instantiateSettingControl(Class<? extends SettingControl> settingControlClass) throws IllegalAccessException, InstantiationException {
|
|
|
|
SecuritySupport.makeVisibleToJFR(settingControlClass);
|
|
|
|
final Constructor<?> cc;
|
|
|
|
try {
|
|
|
|
cc = settingControlClass.getDeclaredConstructors()[0];
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw (Error) new InternalError("Could not get constructor for " + settingControlClass.getName()).initCause(e);
|
|
|
|
}
|
2025-01-10 13:46:57 +00:00
|
|
|
cc.setAccessible(true);
|
2018-05-15 20:24:34 +02:00
|
|
|
try {
|
|
|
|
return (SettingControl) cc.newInstance();
|
|
|
|
} catch (IllegalArgumentException | InvocationTargetException e) {
|
2020-07-08 17:37:27 +02:00
|
|
|
throw new InternalError("Could not instantiate setting for class " + settingControlClass.getName());
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Control defineEnabled(PlatformEventType type) {
|
|
|
|
// Java events are enabled by default,
|
|
|
|
// JVM events are not, maybe they should be? Would lower learning curve
|
|
|
|
// there too.
|
2024-05-07 18:59:41 +00:00
|
|
|
Boolean defaultValue = Boolean.valueOf(!type.isJVM());
|
|
|
|
String def = type.getAnnotationValue(Enabled.class, defaultValue).toString();
|
2018-05-15 20:24:34 +02:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_ENABLED, Enabled.NAME, def, Collections.emptyList()));
|
2020-07-08 17:37:27 +02:00
|
|
|
return new Control(new EnabledSetting(type, def), def);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Control defineThreshold(PlatformEventType type) {
|
2024-07-30 13:47:58 +00:00
|
|
|
String def = type.getAnnotationValue(Threshold.class, ThresholdSetting.DEFAULT_VALUE);
|
2018-05-15 20:24:34 +02:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_THRESHOLD, Threshold.NAME, def, Collections.emptyList()));
|
2025-05-19 13:38:38 +00:00
|
|
|
return new Control(new ThresholdSetting(type, def), def);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Control defineStackTrace(PlatformEventType type) {
|
2024-05-07 18:59:41 +00:00
|
|
|
String def = type.getAnnotationValue(StackTrace.class, Boolean.TRUE).toString();
|
2018-05-15 20:24:34 +02:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_STACK_TRACE, StackTrace.NAME, def, Collections.emptyList()));
|
2020-07-08 17:37:27 +02:00
|
|
|
return new Control(new StackTraceSetting(type, def), def);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Control defineCutoff(PlatformEventType type) {
|
2024-07-30 13:47:58 +00:00
|
|
|
String def = type.getAnnotationValue(Cutoff.class, CutoffSetting.DEFAULT_VALUE);
|
2018-05-15 20:24:34 +02:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_CUTOFF, Cutoff.NAME, def, Collections.emptyList()));
|
2025-05-19 13:38:38 +00:00
|
|
|
return new Control(new CutoffSetting(type, def), def);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:33:48 +00:00
|
|
|
private static Control defineThrottle(PlatformEventType type) {
|
2024-07-30 13:47:58 +00:00
|
|
|
String def = type.getAnnotationValue(Throttle.class, ThrottleSetting.DEFAULT_VALUE);
|
2020-12-10 12:33:48 +00:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_THROTTLE, Throttle.NAME, def, Collections.emptyList()));
|
2025-06-05 08:18:18 +00:00
|
|
|
if (type.getName().equals("jdk.CPUTimeSample")) {
|
|
|
|
return new Control(new CPUThrottleSetting(type), def);
|
|
|
|
}
|
2025-05-19 13:38:38 +00:00
|
|
|
return new Control(new ThrottleSetting(type, def), def);
|
2020-12-10 12:33:48 +00:00
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
|
2023-12-07 10:45:55 +00:00
|
|
|
private static Control defineLevel(PlatformEventType type) {
|
2024-05-07 18:59:41 +00:00
|
|
|
String[] levels = type.getAnnotationValue(Level.class, new String[0]);
|
|
|
|
String def = levels[0]; // Level value always exists
|
2023-12-07 10:45:55 +00:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_LEVEL, Level.NAME, def, Collections.emptyList()));
|
2024-05-07 18:59:41 +00:00
|
|
|
return new Control(new LevelSetting(type, levels), def);
|
2023-12-07 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:24:34 +02:00
|
|
|
private static Control definePeriod(PlatformEventType type) {
|
2024-07-30 13:47:58 +00:00
|
|
|
String def = type.getAnnotationValue(Period.class, PeriodSetting.DEFAULT_VALUE);
|
2018-05-15 20:24:34 +02:00
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_PERIOD, PeriodSetting.NAME, def, Collections.emptyList()));
|
2025-05-19 13:38:38 +00:00
|
|
|
return new Control(new PeriodSetting(type, def), def);
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
2025-05-29 08:31:17 +00:00
|
|
|
private Control defineMethodFilter(PlatformEventType type, Modification modification) {
|
|
|
|
String def = "";
|
|
|
|
type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_METHOD_FILTER, "filter", def, Collections.emptyList()));
|
|
|
|
return new Control(new MethodSetting(type, modification, def), def);
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:24:34 +02:00
|
|
|
void disable() {
|
2019-10-30 19:43:52 +01:00
|
|
|
for (NamedControl nc : namedControls) {
|
2020-07-08 17:37:27 +02:00
|
|
|
if (nc.control.isType(EnabledSetting.class)) {
|
|
|
|
nc.control.setValue("false");
|
2018-05-15 20:24:34 +02:00
|
|
|
return;
|
2025-05-29 08:31:17 +00:00
|
|
|
} else {
|
|
|
|
String v = nc.control.getDefaultValue();
|
|
|
|
// Avoids slow retransformation during shutdown
|
|
|
|
if (v != null && !PlatformRecorder.isInShutDown()) {
|
|
|
|
nc.control.setValue(v);
|
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 20:23:53 +00:00
|
|
|
void writeActiveSettingEvent(long timestamp) {
|
2018-05-15 20:24:34 +02:00
|
|
|
if (!type.isRegistered()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-30 19:43:52 +01:00
|
|
|
for (NamedControl nc : namedControls) {
|
2023-06-19 17:46:23 +00:00
|
|
|
if (nc.control.isVisible(type.hasEventHook()) && type.isVisible()) {
|
2019-10-30 19:43:52 +01:00
|
|
|
String value = nc.control.getLastValue();
|
2018-05-15 20:24:34 +02:00
|
|
|
if (value == null) {
|
2019-10-30 19:43:52 +01:00
|
|
|
value = nc.control.getDefaultValue();
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
2022-06-20 11:48:27 +00:00
|
|
|
if (ActiveSettingEvent.enabled()) {
|
2023-10-31 15:36:12 +00:00
|
|
|
ActiveSettingEvent.commit(timestamp, type.getId(), nc.name(), value);
|
2022-05-17 20:23:53 +00:00
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-30 19:43:52 +01:00
|
|
|
public ArrayList<NamedControl> getNamedControls() {
|
|
|
|
return namedControls;
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public PlatformEventType getEventType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSettingsId() {
|
|
|
|
return idName;
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:56:34 +00:00
|
|
|
public List<SettingControl> getSettingControls() {
|
|
|
|
return settingControls;
|
2018-05-15 20:24:34 +02:00
|
|
|
}
|
|
|
|
}
|