From ddb1bd8badd0b3f7c76f969d2c6a6d0064216939 Mon Sep 17 00:00:00 2001 From: "tadei.bilan" Date: Thu, 13 Aug 2020 10:58:27 +0300 Subject: [PATCH] Remove java.desktop dependency Remove java.beans dependency to be able to run without java.desktop module JIRA: CONTROLLER-1910 Change-Id: Ib7cfba1e0ec4694e0f63586837486a00e9863ea3 Signed-off-by: tadei.bilan --- .../raft/client/messages/FollowerInfo.java | 4 +- .../common/util/jmx/ThreadExecutorStats.java | 4 +- .../DatastoreContextIntrospector.java | 65 ++++++++++--------- .../messages/DataTreeListenerInfo.java | 4 +- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java index 067a7d1c02..a2677de18b 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.raft.client.messages; -import java.beans.ConstructorProperties; +import javax.management.ConstructorParameters; /** * A bean class containing a snapshot of information for a follower returned from GetOnDemandRaftStats. @@ -22,7 +22,7 @@ public class FollowerInfo { private final String timeSinceLastActivity; private final boolean isVoting; - @ConstructorProperties({"id","nextIndex", "matchIndex", "active", "timeSinceLastActivity", "voting"}) + @ConstructorParameters({"id","nextIndex", "matchIndex", "active", "timeSinceLastActivity", "voting"}) public FollowerInfo(String id, long nextIndex, long matchIndex, boolean active, String timeSinceLastActivity, boolean voting) { this.id = id; diff --git a/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStats.java b/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStats.java index 0a766c013d..2e8b8376d6 100644 --- a/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStats.java +++ b/opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/md/sal/common/util/jmx/ThreadExecutorStats.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.md.sal.common.util.jmx; -import java.beans.ConstructorProperties; +import javax.management.ConstructorParameters; /** * A bean class that holds various thread executor statistic metrics. This class is suitable for @@ -33,7 +33,7 @@ public class ThreadExecutorStats { private final Long largestQueueSize; private final Long rejectedTaskCount; - @ConstructorProperties({"activeThreadCount","currentThreadPoolSize","largestThreadPoolSize", + @ConstructorParameters({"activeThreadCount","currentThreadPoolSize","largestThreadPoolSize", "maxThreadPoolSize","currentQueueSize","largestQueueSize","maxQueueSize", "completedTaskCount","totalTaskCount","rejectedTaskCount"}) public ThreadExecutorStats(long activeThreadCount, long currentThreadPoolSize, diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java index a6f5f01930..c94f86989f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java @@ -12,12 +12,6 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Primitives; -import java.beans.BeanInfo; -import java.beans.ConstructorProperties; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.MethodDescriptor; -import java.beans.PropertyDescriptor; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -30,6 +24,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.Function; +import javax.management.ConstructorParameters; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.WordUtils; import org.checkerframework.checker.lock.qual.GuardedBy; @@ -72,7 +67,7 @@ public class DatastoreContextIntrospector { introspectDatastoreContextBuilder(); introspectDataStoreProperties(); introspectPrimitiveTypes(); - } catch (final IntrospectionException e) { + } catch (final IllegalArgumentException e) { LOG.error("Error initializing DatastoreContextIntrospector", e); } } @@ -92,7 +87,7 @@ public class DatastoreContextIntrospector { processPropertyType(primitive); } catch (final NoSuchMethodException e) { // Ignore primitives that can't be constructed from a String, eg Character and Void. - } catch (SecurityException | IntrospectionException e) { + } catch (SecurityException | IllegalArgumentException e) { LOG.error("Error introspect primitive type {}", primitive, e); } } @@ -117,24 +112,26 @@ public class DatastoreContextIntrospector { * yang grouping. We use the bean Introspector to find the types of all the properties defined * in the interface (this is the type returned from the getter method). For each type, we find * the appropriate constructor that we will use. + * + * @throws IllegalArgumentException if failed to process yang-defined property */ - private static void introspectDataStoreProperties() throws IntrospectionException { - final BeanInfo beanInfo = Introspector.getBeanInfo(DataStoreProperties.class); - for (final PropertyDescriptor desc: beanInfo.getPropertyDescriptors()) { - processDataStoreProperty(desc.getName(), desc.getPropertyType(), desc.getReadMethod()); + private static void introspectDataStoreProperties() { + for (final Method method : DataStoreProperties.class.getDeclaredMethods()) { + final String propertyName = getPropertyName(method); + if (propertyName != null) { + processDataStoreProperty(propertyName, method.getReturnType(), method); + } } + } - // Getter methods that return Boolean and start with "is" instead of "get" aren't recognized as - // properties and thus aren't returned from getPropertyDescriptors. A getter starting with - // "is" is only supported if it returns primitive boolean. So we'll check for these via - // getMethodDescriptors. - for (final MethodDescriptor desc: beanInfo.getMethodDescriptors()) { - final String methodName = desc.getName(); - if (Boolean.class.equals(desc.getMethod().getReturnType()) && methodName.startsWith("is")) { - final String propertyName = WordUtils.uncapitalize(methodName.substring(2)); - processDataStoreProperty(propertyName, Boolean.class, desc.getMethod()); - } + private static String getPropertyName(final Method method) { + final String methodName = method.getName(); + if (Boolean.class.equals(method.getReturnType()) && methodName.startsWith("is")) { + return WordUtils.uncapitalize(methodName.substring(2)); + } else if (methodName.startsWith("get")) { + return WordUtils.uncapitalize(methodName.substring(3)); } + return null; } /** @@ -157,9 +154,11 @@ public class DatastoreContextIntrospector { /** * Finds the appropriate constructor for the specified type that we will use to construct * instances. + * + * @throws IllegalArgumentException if yang-defined type has no property, annotated by ConstructorParameters */ private static void processPropertyType(final Class propertyType) - throws NoSuchMethodException, SecurityException, IntrospectionException { + throws NoSuchMethodException, SecurityException { final Class wrappedType = Primitives.wrap(propertyType); if (CONSTRUCTORS.containsKey(wrappedType)) { return; @@ -176,9 +175,9 @@ public class DatastoreContextIntrospector { // validation (eg range checking). The yang-generated types have a couple single-argument // constructors but the one we want has the bean ConstructorProperties annotation. for (final Constructor ctor: propertyType.getConstructors()) { - final ConstructorProperties ctorPropsAnnotation = ctor.getAnnotation(ConstructorProperties.class); - if (ctor.getParameterCount() == 1 && ctorPropsAnnotation != null) { - findYangTypeGetter(propertyType, ctorPropsAnnotation.value()[0]); + final ConstructorParameters ctorParAnnotation = ctor.getAnnotation(ConstructorParameters.class); + if (ctor.getParameterCount() == 1 && ctorParAnnotation != null) { + findYangTypeGetter(propertyType, ctorParAnnotation.value()[0]); CONSTRUCTORS.put(propertyType, ctor); break; } @@ -188,17 +187,19 @@ public class DatastoreContextIntrospector { /** * Finds the getter method on a yang-generated type for the specified property name. + * + * @throws IllegalArgumentException if passed type has no passed property */ - private static void findYangTypeGetter(final Class type, final String propertyName) - throws IntrospectionException { - for (final PropertyDescriptor desc: Introspector.getBeanInfo(type).getPropertyDescriptors()) { - if (desc.getName().equals(propertyName)) { - YANG_TYPE_GETTERS.put(type, desc.getReadMethod()); + private static void findYangTypeGetter(final Class type, final String propertyName) { + for (Method method : type.getDeclaredMethods()) { + final String property = getPropertyName(method); + if (property != null && property.equals(propertyName)) { + YANG_TYPE_GETTERS.put(type, method); return; } } - throw new IntrospectionException(String.format( + throw new IllegalArgumentException(String.format( "Getter method for constructor property %s not found for YANG type %s", propertyName, type)); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataTreeListenerInfo.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataTreeListenerInfo.java index 62505d9224..5137b7c9a3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataTreeListenerInfo.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataTreeListenerInfo.java @@ -9,7 +9,7 @@ package org.opendaylight.controller.cluster.datastore.messages; import static java.util.Objects.requireNonNull; -import java.beans.ConstructorProperties; +import javax.management.ConstructorParameters; /** * Response to a {@link GetInfo} query from a data tree listener actor. @@ -22,7 +22,7 @@ public class DataTreeListenerInfo { private final boolean isEnabled; private final long notificationCount; - @ConstructorProperties({"listener","registeredPath", "isEnabled", "notificationCount"}) + @ConstructorParameters({"listener","registeredPath", "isEnabled", "notificationCount"}) public DataTreeListenerInfo(final String listener, final String registeredPath, final boolean isEnabled, final long notificationCount) { this.listener = requireNonNull(listener); -- 2.36.6