From d23d81727967cea6d72ca47815d753c9c139ac2c Mon Sep 17 00:00:00 2001 From: Alex Macdonald Date: Tue, 30 Apr 2024 13:42:37 -0400 Subject: [PATCH] chore(jmc-core): update to JMC version 9.0.0 --- pom.xml | 31 +- scripts/jmc-diff.sh | 90 --- scripts/jmc-embed.sh | 74 -- .../io/cryostat/core/EventOptionsBuilder.java | 8 +- .../cryostat/core/EventOptionsCustomizer.java | 2 +- .../cryostat/core/agent/AgentJMXHelper.java | 2 +- .../core/jmc/CopyRecordingDescriptor.java | 2 +- .../io/cryostat/core/jmc/SecurityManager.java | 8 +- .../net/CryostatFlightRecorderService.java | 14 +- .../io/cryostat/core/net/JFRConnection.java | 6 +- .../core/net/JFRConnectionToolkit.java | 6 +- .../cryostat/core/net/JFRJMXConnection.java | 62 +- .../core/net/JmxFlightRecorderService.java | 14 +- .../SerializableEventTypeInfo.java | 2 +- .../SerializableRecordingDescriptor.java | 4 +- .../templates/AbstractTemplateService.java | 4 +- .../LocalStorageTemplateService.java | 12 +- .../core/templates/RemoteTemplateService.java | 12 +- .../configuration/ConfigurationToolkit.java | 116 --- .../IRecorderConfigurationService.java | 61 -- .../configuration/OptionInfo.java | 79 --- .../configuration/events/EventOptionID.java | 74 -- .../events/IEventConfiguration.java | 233 ------ .../configuration/events/IEventTypeID.java | 82 --- .../configuration/events/SchemaVersion.java | 84 --- .../internal/CommonConstraints.java | 361 ---------- .../internal/DefaultValueMap.java | 157 ---- .../internal/EventOptionDescriptorMapper.java | 66 -- .../configuration/internal/EventTypeIDV1.java | 120 ---- .../configuration/internal/EventTypeIDV2.java | 94 --- .../internal/FixedDescriptorMap.java | 106 --- .../configuration/internal/IMapper.java | 60 -- .../internal/KeyTranslatingMap.java | 141 ---- .../internal/KnownEventOptions.java | 104 --- .../internal/KnownRecordingOptions.java | 131 ---- .../internal/ValidationException.java | 49 -- .../internal/ValidationToolkit.java | 84 --- .../recording/RecordingOptionsBuilder.java | 150 ---- .../spi/IConfigurationStorageDelegate.java | 109 --- .../controlpanel/ui/ControlPanel.java | 49 -- .../model/xml/IXMLValidator.java | 67 -- .../configuration/model/xml/JFCGrammar.java | 180 ----- .../model/xml/JFCXMLValidator.java | 265 ------- .../model/xml/PrettyPrinter.java | 119 ---- .../configuration/model/xml/XMLAttribute.java | 140 ---- .../model/xml/XMLAttributeInstance.java | 108 --- .../ui/configuration/model/xml/XMLModel.java | 369 ---------- .../ui/configuration/model/xml/XMLNode.java | 51 -- .../configuration/model/xml/XMLNodeType.java | 44 -- .../ui/configuration/model/xml/XMLTag.java | 94 --- .../model/xml/XMLTagInstance.java | 238 ------- .../model/xml/XMLValidationResult.java | 59 -- .../ui/model/EventConfiguration.java | 671 ------------------ .../ui/model/VolatileStorageDelegate.java | 111 --- .../jmc/rjmx/ConnectionDescriptorBuilder.java | 174 ----- .../openjdk/jmc/rjmx/ConnectionException.java | 55 -- .../openjdk/jmc/rjmx/ConnectionToolkit.java | 449 ------------ .../jmc/rjmx/IConnectionDescriptor.java | 73 -- .../openjdk/jmc/rjmx/IConnectionHandle.java | 131 ---- .../openjdk/jmc/rjmx/IConnectionListener.java | 46 -- .../jmc/rjmx/IPropertySyntheticAttribute.java | 50 -- .../openjdk/jmc/rjmx/IServerDescriptor.java | 72 -- .../org/openjdk/jmc/rjmx/IServerHandle.java | 114 --- .../openjdk/jmc/rjmx/ISyntheticAttribute.java | 97 --- .../jmc/rjmx/ISyntheticNotification.java | 105 --- .../openjdk/jmc/rjmx/JVMSupportToolkit.java | 228 ------ .../java/org/openjdk/jmc/rjmx/RJMXPlugin.java | 105 --- .../rjmx/ServiceNotAvailableException.java | 52 -- .../IActionProviderFactory.java | 52 -- .../internal/ActionProvider.java | 68 -- .../internal/ActionProviderGrammar.java | 50 -- .../internal/ActionProviderRepository.java | 45 -- .../IDescriptorListener.java | 58 -- .../IDescriptorProvider.java | 58 -- .../internal/DefaultConnectionHandle.java | 231 ------ .../jmc/rjmx/internal/IDisposableService.java | 44 -- .../internal/JMXConnectionDescriptor.java | 122 ---- .../JMXRMISystemPropertiesProvider.java | 92 --- .../rjmx/internal/MBeanOperationWrapper.java | 209 ------ .../internal/MCMBeanServerConnection.java | 589 --------------- .../jmc/rjmx/internal/RJMXConnection.java | 595 ---------------- .../jmc/rjmx/internal/RJMXSingleton.java | 109 --- .../jmc/rjmx/internal/ServerDescriptor.java | 79 --- .../jmc/rjmx/internal/ServerHandle.java | 189 ----- .../jmc/rjmx/internal/ServerToolkit.java | 112 --- .../internal/SyntheticAttributeEntry.java | 135 ---- .../SyntheticAttributeMBeanEntry.java | 156 ---- .../SyntheticAttributeRepository.java | 279 -------- .../internal/SyntheticNotificationEntry.java | 113 --- .../internal/SyntheticNotificationMBean.java | 88 --- .../SyntheticNotificationRepository.java | 218 ------ .../internal/WrappedConnectionException.java | 112 --- .../rjmx/preferences/JMXRMIPreferences.java | 95 --- .../jmc/rjmx/preferences/PreferencesKeys.java | 71 -- .../jmc/rjmx/servermodel/IDiscoveryInfo.java | 45 -- .../openjdk/jmc/rjmx/servermodel/IServer.java | 69 -- .../jmc/rjmx/servermodel/IServerModel.java | 42 -- .../servermodel/internal/DiscoveryInfo.java | 57 -- .../internal/ModelPersistence.java | 151 ---- .../jmc/rjmx/servermodel/internal/Server.java | 167 ----- .../servermodel/internal/ServerModel.java | 150 ---- .../jmc/rjmx/services/IAttributeInfo.java | 47 -- .../jmc/rjmx/services/IAttributeStorage.java | 47 -- .../services/IAttributeStorageService.java | 43 -- .../services/ICommercialFeaturesService.java | 60 -- .../services/IDiagnosticCommandService.java | 59 -- .../jmc/rjmx/services/IDummyService.java | 44 -- .../openjdk/jmc/rjmx/services/IOperation.java | 54 -- .../jmc/rjmx/services/IServiceFactory.java | 56 -- .../services/IllegalOperandException.java | 71 -- .../jmc/rjmx/services/MRIDataSeries.java | 42 -- .../services/internal/AbstractOperation.java | 81 --- .../AttributeStorageServiceFactory.java | 55 -- .../CommercialFeaturesServiceFactory.java | 65 -- .../DiagnosticCommandServiceFactory.java | 55 -- .../HotSpot23CommercialFeaturesService.java | 105 --- .../HotSpot24DiagnosticCommandService.java | 354 --------- .../internal/HotspotManagementToolkit.java | 91 --- .../internal/MRIMetadataServiceFactory.java | 54 -- .../internal/NoCommercialFeaturesService.java | 56 -- .../rjmx/services/internal/ServiceEntry.java | 88 --- .../internal/ServiceFactoryManager.java | 204 ------ .../internal/SubscriptionServiceFactory.java | 54 -- .../services/jfr/FlightRecorderException.java | 48 -- .../services/jfr/FlightRecorderToolkit.java | 156 ---- .../jmc/rjmx/services/jfr/IEventTypeInfo.java | 83 --- .../services/jfr/IFlightRecorderService.java | 268 ------- .../services/jfr/IRecordingDescriptor.java | 161 ----- .../jfr/internal/EventOptionsToolkitV1.java | 210 ------ .../jfr/internal/EventTypeMetadataV1.java | 115 --- .../jfr/internal/EventTypeMetadataV2.java | 192 ----- .../internal/ExcludingEventOptionMapper.java | 57 -- .../FlightRecorderCommunicationHelperV1.java | 108 --- .../FlightRecorderCommunicationHelperV2.java | 134 ---- .../FlightRecorderServiceFactory.java | 56 -- .../jfr/internal/FlightRecorderServiceV1.java | 504 ------------- .../jfr/internal/FlightRecorderServiceV2.java | 508 ------------- .../IFlightRecorderCommunicationHelper.java | 48 -- .../internal/JfrRecordingInputStreamV1.java | 196 ----- .../internal/JfrRecordingInputStreamV2.java | 211 ------ .../jfr/internal/OpenTypeConverter.java | 188 ----- .../RecordingDescriptorToolkitV1.java | 129 ---- .../jfr/internal/RecordingDescriptorV1.java | 214 ------ .../jfr/internal/RecordingDescriptorV2.java | 194 ----- .../internal/RecordingOptionsToolkitV1.java | 203 ------ .../internal/RecordingOptionsToolkitV2.java | 129 ---- .../internal/RecordingTemplateToolkit.java | 62 -- .../subscription/IMBeanHelperService.java | 146 ---- .../IMBeanServerChangeListener.java | 56 -- .../jmc/rjmx/subscription/IMRIMetadata.java | 69 -- .../subscription/IMRIMetadataProvider.java | 68 -- .../IMRIMetadataProviderService.java | 52 -- .../subscription/IMRIMetadataService.java | 75 -- .../jmc/rjmx/subscription/IMRIService.java | 57 -- .../rjmx/subscription/IMRISubscription.java | 80 --- .../rjmx/subscription/IMRITransformation.java | 82 --- .../IMRITransformationFactory.java | 78 -- .../rjmx/subscription/IMRIValueListener.java | 48 -- .../subscription/ISubscriptionService.java | 148 ---- .../jmc/rjmx/subscription/IUpdatePolicy.java | 49 -- .../openjdk/jmc/rjmx/subscription/MRI.java | 311 -------- .../rjmx/subscription/MRIMetadataToolkit.java | 302 -------- .../jmc/rjmx/subscription/MRIValueEvent.java | 125 ---- .../AbstractAttributeSubscription.java | 254 ------- .../AbstractPropertySyntheticAttribute.java | 157 ---- .../AbstractSingleMRITransformation.java | 112 --- .../internal/AbstractSyntheticAttribute.java | 54 -- .../AbstractSyntheticNotification.java | 101 --- .../internal/AbstractUpdatePolicy.java | 60 -- .../internal/AttributeExceptionEvent.java | 66 -- .../internal/AttributeReregisteredEvent.java | 53 -- .../internal/AttributeValueToolkit.java | 197 ----- .../internal/AverageTransformation.java | 77 -- .../internal/ConnectionLostEvent.java | 55 -- .../DeadlockedThreadCountAttribute.java | 105 --- .../DefaultAttributeSubscription.java | 45 -- .../DefaultAttributeSubscriptionService.java | 411 ----------- .../DefaultAttributeSubscriptionThread.java | 551 -------------- .../internal/DefaultMRIMetadataService.java | 124 ---- ...efaultNotificationSubscriptionManager.java | 263 ------- .../DefaultSubscriptionDebugInformation.java | 105 --- .../internal/DefaultUpdatePolicy.java | 67 -- .../internal/DeltaTransformation.java | 56 -- .../internal/DifferenceAttribute.java | 79 --- .../internal/DifferenceTransformation.java | 72 -- .../internal/DivisionAttribute.java | 92 --- .../internal/ExtendedMRIMetadataToolkit.java | 64 -- .../ExtensionMetadataProviderService.java | 73 -- .../internal/FileMRIMetadata.java | 160 ----- .../internal/FileMRIMetadataDB.java | 158 ----- .../internal/HotSpotGcNotification.java | 145 ---- .../internal/HotSpotLastGcAttribute.java | 127 ---- .../internal/HotSpotLiveSetAttribute.java | 201 ------ .../internal/IIntervalUpdatePolicy.java | 48 -- .../IMRISubscriptionDebugInformation.java | 62 -- .../internal/ISubscriptionDebugService.java | 47 -- .../InvoluntaryDisconnectException.java | 43 -- .../internal/LongDifferenceAttribute.java | 79 --- .../internal/MBeanMRIMetadataDB.java | 308 -------- .../internal/MRIMetadataWrapper.java | 97 --- .../internal/MRITransformationToolkit.java | 183 ----- ...nitoredDeadlockedThreadCountAttribute.java | 88 --- .../internal/OneShotUpdatePolicy.java | 59 -- .../internal/SimpleUpdatePolicy.java | 89 --- .../SingleMRITransformationFactory.java | 97 --- .../internal/SyntheticAttributeToolkit.java | 121 ---- .../internal/TransformationSubscription.java | 87 --- .../UnavailableChildSubscriptions.java | 130 ---- .../UnavailableSubscriptionsRepository.java | 270 ------- .../internal/UpdatePolicyToolkit.java | 141 ---- .../internal/BufferingAttributeStorage.java | 149 ---- .../DefaultAttributeStorageService.java | 94 --- .../util/internal/SimpleAttributeInfo.java | 100 --- .../org/openjdk/jmc/ui/common/CorePlugin.java | 58 -- .../jmc/ui/common/action/Executable.java | 45 -- .../jmc/ui/common/action/IActionProvider.java | 54 -- .../jmc/ui/common/action/IUserAction.java | 42 -- .../jmc/ui/common/jvm/Connectable.java | 60 -- .../openjdk/jmc/ui/common/jvm/JVMArch.java | 57 -- .../ui/common/jvm/JVMCommandLineToolkit.java | 84 --- .../jmc/ui/common/jvm/JVMDescriptor.java | 113 --- .../openjdk/jmc/ui/common/jvm/JVMType.java | 74 -- .../ui/common/labelingrules/Constants.java | 87 --- .../ui/common/labelingrules/Formatter.java | 128 ---- .../labelingrules/IVariableEvaluator.java | 42 -- .../jmc/ui/common/labelingrules/Matcher.java | 75 -- .../common/labelingrules/NameConverter.java | 193 ----- .../ui/common/labelingrules/NamingRule.java | 141 ---- .../ui/common/labelingrules/Variables.java | 193 ----- .../ui/common/resource/IImageResource.java | 41 -- .../jmc/ui/common/resource/Resource.java | 61 -- .../security/ActionNotGrantedException.java | 42 -- .../CredentialsNotAvailableException.java | 42 -- .../security/FailedToSaveException.java | 41 -- .../jmc/ui/common/security/ICredentials.java | 55 -- .../ui/common/security/ISecurityManager.java | 214 ------ .../common/security/InMemoryCredentials.java | 61 -- .../security/PersistentCredentials.java | 92 --- .../security/SecurelyStoredByteArray.java | 58 -- .../ui/common/security/SecurityException.java | 57 -- .../security/SecurityManagerFactory.java | 77 -- .../openjdk/jmc/ui/common/tree/IArray.java | 52 -- .../openjdk/jmc/ui/common/tree/IParent.java | 53 -- .../jmc/ui/common/util/Environment.java | 147 ---- .../openjdk/jmc/ui/common/util/Filename.java | 79 --- .../openjdk/jmc/ui/common/util/ICopyable.java | 54 -- .../jmc/ui/common/util/IObservable.java | 61 -- .../jmc/ui/common/xydata/DataSeries.java | 57 -- .../common/xydata/DefaultTimestampedData.java | 79 --- .../jmc/ui/common/xydata/DefaultXYData.java | 56 -- .../ui/common/xydata/ITimestampedData.java | 41 -- .../openjdk/jmc/ui/common/xydata/IXYData.java | 49 -- .../core/EventOptionsCustomizerTest.java | 2 +- .../core/net/JFRConnectionToolkitTest.java | 2 +- 254 files changed, 123 insertions(+), 28757 deletions(-) delete mode 100755 scripts/jmc-diff.sh delete mode 100755 scripts/jmc-embed.sh delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/ConfigurationToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/IRecorderConfigurationService.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/OptionInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/EventOptionID.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventConfiguration.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventTypeID.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/SchemaVersion.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/CommonConstraints.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/DefaultValueMap.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventOptionDescriptorMapper.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV1.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV2.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/FixedDescriptorMap.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/IMapper.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KeyTranslatingMap.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownEventOptions.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownRecordingOptions.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationException.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/recording/RecordingOptionsBuilder.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/configuration/spi/IConfigurationStorageDelegate.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/ControlPanel.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/IXMLValidator.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCGrammar.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCXMLValidator.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/PrettyPrinter.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttributeInstance.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLModel.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNode.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNodeType.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTag.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTagInstance.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLValidationResult.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/EventConfiguration.java delete mode 100644 src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/VolatileStorageDelegate.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ConnectionDescriptorBuilder.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ConnectionException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IConnectionDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IConnectionHandle.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IConnectionListener.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IPropertySyntheticAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IServerDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/IServerHandle.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ISyntheticAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ISyntheticNotification.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/RJMXPlugin.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/ServiceNotAvailableException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/actionprovider/IActionProviderFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProvider.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderGrammar.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderRepository.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorListener.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorProvider.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/DefaultConnectionHandle.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/IDisposableService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/JMXConnectionDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/JMXRMISystemPropertiesProvider.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/MBeanOperationWrapper.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/MCMBeanServerConnection.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/RJMXConnection.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/RJMXSingleton.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/ServerDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/ServerHandle.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/ServerToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeEntry.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeMBeanEntry.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeRepository.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationEntry.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationMBean.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationRepository.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/internal/WrappedConnectionException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/preferences/JMXRMIPreferences.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/preferences/PreferencesKeys.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/IDiscoveryInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/IServer.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/IServerModel.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/DiscoveryInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ModelPersistence.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/Server.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ServerModel.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IAttributeInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorage.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorageService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/ICommercialFeaturesService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IDiagnosticCommandService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IDummyService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IOperation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/IllegalOperandException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/MRIDataSeries.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/AbstractOperation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/AttributeStorageServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/CommercialFeaturesServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/DiagnosticCommandServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot24DiagnosticCommandService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/HotspotManagementToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/MRIMetadataServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/NoCommercialFeaturesService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceEntry.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceFactoryManager.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/internal/SubscriptionServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/IEventTypeInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/IFlightRecorderService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/IRecordingDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventOptionsToolkitV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/ExcludingEventOptionMapper.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/IFlightRecorderCommunicationHelper.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/OpenTypeConverter.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorToolkitV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV1.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV2.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingTemplateToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanHelperService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanServerChangeListener.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadata.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProvider.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProviderService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRISubscription.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformationFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIValueListener.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/ISubscriptionService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/IUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/MRI.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/MRIMetadataToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/MRIValueEvent.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractAttributeSubscription.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractPropertySyntheticAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSingleMRITransformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticNotification.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeExceptionEvent.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeReregisteredEvent.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeValueToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AverageTransformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ConnectionLostEvent.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeadlockedThreadCountAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscription.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionThread.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultMRIMetadataService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultNotificationSubscriptionManager.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultSubscriptionDebugInformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeltaTransformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceTransformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DivisionAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtendedMRIMetadataToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtensionMetadataProviderService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadata.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadataDB.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotGcNotification.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLastGcAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLiveSetAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IIntervalUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IMRISubscriptionDebugInformation.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ISubscriptionDebugService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/InvoluntaryDisconnectException.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/LongDifferenceAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MBeanMRIMetadataDB.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRIMetadataWrapper.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRITransformationToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MonitoredDeadlockedThreadCountAttribute.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/OneShotUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SimpleUpdatePolicy.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SingleMRITransformationFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SyntheticAttributeToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/TransformationSubscription.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableChildSubscriptions.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableSubscriptionsRepository.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UpdatePolicyToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/BufferingAttributeStorage.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/DefaultAttributeStorageService.java delete mode 100644 src/main/java/org/openjdk/jmc/rjmx/util/internal/SimpleAttributeInfo.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/CorePlugin.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/action/Executable.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/action/IActionProvider.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/action/IUserAction.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/jvm/Connectable.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/jvm/JVMArch.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/jvm/JVMCommandLineToolkit.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/jvm/JVMType.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/Constants.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/Formatter.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/IVariableEvaluator.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/Matcher.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/NameConverter.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/NamingRule.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/labelingrules/Variables.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/resource/IImageResource.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/resource/Resource.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/ActionNotGrantedException.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/CredentialsNotAvailableException.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/FailedToSaveException.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/ICredentials.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/ISecurityManager.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/InMemoryCredentials.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/PersistentCredentials.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/SecurelyStoredByteArray.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/SecurityException.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/security/SecurityManagerFactory.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/tree/IArray.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/tree/IParent.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/util/Environment.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/util/Filename.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/util/ICopyable.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/util/IObservable.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/xydata/DataSeries.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultTimestampedData.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultXYData.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/xydata/ITimestampedData.java delete mode 100644 src/main/java/org/openjdk/jmc/ui/common/xydata/IXYData.java diff --git a/pom.xml b/pom.xml index 12e3ee20..fcd2d0b5 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,15 @@ + + + jmc-libs + Adoptium JDK Mission Control Core Libraries + https://adoptium.jfrog.io/artifactory/jmc-libs + default + + + github @@ -63,7 +72,7 @@ 11 ${java.version} ${java.version} - 8.2.0 + 9.0.0 3.1.7 3.13.0 @@ -96,27 +105,37 @@ org.openjdk.jmc common - ${jmc.version} + ${org.openjdk.jmc.version} org.openjdk.jmc flightrecorder - ${jmc.version} + ${org.openjdk.jmc.version} + + + org.openjdk.jmc + flightrecorder.configuration + ${org.openjdk.jmc.version} org.openjdk.jmc flightrecorder.rules - ${jmc.version} + ${org.openjdk.jmc.version} org.openjdk.jmc flightrecorder.rules.jdk - ${jmc.version} + ${org.openjdk.jmc.version} org.openjdk.jmc jdp - ${jmc.version} + ${org.openjdk.jmc.version} + + + org.openjdk.jmc + rjmx.common + ${org.openjdk.jmc.version} org.apache.commons diff --git a/scripts/jmc-diff.sh b/scripts/jmc-diff.sh deleted file mode 100755 index 28cda5bc..00000000 --- a/scripts/jmc-diff.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - -# -# Copyright The Cryostat Authors -# -# The Universal Permissive License (UPL), Version 1.0 -# -# Subject to the condition set forth below, permission is hereby granted to any -# person obtaining a copy of this software, associated documentation and/or data -# (collectively the "Software"), free of charge and under any and all copyright -# rights in the Software, and any and all patent rights owned or freely -# licensable by each licensor hereunder covering either (i) the unmodified -# Software as contributed to or provided by such licensor, or (ii) the Larger -# Works (as defined below), to deal in both -# -# (a) the Software, and -# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if -# one is included with the Software (each a "Larger Work" to which the Software -# is contributed by such licensors), -# -# without restriction, including without limitation the rights to copy, create -# derivative works of, display, perform, and distribute the Software and make, -# use, sell, offer for sale, import, export, have made, and have sold the -# Software and the Larger Work(s), and to sublicense the foregoing rights on -# either these or other terms. -# -# This license is subject to the following condition: -# The above copyright notice and either this complete permission notice or at -# a minimum a reference to the UPL must be included in all copies or -# substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -# This script compares the differences between a JMC 7 source and the -# embedded JMC source files within this repo -if [ $# -ne 1 ]; then - echo "usage: $0 /path/to/jmc7" >&2 - exit 1 -fi - -JMC_DIR=$1 -ROOT_DIR="$(readlink -f "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/..")" -SUMMARIZE_MISSING="${SUMMARIZE_MISSING:-false}" -MISSING_FILES="" - -diffBundle () { - local bundle_name="$1" - local src_dir="$2" - local exclude_dir="$3" - - pushd "${JMC_DIR}/application/${bundle_name}" >/dev/null - if [ -n "$exclude_dir" ]; then - local srcFiles=$(find "${src_dir}" -type f -not -path "${exclude_dir}/*") - else - local srcFiles=$(find "${src_dir}" -type f) - fi - - local diff_flags="-u" - if [ "${SUMMARIZE_MISSING}" != true ]; then - diff_flags="${diff_flags} -N" - fi - - for i in ${srcFiles}; do - if [ "${SUMMARIZE_MISSING}" = true -a ! -f "${ROOT_DIR}/$i" ]; then - MISSING_FILES="${MISSING_FILES}\n$i" - else - diff ${diff_flags} --label="a/$i" --label="b/$i" "${JMC_DIR}/application/${bundle_name}/$i" "${ROOT_DIR}/$i" - fi - done - popd >/dev/null -} - -diffBundle "org.openjdk.jmc.flightrecorder.configuration" "src/main/java/org/openjdk/jmc/flightrecorder/configuration/" -diffBundle "org.openjdk.jmc.flightrecorder.controlpanel.ui" "src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui" "src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration" -diffBundle "org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration" "src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration" -diffBundle "org.openjdk.jmc.rjmx" "src/main/java/org/openjdk/jmc/rjmx" "src/main/java/org/openjdk/jmc/rjmx/services/jfr" -diffBundle "org.openjdk.jmc.rjmx.services.jfr" "src/main/java/org/openjdk/jmc/rjmx/services/jfr" -diffBundle "org.openjdk.jmc.jdp" "src/main/java/org/openjdk/jmc/jdp" -diffBundle "org.openjdk.jmc.ui.common" "src/main/java/org/openjdk/jmc/ui/common" - -if [ "${SUMMARIZE_MISSING}" = true ]; then - echo -e "\nRemoved files:${MISSING_FILES}" -fi diff --git a/scripts/jmc-embed.sh b/scripts/jmc-embed.sh deleted file mode 100755 index 87edc456..00000000 --- a/scripts/jmc-embed.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# -# Copyright The Cryostat Authors -# -# The Universal Permissive License (UPL), Version 1.0 -# -# Subject to the condition set forth below, permission is hereby granted to any -# person obtaining a copy of this software, associated documentation and/or data -# (collectively the "Software"), free of charge and under any and all copyright -# rights in the Software, and any and all patent rights owned or freely -# licensable by each licensor hereunder covering either (i) the unmodified -# Software as contributed to or provided by such licensor, or (ii) the Larger -# Works (as defined below), to deal in both -# -# (a) the Software, and -# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if -# one is included with the Software (each a "Larger Work" to which the Software -# is contributed by such licensors), -# -# without restriction, including without limitation the rights to copy, create -# derivative works of, display, perform, and distribute the Software and make, -# use, sell, offer for sale, import, export, have made, and have sold the -# Software and the Larger Work(s), and to sublicense the foregoing rights on -# either these or other terms. -# -# This license is subject to the following condition: -# The above copyright notice and either this complete permission notice or at -# a minimum a reference to the UPL must be included in all copies or -# substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -# This script copies JMC 7 classes used by Cryostat Core into -# the src/main/java directory -if [ $# -ne 1 ]; then - echo "usage: $0 /path/to/jmc7" >&2 - exit 1 -fi - -JMC_DIR=$1 -ROOT_DIR="$(readlink -f "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/..")" - -copyBundle () { - local bundle_name="$1" - cp -rv "${JMC_DIR}/application/${bundle_name}/src/main/java/org" "${ROOT_DIR}/src/main/java/" -} - -copyResource() { - local bundle_name="$1" - local resource_path="$2" - - mkdir -p "$(dirname "${ROOT_DIR}/src/main/resources/${resource_path}")" - cp -rv "${JMC_DIR}/application/${bundle_name}/src/main/resources/${resource_path}" "${ROOT_DIR}/src/main/resources/${resource_path}" -} -# src/main/resources/org/openjdk/jmc/rjmx/subscription/internal/mrimetadata.xml -copyBundle "org.openjdk.jmc.flightrecorder.configuration" -copyBundle "org.openjdk.jmc.flightrecorder.controlpanel.ui" -copyBundle "org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration" -copyBundle "org.openjdk.jmc.rjmx" -copyBundle "org.openjdk.jmc.rjmx.services.jfr" -copyBundle "org.openjdk.jmc.jdp" -copyBundle "org.openjdk.jmc.ui.common" - -copyResource "org.openjdk.jmc.flightrecorder.configuration" "org/openjdk/jmc/flightrecorder/configuration/events/jfc_v1.xsd" -copyResource "org.openjdk.jmc.flightrecorder.configuration" "org/openjdk/jmc/flightrecorder/configuration/events/jfc_v2.xsd" -copyResource "org.openjdk.jmc.rjmx" "org/openjdk/jmc/rjmx/subscription/internal/mrimetadata.xml" diff --git a/src/main/java/io/cryostat/core/EventOptionsBuilder.java b/src/main/java/io/cryostat/core/EventOptionsBuilder.java index 7318c788..40bec48b 100644 --- a/src/main/java/io/cryostat/core/EventOptionsBuilder.java +++ b/src/main/java/io/cryostat/core/EventOptionsBuilder.java @@ -27,9 +27,9 @@ import org.openjdk.jmc.common.unit.QuantityConversionException; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; -import org.openjdk.jmc.rjmx.services.jfr.internal.FlightRecorderServiceV2; +import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeInfo; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; +import org.openjdk.jmc.rjmx.common.services.jfr.internal.FlightRecorderServiceV2; import io.cryostat.core.net.JFRConnection; @@ -96,7 +96,7 @@ public static class EventOptionException extends Exception { public static class Factory { public EventOptionsBuilder create(JFRConnection connection) throws IOException, ServiceNotAvailableException, - org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException { + org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException { if (!FlightRecorderServiceV2.isAvailable(connection.getHandle())) { throw new UnsupportedOperationException("Only FlightRecorder V2 is supported"); } diff --git a/src/main/java/io/cryostat/core/EventOptionsCustomizer.java b/src/main/java/io/cryostat/core/EventOptionsCustomizer.java index 64021f96..b12f03b8 100644 --- a/src/main/java/io/cryostat/core/EventOptionsCustomizer.java +++ b/src/main/java/io/cryostat/core/EventOptionsCustomizer.java @@ -25,7 +25,7 @@ import org.openjdk.jmc.common.unit.QuantityConversionException; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; +import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeInfo; import io.cryostat.core.net.JFRConnection; diff --git a/src/main/java/io/cryostat/core/agent/AgentJMXHelper.java b/src/main/java/io/cryostat/core/agent/AgentJMXHelper.java index 6515485a..d9f91bc7 100644 --- a/src/main/java/io/cryostat/core/agent/AgentJMXHelper.java +++ b/src/main/java/io/cryostat/core/agent/AgentJMXHelper.java @@ -26,7 +26,7 @@ import javax.management.ObjectName; import javax.management.ReflectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; +import org.openjdk.jmc.rjmx.common.IConnectionHandle; public class AgentJMXHelper { diff --git a/src/main/java/io/cryostat/core/jmc/CopyRecordingDescriptor.java b/src/main/java/io/cryostat/core/jmc/CopyRecordingDescriptor.java index 77c19cda..3191da98 100644 --- a/src/main/java/io/cryostat/core/jmc/CopyRecordingDescriptor.java +++ b/src/main/java/io/cryostat/core/jmc/CopyRecordingDescriptor.java @@ -20,7 +20,7 @@ import javax.management.ObjectName; import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; +import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor; public class CopyRecordingDescriptor implements IRecordingDescriptor { private final IRecordingDescriptor original; diff --git a/src/main/java/io/cryostat/core/jmc/SecurityManager.java b/src/main/java/io/cryostat/core/jmc/SecurityManager.java index ad15bd76..64b2a2d6 100644 --- a/src/main/java/io/cryostat/core/jmc/SecurityManager.java +++ b/src/main/java/io/cryostat/core/jmc/SecurityManager.java @@ -18,10 +18,10 @@ import java.util.Collections; import java.util.Set; -import org.openjdk.jmc.ui.common.security.ActionNotGrantedException; -import org.openjdk.jmc.ui.common.security.FailedToSaveException; -import org.openjdk.jmc.ui.common.security.ISecurityManager; -import org.openjdk.jmc.ui.common.security.SecurityException; +import org.openjdk.jmc.common.security.ActionNotGrantedException; +import org.openjdk.jmc.common.security.FailedToSaveException; +import org.openjdk.jmc.common.security.ISecurityManager; +import org.openjdk.jmc.common.security.SecurityException; import io.cryostat.core.jmc.internal.Store; diff --git a/src/main/java/io/cryostat/core/net/CryostatFlightRecorderService.java b/src/main/java/io/cryostat/core/net/CryostatFlightRecorderService.java index 06cb85a6..25ef2327 100644 --- a/src/main/java/io/cryostat/core/net/CryostatFlightRecorderService.java +++ b/src/main/java/io/cryostat/core/net/CryostatFlightRecorderService.java @@ -20,14 +20,14 @@ import org.openjdk.jmc.common.unit.IConstrainedMap; import org.openjdk.jmc.common.unit.QuantityConversionException; +import org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException; +import org.openjdk.jmc.flightrecorder.configuration.IFlightRecorderService; +import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor; +import org.openjdk.jmc.flightrecorder.configuration.events.EventConfiguration; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.model.EventConfiguration; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLModel; +import org.openjdk.jmc.rjmx.common.ConnectionException; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; import io.cryostat.core.EventOptionsBuilder.EventOptionException; import io.cryostat.core.EventOptionsBuilder.EventTypeException; diff --git a/src/main/java/io/cryostat/core/net/JFRConnection.java b/src/main/java/io/cryostat/core/net/JFRConnection.java index 6b729c2c..9d7b321f 100644 --- a/src/main/java/io/cryostat/core/net/JFRConnection.java +++ b/src/main/java/io/cryostat/core/net/JFRConnection.java @@ -22,9 +22,9 @@ import javax.management.ReflectionException; import javax.management.remote.JMXServiceURL; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; +import org.openjdk.jmc.rjmx.common.ConnectionException; +import org.openjdk.jmc.rjmx.common.IConnectionHandle; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; import io.cryostat.core.JvmIdentifier; import io.cryostat.core.sys.Clock; diff --git a/src/main/java/io/cryostat/core/net/JFRConnectionToolkit.java b/src/main/java/io/cryostat/core/net/JFRConnectionToolkit.java index bf7a2c64..6ce69372 100644 --- a/src/main/java/io/cryostat/core/net/JFRConnectionToolkit.java +++ b/src/main/java/io/cryostat/core/net/JFRConnectionToolkit.java @@ -26,9 +26,9 @@ import javax.management.MBeanServerConnection; import javax.management.remote.JMXServiceURL; -import org.openjdk.jmc.rjmx.ConnectionDescriptorBuilder; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; +import org.openjdk.jmc.rjmx.common.ConnectionDescriptorBuilder; +import org.openjdk.jmc.rjmx.common.ConnectionException; +import org.openjdk.jmc.rjmx.common.ConnectionToolkit; import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem; diff --git a/src/main/java/io/cryostat/core/net/JFRJMXConnection.java b/src/main/java/io/cryostat/core/net/JFRJMXConnection.java index f1244e25..cc4bced2 100644 --- a/src/main/java/io/cryostat/core/net/JFRJMXConnection.java +++ b/src/main/java/io/cryostat/core/net/JFRJMXConnection.java @@ -37,19 +37,24 @@ import javax.management.openmbean.TabularData; import javax.management.remote.JMXServiceURL; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.IConnectionListener; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.internal.DefaultConnectionHandle; -import org.openjdk.jmc.rjmx.internal.RJMXConnection; -import org.openjdk.jmc.rjmx.internal.ServerDescriptor; -import org.openjdk.jmc.rjmx.services.jfr.internal.FlightRecorderServiceFactory; -import org.openjdk.jmc.rjmx.services.jfr.internal.FlightRecorderServiceV2; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; +import org.openjdk.jmc.rjmx.common.ConnectionException; +import org.openjdk.jmc.rjmx.common.ConnectionToolkit; +import org.openjdk.jmc.rjmx.common.IConnectionDescriptor; +import org.openjdk.jmc.rjmx.common.IConnectionHandle; +import org.openjdk.jmc.rjmx.common.IConnectionListener; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; +import org.openjdk.jmc.rjmx.common.internal.DefaultConnectionHandle; +import org.openjdk.jmc.rjmx.common.internal.RJMXConnection; +import org.openjdk.jmc.rjmx.common.internal.ServerDescriptor; +import org.openjdk.jmc.rjmx.common.services.internal.AttributeStorageServiceFactory; +import org.openjdk.jmc.rjmx.common.services.internal.CommercialFeaturesServiceFactory; +import org.openjdk.jmc.rjmx.common.services.internal.DiagnosticCommandServiceFactory; +import org.openjdk.jmc.rjmx.common.services.internal.ServiceEntry; +import org.openjdk.jmc.rjmx.common.services.internal.SubscriptionServiceFactory; +import org.openjdk.jmc.rjmx.common.services.jfr.internal.FlightRecorderServiceFactory; +import org.openjdk.jmc.rjmx.common.services.jfr.internal.FlightRecorderServiceV2; +import org.openjdk.jmc.rjmx.common.subscription.MRI; +import org.openjdk.jmc.rjmx.common.subscription.MRI.Type; import io.cryostat.core.JvmIdentifier; import io.cryostat.core.sys.Clock; @@ -68,6 +73,7 @@ public class JFRJMXConnection implements JFRConnection { protected final Environment env; protected final FlightRecorderServiceFactory serviceFactory; protected final List closeListeners; + protected final List> serviceEntries; protected RJMXConnection rjmxConnection; protected IConnectionHandle handle; protected IConnectionDescriptor connectionDescriptor; @@ -84,6 +90,33 @@ public class JFRJMXConnection implements JFRConnection { this.connectionDescriptor = cd; this.closeListeners = new ArrayList<>(listeners); this.serviceFactory = new FlightRecorderServiceFactory(); + this.serviceEntries = new ArrayList<>(); + initializeServiceEntries(); + } + + private void initializeServiceEntries() { + serviceEntries.add( + new ServiceEntry<>( + new AttributeStorageServiceFactory(), + "Attribute Storage", + "Service for storing attribute values")); + serviceEntries.add( + new ServiceEntry<>( + new CommercialFeaturesServiceFactory(), + "Commercial Features", + "Service for checking and enabling the state of the commercial features" + + " in hotspot.")); + serviceEntries.add( + new ServiceEntry<>( + new DiagnosticCommandServiceFactory(), + "Diagnostic Commands", + "Diagnostic Commands")); + serviceEntries.add( + new ServiceEntry<>( + new SubscriptionServiceFactory(), + "Subscription Engine", + "Service for controlling the client side attribute subscription" + + " engine")); } JFRJMXConnection(ClientWriter cw, FileSystem fs, Environment env, IConnectionDescriptor cd) { @@ -307,7 +340,8 @@ public void onConnectionChange( } }) .collect(Collectors.toList()) - .toArray(new IConnectionListener[0])); + .toArray(new IConnectionListener[0]), + serviceEntries); } public synchronized void disconnect() { diff --git a/src/main/java/io/cryostat/core/net/JmxFlightRecorderService.java b/src/main/java/io/cryostat/core/net/JmxFlightRecorderService.java index 15c08dfe..c4237200 100644 --- a/src/main/java/io/cryostat/core/net/JmxFlightRecorderService.java +++ b/src/main/java/io/cryostat/core/net/JmxFlightRecorderService.java @@ -27,15 +27,15 @@ import org.openjdk.jmc.common.unit.IOptionDescriptor; import org.openjdk.jmc.common.unit.IQuantity; import org.openjdk.jmc.common.unit.QuantityConversionException; +import org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException; +import org.openjdk.jmc.flightrecorder.configuration.IFlightRecorderService; +import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; -import org.openjdk.jmc.rjmx.services.jfr.internal.FlightRecorderServiceFactory; +import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeInfo; +import org.openjdk.jmc.rjmx.common.ConnectionException; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; +import org.openjdk.jmc.rjmx.common.services.jfr.internal.FlightRecorderServiceFactory; import io.cryostat.core.EventOptionsBuilder; import io.cryostat.core.EventOptionsBuilder.EventOptionException; diff --git a/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java b/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java index 514bd279..71fd0b9f 100644 --- a/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java +++ b/src/main/java/io/cryostat/core/serialization/SerializableEventTypeInfo.java @@ -20,7 +20,7 @@ import java.util.Map; import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; +import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeInfo; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; diff --git a/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java b/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java index fa50930d..b7126556 100644 --- a/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java +++ b/src/main/java/io/cryostat/core/serialization/SerializableRecordingDescriptor.java @@ -22,8 +22,8 @@ import org.openjdk.jmc.common.unit.IQuantity; import org.openjdk.jmc.common.unit.QuantityConversionException; import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor.RecordingState; +import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor; +import org.openjdk.jmc.flightrecorder.configuration.IRecordingDescriptor.RecordingState; import jdk.jfr.Recording; import org.apache.commons.lang3.builder.EqualsBuilder; diff --git a/src/main/java/io/cryostat/core/templates/AbstractTemplateService.java b/src/main/java/io/cryostat/core/templates/AbstractTemplateService.java index 8fe5d0db..30deb5b9 100644 --- a/src/main/java/io/cryostat/core/templates/AbstractTemplateService.java +++ b/src/main/java/io/cryostat/core/templates/AbstractTemplateService.java @@ -19,8 +19,8 @@ import java.util.Objects; import java.util.stream.Collectors; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLTagInstance; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLModel; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLTagInstance; import io.cryostat.core.FlightRecorderException; diff --git a/src/main/java/io/cryostat/core/templates/LocalStorageTemplateService.java b/src/main/java/io/cryostat/core/templates/LocalStorageTemplateService.java index bf97c3f1..312b930d 100644 --- a/src/main/java/io/cryostat/core/templates/LocalStorageTemplateService.java +++ b/src/main/java/io/cryostat/core/templates/LocalStorageTemplateService.java @@ -29,13 +29,13 @@ import org.openjdk.jmc.common.unit.IConstrainedMap; import org.openjdk.jmc.common.unit.SimpleConstrainedMap; import org.openjdk.jmc.common.unit.UnitLookup; +import org.openjdk.jmc.flightrecorder.configuration.events.EventConfiguration; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLAttributeInstance; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLTagInstance; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLValidationResult; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.model.EventConfiguration; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.JFCGrammar; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLAttributeInstance; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLModel; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLTagInstance; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLValidationResult; import io.cryostat.core.FlightRecorderException; import io.cryostat.core.sys.Environment; diff --git a/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java b/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java index e7271fb6..30371cd7 100644 --- a/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java +++ b/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java @@ -23,11 +23,11 @@ import java.util.stream.Collectors; import org.openjdk.jmc.common.unit.IConstrainedMap; +import org.openjdk.jmc.flightrecorder.configuration.IFlightRecorderService; +import org.openjdk.jmc.flightrecorder.configuration.events.EventConfiguration; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.model.EventConfiguration; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; +import org.openjdk.jmc.flightrecorder.configuration.model.xml.XMLModel; +import org.openjdk.jmc.rjmx.common.ServiceNotAvailableException; import io.cryostat.core.FlightRecorderException; import io.cryostat.core.net.JFRConnection; @@ -84,7 +84,7 @@ public Optional getXml(String templateName, TemplateType type) return configuration.attr("label").equals(templateName); }) .findFirst(); - } catch (org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException + } catch (org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException | IOException | ServiceNotAvailableException e) { throw new FlightRecorderException("Could not get XML", e); @@ -137,7 +137,7 @@ protected List getTemplateModels() throws FlightRecorderException { }) .filter(Objects::nonNull) .collect(Collectors.toList()); - } catch (org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException + } catch (org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException | IOException | ServiceNotAvailableException e) { throw new FlightRecorderException("Could not get template models", e); diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/ConfigurationToolkit.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/ConfigurationToolkit.java deleted file mode 100644 index 965b2175..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/ConfigurationToolkit.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.configuration.events.SchemaVersion; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV1; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV2; -import org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions; -import org.openjdk.jmc.flightrecorder.configuration.internal.KnownRecordingOptions; - -/** - * Provisional entry point to obtain Flight Recorder meta data. - */ -public class ConfigurationToolkit { - private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.flightrecorder.configuration"); //$NON-NLS-1$ - - public static Logger getLogger() { - return LOGGER; - } - - public static IDescribedMap getRecordingOptions(JavaVersion version) { - if (version.isGreaterOrEqualThan(JavaVersionSupport.JDK_9)) { - return KnownRecordingOptions.OPTION_DEFAULTS_V2; - } else if (version.isGreaterOrEqualThan(JavaVersionSupport.JDK_7_U_4)) { - return KnownRecordingOptions.OPTION_DEFAULTS_V1; - } - return null; - } - - public static IDescribedMap getRecordingOptions(SchemaVersion version) { - switch (version) { - case V1: - return KnownRecordingOptions.OPTION_DEFAULTS_V1; - case V2: - return KnownRecordingOptions.OPTION_DEFAULTS_V2; - default: - } - return null; - } - - public static IDescribedMap getEventOptions(SchemaVersion version) { - switch (version) { - case V1: - return KnownEventOptions.OPTION_DEFAULTS_V1; - case V2: - return KnownEventOptions.OPTION_DEFAULTS_V2; - default: - } - return null; - } - - public static IEventTypeID createEventTypeID(String producerURI, String eventPath) { - return new EventTypeIDV1(producerURI, eventPath); - } - - public static IEventTypeID createEventTypeID(String eventName) { - return new EventTypeIDV2(eventName); - } - - public static IConstrainedMap extractDelta(IConstrainedMap options, IConstrainedMap baseline) { - IMutableConstrainedMap deltas = options.emptyWithSameConstraints(); - for (K key : options.keySet()) { - Object value = options.get(key); - if ((value != null) && !value.equals(baseline.get(key))) { - try { - deltas.put(key, value); - } catch (QuantityConversionException e) { - // Shouldn't really happen. - LOGGER.log(Level.FINE, "Couldn't convert when extracting delta.", e); //$NON-NLS-1$ - } - } - } - return deltas; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/IRecorderConfigurationService.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/IRecorderConfigurationService.java deleted file mode 100644 index c84f296a..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/IRecorderConfigurationService.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration; - -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; - -public interface IRecorderConfigurationService { - /** - * The version of JDK Flight Recorder this service instance represents. The format is entirely - * internal and may change at any time. - */ - String getVersion(); - - /** - * Returns the default recording options, with descriptions. These should not change over time, - * for a particular service instance. - * - * @return an immutable {@link IDescribedMap} with descriptions of options and their default - * values. - */ - IDescribedMap getDefaultRecordingOptions(); - - /** - * Returns the default event options, with descriptions. - * - * @return an immutable {@link IDescribedMap} with descriptions of options and their default - * values. - */ - IDescribedMap getDefaultEventOptions(); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/OptionInfo.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/OptionInfo.java deleted file mode 100644 index 768f24e3..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/OptionInfo.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IOptionDescriptor; - -public class OptionInfo implements IOptionDescriptor { - public static final IOptionDescriptor DISALLOWED_OPTION = new OptionInfo<>(null, - "Disallowed option", null, null); - - private final String label; - private final String description; - private final T defaultValue; - private final IConstraint constraint; - - public OptionInfo(String label, String description, IConstraint constraint, T defaultValue) { - this.label = label; - this.description = description; - this.constraint = constraint; - this.defaultValue = defaultValue; - } - - @Override - public String getName() { - return label; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public T getDefault() { - return defaultValue; - } - - @Override - public IConstraint getConstraint() { - return constraint; - } - - @Override - @SuppressWarnings("nls") - public String toString() { - return "OptionInfo [label=" + label + ", default=" + defaultValue + ", constraint=" + constraint + ']'; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/EventOptionID.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/EventOptionID.java deleted file mode 100644 index 71256e77..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/EventOptionID.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.events; - -/** - * Identifier class needed since, for JFR 1.0, you cannot from a single option or event URI identify - * where the descriptive event path begins. - */ -public final class EventOptionID { - private final IEventTypeID eventTypeID; - private final String optionKey; - - public EventOptionID(IEventTypeID eventTypeID, String optionKey) { - this.eventTypeID = eventTypeID; - this.optionKey = optionKey; - } - - public IEventTypeID getEventTypeID() { - return eventTypeID; - } - - public String getOptionKey() { - return optionKey; - } - - @Override - public boolean equals(Object other) { - if (other instanceof EventOptionID) { - EventOptionID otherID = (EventOptionID) other; - return eventTypeID.equals(otherID.eventTypeID) && optionKey.equals(otherID.optionKey); - } - return false; - } - - @Override - public int hashCode() { - return eventTypeID.hashCode() ^ optionKey.hashCode(); - } - - @Override - public String toString() { - return eventTypeID.getFullKey(optionKey); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventConfiguration.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventConfiguration.java deleted file mode 100644 index 61fb0c65..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventConfiguration.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.events; - -import java.io.File; -import java.io.IOException; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.flightrecorder.configuration.spi.IConfigurationStorageDelegate; - -/** - * Interface for JDK Flight Recorder configurations. Note that this interface is (and should - * remain) agnostic as to how the configuration is represented. - */ -public interface IEventConfiguration { - String JFC_FILE_EXTENSION = ".jfc"; //$NON-NLS-1$ - - /** - * @return the name of this configuration, as shown when selecting among configuration - * templates. - */ - String getName(); - - /** - * Set the name of this configuration, as shown when selecting among configuration templates. - * - * @param name - */ - void setName(String name); - - /** - * @return the description of this configuration, as shown when selecting among configuration - * templates. - */ - String getDescription(); - - /** - * Set the description of this configuration, as shown when selecting among configuration - * templates. - * - * @param description - */ - void setDescription(String description); - - /** - * @return a description of where this configuration is stored, or null if this is unimportant - * to the user. - */ - String getLocationInfo(); - - /** - * Whether this particular configuration offers some kind of simplified, higher level control - * over what to include in the recording, compared to setting individual low level options. - * - * @return true iff the configuration has some kind of simplified control mechanism. - */ - boolean hasControlElements(); - - /** - * Remove all kinds of simplified, higher level controls over what to include in the recording, - * compared to setting individual low level options. This is typically called when the - * configuration is about to be modified by the user at the low level, and higher level controls - * could interfere with that. - * - * @return true iff the configuration had some kind of simplified control mechanism. - */ - boolean removeControlElements(); - - /** - * If this configuration can likely be deleted permanently, that is, beyond the life cycle of - * this instance and any repositories containing it. Note that returning true here does not - * guarantee that a {@link #delete()} will succeed, only that it can be attempted. - * - * @return - */ - boolean isDeletable(); - - /** - * Attempt to delete this configuration permanently, that is, beyond the life cycle of this - * instance and any repositories containing it. - * - * @return true iff this configuration was deleted permanently. - */ - boolean delete(); - - /** - * If this configuration can likely be saved permanently, that is, beyond the life cycle of this - * instance and any repositories containing it. This method can be used to enable or disable - * save options. Note that returning true here does not guarantee that a {@link #save()} will - * succeed, only that it can be attempted. - * - * @return - */ - boolean isSaveable(); - - /** - * Save this configuration permanently, that is, beyond the life cycle of this instance and any - * repositories containing it. - * - * @return true iff this configuration was saved permanently. - */ - boolean save(); - - /** - * If this configuration can be cloned, and it makes sense to do it. - * - * @return - */ - boolean isCloneable(); - - /** - * Warning, this creates a clone with the same underlying storage. This might not be what you - * want. - * - * @return a clone using the same storage as this configuration - * @see #createCloneWithStorage(IConfigurationStorageDelegate) - */ - IEventConfiguration createClone(); - - /** - * Create a clone using the specified underlying storage. - * - * @param storageDelegate - * @return a clone using {@code storageDelegate} as underlying storage. - */ - IEventConfiguration createCloneWithStorage(IConfigurationStorageDelegate storageDelegate); - - /** - * Create a working copy of this configuration, with no backing storage. The returned - * configuration will return this configuration from its {@link #getOriginal()} method. - * - * @return a new {@link IEventConfiguration} - */ - IEventConfiguration createWorkingCopy(); - - /** - * If this is a working copy configuration, return the original configuration, otherwise return - * null. - * - * @return a {@link IEventConfiguration} or null - */ - IEventConfiguration getOriginal(); - - /** - * Check if the settings held by this configuration is the same as those held by {@code other}. - * The textual representation doesn't matter, nor does control elements. - * - * @param other - * @return true if the settings are the same, false otherwise - */ - boolean equalSettings(IEventConfiguration other); - - IConstrainedMap getEventOptions(IMutableConstrainedMap options); - - /** - * Get the persistable string for the option specified by {@code optionID}. If the option is - * unset, {@code null} will be returned. - * - * @param optionID - */ - String getPersistableString(EventOptionID optionID); - - /** - * Set the option specified by {@code optionID} to the given persisted value. - * - * @param optionID - * @param persisted - */ - void putPersistedString(EventOptionID optionID, String persisted); - - /** - * If this configuration can be exported, and it makes sense to do it. - * - * @return - */ - boolean isExportable(); - - /** - * Export this configuration to the given file. - * - * @param file - * the destination file. - * @throws IOException - * if there were trouble writing to {@code file}. - */ - void exportToFile(File file) throws IOException; - - /** - * The schema version for this configuration - * - * @return schema version - */ - SchemaVersion getVersion(); - - /** - * Gets the location of the underlying storage delegate, see - * {@link IConfigurationStorageDelegate#getLocationPath()}. - * - * @return a string that represents the file system location of this template, or null. - */ - String getLocationPath(); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventTypeID.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventTypeID.java deleted file mode 100644 index 2b9b76d7..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/IEventTypeID.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.events; - -/** - * Abstraction of a persistable identifier for an event type in JFR. - */ -public interface IEventTypeID { - - /** - * The identifying key of the producer of this event type. This is only relevant for some JFR - * versions. For all other versions, this is {@code null}. The format of the key is JFR version - * specific. - * - * @return a producer key or {@code null} - */ - String getProducerKey(); - - /** - * The persistable key identifying this event type, within its {@link #getProducerKey() - * producer}, if applicable. The format of the key is JFR version specific. - * - * @return a event type key, never {@code null} - */ - String getRelativeKey(); - - /** - * A string array representing some sort of categorization to be used only when the - * corresponding {@link IEventTypeInfo} is unavailable. Note that, unlike in - * {@link IEventTypeInfo#getHierarchicalCategory()}, the last element in the array represents - * the event type itself. - * - * @return - */ - String[] getFallbackHierarchy(); - - /** - * The persistable key uniquely identifying this event type. The format of the key is JFR - * version specific. - * - * @return a qualified event type key, never {@code null} - */ - String getFullKey(); - - /** - * The persistable key uniquely identifying the event option specified by {@code optionKey} in - * this event type. The format of the key is JFR version specific. - * - * @return a qualified event option key, never {@code null} - */ - String getFullKey(String optionKey); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/SchemaVersion.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/SchemaVersion.java deleted file mode 100644 index 946850f1..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/events/SchemaVersion.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.events; - -import java.io.InputStream; - -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.common.version.JavaVersionSupport; - -public enum SchemaVersion { - V1("1.0", "jfc_v1.xsd", "JDK 7/8"), //$NON-NLS-1$ //$NON-NLS-2$ - V2("2.0", "jfc_v2.xsd", "JDK 9+"); //$NON-NLS-1$ //$NON-NLS-2$ - - public static SchemaVersion fromBeanVersion(String beanVersion) { - for (SchemaVersion version : values()) { - if (version.version.equals(beanVersion)) { - return version; - } - } - return null; - } - - public static SchemaVersion fromJavaVersion(JavaVersion javaVersion) { - return javaVersion.isGreaterOrEqualThan(JavaVersionSupport.JDK_9) ? V2 - : javaVersion.isGreaterOrEqualThan(JavaVersionSupport.JDK_7_U_4) ? V1 : null; - } - - private final String version; - private final String xsdFile; - private final String description; - - private SchemaVersion(String version, String xsdFile, String description) { - this.version = version; - this.xsdFile = xsdFile; - this.description = description; - } - - public String attributeValue() { - return version; - } - - public InputStream createSchemaStream() { - return SchemaVersion.class.getResourceAsStream(xsdFile); - } - - @Override - public String toString() { - return version + " (" + xsdFile + ')'; //$NON-NLS-1$ - } - - public String getDescription() { - return description; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/CommonConstraints.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/CommonConstraints.java deleted file mode 100644 index f056dc0a..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/CommonConstraints.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import static org.openjdk.jmc.common.unit.BinaryPrefix.EXBI; -import static org.openjdk.jmc.common.unit.DecimalPrefix.MICRO; -import static org.openjdk.jmc.common.unit.DecimalPrefix.MILLI; -import static org.openjdk.jmc.common.unit.DecimalPrefix.NANO; -import static org.openjdk.jmc.common.unit.DecimalPrefix.NONE; -import static org.openjdk.jmc.common.unit.UnitLookup.BYTE; -import static org.openjdk.jmc.common.unit.UnitLookup.DAY; -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS; -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_NS; -import static org.openjdk.jmc.common.unit.UnitLookup.HOUR; -import static org.openjdk.jmc.common.unit.UnitLookup.MEMORY; -import static org.openjdk.jmc.common.unit.UnitLookup.MINUTE; -import static org.openjdk.jmc.common.unit.UnitLookup.NANOSECOND; -import static org.openjdk.jmc.common.unit.UnitLookup.SECOND; -import static org.openjdk.jmc.common.unit.UnitLookup.TIMESPAN; -import static org.openjdk.jmc.common.unit.UnitLookup.YEAR; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.logging.Level; - -import org.openjdk.jmc.common.unit.ComparableConstraint; -import org.openjdk.jmc.common.unit.CustomUnitSelector; -import org.openjdk.jmc.common.unit.DecimalPrefix; -import org.openjdk.jmc.common.unit.DecimalUnitSelector; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IFormatter; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.ITypedQuantity; -import org.openjdk.jmc.common.unit.IUnit; -import org.openjdk.jmc.common.unit.LinearKindOfQuantity.LinearUnitSelector; -import org.openjdk.jmc.common.unit.LinearUnit; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.common.unit.WrappingPersister; -import org.openjdk.jmc.flightrecorder.configuration.ConfigurationToolkit; - -/** - * Constraints common for multiple JFR versions. - */ -public class CommonConstraints { - public final static IQuantity EVERY_CHUNK_MAGIC_INSTANCE = NANOSECOND.quantity(0); - public final static IQuantity BEGIN_CHUNK_MAGIC_INSTANCE = NANOSECOND.quantity(0); - public final static IQuantity END_CHUNK_MAGIC_INSTANCE = NANOSECOND.quantity(0); - private final static String EVERY_CHUNK = "everyChunk"; //$NON-NLS-1$ - private final static String BEGIN_CHUNK = "beginChunk"; //$NON-NLS-1$ - private final static String END_CHUNK = "endChunk"; //$NON-NLS-1$ - - /** - * Constraint that persists and parses duration values compatible with the non-SI-conforming - * representation that JFR unfortunately uses. However, the output is always SI-conforming. - */ - private static class TimePersisterBrokenSI extends WrappingPersister { - private static final LinearUnitSelector UNIT_SELECTOR; - private static final IQuantity MIN_REPRESENTABLE = NANOSECOND.quantity(1); - - static { - // Error message claims: '1 min' is not a valid timespan. Shoule be numeric value followed by a unit, i.e. 20 ms. Valid units are ns, us, s, m, h and d. - DecimalPrefix[] prefixes = {NANO, MICRO, MILLI, NONE}; - LinearUnitSelector systemSelector = new DecimalUnitSelector(TIMESPAN, Arrays.asList(prefixes)); - // Omitting MINUTE since JFR cannot handle SI and we do not want to spread non-SI. - LinearUnit[] units = {HOUR, DAY}; - // Simplest tick set that will pass the checks in CustomUnitSelector. Not actually used. - SortedSet> ticks = new TreeSet<>(Collections.singleton(HOUR.quantity(1))); - UNIT_SELECTOR = new CustomUnitSelector(TIMESPAN, systemSelector, Arrays.asList(units), - new DecimalUnitSelector(TIMESPAN, DAY), ticks); - } - - public TimePersisterBrokenSI() { - super(TIMESPAN); - } - - @Override - @SuppressWarnings("nls") - public String persistableString(IQuantity value) { - if (MIN_REPRESENTABLE.compareTo(value) > 0) { - return "0 ns"; - } - @SuppressWarnings("unchecked") - ITypedQuantity typedValue = (ITypedQuantity) value; - LinearUnit unit = UNIT_SELECTOR.getLargestExactUnit(typedValue); - if (unit == null) { - unit = UNIT_SELECTOR.getPreferredUnit(typedValue, 1, 1000000000); - if (unit == null) { - unit = NANOSECOND; - } - } - // NOTE: We might theoretically get out of range here, but in practice values are constrained in magnitude when this class is used. - return super.persistableString(unit.quantity(value.clampedLongValueIn(unit))); - } - - @Override - @SuppressWarnings("nls") - public IQuantity parsePersisted(String persistedValue) throws QuantityConversionException { - if (persistedValue.endsWith("m")) { - persistedValue += "in"; - // FIXME: Log or warn that non-SI-conforming input was received. - } - IQuantity value = super.parsePersisted(persistedValue); - if ((value.getUnit() == SECOND) && (value.longValue() % 60 == 0)) { - return MINUTE.quantity(value.clampedLongValueIn(MINUTE)); - } - return value; - } - } - - private static final class PeriodPersister extends TimePersisterBrokenSI implements IFormatter { - @Override - public boolean validate(IQuantity value) { - if (value == EVERY_CHUNK_MAGIC_INSTANCE) { - return true; - } - return super.validate(value); - } - - @Override - public String persistableString(IQuantity value) { - return (value == EVERY_CHUNK_MAGIC_INSTANCE) ? EVERY_CHUNK : super.persistableString(value); - } - - @Override - public IQuantity parsePersisted(String persistedValue) throws QuantityConversionException { - return EVERY_CHUNK.equals(persistedValue) ? EVERY_CHUNK_MAGIC_INSTANCE - : super.parsePersisted(persistedValue); - } - - @Override - @SuppressWarnings("nls") - public String interactiveFormat(IQuantity value) { - return (value == EVERY_CHUNK_MAGIC_INSTANCE) ? "" : super.interactiveFormat(value); - } - - @Override - public IQuantity parseInteractive(String interactiveValue) throws QuantityConversionException { - return (interactiveValue.isEmpty()) ? EVERY_CHUNK_MAGIC_INSTANCE : super.parseInteractive(interactiveValue); - } - - @Override - public String format(IQuantity value) { - // FIXME: Migrate localized value from configuration GUI. - return (value == EVERY_CHUNK_MAGIC_INSTANCE) - ? "Once every chunk" : super.interactiveFormat(value); - } - } - - private static final class PeriodPersisterV2 extends TimePersisterBrokenSI implements IFormatter { - - @Override - public boolean validate(IQuantity value) { - if (value == EVERY_CHUNK_MAGIC_INSTANCE || value == BEGIN_CHUNK_MAGIC_INSTANCE - || value == END_CHUNK_MAGIC_INSTANCE) { - return true; - } - return super.validate(value); - } - - @Override - public String persistableString(IQuantity value) { - if (value == EVERY_CHUNK_MAGIC_INSTANCE) { - return EVERY_CHUNK; - } else if (value == BEGIN_CHUNK_MAGIC_INSTANCE) { - return BEGIN_CHUNK; - } else if (value == END_CHUNK_MAGIC_INSTANCE) { - return END_CHUNK; - } - return super.persistableString(value); - } - - @Override - public IQuantity parsePersisted(String persistedValue) throws QuantityConversionException { - if (EVERY_CHUNK.equals(persistedValue)) { - return EVERY_CHUNK_MAGIC_INSTANCE; - } else if (BEGIN_CHUNK.equals(persistedValue)) { - return BEGIN_CHUNK_MAGIC_INSTANCE; - } else if (END_CHUNK.equals(persistedValue)) { - return END_CHUNK_MAGIC_INSTANCE; - } - return super.parsePersisted(persistedValue); - } - - @Override - public String interactiveFormat(IQuantity value) { - if (value == EVERY_CHUNK_MAGIC_INSTANCE) { - return ""; //$NON-NLS-1$ - } - return super.interactiveFormat(value); - } - - @Override - public IQuantity parseInteractive(String interactiveValue) throws QuantityConversionException { - if (interactiveValue.isEmpty()) { - return EVERY_CHUNK_MAGIC_INSTANCE; - } - return super.parseInteractive(interactiveValue); - } - - @Override - public String format(IQuantity value) { - // FIXME: Migrate localized value from configuration GUI. - if (value == EVERY_CHUNK_MAGIC_INSTANCE) { - return "Once every chunk"; - } else if (value == BEGIN_CHUNK_MAGIC_INSTANCE) { - return "Beginning of every chunk"; - } else if (value == END_CHUNK_MAGIC_INSTANCE) { - return "End of every chunk"; - } - return super.interactiveFormat(value); - } - } - - private static class LongInUnitPersister extends WrappingPersister { - private final IUnit unit; - - public LongInUnitPersister(IUnit unit) { - super(unit.getContentType()); - this.unit = unit; - } - - @Override - public String persistableString(IQuantity value) { - return Long.toString(value.clampedLongValueIn(unit)); - } - - @Override - public IQuantity parsePersisted(String persistedValue) throws QuantityConversionException { - try { - return unit.quantity(Long.parseLong(persistedValue)); - } catch (NumberFormatException e) { - throw QuantityConversionException.unparsable(persistedValue, unit.quantity(1234), this); - } - } - } - - public final static IConstraint POSITIVE_TIMESPAN = new ComparableConstraint<>( - new TimePersisterBrokenSI(), SECOND.quantity(0), EPOCH_NS.quantity(Long.MAX_VALUE)); - public final static IConstraint PERIOD_V1 = new ComparableConstraint<>(new PeriodPersister(), - NANOSECOND.quantity(1), YEAR.quantity(1)); - public final static IConstraint PERIOD_V2 = new ComparableConstraint<>(new PeriodPersisterV2(), - NANOSECOND.quantity(1), YEAR.quantity(1)); - public final static IConstraint POSITIVE_MEMORY = new ComparableConstraint<>( - new LongInUnitPersister(BYTE), BYTE.quantity(0), MEMORY.getUnit(EXBI).quantity(4)); - public final static IConstraint POINT_IN_TIME = new ComparableConstraint<>( - new LongInUnitPersister(EPOCH_MS), EPOCH_MS.quantity(0), EPOCH_MS.quantity(Long.MAX_VALUE)); - - private static final Map> JFR1_TYPE_TO_CONSTRAINT; - - private static final Map> JFR2_TYPE_TO_CONSTRAINT; - private static final Map, String> CONSTRAINT_TO_JFR2_TYPE; - - static { - JFR1_TYPE_TO_CONSTRAINT = makeJFRv1ConstraintMap(); - JFR2_TYPE_TO_CONSTRAINT = makeJFRv2ConstraintMap(); - - Map, String> constraintToContentType = new HashMap<>(); - for (Entry> entry : JFR2_TYPE_TO_CONSTRAINT.entrySet()) { - constraintToContentType.put(entry.getValue(), entry.getKey()); - } - // Remove constraint used for fallback when no content type was specified, so that this isn't persisted. - // This may need to be adjusted so that fallbacks can be distinguished if usage changes. - constraintToContentType.remove(UnitLookup.PLAIN_TEXT.getPersister()); - CONSTRAINT_TO_JFR2_TYPE = constraintToContentType; - } - - @SuppressWarnings("nls") - private static Map> makeJFRv1ConstraintMap() { - Map> jfr1types = new HashMap<>(); - // These are the content types known to have been used in JFC files. More might have worked. Unsure if there's any specification. - jfr1types.put("timespan", POSITIVE_TIMESPAN); - jfr1types.put("text", UnitLookup.PLAIN_TEXT.getPersister()); - return jfr1types; - } - - @SuppressWarnings("nls") - private static Map> makeJFRv2ConstraintMap() { - Map> jfr2types = new HashMap<>(); - final String jfrPkg = "jdk.jfr."; - jfr2types.put(jfrPkg + "Percentage", UnitLookup.PERCENTAGE); - jfr2types.put(jfrPkg + "Timespan", POSITIVE_TIMESPAN); - jfr2types.put(jfrPkg + "Timestamp", POINT_IN_TIME); - jfr2types.put(jfrPkg + "Period", PERIOD_V2); - // Format never seen, not sufficiently specified. (Used to be mixed up with PERIOD.) -// jfr2types.put(jfrPkg + "Frequency", null); - jfr2types.put(jfrPkg + "Flag", UnitLookup.FLAG.getPersister()); - jfr2types.put(jfrPkg + "MemoryAddress", UnitLookup.ADDRESS); - jfr2types.put(jfrPkg + "DataAmount", POSITIVE_MEMORY); - return jfr2types; - } - - public static IConstraint forContentTypeV1(String typeName) { - IConstraint constraint = JFR1_TYPE_TO_CONSTRAINT.get(typeName); - return (constraint != null) ? constraint : UnitLookup.PLAIN_TEXT.getPersister(); - } - - public static String toMatchingContentTypeV2(IConstraint constraint) { - return CONSTRAINT_TO_JFR2_TYPE.get(constraint); - } - - public static IConstraint forContentTypeV2(String typeName, String defaultPersistedString) { - IConstraint constraint = JFR2_TYPE_TO_CONSTRAINT.get(typeName); - if (constraint != null) { - try { - constraint.parsePersisted(defaultPersistedString); - return constraint; - } catch (QuantityConversionException e) { - ConfigurationToolkit.getLogger().log(Level.WARNING, e.getMessage(), e); - // Fall through to PLAIN_TEXT - } - } else if ("true".equals(defaultPersistedString) || "false".equals(defaultPersistedString)) { //$NON-NLS-1$ //$NON-NLS-2$ - // Patch for Thread (at least) - return UnitLookup.FLAG.getPersister(); - } else { - // FIXME: Only log newly encountered (determined by inserting into other set, preferably). - ConfigurationToolkit.getLogger().log(Level.WARNING, "Couldn't find constraint for " + typeName); //$NON-NLS-1$ - } - return UnitLookup.PLAIN_TEXT.getPersister(); - } - - public static IConstraint forContentTypeV2(String typeName) { - IConstraint constraint = JFR2_TYPE_TO_CONSTRAINT.get(typeName); - return (constraint != null) ? constraint : UnitLookup.PLAIN_TEXT.getPersister(); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/DefaultValueMap.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/DefaultValueMap.java deleted file mode 100644 index 194876ae..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/DefaultValueMap.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.QuantityConversionException; - -/** - * Describable map with defaults values for all known keys, and acceptable optional keys, if any. - * - * @param - */ -public class DefaultValueMap implements IDescribedMap { - // NOTE: This should not be modifiable. - private final Map> knownOptions; - // NOTE: This should ideally be a (JDK 8) Function. May be null. - private final IMapper> fallbacks; - - private static final Logger LOGGER = Logger.getLogger("org.openjdk.jmc.flightrecorder.configuration"); - - public DefaultValueMap(Map> knownOptions) { - this(knownOptions, null); - } - - public DefaultValueMap(IMapper> fallbacks) { - this(Collections.emptyMap(), fallbacks); - } - - public DefaultValueMap(Map> knownOptions, - IMapper> fallbacks) { - this.knownOptions = knownOptions; - this.fallbacks = fallbacks; - } - - @Override - public IMutableConstrainedMap emptyWithSameConstraints() { - return new FixedDescriptorMap<>(makeCombinedMapper()); - } - - @Override - public IMutableConstrainedMap mutableCopy() { - FixedDescriptorMap copy = new FixedDescriptorMap<>(makeCombinedMapper()); - try { - for (Entry> entry : knownOptions.entrySet()) { - Object value = entry.getValue().getDefault(); - if (value != null) { - copy.put(entry.getKey(), value); - } - } - } catch (QuantityConversionException e) { - throw new RuntimeException("Implementation error", e); //$NON-NLS-1$ - } - return copy; - } - - protected IMapper> makeCombinedMapper() { - if (knownOptions.isEmpty()) { - // FIXME: fallbacks may be null here, but it is unlikely in practice. Should be handled. - return fallbacks; - } else if (fallbacks == null) { - return new IMapper.MapMapper<>(knownOptions); - } else { - return new IMapper>() { - @Override - public IOptionDescriptor get(K key) { - IOptionDescriptor desc = knownOptions.get(key); - return (desc != null) ? desc : fallbacks.get(key); - }; - }; - } - } - - protected IOptionDescriptor getDescriptor(K key) { - IOptionDescriptor desc = knownOptions.get(key); - return ((desc == null) && (fallbacks != null)) ? fallbacks.get(key) : desc; - } - - @Override - public IConstraint getConstraint(K key) { - IOptionDescriptor desc = getDescriptor(key); - return (desc != null) ? desc.getConstraint() : null; - } - - @Override - public IOptionDescriptor getDescribable(K key) { - return getDescriptor(key); - } - - @Override - public Set keySet() { - return knownOptions.keySet(); - } - - @Override - public Object get(K key) { - // NOTE: Only return non-null values for the known keys, for the valueKeySet() contract to hold. - IOptionDescriptor desc = knownOptions.get(key); - return (desc != null) ? desc.getDefault() : null; - } - - @Override - public String getPersistableString(K key) { - return getPersistableDefault(getDescriptor(key)); - } - - private String getPersistableDefault(IOptionDescriptor desc) { - if (desc != null) { - try { - V value = desc.getDefault(); - return (value == null) ? null : desc.getConstraint().persistableString(value); - } catch (QuantityConversionException e) { - LOGGER.log(Level.WARNING, "Problem parsing option default", e); //$NON-NLS-1$ - } - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventOptionDescriptorMapper.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventOptionDescriptorMapper.java deleted file mode 100644 index 9b8a4257..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventOptionDescriptorMapper.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.Map; - -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; - -/** - * Mapping function to return an {@link IOptionDescriptor} for all {@link EventOptionID option IDs} - * formed by a specific class of {@link IEventTypeID event type ID} and a well-known option key. - */ -public class EventOptionDescriptorMapper implements IMapper> { - private final Class typeClass; - private final Map> map; - private final boolean allowOther; - - public EventOptionDescriptorMapper(Class typeClass, Map> map, - boolean allowOther) { - this.map = map; - this.typeClass = typeClass; - this.allowOther = allowOther; - } - - @Override - public IOptionDescriptor get(EventOptionID key) { - if (typeClass.isInstance(key.getEventTypeID())) { - IOptionDescriptor desc = map.get(key.getOptionKey()); - return (allowOther || (desc != null)) ? desc : OptionInfo.DISALLOWED_OPTION; - } - return OptionInfo.DISALLOWED_OPTION; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV1.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV1.java deleted file mode 100644 index 033c7177..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV1.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.internal.EventAppearance; - -/** - * Identifier class needed since currently you cannot from a single event URI identify where the - * descriptive event path begins. - */ -public final class EventTypeIDV1 implements IEventTypeID { - - // FIXME: When usage has settled, revise stored state and convenience methods. - private final String producerURI; - private final String eventURI; - private final String eventPath; - private String[] cachedFallbackHierarchy; - - /** - * By (accidental?) convention, {@code producerURI} should end in a slash. {@code eventPath} - * should not begin, nor end, in a slash. - * - * @param producerURI - * @param eventPath - */ - public EventTypeIDV1(String producerURI, String eventPath) { - this(producerURI + eventPath, producerURI.length()); - } - - public EventTypeIDV1(String eventURI, int producerEndPos) { - // This ensures that the various strings are consistent (and reuses the same char[], which may be non-optimal). - this.eventURI = eventURI; - eventPath = eventURI.substring(producerEndPos); - producerURI = eventURI.substring(0, producerEndPos); - } - - /** - * May be null. - * - * @return - */ - @Override - public String getProducerKey() { - return producerURI; - } - - @Override - public String getRelativeKey() { - return eventPath; - } - - @Override - public String[] getFallbackHierarchy() { - if (cachedFallbackHierarchy == null) { - cachedFallbackHierarchy = EventAppearance.getHumanSegmentArray(eventPath); - } - return cachedFallbackHierarchy; - } - - @Override - public String getFullKey() { - return eventURI; - } - - @Override - public String getFullKey(String optionKey) { - // FIXME: Use slash instead? - return eventURI + ':' + optionKey; - } - - @Override - public boolean equals(Object other) { - if (other instanceof EventTypeIDV1) { - EventTypeIDV1 otherID = (EventTypeIDV1) other; - return eventURI.equals(otherID.eventURI) && eventPath.equals(otherID.eventPath); - } - return false; - } - - @Override - public int hashCode() { - return eventURI.hashCode(); - } - - @Override - public String toString() { - return eventURI; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV2.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV2.java deleted file mode 100644 index 89a9f86c..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/EventTypeIDV2.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.regex.Pattern; - -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; - -/** - * Event type identifier class for JFR 2.0 intended to simplify co-existence with JFR 1.0. - */ -public final class EventTypeIDV2 implements IEventTypeID { - private static final Pattern PACKAGE_SPLIT_REGEX = Pattern.compile("\\."); //$NON-NLS-1$ - - private final String eventName; - - public EventTypeIDV2(String eventName) { - this.eventName = eventName; - } - - @Override - public String getProducerKey() { - return null; - } - - @Override - public String getRelativeKey() { - return eventName; - } - - @Override - public String[] getFallbackHierarchy() { - return PACKAGE_SPLIT_REGEX.split(eventName); - } - - @Override - public String getFullKey() { - return eventName; - } - - @Override - public String getFullKey(String optionKey) { - return eventName + '#' + optionKey; - } - - @Override - public boolean equals(Object other) { - if (other instanceof EventTypeIDV2) { - EventTypeIDV2 otherID = (EventTypeIDV2) other; - return eventName.equals(otherID.eventName); - } - return false; - } - - @Override - public int hashCode() { - return eventName.hashCode(); - } - - @Override - public String toString() { - return eventName; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/FixedDescriptorMap.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/FixedDescriptorMap.java deleted file mode 100644 index d8574315..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/FixedDescriptorMap.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.MutableConstrainedMap; -import org.openjdk.jmc.common.unit.UnitLookup; - -/** - * General mutable {@link IOptionDescriptor} based {@link IDescribedMap} with possibility to add - * constraints. - * - * @param - */ -// FIXME: Rename to something more accurate. -public class FixedDescriptorMap extends MutableConstrainedMap implements IDescribedMap { - private final IMapper> mapper; - protected final Map> constraints; - - public FixedDescriptorMap(IMapper> mapper) { - this(mapper, new HashMap()); - } - - protected FixedDescriptorMap(IMapper> mapper, HashMap values) { - this(mapper, values, new HashMap>()); - } - - protected FixedDescriptorMap(IMapper> mapper, HashMap values, - HashMap> constraints) { - super(values); - this.mapper = mapper; - this.constraints = constraints; - } - - @Override - public IMutableConstrainedMap emptyWithSameConstraints() { - return new FixedDescriptorMap<>(mapper, new HashMap(), new HashMap<>(constraints)); - } - - @Override - public IMutableConstrainedMap mutableCopy() { - return new FixedDescriptorMap<>(mapper, new HashMap<>(values), new HashMap<>(constraints)); - } - - @Override - public IConstraint getConstraint(K key) { - IOptionDescriptor desc = mapper.get(key); - return (desc != null) ? desc.getConstraint() : constraints.get(key); - } - - @Override - protected IConstraint getSuggestedConstraint(K key) { - IOptionDescriptor desc = mapper.get(key); - return (desc != null) ? null : UnitLookup.PLAIN_TEXT.getPersister(); - } - - @Override - public IOptionDescriptor getDescribable(K key) { - return mapper.get(key); - } - - @Override - protected void addConstraint(K key, IConstraint constraint) { - IOptionDescriptor desc = mapper.get(key); - if (desc != null) { - throw new IllegalArgumentException("Key '" + key + "' is expressly prohibited in this map."); //$NON-NLS-1$ //$NON-NLS-2$ - } - constraints.put(key, constraint); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/IMapper.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/IMapper.java deleted file mode 100644 index 9b71cf81..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/IMapper.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.Map; - -/** - * Simple mapping function, to be replaced with java.util.function.Function in JDK 8. - * - * @param - * key - * @param - * value - */ -public interface IMapper { - public static class MapMapper implements IMapper { - private final Map map; - - public MapMapper(Map map) { - this.map = map; - } - - @Override - public V get(K key) { - return map.get(key); - } - } - - V get(K key); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KeyTranslatingMap.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KeyTranslatingMap.java deleted file mode 100644 index d5f562f7..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KeyTranslatingMap.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import java.util.Map; -import java.util.Set; - -import org.openjdk.jmc.common.IDescribable; -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.QuantityConversionException; - -/** - * Abstract base class for {@link IConstrainedMap constrained map} wrappers that can re-map a fixed - * number of keys into other keys before delegating to the underlying map. All other keys are passed - * through. - * - * @param - * @param - */ -public abstract class KeyTranslatingMap> implements IConstrainedMap { - protected final M delegate; - private final Map translations; - - public KeyTranslatingMap(M delegate, Map translations) { - this.delegate = delegate; - this.translations = translations; - } - - protected final K translate(K key) { - K translation = translations.get(key); - return (translation != null) ? translation : key; - } - - @Override - public Set keySet() { - return delegate.keySet(); - } - - @Override - public Object get(K key) { - return delegate.get(translate(key)); - } - - @Override - public IConstraint getConstraint(K key) { - return delegate.getConstraint(translate(key)); - } - - @Override - public String getPersistableString(K key) { - return delegate.getPersistableString(translate(key)); - } - - @Override - public IMutableConstrainedMap emptyWithSameConstraints() { - return new Mutable<>(delegate.emptyWithSameConstraints(), translations); - } - - @Override - public IMutableConstrainedMap mutableCopy() { - return new Mutable<>(delegate.mutableCopy(), translations); - } - - public static class Constrained extends KeyTranslatingMap> { - public Constrained(IConstrainedMap delegate, Map translations) { - super(delegate, translations); - } - } - - public static class Described extends KeyTranslatingMap> implements IDescribedMap { - public Described(IDescribedMap delegate, Map translations) { - super(delegate, translations); - } - - @Override - public IDescribable getDescribable(K key) { - return delegate.getDescribable(translate(key)); - } - } - - public static class Mutable extends KeyTranslatingMap> - implements IMutableConstrainedMap { - public Mutable(IMutableConstrainedMap delegate, Map translations) { - super(delegate, translations); - } - - @Override - public void put(K key, Object value) throws QuantityConversionException { - delegate.put(translate(key), value); - } - - @Override - public void putPersistedString(K key, String persisted) throws QuantityConversionException { - delegate.putPersistedString(translate(key), persisted); - } - - @Override - public void put(K key, IConstraint constraint, T value) throws QuantityConversionException { - delegate.put(translate(key), value); - } - - @Override - public void putPersistedString(K key, IConstraint constraint, String persisted) - throws QuantityConversionException { - delegate.putPersistedString(translate(key), constraint, persisted); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownEventOptions.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownEventOptions.java deleted file mode 100644 index c27bc787..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownEventOptions.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.NANOSECOND; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.PERIOD_V1; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.PERIOD_V2; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POSITIVE_TIMESPAN; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; - -public class KnownEventOptions { - public final static String KEY_THRESHOLD = "threshold"; //$NON-NLS-1$ - public final static String KEY_STACKTRACE = "stackTrace"; //$NON-NLS-1$ - public final static String KEY_PERIOD = "period"; //$NON-NLS-1$ - public final static String KEY_ENABLED = "enabled"; //$NON-NLS-1$ - - private static final String ENABLED_LABEL = "Enabled"; - private static final String ENABLED_DESC = "Whether or not events of this type will be included."; - private static final String PERIOD_LABEL = "Period"; - private static final String PERIOD_DESC = "The request period."; - private static final String STACKTRACE_LABEL = "Stack Trace"; - private static final String STACKTRACE_DESC = "Whether or not to include stack traces in the events."; - private static final String THRESHOLD_LABEL = "Threshold"; - private static final String THRESHOLD_DESC = "Only include events with at least this duration."; - - public final static Map> EVENT_OPTIONS_BY_KEY_V1; - public final static Map> EVENT_OPTIONS_BY_KEY_V2; - - public final static IDescribedMap OPTION_DEFAULTS_V1; - public final static IDescribedMap OPTION_DEFAULTS_V2; - - static { - Map> eventOptionsV1 = new LinkedHashMap<>(); - // Options identical between JFR V1 and V2 - eventOptionsV1.put(KEY_THRESHOLD, option(KEY_THRESHOLD, POSITIVE_TIMESPAN, NANOSECOND.quantity(20), THRESHOLD_LABEL, THRESHOLD_DESC)); - eventOptionsV1.put(KEY_STACKTRACE, option(KEY_STACKTRACE, UnitLookup.FLAG.getPersister(), Boolean.TRUE, STACKTRACE_LABEL, STACKTRACE_DESC)); - eventOptionsV1.put(KEY_ENABLED, option(KEY_ENABLED, UnitLookup.FLAG.getPersister(), Boolean.TRUE, ENABLED_LABEL, ENABLED_DESC)); - - // Initialize V2 options from V1 options so far - Map> eventOptionsV2 = new LinkedHashMap<>(eventOptionsV1); - - // Option differing between JFR V1 and V2 - eventOptionsV1.put(KEY_PERIOD, option(KEY_PERIOD, PERIOD_V1, UnitLookup.MILLISECOND.quantity(20), PERIOD_LABEL, PERIOD_DESC)); - eventOptionsV2.put(KEY_PERIOD, option(KEY_PERIOD, PERIOD_V2, UnitLookup.MILLISECOND.quantity(20), PERIOD_LABEL, PERIOD_DESC)); - - EVENT_OPTIONS_BY_KEY_V1 = Collections.unmodifiableMap(eventOptionsV1); - EVENT_OPTIONS_BY_KEY_V2 = Collections.unmodifiableMap(eventOptionsV2); - - OPTION_DEFAULTS_V1 = new DefaultValueMap<>( - new EventOptionDescriptorMapper(EventTypeIDV1.class, eventOptionsV1, false)); - OPTION_DEFAULTS_V2 = new DefaultValueMap<>( - new EventOptionDescriptorMapper(EventTypeIDV2.class, eventOptionsV2, true)); - } - - private static OptionInfo option(String optionName, IConstraint constraint, T defaultValue, - String label, String desc) { - return new OptionInfo<>(label, desc, constraint, defaultValue); - } - - private KnownEventOptions() { - throw new AssertionError("Not to be instantiated!"); //$NON-NLS-1$ - } - -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownRecordingOptions.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownRecordingOptions.java deleted file mode 100644 index 8ad57387..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/KnownRecordingOptions.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.BYTE; -import static org.openjdk.jmc.common.unit.UnitLookup.FLAG; -import static org.openjdk.jmc.common.unit.UnitLookup.PLAIN_TEXT; -import static org.openjdk.jmc.common.unit.UnitLookup.SECOND; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POINT_IN_TIME; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POSITIVE_MEMORY; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POSITIVE_TIMESPAN; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DESTINATION_COMPRESSED; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DESTINATION_FILE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DUMP_ON_EXIT; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DURATION; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_MAX_AGE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_MAX_SIZE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_NAME; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_START_TIME; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_TO_DISK; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; - -public class KnownRecordingOptions { - public final static Map> DESCRIPTORS_BY_KEY_V1; - public final static Map> DESCRIPTORS_BY_KEY_V2; - - public final static IDescribedMap OPTION_DEFAULTS_V1; - public final static IDescribedMap OPTION_DEFAULTS_V2; - - private final static String KEY_TO_DISK_V2 = "disk"; //$NON-NLS-1$ - - private static final String RECORDING_NAME_LABEL = "Name"; - private static final String RECORDING_NAME_DESC = "Recording name"; - private static final String TO_DISK_LABEL = "To disk"; - private static final String TO_DISK_DESC = "Record to disk"; - private static final String DURATION_LABEL = "Duration"; - private static final String DURATION_DESC = "Duration of recording"; - private static final String MAXIMUM_SIZE_LABEL = "Max Size"; - private static final String MAXIMUM_SIZE_DESC = "Maximum size of recording"; - private static final String MAXIMUM_AGE_LABEL = "Max Age"; - private static final String MAXIMUM_AGE_DESC = "Maximum age of the events in the recording"; - // Options unique to JFR V1 - private static final String DESTINATION_FILE_LABEL = "File Name"; - private static final String DESTINATION_FILE_DESC = "Target file for resulting recording"; - private static final String START_TIME_LABEL = "Start Time"; - private static final String START_TIME_DESC = "Start time of recording"; - private static final String DESTINATION_COMPRESSED_LABEL = "File Compression"; - private static final String DESTINATION_COMPRESSED_DESC = "Should destination file be compressed"; - // Option unique to JFR V2 - private static final String DUMP_ON_EXIT_LABEL = "Dump on Exit"; - private static final String DUMP_ON_EXIT_DESC = "Dump recording data to disk on JVM exit"; - - - static { - Map> recOptionsV1 = new LinkedHashMap<>(); - // Options common to JFR V1 and V2 - recOptionsV1.put(KEY_NAME, option("RECORDING_NAME", PLAIN_TEXT.getPersister(), //$NON-NLS-1$ - "Recording", RECORDING_NAME_LABEL, RECORDING_NAME_DESC)); - recOptionsV1.put(KEY_DURATION, option("DURATION", POSITIVE_TIMESPAN, SECOND.quantity(30), DURATION_LABEL, DURATION_DESC)); //$NON-NLS-1$ - recOptionsV1.put(KEY_MAX_SIZE, option("MAXIMUM_SIZE", POSITIVE_MEMORY, BYTE.quantity(0), MAXIMUM_SIZE_LABEL, MAXIMUM_SIZE_DESC)); //$NON-NLS-1$ - recOptionsV1.put(KEY_MAX_AGE, option("MAXIMUM_AGE", POSITIVE_TIMESPAN, SECOND.quantity(0), MAXIMUM_AGE_LABEL, MAXIMUM_AGE_DESC)); //$NON-NLS-1$ - - // Initialize V2 options from V1 options so far - Map> recOptionsV2 = new LinkedHashMap<>(recOptionsV1); - - // Options unique to JFR V1 - recOptionsV1.put(KEY_DESTINATION_FILE, - option("DESTINATION_FILE", UnitLookup.PLAIN_TEXT.getPersister(), "recording.jfr", DESTINATION_FILE_LABEL, DESTINATION_FILE_DESC)); //$NON-NLS-1$ //$NON-NLS-2$ - recOptionsV1.put(KEY_START_TIME, option("START_TIME", POINT_IN_TIME, null, START_TIME_LABEL, START_TIME_DESC)); //$NON-NLS-1$ - recOptionsV1.put(KEY_DESTINATION_COMPRESSED, - option("DESTINATION_COMPRESSED", FLAG.getPersister(), Boolean.FALSE, DESTINATION_COMPRESSED_LABEL, DESTINATION_COMPRESSED_DESC)); //$NON-NLS-1$ - // Option renamed from JFR V1 to V2 - OptionInfo diskOption = option("TO_DISK", FLAG.getPersister(), Boolean.FALSE, TO_DISK_LABEL, TO_DISK_DESC); //$NON-NLS-1$ - recOptionsV1.put(KEY_TO_DISK, diskOption); - recOptionsV2.put(KEY_TO_DISK_V2, diskOption); - - // Option unique to JFR V2 - recOptionsV2.put(KEY_DUMP_ON_EXIT, option("DUMP_ON_EXIT", FLAG.getPersister(), Boolean.FALSE, DUMP_ON_EXIT_LABEL, DUMP_ON_EXIT_DESC)); //$NON-NLS-1$ - - DESCRIPTORS_BY_KEY_V1 = Collections.unmodifiableMap(recOptionsV1); - DESCRIPTORS_BY_KEY_V2 = Collections.unmodifiableMap(recOptionsV2); - - OPTION_DEFAULTS_V1 = new DefaultValueMap<>(recOptionsV1); - OPTION_DEFAULTS_V2 = new KeyTranslatingMap.Described<>(new DefaultValueMap<>(recOptionsV2), - Collections.singletonMap(KEY_TO_DISK, KEY_TO_DISK_V2)); - } - - private static OptionInfo option(String optionName, IConstraint constraint, T defaultValue, - String label, String desc) { - return new OptionInfo<>(label, desc, constraint, defaultValue); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationException.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationException.java deleted file mode 100644 index a9d68bfd..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -public class ValidationException extends IllegalArgumentException { - - private static final long serialVersionUID = 1L; - private final String localizedMessage; - - public ValidationException(String message, String localizedMessage) { - super(message); - this.localizedMessage = localizedMessage; - } - - @Override - public String getLocalizedMessage() { - return localizedMessage; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationToolkit.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationToolkit.java deleted file mode 100644 index c7230f19..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/internal/ValidationToolkit.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.internal; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.QuantityConversionException; - -/** - * Helpers for validating entire settings maps. - */ -public final class ValidationToolkit { - - /** - * Will validate the entire map and collect all validation problems in a big validation - * exception. If there are no errors, no exception will be thrown - * - * @param options - * @throws ValidationException - */ - public static void validate(IConstrainedMap options) throws ValidationException { - StringBuilder messageBuilder = new StringBuilder(); - StringBuilder localizedMessageBuilder = new StringBuilder(); - boolean caught = false; - try { - for (K key : options.keySet()) { - Object value = options.get(key); - if (value != null) { - validate(options.getConstraint(key), value); - } - } - } catch (QuantityConversionException e) { - caught = true; - messageBuilder.append(e.getMessage()); - messageBuilder.append(System.getProperty("line.separator")); //$NON-NLS-1$ - localizedMessageBuilder.append(e.getLocalizedMessage()); - localizedMessageBuilder.append(System.getProperty("line.separator")); //$NON-NLS-1$ - } catch (IllegalArgumentException e) { - caught = true; - messageBuilder.append(e.getMessage()); - messageBuilder.append(System.getProperty("line.separator")); //$NON-NLS-1$ - localizedMessageBuilder.append(e.getLocalizedMessage()); - localizedMessageBuilder.append(System.getProperty("line.separator")); //$NON-NLS-1$ - } - if (caught) { - throw new ValidationException(messageBuilder.toString(), localizedMessageBuilder.toString()); - } - } - - @SuppressWarnings("unchecked") - private static void validate(IConstraint constraint, Object value) throws QuantityConversionException { - constraint.validate((T) value); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/recording/RecordingOptionsBuilder.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/recording/RecordingOptionsBuilder.java deleted file mode 100644 index 26ee6bf3..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/recording/RecordingOptionsBuilder.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.recording; - -import java.util.Date; -import java.util.Properties; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.flightrecorder.configuration.IRecorderConfigurationService; -import org.openjdk.jmc.flightrecorder.configuration.internal.ValidationToolkit; - -/** - * Builder to help build recording options. These are typically the options relevant to the - * recording other than the event type options, such as the duration or when to start the recording. - */ -public class RecordingOptionsBuilder { - public final static String KEY_NAME = "name"; //$NON-NLS-1$ - /** The requested duration of a recording */ - public final static String KEY_DURATION = "duration"; //$NON-NLS-1$ - public final static String KEY_DESTINATION_FILE = "destinationFile"; //$NON-NLS-1$ - public final static String KEY_DESTINATION_COMPRESSED = "destinationCompressed"; //$NON-NLS-1$ - public final static String KEY_START_TIME = "startTime"; //$NON-NLS-1$ - public final static String KEY_MAX_SIZE = "maxSize"; //$NON-NLS-1$ - public final static String KEY_MAX_AGE = "maxAge"; //$NON-NLS-1$ - public final static String KEY_TO_DISK = "toDisk"; //$NON-NLS-1$ - public final static String KEY_DUMP_ON_EXIT = "dumpOnExit"; //$NON-NLS-1$ - private final static String DEFAULT_NAME = "Unnamed Recording"; //$NON-NLS-1$ - private final IMutableConstrainedMap map; - - public RecordingOptionsBuilder(IRecorderConfigurationService service) throws QuantityConversionException { - this(service.getDefaultRecordingOptions().emptyWithSameConstraints()); - } - - public RecordingOptionsBuilder(IMutableConstrainedMap map) throws QuantityConversionException { - this.map = map; - name(DEFAULT_NAME); - } - - public RecordingOptionsBuilder duration(long duration) throws QuantityConversionException { - return duration(UnitLookup.MILLISECOND.quantity(duration)); - } - - public RecordingOptionsBuilder duration(IQuantity duration) throws QuantityConversionException { - map.put(KEY_DURATION, duration); - return this; - } - - public RecordingOptionsBuilder destinationFile(String fileName) throws QuantityConversionException { - map.put(KEY_DESTINATION_FILE, fileName); - return this; - } - - public RecordingOptionsBuilder destinationCompressed(boolean compress) throws QuantityConversionException { - map.put(KEY_DESTINATION_COMPRESSED, Boolean.valueOf(compress)); - return this; - } - - public RecordingOptionsBuilder startTime(Date startTime) throws QuantityConversionException { - return startTime(UnitLookup.fromDate(startTime)); - } - - public RecordingOptionsBuilder startTime(IQuantity startTime) throws QuantityConversionException { - map.put(KEY_START_TIME, startTime); - return this; - } - - public RecordingOptionsBuilder maxSize(long maxSize) throws QuantityConversionException { - return maxSize(UnitLookup.BYTE.quantity(maxSize)); - } - - public RecordingOptionsBuilder maxSize(IQuantity maxSize) throws QuantityConversionException { - map.put(KEY_MAX_SIZE, maxSize); - return this; - } - - public RecordingOptionsBuilder maxAge(long maxAge) throws QuantityConversionException { - return maxAge(UnitLookup.SECOND.quantity(maxAge)); - } - - public RecordingOptionsBuilder maxAge(IQuantity maxAge) throws QuantityConversionException { - map.put(KEY_MAX_AGE, maxAge); - return this; - } - - public RecordingOptionsBuilder name(String name) throws QuantityConversionException { - map.put(KEY_NAME, name); - return this; - } - - public RecordingOptionsBuilder toDisk(boolean toDisk) throws QuantityConversionException { - map.put(KEY_TO_DISK, Boolean.valueOf(toDisk)); - return this; - } - - /** - * Will initialize the builder from a properties collection. Typing of individual content will - * be attempted. - */ - public RecordingOptionsBuilder fromProperties(Properties props) throws QuantityConversionException { - for (Object element : props.keySet()) { - String key = (String) element; - addByKey(key, props.getProperty(key)); - } - return this; - } - - public RecordingOptionsBuilder addByKey(String key, String property) throws QuantityConversionException { - map.putPersistedString(key, property); - return this; - } - - public IConstrainedMap build() throws QuantityConversionException { - ValidationToolkit.validate(map); - return map; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/spi/IConfigurationStorageDelegate.java b/src/main/java/org/openjdk/jmc/flightrecorder/configuration/spi/IConfigurationStorageDelegate.java deleted file mode 100644 index b9eb2670..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/configuration/spi/IConfigurationStorageDelegate.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.configuration.spi; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Storage delegate for storing text based configuration files. It can be thought of as a fancy URL - * wrapper. - */ -public interface IConfigurationStorageDelegate { - /** - * The only currently supported character encoding. - */ - final static String CHARSET_UTF8 = "UTF-8"; //$NON-NLS-1$ - - /** - * @return an input stream or null if the underlying storage does not yet have any contents. - */ - InputStream getContents(); - - /** - * If the underlying storage can be saved to. This method can be used to enable or disable save - * options. Also optionally to avoid having to generate the content for {@link #save(String)}, - * when it won't be used. - * - * @return - */ - boolean isSaveable(); - - /** - * Save the given content string to the underlying storage, replacing previous content. The - * character encoding is currently forced to be {@value #CHARSET_UTF8}, as specified by - * {@link #CHARSET_UTF8}, which is important for XML stating the encoding. - *

- * NOTE: Passing the contents as a String are fine for small files that are seldom written to. - * Should this method be used more often or with larger files, a callback with methods for - * writing to a output stream and for providing an input stream (for IResource destinations) - * could be passed instead. - * - * @param fileContent - * @return true iff the save operation succeded. - * @throws IOException - * if some problem occurred while writing to the underlying storage. The contents - * might have been partially written. - */ - boolean save(String fileContent) throws IOException; - - /** - * If the underlying storage can likely be deleted permanently. Note that returning true here - * does not guarantee that a {@link #delete()} will succeed, only that it can be attempted. - * - * @return - */ - boolean isDeletable(); - - /** - * Attempt to delete the underlying storage. If successful, the storage delegate should no - * longer be used, which might be enforced in the future. - * - * @return true iff the underlying storage was deleted. - */ - boolean delete(); - - /** - * Get additional information on the underlying storage, if available. - * - * @return a descriptive string which the name of the template can be augmented with, or null. - */ - String getLocationInfo(); - - /** - * Get information on the file system location for the underlying storage, if available. - * - * @return a string that represents the file system location of this template, or null. - */ - String getLocationPath(); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/ControlPanel.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/ControlPanel.java deleted file mode 100644 index 46b43767..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/ControlPanel.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui; - -import java.util.logging.Level; -import java.util.logging.Logger; - -public class ControlPanel { - - public static ControlPanel getDefault() { - return new ControlPanel(); - } - - public Logger getLogger() { - Logger logger = Logger.getGlobal(); - logger.setLevel(Level.ALL); - return logger; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/IXMLValidator.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/IXMLValidator.java deleted file mode 100644 index 91b70467..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/IXMLValidator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.util.List; -import java.util.Set; - -/** - * Stateless validator of {@link XMLModel}s. Preliminary interface until generic XML validation has - * been separated from schema specifics. Currently also provides the starting point for the XML - * grammar. - */ -interface IXMLValidator { - /** - * Validate all aspects of the given model. - * - * @param model - * @return - */ - List validate(XMLModel model); - - /** - * The expected root element type for models this validator validates. - * - * @return an XML element type - */ - XMLTag getRootElementType(); - - /** - * A set of {@link XMLTag}s that should be output on one line to make the XML more readable. - * (This may seem out of place in the validator. It was put here mostly because it was simplest, - * but it was also thought that it might be useful when outputting validation problems.) - * - * @return - */ - Set getElementsTooKeepOnOneLine(); -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCGrammar.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCGrammar.java deleted file mode 100644 index bf0b4708..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCGrammar.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * Describes the XML grammar of a Flight Recorder Configuration. This should match with the XML - * Schema {@code jfc_.xsd}, to the extent that the grammar can be expressed in both. - */ -@SuppressWarnings("nls") -public final class JFCGrammar { - /** - * XML elements that should be kept on one line when outputting the {@link XMLModel} as text. - */ - public static final Set ONE_LINE_ELEMENTS; - - public static final String[] DATA_TYPE = {"int", "long", "string", "boolean"}; - public static final String FLAG_CONTENT_TYPE = "flag"; - public static final String TIMESPAN_CONTENT_TYPE = "timespan"; - public static final String[] CONTENT_TYPE = {FLAG_CONTENT_TYPE, TIMESPAN_CONTENT_TYPE}; - public static final String[] OPERATORS = {"equal"}; - - public static final XMLAttribute ATTRIBUTE_LABEL_MANDATORY = new XMLAttribute("label", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_LABEL = new XMLAttribute("label", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_DESCRIPTION = new XMLAttribute("description", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_NAME = new XMLAttribute("name", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_NAME_DEFINITION = new XMLAttribute("name", true, XMLNodeType.DEFINITION); - - public static final XMLAttribute ATTRIBUTE_DEFAULT = new XMLAttribute("default", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_VALUE = new XMLAttribute("value", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_TRUE = new XMLAttribute("true", false, XMLNodeType.TEXT, "true"); - // NOTE: Do not provide a default value for false, since that would prevent multiple conditions for the same variable from working. - // Compare with the else attribute in Apache Ant's condition task. - public static final XMLAttribute ATTRIBUTE_FALSE = new XMLAttribute("false", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_PATH = new XMLAttribute("path", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_VERSION = new XMLAttribute("version", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_PROVIDER = new XMLAttribute("provider", false, XMLNodeType.TEXT); - - public static final XMLAttribute ATTRIBUTE_NAME_REFERENCE = new XMLAttribute("name", false, XMLNodeType.REFERENCE); - public static final XMLAttribute ATTRIBUTE_CONTROL_REFERENCE = new XMLAttribute("control", false, - XMLNodeType.REFERENCE); - public static final XMLAttribute ATTRIBUTE_OPERATOR = new XMLAttribute("operator", true, XMLNodeType.TEXT, - OPERATORS); - public static final XMLAttribute ATTRIBUTE_URI = new XMLAttribute("uri", true, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_CONTENT_TYPE = new XMLAttribute("contentType", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_TYPE = new XMLAttribute("type", true, XMLNodeType.TEXT, DATA_TYPE); - public static final XMLAttribute ATTRIBUTE_MINIMUM = new XMLAttribute("minimum", false, XMLNodeType.TEXT); - public static final XMLAttribute ATTRIBUTE_MAXIMUM = new XMLAttribute("maximum", false, XMLNodeType.TEXT); - - public static final XMLTag ROOT = new XMLTag("root"); - public static final XMLTag TAG_CONFIGURATION_V1 = new XMLTag.Predicated("configuration", ATTRIBUTE_VERSION, "1.0"); - public static final XMLTag TAG_CONFIGURATION_V2 = new XMLTag("configuration"); - public static final XMLTag TAG_PRODUCER = new XMLTag("producer"); - public static final XMLTag TAG_CONTROL = new XMLTag("control"); - public static final XMLTag TAG_SELECTION = new XMLTag("selection"); - public static final XMLTag TAG_OPTION = new XMLTag("option", XMLNodeType.ELEMENT_WITH_CONTENT); - public static final XMLTag TAG_FLAG = new XMLTag("flag", XMLNodeType.ELEMENT_WITH_CONTENT); - public static final XMLTag TAG_TEXT = new XMLTag("text", XMLNodeType.ELEMENT_WITH_CONTENT);; - public static final XMLTag TAG_VARIABLE = new XMLTag("variable", XMLNodeType.ELEMENT_WITH_CONTENT); - public static final XMLTag TAG_CONDITION = new XMLTag("condition"); - public static final XMLTag TAG_AND = new XMLTag("and", XMLNodeType.ELEMENT_WITH_AT_LEAST_ONE_CHILD); - public static final XMLTag TAG_OR = new XMLTag("or", XMLNodeType.ELEMENT_WITH_AT_LEAST_ONE_CHILD); - public static final XMLTag TAG_NOT = new XMLTag("not", XMLNodeType.ELEMENT_WITH_AT_LEAST_ONE_CHILD); - public static final XMLTag TAG_TEST = new XMLTag("test"); - public static final XMLTag TAG_EVENTTYPE_V1 = new XMLTag("event"); - public static final XMLTag TAG_EVENTTYPE_V2 = new XMLTag("event"); - public static final XMLTag TAG_SETTING = new XMLTag("setting", XMLNodeType.ELEMENT_WITH_CONTENT); - public static final XMLTag TAG_CATEGORY = new XMLTag("category"); - - /* - * Currently used values for the "name" attribute of elements. With the exception of - * "enabled", these shouldn't really be treated specially anywhere, since more will be added in - * "JFR 2.0". However, since some currently are special treated, we should at least have - * constants for them, so their usage can be tracked. - * - * FIXME: These should probably not be defined in multiple places. - * - * But since they were only defined in the RJMX project, which is utterly wrong (in - * org.openjdk.jmc.rjmx.services.flr.internal.RecordingSettingsToolkit), they are temporarily - * defined here. - */ - public static final String SETTING_ENABLED = "enabled"; - public static final String SETTING_STACKTRACE = "stackTrace"; - public static final String SETTING_THRESHOLD = "threshold"; - public static final String SETTING_PERIOD = "period"; - - public static final String PERIOD_EVERY_CHUNK = "everyChunk"; - - static { - // Wire it up! - ROOT.add(TAG_CONFIGURATION_V1, TAG_CONFIGURATION_V2); - - TAG_CONFIGURATION_V1.add(TAG_PRODUCER, ATTRIBUTE_VERSION, ATTRIBUTE_NAME, ATTRIBUTE_DESCRIPTION, - ATTRIBUTE_PROVIDER); - - TAG_PRODUCER.add(TAG_CONTROL, TAG_SETTING, TAG_EVENTTYPE_V1, ATTRIBUTE_URI, ATTRIBUTE_LABEL, - ATTRIBUTE_DESCRIPTION); - - TAG_EVENTTYPE_V1.add(TAG_SETTING, ATTRIBUTE_PATH, ATTRIBUTE_LABEL, ATTRIBUTE_DESCRIPTION); - - TAG_CONFIGURATION_V2.add(TAG_CONTROL, TAG_CATEGORY, TAG_EVENTTYPE_V2, ATTRIBUTE_VERSION, - ATTRIBUTE_LABEL_MANDATORY, ATTRIBUTE_DESCRIPTION, ATTRIBUTE_PROVIDER); - - TAG_CATEGORY.add(ATTRIBUTE_LABEL_MANDATORY, TAG_CATEGORY, TAG_EVENTTYPE_V2); - - TAG_EVENTTYPE_V2.add(TAG_SETTING, ATTRIBUTE_NAME, ATTRIBUTE_LABEL, ATTRIBUTE_DESCRIPTION); - - TAG_CONTROL.add(TAG_FLAG, TAG_TEXT, TAG_SELECTION, TAG_VARIABLE, TAG_CONDITION); - - TAG_SELECTION.add(TAG_OPTION, ATTRIBUTE_NAME_DEFINITION, ATTRIBUTE_DEFAULT, ATTRIBUTE_LABEL_MANDATORY, - ATTRIBUTE_DESCRIPTION); - - TAG_OPTION.add(ATTRIBUTE_LABEL_MANDATORY, ATTRIBUTE_DESCRIPTION, ATTRIBUTE_NAME); - - TAG_TEXT.add(ATTRIBUTE_NAME_DEFINITION, ATTRIBUTE_LABEL_MANDATORY, ATTRIBUTE_DESCRIPTION, - ATTRIBUTE_CONTENT_TYPE, ATTRIBUTE_MINIMUM, ATTRIBUTE_MAXIMUM); - - TAG_VARIABLE.add(ATTRIBUTE_NAME_DEFINITION); - - TAG_CONDITION.add(TAG_OR, TAG_AND, TAG_NOT, TAG_TEST, ATTRIBUTE_NAME_DEFINITION, ATTRIBUTE_TRUE, - ATTRIBUTE_FALSE); - - TAG_TEST.add(ATTRIBUTE_NAME_REFERENCE, ATTRIBUTE_CONTENT_TYPE, ATTRIBUTE_OPERATOR, ATTRIBUTE_VALUE); - - TAG_OR.add(TAG_AND, TAG_NOT, TAG_TEST, TAG_OR); - - TAG_NOT.add(TAG_OR, TAG_AND, TAG_TEST, TAG_NOT); - - TAG_AND.add(TAG_OR, TAG_NOT, TAG_TEST, TAG_AND); - - TAG_FLAG.add(ATTRIBUTE_NAME_DEFINITION, ATTRIBUTE_LABEL_MANDATORY, ATTRIBUTE_DESCRIPTION); - - TAG_SETTING.add(ATTRIBUTE_NAME, ATTRIBUTE_CONTROL_REFERENCE, ATTRIBUTE_LABEL, ATTRIBUTE_DESCRIPTION, - ATTRIBUTE_CONTENT_TYPE); - - { - Set oneLineElements = new HashSet<>(); - oneLineElements.add(TAG_SETTING); - oneLineElements.add(TAG_OPTION); - oneLineElements.add(TAG_NOT); - oneLineElements.add(TAG_AND); - oneLineElements.add(TAG_OR); - oneLineElements.add(TAG_TEST); - ONE_LINE_ELEMENTS = Collections.unmodifiableSet(oneLineElements); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCXMLValidator.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCXMLValidator.java deleted file mode 100644 index 988adfbf..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/JFCXMLValidator.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_LABEL_MANDATORY; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_NAME; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_CONFIGURATION_V1; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A stateless validator of {@link XMLModel}s used for Flight Recording Configurations. Should - * perhaps factor out aspects that can be expressed using {@link JFCGrammar}. - */ -public final class JFCXMLValidator implements IXMLValidator { - private static final JFCXMLValidator SHARED = new JFCXMLValidator(); - - private static final Logger LOGGER = Logger.getLogger("org.openjdk.jmc.ui"); - - interface IXMLNodeValidator { - XMLValidationResult validate(Object parentNode, Object node); - } - - private static class DanglingReference implements IXMLNodeValidator { - private final Set m_variableNames; - private final URI m_baseURI; - - DanglingReference(Set variableNames, URI baseURI) { - m_variableNames = variableNames; - m_baseURI = baseURI; - } - - @Override - public XMLValidationResult validate(Object parentNode, Object node) { - if (node instanceof XMLAttributeInstance) { - XMLAttributeInstance i = (XMLAttributeInstance) node; - if (i.getAttribute().getType() == XMLNodeType.REFERENCE) { - String variableName = i.getValue(); - if (!variableName.isEmpty()) { - variableName = m_baseURI.resolve(variableName).toString(); - if (!m_variableNames.contains(variableName)) { - return new XMLValidationResult(i, "Variable '" + variableName + "' can't be found.", true); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - } - return XMLValidationResult.OK; - } - }; - - private static class DuplicateDefinition implements IXMLNodeValidator { - private final Set m_variables = new HashSet<>(); - - @Override - public XMLValidationResult validate(Object parentNode, Object node) { - if (node instanceof XMLAttributeInstance) { - XMLAttributeInstance i = (XMLAttributeInstance) node; - if (i.getAttribute().getType() == XMLNodeType.DEFINITION) { - if (parentNode instanceof XMLTagInstance) { - // Only conditions are allowed to define duplicates. - XMLTagInstance parent = (XMLTagInstance) parentNode; - if (parent.getTag() == JFCGrammar.TAG_CONDITION) { - return XMLValidationResult.OK; - } - } - String name = i.getValue(); - if (m_variables.contains(name)) { - return new XMLValidationResult(i, "Variable '" + name + "' is defined more than once.", true); //$NON-NLS-1$ //$NON-NLS-2$ - } - m_variables.add(i.getValue()); - } - } - return XMLValidationResult.OK; - } - }; - - private static class MissingChild implements IXMLNodeValidator { - @Override - public XMLValidationResult validate(Object parentNode, Object node) { - if (node instanceof XMLTagInstance) { - XMLTagInstance i = (XMLTagInstance) node; - if (i.getTag().getType() == XMLNodeType.ELEMENT_WITH_AT_LEAST_ONE_CHILD - && i.getTagsInstances().isEmpty()) { - return new XMLValidationResult(i, i.getTag().getName() + " must have at least on child element.", //$NON-NLS-1$ - true); - } - } - return XMLValidationResult.OK; - } - }; - - private static class InvalidAttribute implements IXMLNodeValidator { - @Override - public XMLValidationResult validate(Object parentNode, Object node) { - if (node instanceof XMLAttributeInstance) { - XMLAttributeInstance instance = (XMLAttributeInstance) node; - XMLAttribute attribute = instance.getAttribute(); - if (attribute.isRequired() && instance.isImplicitDefault()) { - return new XMLValidationResult(instance, - "'" + instance.getAttribute().getName() + "' is missing content.", true); //$NON-NLS-1$ //$NON-NLS-2$ - } - Collection validValues = attribute.getValidValues(); - if (!validValues.isEmpty() && !validValues.contains(instance.getValue().toLowerCase())) { - StringBuilder textBuf = new StringBuilder("Attribute '"); //$NON-NLS-1$ - textBuf.append(instance.getAttribute().getName()); - textBuf.append("' must have one of these values: \""); //$NON-NLS-1$ - Iterator values = validValues.iterator(); - while (values.hasNext()) { - textBuf.append(values.next()); - if (values.hasNext()) { - textBuf.append("\", \""); //$NON-NLS-1$ - } - } - textBuf.append("\"."); //$NON-NLS-1$ - - return new XMLValidationResult(instance, textBuf.toString(), true); - } - } - return XMLValidationResult.OK; - } - } - - public static IXMLValidator getValidator() { - return SHARED; - } - - private JFCXMLValidator() { - } - - @Override - public List validate(XMLModel model) { - String label; - if (model.getRoot().getTag() == TAG_CONFIGURATION_V1) { - label = model.getRoot().getValue(ATTRIBUTE_NAME); - } else { - label = model.getRoot().getValue(ATTRIBUTE_LABEL_MANDATORY); - } - LOGGER.log(Level.FINE, "Running JFC validation on " + label); //$NON-NLS-1$ - List errors = new ArrayList<>(); - XMLTagInstance configuration = model.getRoot(); - List producers = configuration.getTagsInstances(JFCGrammar.TAG_PRODUCER); - // General stuff - collectErrors(null, configuration, new MissingChild(), errors); - collectErrors(null, configuration, new InvalidAttribute(), errors); - - /* - * Check variables for each producer Variables can span multiple producers, if the are - * prefixed with producer uri. Example: http://www.oracle.com/hotspot/jvm/file-io-threshold - */ - Set qualifiedVariableNames = createQualifiedVariableSet(producers, JFCGrammar.ATTRIBUTE_URI); - for (XMLTagInstance producer : producers) { - URI producerURI = createTrailingSlashURI(producer.getValue(JFCGrammar.ATTRIBUTE_URI)); - collectErrors(null, producer, new DuplicateDefinition(), errors); - collectErrors(null, producer, new DanglingReference(qualifiedVariableNames, producerURI), errors); - } - return errors; - } - - private void collectErrors(Object parent, Object o, IXMLNodeValidator validator, List result) { - result.add(validator.validate(parent, o)); - if (o instanceof XMLTagInstance) { - XMLTagInstance t = (XMLTagInstance) o; - for (XMLTagInstance i : t.getTagsInstances()) { - collectErrors(o, i, validator, result); - } - for (XMLAttributeInstance i : t.getAttributeInstances()) { - collectErrors(o, i, validator, result); - } - } - } - - // FIXME: Generalize so that an overriding base URI can be applied at any element level? - // Consider xml:base (http://en.wikipedia.org/wiki/XML_Base). - public static Set createQualifiedVariableSet( - List rootElements, XMLAttribute baseUriAttribute) { - List variables = new ArrayList<>(); - for (XMLTagInstance rootElement : rootElements) { - URI baseURI = createTrailingSlashURI(rootElement.getValue(baseUriAttribute)); - Queue q = new LinkedList<>(); - q.add(rootElement); - while (!q.isEmpty()) { - Object o = q.poll(); - if (o instanceof XMLTagInstance) { - for (XMLTagInstance tagInstance : ((XMLTagInstance) o).getTagsInstances()) { - q.add(tagInstance); - } - for (XMLAttributeInstance attributeInstance : ((XMLTagInstance) o).getAttributeInstances()) { - q.add(attributeInstance); - } - } - - if (o instanceof XMLAttributeInstance) { - XMLAttributeInstance ai = (XMLAttributeInstance) o; - if (ai.getAttribute().getType() == XMLNodeType.DEFINITION) { - String value = ai.getValue(); - if (!value.trim().isEmpty()) { - String variableName = baseURI.resolve(value).toString(); - variables.add(variableName); - } - } - } - } - } - variables.sort(null); - return new LinkedHashSet<>(variables); - } - - @Override - public XMLTag getRootElementType() { - return JFCGrammar.ROOT; - } - - @Override - public Set getElementsTooKeepOnOneLine() { - return JFCGrammar.ONE_LINE_ELEMENTS; - } - - private static URI createTrailingSlashURI(String uri) { - if (uri.endsWith("/")) { //$NON-NLS-1$ - return URI.create(uri); - } - return URI.create(uri + '/'); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/PrettyPrinter.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/PrettyPrinter.java deleted file mode 100644 index 4ff81238..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/PrettyPrinter.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.io.PrintWriter; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.openjdk.jmc.common.util.XmlToolkit; - -final class PrettyPrinter { - private final PrintWriter m_out; - // Elements to output on a single line - private final Set m_detailTags; - - /** - * Create a pretty printer to output {@link XMLModel}s as text. - * - * @param out - * where to output - * @param oneLineElements - * XML tags to output on a single line - */ - PrettyPrinter(PrintWriter out, Set oneLineElements) { - m_out = out; - if (oneLineElements != null) { - m_detailTags = oneLineElements; - } else { - m_detailTags = Collections.emptySet(); - } - } - - public void print(XMLModel model) { - printHeader(); - prettyPrint("", model.getRoot()); //$NON-NLS-1$ - } - - private void printHeader() { - // FIXME: Don't hardcode to UTF8. - m_out.println(""); //$NON-NLS-1$ - } - - private void prettyPrint(final String padding, XMLTagInstance tagInstance) { - String tagName = tagInstance.getTag().getName(); - - if (tagInstance.getTagsInstances().size() == 0 && !tagInstance.hasContent()) { - m_out.print(padding + '<' + tagName); - printAttributes(tagInstance.getAttributeInstances()); - m_out.println("/>"); //$NON-NLS-1$ - } else { - // TODO: clean up logic - m_out.print(padding + '<' + tagName); - printAttributes(tagInstance.getAttributeInstances()); - m_out.print('>'); - m_out.print(XmlToolkit.escapeAll(tagInstance.getContent().trim())); - if (tagInstance.getTagsInstances().size() > 0) { - m_out.println(""); //$NON-NLS-1$ - boolean first = true; - for (XMLTagInstance childTagInstance : tagInstance.getTagsInstances()) { - boolean keepOnOneRow = m_detailTags.contains(childTagInstance.getTag()); - if (first && !keepOnOneRow) { - m_out.println(""); //$NON-NLS-1$ - } - prettyPrint(padding + " ", childTagInstance); //$NON-NLS-1$ - if (!keepOnOneRow) { - m_out.println(""); //$NON-NLS-1$ - } - first = false; - } - m_out.println(padding + "'); //$NON-NLS-1$ - } else { - m_out.println("'); //$NON-NLS-1$ - } - } - } - - private void printAttributes(List attributeInstances) { - for (XMLAttributeInstance ai : attributeInstances) { - if (!ai.isImplicitDefault() || ai.getAttribute().isRequired()) { - m_out.print(' '); - m_out.print(ai.getAttribute().getName()); - m_out.print("=\""); //$NON-NLS-1$ - m_out.print(XmlToolkit.escapeAll(ai.getValue())); - m_out.print('\"'); - } - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttribute.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttribute.java deleted file mode 100644 index c9910dc4..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttribute.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Holds metadata about a tag attribute. - */ -public final class XMLAttribute extends XMLNode { - private final Collection m_validValues; - private final String m_defaultValue; - private final boolean m_required; - - /** - * Creates an attribute allowing any value, with no default value. - * - * @param name - * the name of the attribute - * @param required - * if the attribute is necessary - * @param type - * which kind of node it is - */ - public XMLAttribute(String name, boolean required, XMLNodeType type) { - this(name, required, type, (String) null); - } - - /** - * Creates an attribute with a specified default value, but allowing any value. - * - * @param name - * the name of the attribute - * @param required - * if the attribute is necessary - * @param type - * which kind of node it is - * @param defaultValue - * the default value. (Any value will still be allowed.) - */ - public XMLAttribute(String name, boolean required, XMLNodeType type, String defaultValue) { - super(name, type); - - m_validValues = Collections.emptyList(); - m_defaultValue = defaultValue; - m_required = required; - } - - /** - * Creates an attribute only allowing specified values, with the first value as default. - * - * @param name - * the name of the attribute - * @param required - * if the attribute is necessary - * @param type - * which kind of node it is - * @param values - * valid values. The first value in the array becomes the default value. - */ - public XMLAttribute(String name, boolean required, XMLNodeType type, String ... values) { - super(name, type); - - assert values.length > 0; - List lowerCasedValues = new ArrayList<>(values.length); - for (String value : values) { - assert value != null; - lowerCasedValues.add(value.trim().toLowerCase()); - } - m_validValues = Collections.unmodifiableList(lowerCasedValues); - m_defaultValue = lowerCasedValues.get(0); - m_required = required; - } - - public boolean isRequired() { - return m_required; - } - - /** - * A collection of valid values, all in lower case. - * - * @return a collection of valid values, or an empty collection if any value is valid. - */ - public Collection getValidValues() { - return m_validValues; - } - - /** - * @return the default value, or null if none has been set explicitly - */ - public String getDefaultValue() { - return m_defaultValue; - } - - @Override - public String toString() { - return "Attribute: " + getName(); //$NON-NLS-1$ - } - - public String getLabel() { - if (getName().length() >= 2) { - return getName().substring(0, 1).toUpperCase() + getName().substring(1); - } else { - return getName(); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttributeInstance.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttributeInstance.java deleted file mode 100644 index 5e40f425..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLAttributeInstance.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -public final class XMLAttributeInstance { - private final XMLAttribute m_attribute; - - /** - * The value of this attribute, or null to mean that it hasn't been set explicitly and the - * default value should be used. - */ - private String m_value; - - XMLAttributeInstance(XMLAttribute attribute) { - m_attribute = attribute; - m_value = null; - } - - public XMLAttribute getAttribute() { - return m_attribute; - } - - /** - * Does this attribute have its default value because none was set explicitly? This is typically - * used when outputting the XML as text, to omit implicit attributes, thereby enabling - * preservation of the text representation. - * - * @return true iff the value of this attribute has not been set explicitly. - */ - public boolean isImplicitDefault() { - return (m_value == null); - } - - /** - * @return the current value of this attribute, possibly the default, never null. - */ - public String getValue() { - if (m_value != null) { - return m_value; - } - String def = m_attribute.getDefaultValue(); - return (def != null) ? def : ""; //$NON-NLS-1$ - } - - /** - * Similar to {@link #getValue()}, but returns null if the attribute hasn't explicitly been - * specified, and the attribute doesn't have a default value. - * - * @return the current value of this attribute, or the default if one has explicitly been set, - * otherwise null. - */ - public String getExplicitValue() { - return (m_value != null) ? m_value : m_attribute.getDefaultValue(); - } - - /** - * Set the value of this attribute, either to the specified value, or implicitly to the default - * value. Specifying null will effectively remove the attribute from the text representation of - * its parent element. - * - * @param value - * the desired value, or null to implicitly use the default. - * @return true iff this instance changed in any way - */ - public boolean setValue(String value) { - // FIXME: Validate against allowed values - if ((m_value == null) ? (value != null) : !m_value.equals(value)) { - m_value = value; - return true; - } - return false; - } - - @Override - public String toString() { - return m_attribute.getName() + "=\"" + getValue() + '"'; //$NON-NLS-1$ - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLModel.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLModel.java deleted file mode 100644 index e7ef3654..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLModel.java +++ /dev/null @@ -1,369 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.nio.charset.Charset; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Observable; -import java.util.Stack; -import java.util.logging.Logger; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.validation.Schema; - -import org.openjdk.jmc.common.io.IOToolkit; -import org.openjdk.jmc.common.util.XmlToolkit; -import org.xml.sax.Attributes; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; - -public final class XMLModel extends Observable { - final private static class XMLModelBuilder extends DefaultHandler { - private final Stack m_stack = new Stack<>(); - private StringBuilder characterBuilder; - - public XMLModelBuilder(XMLTagInstance dummyRoot) { - m_stack.push(dummyRoot); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - XMLTagInstance current = m_stack.peek(); - XMLTagInstance child = current.create(qName, createMap(attributes)); - m_stack.push(child); - characterBuilder = new StringBuilder(); - } - - @Override - public void characters(char ch[], int start, int length) throws SAXException { - characterBuilder.append(ch, start, length); - } - - @Override - public void endElement(String uri, String localName, String qName) { - String content = characterBuilder.toString().trim(); - if (content.length() != 0) { - if (m_stack.peek().hasContent()) { - m_stack.peek().setContent(content); - } - } - - XMLTagInstance current = m_stack.peek(); - if (current.getTag().getName().equalsIgnoreCase(qName)) { - m_stack.pop(); - } else { - throw new IllegalStateException("Unexpected <" + qName + "/>"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - private Map createMap(Attributes attributes) { - LinkedHashMap map = new LinkedHashMap<>(); - for (int i = 0; i < attributes.getLength(); i++) { - map.put(attributes.getQName(i), attributes.getValue(i).trim()); - } - return map; - } - } - - private final XMLTagInstance m_root; - private final Map m_resultLookup = new LinkedHashMap<>(); - private final IXMLValidator m_validator; - private boolean m_dirty; - - /** - * Create a new XML model. - * - * @param root - * the root element - * @param validator - * a validator or null - */ - XMLModel(XMLTagInstance root, IXMLValidator validator) { - m_root = root; - m_validator = validator; - checkErrors(); - } - - public static XMLModel createEmpty(IXMLValidator validator, Map attributes) { - XMLTagInstance dummyRoot = new XMLTagInstance(null, validator.getRootElementType()); - XMLTagInstance container = dummyRoot.create(dummyRoot.getTag().getTags().get(0).getName(), attributes); - // Attempt to pass validation by setting all required attributes to their implicit defaults. - for (XMLAttributeInstance attr : container.getAttributeInstances()) { - if (attr.getAttribute().isRequired()) { - attr.setValue(attr.getValue()); - } - } - return new XMLModel(container, validator); - } - - public static XMLModel create(InputSource input, IXMLValidator validator) throws IOException, ParseException { - try { - XMLTagInstance dummyRoot = new XMLTagInstance(null, validator.getRootElementType()); - - SAXParserFactory spf = XmlToolkit.createSAXParserFactory(); - - SAXParser sp = spf.newSAXParser(); - XMLReader xr = sp.getXMLReader(); - XMLModelBuilder dataHandler = new XMLModelBuilder(dummyRoot); - xr.setContentHandler(dataHandler); - xr.parse(input); - List instances = dummyRoot.getTagsInstances(); - if (instances.size() != 1) { - throw new ParseException("There must be exactly one root element", 1); //$NON-NLS-1$ - } - return new XMLModel(instances.get(0), validator); - } catch (SAXParseException sp) { - ParseException pe = new ParseException(sp.getMessage(), sp.getLineNumber()); - pe.initCause(sp); - throw pe; - } catch (SAXException s) { - ParseException pe = new ParseException("Could not parse XML", -1); //$NON-NLS-1$ - pe.initCause(s); - throw pe; - } catch (ParserConfigurationException s) { - ParseException pe = new ParseException("Could not parse XML", -1); //$NON-NLS-1$ - pe.initCause(s); - throw pe; - } - - } - - public static void validate(InputStream xmlStream, String streamName, Schema schema) - throws ParseException, IOException { - try { - validateAgainstSchema(xmlStream, schema); - } catch (SAXParseException spe) { - throw new ParseException(spe.getMessage(), spe.getLineNumber()); - } catch (SAXException e) { - throw new IOException("Could not validate " + streamName, e); //$NON-NLS-1$ - } catch (ParserConfigurationException e) { - throw new IOException("Could not validate " + streamName, e); //$NON-NLS-1$ - } catch (IOException e) { - throw new IOException("Could not validate " + streamName, e); //$NON-NLS-1$ - } - } - - private static void validateAgainstSchema(InputStream xmlStream, Schema schema) - throws SAXException, ParserConfigurationException, IOException, ParseException { - class SimpleErrorHandler implements ErrorHandler { - private final List exceptions = new ArrayList<>(); - - @Override - public void warning(SAXParseException se) throws SAXException { - exceptions.add(se); - } - - @Override - public void error(SAXParseException se) throws SAXException { - exceptions.add(se); - } - - @Override - public void fatalError(SAXParseException se) throws SAXException { - exceptions.add(se); - } - } - - try { - SAXParserFactory factory = XmlToolkit.createSAXParserFactory(); - factory.setNamespaceAware(true); - factory.setSchema(schema); - - SimpleErrorHandler seh = new SimpleErrorHandler(); - - SAXParser parser = factory.newSAXParser(); - XMLReader reader = parser.getXMLReader(); - reader.setErrorHandler(seh); - reader.parse(new InputSource(xmlStream)); - if (!seh.exceptions.isEmpty()) { - throwParseException(seh.exceptions); - } - } finally { - IOToolkit.closeSilently(xmlStream); - } - } - - private static void throwParseException(List exceptions) throws ParseException { - StringBuilder sb = new StringBuilder(); - int firstError = -1; - for (SAXParseException spe : exceptions) { - if (firstError == -1) { - firstError = spe.getLineNumber(); - } - sb.append("Line " + spe.getLineNumber() + " " + spe.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ - sb.append("\r\n"); //$NON-NLS-1$ - sb.append("\r\n"); //$NON-NLS-1$ - } - throw new ParseException(sb.toString(), firstError); - } - - /** - * Saves the model to the given {@link File}. If successful, sets dirtyness to false, as - * returned by {@link #isModified()}. - * - * @param writer - * @param oneLineElements - * XML tags to output on a single line - */ - public void saveToFile(File file) throws IOException { - // NOTE: The pretty printer writes that the encoding is UTF-8, so we must make sure it is. - // Ensure charset exists before opening file for writing. - Charset charset = Charset.forName("UTF-8"); //$NON-NLS-1$ - try (Writer osw = new OutputStreamWriter(new FileOutputStream(file), charset)) { - if (writeTo(osw)) { - setDirty(false); - } - } - } - - /** - * Writes the model to the given {@link Writer}. Does not change dirtyness, as returned by - * {@link #isModified()}. - * - * @param writer - * @param oneLineElements - * XML tags to output on a single line - * @return true iff the model was successfully written to the {@link Writer}. - */ - public boolean writeTo(Writer writer) { - try (PrintWriter pw = new PrintWriter(writer)) { - PrettyPrinter pp = new PrettyPrinter(pw, m_validator.getElementsTooKeepOnOneLine()); - pp.print(this); - pw.flush(); - // PrintWriter never throws any exceptions, so this is how we find out if something went wrong. - return !pw.checkError(); - } - } - - public XMLTagInstance getRoot() { - return m_root; - } - - public void markDirty() { - /* - * FIXME: Mixing up "dirty" as in not-saved-to-file, with notification of - * in-memory-model-change? Or is it that the observable state is the dirtyness? Still, only - * the transition from non-dirty to dirty is reported. And only if this method is used. This - * can be called if the underlying file has changed to some other reason, and result in the - * JFCEditor being marked dirty, when it shouldn't. - */ - if (!m_dirty) { - m_dirty = true; - setChanged(); - notifyObservers(); - } - } - - public void setDirty(boolean dirty) { - m_dirty = dirty; - } - - public boolean isModified() { - return m_dirty; - } - - public void checkErrors() { - m_resultLookup.clear(); - if (m_validator != null) { - for (XMLValidationResult r : m_validator.validate(this)) { - // NOTE: This will only keep one result per node, although many may have been found. - m_resultLookup.put(r.getObject(), r); - if (r.isError()) { - Logger logger = Logger - .getLogger("org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml"); //$NON-NLS-1$ - logger.severe(r.getObject() + ": " + r.getText()); //$NON-NLS-1$ - } - } - } - } - - public Collection getResults() { - return m_resultLookup.values(); - } - - public XMLValidationResult getResult(Object o) { - return m_resultLookup.get(o); - } - - public boolean hasErrors() { - for (XMLValidationResult r : m_resultLookup.values()) { - if (r.isError()) { - return true; - } - } - return false; - } - - public XMLModel deepClone() { - StringWriter sw = new StringWriter(2000); // Below 2048 to keep initial char array within 4kB, next within 8kB, - // and so on. - if (writeTo(sw)) { - try { - return XMLModel.create(new InputSource(new StringReader(sw.toString())), m_validator); - } catch (Exception e) { - // Shouldn't happen - throw new IllegalStateException(e); - } - } - throw new IllegalStateException("Could not write model to string"); //$NON-NLS-1$ - } - - @Override - public String toString() { - StringWriter sw = new StringWriter(2000); // Below 2048 to keep initial char array within 4kB, next within 8kB, - // and so on. - writeTo(sw); - return sw.toString(); - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNode.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNode.java deleted file mode 100644 index a1ee3d74..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNode.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -abstract class XMLNode { - private final String m_name; - private final XMLNodeType m_type; - - protected XMLNode(String name, XMLNodeType type) { - m_name = name; - m_type = type; - } - - public final String getName() { - return m_name; - } - - public final XMLNodeType getType() { - return m_type; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNodeType.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNodeType.java deleted file mode 100644 index 726485db..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLNodeType.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -public enum XMLNodeType { - DEFINITION, - REFERENCE, - URI, - TEXT, - ELEMENT, - ELEMENT_WITH_CONTENT, - ELEMENT_WITH_OPTIONAL_CHILDREN, - ELEMENT_WITH_AT_LEAST_ONE_CHILD -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTag.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTag.java deleted file mode 100644 index 268611fa..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTag.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class XMLTag extends XMLNode { - static class Predicated extends XMLTag { - private final String key; - private final String value; - - public Predicated(String name, XMLAttribute attribute, String value) { - super(name); - key = attribute.getName(); - this.value = value; - } - - @Override - public boolean accepts(Map attributes) { - return value.equals(attributes.get(key)); - } - } - - private final List m_tags = new ArrayList<>(); - private final List m_attributes = new ArrayList<>(); - - public XMLTag(String name) { - super(name, XMLNodeType.ELEMENT); - } - - public XMLTag(String name, XMLNodeType type) { - super(name, type); - } - - public List getTags() { - return m_tags; - } - - public List getAttributes() { - return m_attributes; - } - - public void add(XMLNode ... nodes) { - for (XMLNode node : nodes) { - if (node instanceof XMLTag) { - m_tags.add((XMLTag) node); - } - if (node instanceof XMLAttribute) { - m_attributes.add((XMLAttribute) node); - } - } - } - - @Override - public String toString() { - return "Tag: " + getName(); //$NON-NLS-1$ - } - - public boolean accepts(Map attributes) { - return true; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTagInstance.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTagInstance.java deleted file mode 100644 index f2c56735..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLTagInstance.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * An XML element, with attribute values and child elements. - */ -public final class XMLTagInstance { - private final List m_attributeInstances = new ArrayList<>(); - private final List m_childElements = new ArrayList<>(); - private final XMLTag m_tag; - // NOTE: Non-final to support re-parenting. - private XMLTagInstance m_parent; - - private String m_content = ""; //$NON-NLS-1$ - - XMLTagInstance(XMLTagInstance parent, XMLTag tag) { - m_parent = parent; - m_tag = tag; - } - - public XMLTag getTag() { - return m_tag; - } - - public List getAttributeInstances() { - return m_attributeInstances; - } - - public List getTagsInstances() { - return m_childElements; - } - - public XMLTagInstance getParent() { - return m_parent; - } - - public XMLTagInstance create(String tag, Map attributes) { - for (XMLTag xmlTag : getTag().getTags()) { - if (tag.equalsIgnoreCase(xmlTag.getName()) && xmlTag.accepts(attributes)) { - XMLTagInstance element = new XMLTagInstance(this, xmlTag); - - for (XMLAttribute attribute : xmlTag.getAttributes()) { - XMLAttributeInstance ia = new XMLAttributeInstance(attribute); - element.getAttributeInstances().add(ia); - if (attributes.containsKey(attribute.getName())) { - ia.setValue(attributes.get(attribute.getName())); - } - } - m_childElements.add(element); - return element; - } - } - // FIXME: We might need to allow elements (processContents="skip" or "lax", see XMLSchema). - throw new IllegalArgumentException(tag + " is not allowed under " + getTag().getName()); //$NON-NLS-1$ - } - - public boolean remove(XMLTagInstance child) { - return m_childElements.remove(child); - } - - public void adopt(XMLTagInstance child) { - XMLTagInstance oldParent = child.m_parent; - if (oldParent != this) { - m_childElements.add(child); - child.m_parent = this; - oldParent.m_childElements.remove(child); - } - } - - public void setContent(String content) { - if (content == null) { - throw new IllegalArgumentException("Content can't be null. Use empty string if missing"); //$NON-NLS-1$ - } - m_content = content; - } - - public boolean hasContent() { - return getTag().getType() == XMLNodeType.ELEMENT_WITH_CONTENT; - } - - public XMLTagInstance create(XMLTag tag) { - return create(tag.getName(), new HashMap()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("<"); //$NON-NLS-1$ - builder.append(getTag().getName()); - for (XMLAttributeInstance a : getAttributeInstances()) { - if (!a.isImplicitDefault()) { - builder.append(" "); //$NON-NLS-1$ - builder.append(a.getAttribute().getName()); - builder.append("=\""); //$NON-NLS-1$ - builder.append(a.getValue()); - builder.append("\""); //$NON-NLS-1$ - } - } - builder.append("/>"); //$NON-NLS-1$ - return builder.toString(); - } - - /** - * @param attribute - * @return the value for the given {@link XMLAttribute attribute}, possibly the default, never - * null. - * @see #getExplicitValue(XMLAttribute) - * @throws IllegalArgumentException - * if this tag has no such attribute - */ - public String getValue(XMLAttribute attribute) { - for (XMLAttributeInstance i : m_attributeInstances) { - if (i.getAttribute().equals(attribute)) { - return i.getValue(); - } - } - throw new IllegalArgumentException("Unknown attribute '" + attribute.getName() + "' in element '" //$NON-NLS-1$ //$NON-NLS-2$ - + getTag().getName() + "'"); //$NON-NLS-1$ - } - - /** - * @param attribute - * @return the value for the given {@link XMLAttribute attribute}, or the default if one has - * explicitly been set, otherwise null. - * @see #getValue(XMLAttribute) - * @throws IllegalArgumentException - * if this tag has no such attribute - */ - public String getExplicitValue(XMLAttribute attribute) { - for (XMLAttributeInstance i : m_attributeInstances) { - if (i.getAttribute().equals(attribute)) { - return i.getExplicitValue(); - } - } - throw new IllegalArgumentException("Unknown attribute '" + attribute.getName() + "' in element '" //$NON-NLS-1$ //$NON-NLS-2$ - + getTag().getName() + "'"); //$NON-NLS-1$ - } - - /** - * Set the value of {@code attribute}, either to the specified value, or implicitly to the - * default value. Specifying null will effectively remove the attribute from the text - * representation of this element. - * - * @param newValue - * the desired value, or null to implicitly use the default. - * @return true iff the attribute changed in any way - */ - public boolean setValue(XMLAttribute attribute, String newValue) { - for (XMLAttributeInstance i : m_attributeInstances) { - if (i.getAttribute().equals(attribute)) { - return i.setValue(newValue); - } - } - throw new IllegalArgumentException("Unknown attribute '" + attribute.getName() + "' in element '" //$NON-NLS-1$ //$NON-NLS-2$ - + getTag().getName() + "'"); //$NON-NLS-1$ - } - - public List getTagsInstances(XMLTag tag) { - List elements = new ArrayList<>(); - for (XMLTagInstance element : m_childElements) { - if (element.getTag() == tag) { - elements.add(element); - } - } - return elements; - } - - public XMLTagInstance findTagWithAttribute(XMLTag tag, XMLAttribute attribute, String value) { - for (XMLTagInstance element : m_childElements) { - if ((element.getTag() == tag) && value.equals(element.getValue(attribute))) { - return element; - } - } - return null; - } - - public XMLTagInstance findNestedTagWithAttribute( - XMLTag recurseTag, XMLTag targetTag, XMLAttribute attribute, String value) { - for (XMLTagInstance element : m_childElements) { - XMLTag tag = element.getTag(); - if (tag == targetTag) { - if (value.equals(element.getValue(attribute))) { - return element; - } - } else if (tag == recurseTag) { - XMLTagInstance result = element.findNestedTagWithAttribute(recurseTag, targetTag, attribute, value); - if (result != null) { - return result; - } - } - } - return null; - } - - public String getContent() { - if (hasContent()) { - return m_content; - } else { - return ""; //$NON-NLS-1$ - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLValidationResult.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLValidationResult.java deleted file mode 100644 index f8d72ba2..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/configuration/model/xml/XMLValidationResult.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml; - -public final class XMLValidationResult { - public static final XMLValidationResult OK = new XMLValidationResult(null, "OK", false); //$NON-NLS-1$ - - private final Object m_object; - private final boolean m_error; - private final String m_text; - - XMLValidationResult(Object object, String text, boolean error) { - m_object = object; - m_error = error; - m_text = text; - } - - public Object getObject() { - return m_object; - } - - public String getText() { - return m_text; - } - - public boolean isError() { - return m_error; - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/EventConfiguration.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/EventConfiguration.java deleted file mode 100644 index 6bf0b6e0..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/EventConfiguration.java +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.model; - -import static org.openjdk.jmc.common.unit.UnitLookup.PLAIN_TEXT; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_CONTENT_TYPE; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_CONTROL_REFERENCE; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_DESCRIPTION; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_LABEL; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_LABEL_MANDATORY; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_NAME; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_PATH; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_URI; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.ATTRIBUTE_VERSION; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_CATEGORY; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_CONFIGURATION_V1; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_CONTROL; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_EVENTTYPE_V1; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_EVENTTYPE_V2; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_PRODUCER; -import static org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar.TAG_SETTING; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; - -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.SchemaFactory; - -import org.openjdk.jmc.common.io.IOToolkit; -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.unit.SimpleConstrainedMap; -import org.openjdk.jmc.flightrecorder.configuration.ConfigurationToolkit; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventConfiguration; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.configuration.events.SchemaVersion; -import org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints; -import org.openjdk.jmc.flightrecorder.configuration.spi.IConfigurationStorageDelegate; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.ControlPanel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCGrammar; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.JFCXMLValidator; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLAttribute; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLModel; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLTag; -import org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml.XMLTagInstance; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -/** - * Class that holds a JFR event configuration. - */ -// FIXME: Make two different subclasses of this, V1 and V2? -public final class EventConfiguration implements IEventConfiguration { - - private XMLModel xmlModel; - private final IConfigurationStorageDelegate storageDelegate; - private final SchemaVersion version; - /** - * NOTE: This may be null. It is only non-null for working copies. - */ - private final IEventConfiguration original; - - public static void validate(InputStream xmlStream, String streamName, SchemaVersion version) - throws ParseException, IOException { - try (InputStream schemaStream = version.createSchemaStream()) { - if (schemaStream != null) { - SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$ - XMLModel.validate(xmlStream, streamName, schemaFactory.newSchema(new StreamSource(schemaStream))); - } else { - throw new IOException("Could not locate schema for version " + version); //$NON-NLS-1$ - } - } catch (SAXException e) { - throw new IOException("Trouble parsing schema for version " + version, e); //$NON-NLS-1$ - } - } - - public static IEventConfiguration createEmpty(IConfigurationStorageDelegate delegate, SchemaVersion version) { - Map attributes = Collections.singletonMap(JFCGrammar.ATTRIBUTE_VERSION.getName(), - version.attributeValue()); - XMLModel model = XMLModel.createEmpty(JFCXMLValidator.getValidator(), attributes); - IEventConfiguration config = new EventConfiguration(model, delegate, null); - config.setName("New Template"); - return config; - } - - public static XMLModel createModel(String xmlText) throws ParseException, IOException { - return XMLModel.create(new InputSource(new StringReader(xmlText)), JFCXMLValidator.getValidator()); - } - - public static XMLModel createModel(File file) throws FileNotFoundException, IOException, ParseException { - try (FileInputStream fis = new FileInputStream(file)) { - return createModel(fis); - } - } - - public static XMLModel createModel(InputStream inStream) throws IOException, ParseException { - XMLModel model; - try { - model = XMLModel.create(new InputSource(inStream), JFCXMLValidator.getValidator()); - } finally { - IOToolkit.closeSilently(inStream); - } - return model; - } - - public EventConfiguration(XMLModel xml) { - this(xml, VolatileStorageDelegate.getWorkingCopyDelegate(), null); - } - - public EventConfiguration(IConfigurationStorageDelegate delegate) throws IOException, ParseException { - this(createModel(delegate.getContents()), delegate, null); - } - - public EventConfiguration(XMLModel xml, IConfigurationStorageDelegate storageDelegate) { - this(xml, storageDelegate, null); - } - - public EventConfiguration(XMLModel xml, IConfigurationStorageDelegate storageDelegate, - IEventConfiguration original) { - xmlModel = xml; - this.storageDelegate = storageDelegate; - this.original = original; - version = SchemaVersion.fromBeanVersion(getRoot().getValue(ATTRIBUTE_VERSION)); - if (version == null) { - throw new IllegalArgumentException("Schema version cannot be null"); //$NON-NLS-1$ - } - } - - /** - * Replace the contents of this configuration with that from {@code workingCopy}. - * - * @param workingCopy - * a working copy that was returned by {@link #createWorkingCopy()} on this - * configuration. - * @return true if the contents was successfully replaced, false otherwise. - */ - boolean replaceWithContentsFrom(IEventConfiguration workingCopy) { - if ((workingCopy.getOriginal() == this) && (workingCopy instanceof EventConfiguration)) { - xmlModel = ((EventConfiguration) workingCopy).getXMLModel().deepClone(); - return true; - } - return false; - } - - private XMLTagInstance getRoot() { - return xmlModel.getRoot(); - } - - @Override - public String getName() { - if (getRoot().getTag() == TAG_CONFIGURATION_V1) { - return getRoot().getValue(ATTRIBUTE_NAME); - } else { - return getRoot().getValue(ATTRIBUTE_LABEL_MANDATORY); - } - } - - @Override - public void setName(String name) { - if (getRoot().getTag() == TAG_CONFIGURATION_V1) { - getRoot().setValue(ATTRIBUTE_NAME, name); - } else { - getRoot().setValue(ATTRIBUTE_LABEL_MANDATORY, name); - } - } - - @Override - public String getDescription() { - return getRoot().getValue(ATTRIBUTE_DESCRIPTION); - } - - @Override - public void setDescription(String description) { - getRoot().setValue(ATTRIBUTE_DESCRIPTION, description); - } - - @Override - public SchemaVersion getVersion() { - return version; - } - - @Override - public IConstrainedMap getEventOptions(IMutableConstrainedMap options) { - switch (version) { - case V1: - for (XMLTagInstance producer : getRoot().getTagsInstances(TAG_PRODUCER)) { - String producerURI = producer.getValue(ATTRIBUTE_URI); - for (XMLTagInstance event : producer.getTagsInstances(TAG_EVENTTYPE_V1)) { - String eventPath = event.getValue(ATTRIBUTE_PATH); - IEventTypeID eventTypeID = ConfigurationToolkit.createEventTypeID(producerURI, eventPath); - getOptionsFromEventTo(eventTypeID, event, options); - } - } - break; - - case V2: - getNestedEventOptions(getRoot(), options); - break; - - default: - break; - } - return options; - } - - private void getNestedEventOptions(XMLTagInstance element, IMutableConstrainedMap options) { - for (XMLTagInstance child : element.getTagsInstances()) { - XMLTag childTag = child.getTag(); - if (childTag == TAG_EVENTTYPE_V2) { - String eventName = child.getValue(ATTRIBUTE_NAME); - IEventTypeID eventTypeID = ConfigurationToolkit.createEventTypeID(eventName); - getOptionsFromEventTo(eventTypeID, child, options); - } else if (childTag == TAG_CATEGORY) { - getNestedEventOptions(child, options); - } - } - } - - private void getOptionsFromEventTo( - IEventTypeID eventTypeID, XMLTagInstance event, IMutableConstrainedMap options) { - for (XMLTagInstance option : event.getTagsInstances(TAG_SETTING)) { - EventOptionID optionID = new EventOptionID(eventTypeID, option.getValue(ATTRIBUTE_NAME)); - String contentType = option.getExplicitValue(ATTRIBUTE_CONTENT_TYPE); - // Only add options the map can handle. (JFRv2 should handle almost everything.) - try { - if (contentType != null) { - IConstraint constraint = CommonConstraints.forContentTypeV2(contentType); - options.putPersistedString(optionID, constraint, option.getContent()); - } else { - options.putPersistedString(optionID, option.getContent()); - } - } catch (QuantityConversionException | IllegalArgumentException e) { - ControlPanel.getDefault().getLogger().log(Level.FINE, e.getMessage(), e); - } - } - } - - @Override - public String getPersistableString(EventOptionID optionID) { - XMLTagInstance settingElement = findOption(optionID, false); - return (settingElement != null) ? settingElement.getContent() : null; - } - - public boolean hasOption(EventOptionID eventOptionID) { - return findOption(eventOptionID, false) != null; - } - - private XMLTagInstance findProducer(String producerURI, boolean create) { - XMLTagInstance producer = getRoot().findTagWithAttribute(TAG_PRODUCER, ATTRIBUTE_URI, producerURI); - if (create && (producer == null)) { - producer = getRoot().create(TAG_PRODUCER); - producer.setValue(ATTRIBUTE_URI, producerURI); - } - return producer; - } - - private XMLTagInstance findCategory(XMLTagInstance parent, String category, boolean create) { - XMLTagInstance categoryInstance = parent.findTagWithAttribute(TAG_CATEGORY, ATTRIBUTE_LABEL_MANDATORY, - category); - if (categoryInstance == null) { - for (XMLTagInstance subcategory : parent.getTagsInstances(TAG_CATEGORY)) { - categoryInstance = findCategory(subcategory, category, false); - if (categoryInstance != null) { - return categoryInstance; - } - } - } - if (create && (categoryInstance == null)) { - categoryInstance = parent.create(TAG_CATEGORY); - categoryInstance.setValue(ATTRIBUTE_LABEL_MANDATORY, category); - } - return categoryInstance; - } - - public boolean hasEvent(IEventTypeID eventTypeID) { - return findEvent(eventTypeID, false) != null; - } - - XMLTagInstance findEvent(IEventTypeID eventTypeID, boolean create) { - XMLTagInstance origin; - XMLTag eventTag; - XMLAttribute keyAttribute; - XMLTagInstance eventType; - if (eventTypeID.getProducerKey() != null) { - origin = findProducer(eventTypeID.getProducerKey(), create); - eventTag = TAG_EVENTTYPE_V1; - keyAttribute = ATTRIBUTE_PATH; - eventType = (origin != null) - ? origin.findTagWithAttribute(eventTag, keyAttribute, eventTypeID.getRelativeKey()) : null; - } else { - origin = getRoot(); - eventTag = TAG_EVENTTYPE_V2; - keyAttribute = ATTRIBUTE_NAME; - eventType = origin.findNestedTagWithAttribute(TAG_CATEGORY, eventTag, keyAttribute, - eventTypeID.getRelativeKey()); - } - - if (create && (eventType == null)) { - eventType = origin.create(eventTag); - eventType.setValue(keyAttribute, eventTypeID.getRelativeKey()); - } - return eventType; - } - - private XMLTagInstance findOption(EventOptionID eventOptionID, boolean create) { - XMLTagInstance eventType = findEvent(eventOptionID.getEventTypeID(), create); - XMLTagInstance option = (eventType != null) - ? eventType.findTagWithAttribute(TAG_SETTING, ATTRIBUTE_NAME, eventOptionID.getOptionKey()) : null; - if (create && (option == null)) { - option = eventType.create(TAG_SETTING); - option.setValue(ATTRIBUTE_NAME, eventOptionID.getOptionKey()); - } - return option; - } - - @Override - public void putPersistedString(EventOptionID optionID, String persisted) { - XMLTagInstance optionTag = findOption(optionID, true); - optionTag.setContent(persisted); - } - - /** - * Removes an option - * - * @param optionID - */ - public void removeOption(EventOptionID optionID) { - XMLTagInstance optionTag = findOption(optionID, false); - if (optionTag != null) { - optionTag.getParent().remove(optionTag); - } - } - - @Override - public boolean isCloneable() { - return true; - } - - @Override - public IEventConfiguration createClone() { - return createCloneWithStorage(storageDelegate); - } - - @Override - public IEventConfiguration createCloneWithStorage(IConfigurationStorageDelegate storageDelegate) { - return new EventConfiguration(xmlModel.deepClone(), storageDelegate, original); - } - - @Override - public IEventConfiguration createWorkingCopy() { - return new EventConfiguration(xmlModel.deepClone(), VolatileStorageDelegate.getWorkingCopyDelegate(), this); - } - - @Override - public IEventConfiguration getOriginal() { - return original; - } - - @Override - public boolean isExportable() { - return true; - } - - @Override - public void exportToFile(File file) throws IOException { - xmlModel.saveToFile(file); - } - - @Override - public boolean hasControlElements() { - final XMLTagInstance root = getRoot(); - // JFR 1.0 - for (XMLTagInstance producerTag : root.getTagsInstances(TAG_PRODUCER)) { - if (producerTag.getTagsInstances(TAG_CONTROL).size() > 0) { - return true; - } - } - // JFR 2.0 - if (root.getTagsInstances(TAG_CONTROL).size() > 0) { - return true; - } - return false; - } - - @Override - public boolean removeControlElements() { - boolean changed = false; - final XMLTagInstance root = getRoot(); - switch (version) { - case V1: - for (XMLTagInstance producerElement : root.getTagsInstances(TAG_PRODUCER)) { - for (XMLTagInstance controlElement : producerElement.getTagsInstances(TAG_CONTROL)) { - producerElement.remove(controlElement); - changed = true; - } - for (XMLTagInstance eventElement : producerElement.getTagsInstances(TAG_EVENTTYPE_V1)) { - for (XMLTagInstance settingElement : eventElement.getTagsInstances(TAG_SETTING)) { - changed |= settingElement.setValue(ATTRIBUTE_CONTROL_REFERENCE, null); - } - } - } - break; - - case V2: - for (XMLTagInstance controlElement : root.getTagsInstances(TAG_CONTROL)) { - root.remove(controlElement); - changed = true; - } - changed |= removeNestedControlReferences(root); - break; - - default: - break; - } - return changed; - } - - private boolean removeNestedControlReferences(XMLTagInstance parent) { - boolean changed = false; - for (XMLTagInstance child : parent.getTagsInstances()) { - XMLTag childTag = child.getTag(); - if (childTag == TAG_EVENTTYPE_V2) { - for (XMLTagInstance settingElement : child.getTagsInstances(TAG_SETTING)) { - changed |= settingElement.setValue(ATTRIBUTE_CONTROL_REFERENCE, null); - } - } else if (childTag == TAG_CATEGORY) { - changed |= removeNestedControlReferences(child); - } - } - return changed; - } - - public XMLModel getXMLModel() { - return xmlModel; - } - - @Override - public String getLocationPath() { - return storageDelegate.getLocationPath(); - } - - @Override - public String getLocationInfo() { - return storageDelegate.getLocationInfo(); - } - - @Override - public boolean isDeletable() { - return storageDelegate.isDeletable(); - } - - @Override - public boolean delete() { - return storageDelegate.delete(); - } - - @Override - public boolean isSaveable() { - return storageDelegate.isSaveable(); - } - - @Override - public boolean save() { - Writer writer = new StringWriter(2000); // Below 2048 to keep initial char array within 4kB, next within 8kB, - // and so on. - if (xmlModel.writeTo(writer)) { - try { - return storageDelegate.save(writer.toString()); - } catch (IOException e) { - ControlPanel.getDefault().getLogger().log(Level.WARNING, "Cannot save configuration.", e); //$NON-NLS-1$ - } - } - return false; - } - - @Override - public boolean equalSettings(IEventConfiguration other) { - if (other == this) { - return true; - } - - IMutableConstrainedMap ourOptions = new SimpleConstrainedMap<>(PLAIN_TEXT.getPersister()); - getEventOptions(ourOptions); - for (EventOptionID key : ourOptions.keySet()) { - // FIXME: Check for null? - if (!ourOptions.getPersistableString(key).equals(other.getPersistableString(key))) { - return false; - } - } - /* - * All our settings were in the other holder. Must now check size to ensure the opposite. - * We're doing this last as it might be expensive. Otherwise, we could just have called - * equals() on the maps. - */ - return ourOptions.keySet().size() == other.getEventOptions(ourOptions.emptyWithSameConstraints()).keySet() - .size(); - } - - public Set getConfigEventTypes() { - Set eventTypes = new HashSet<>(); - collectConfigEventTypes(getRoot(), eventTypes); - return eventTypes; - } - - private void collectConfigEventTypes(XMLTagInstance tagInstance, Set eventTypes) { - for (XMLTagInstance childCategory : tagInstance.getTagsInstances(TAG_CATEGORY)) { - collectConfigEventTypes(childCategory, eventTypes); - } - for (XMLTagInstance childCategory : tagInstance.getTagsInstances(TAG_PRODUCER)) { - collectConfigEventTypes(childCategory, eventTypes); - } - XMLTag eventTag = SchemaVersion.V2.equals(version) ? TAG_EVENTTYPE_V2 : TAG_EVENTTYPE_V1; - for (XMLTagInstance event : tagInstance.getTagsInstances(eventTag)) { - IEventTypeID eventTypeID = createEventTypeID(event); - eventTypes.add(eventTypeID); - } - } - - private IEventTypeID createEventTypeID(XMLTagInstance event) { - if (event.getParent().getTag().equals(TAG_PRODUCER)) { - return ConfigurationToolkit.createEventTypeID(event.getParent().getValue(ATTRIBUTE_URI), - event.getValue(ATTRIBUTE_PATH)); - } - return ConfigurationToolkit.createEventTypeID(event.getValue(ATTRIBUTE_NAME)); - } - - public String[] getEventCategory(IEventTypeID eventTypeID) { - List categories = new ArrayList<>(); - XMLTagInstance eventTagInstance = findEvent(eventTypeID, false); - if (eventTagInstance != null) { - XMLTagInstance current = eventTagInstance.getParent(); - while (current.getTag().equals(TAG_CATEGORY)) { - categories.add(0, current.getValue(ATTRIBUTE_LABEL_MANDATORY)); - current = current.getParent(); - } - } - return categories.toArray(new String[categories.size()]); - } - - public String getEventLabel(IEventTypeID eventTypeID) { - XMLTagInstance eventTagInstance = findEvent(eventTypeID, false); - return eventTagInstance != null ? eventTagInstance.getExplicitValue(ATTRIBUTE_LABEL) : null; - } - - public String getEventDescription(IEventTypeID eventTypeID) { - XMLTagInstance eventTagInstance = findEvent(eventTypeID, false); - return eventTagInstance != null ? eventTagInstance.getExplicitValue(ATTRIBUTE_DESCRIPTION) : null; - } - - public Set getOptionIDs(IEventTypeID eventTypeID) { - XMLTagInstance eventType = findEvent(eventTypeID, false); - Set options = new HashSet<>(); - if (eventType != null) { - for (XMLTagInstance setting : eventType.getTagsInstances(TAG_SETTING)) { - EventOptionID optionID = new EventOptionID(eventTypeID, setting.getExplicitValue(ATTRIBUTE_NAME)); - options.add(optionID); - } - } - return options; - } - - public String getConfigOptionLabel(EventOptionID eventOptionID) { - XMLTagInstance option = findOption(eventOptionID, false); - return option != null ? option.getExplicitValue(ATTRIBUTE_LABEL) : null; - } - - public String getConfigOptionDescription(EventOptionID eventOptionID) { - XMLTagInstance option = findOption(eventOptionID, false); - return option != null ? option.getExplicitValue(ATTRIBUTE_DESCRIPTION) : null; - } - - public String getConfigOptionContentType(EventOptionID eventOptionID) { - XMLTagInstance option = findOption(eventOptionID, false); - return option != null ? option.getExplicitValue(ATTRIBUTE_CONTENT_TYPE) : null; - } - - void populateOption( - EventOptionID optionKey, IOptionDescriptor serverOptionInfo, String value, boolean override) { - XMLTagInstance configOption = findOption(optionKey, true); - - if (override || configOption.getExplicitValue(ATTRIBUTE_LABEL) == null) { - configOption.setValue(ATTRIBUTE_LABEL, serverOptionInfo.getName()); - } - if (override || configOption.getExplicitValue(ATTRIBUTE_DESCRIPTION) == null) { - configOption.setValue(ATTRIBUTE_DESCRIPTION, serverOptionInfo.getDescription()); - } - if (override || configOption.getExplicitValue(ATTRIBUTE_CONTENT_TYPE) == null) { - configOption.setValue(ATTRIBUTE_CONTENT_TYPE, - CommonConstraints.toMatchingContentTypeV2(serverOptionInfo.getConstraint())); - } - if (configOption.getContent() == null || configOption.getContent().length() == 0) { - configOption.setContent(value); - } - - } - - void populateEventMetadata(IEventTypeID eventTypeID, IEventTypeInfo serverEventTypeInfo, boolean override) { - XMLTagInstance event = findEvent(eventTypeID, true); - String configEventLabel = getEventLabel(eventTypeID); - String configEventDescription = getEventLabel(eventTypeID); - if (override || configEventLabel == null) { - event.setValue(ATTRIBUTE_LABEL, serverEventTypeInfo.getName()); - } - if (override || configEventDescription == null) { - event.setValue(ATTRIBUTE_DESCRIPTION, serverEventTypeInfo.getDescription()); - } - } - - void putEventInCategory(IEventTypeID eventTypeID, String[] categories) { - XMLTagInstance categoryParent = getRoot(); - for (String category : categories) { - categoryParent = findCategory(categoryParent, category, true); - } - XMLTagInstance event = findEvent(eventTypeID, false); - if (event != null) { - categoryParent.adopt(event); - } else { - event = categoryParent.create(TAG_EVENTTYPE_V2); - event.setValue(ATTRIBUTE_NAME, eventTypeID.getFullKey()); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/VolatileStorageDelegate.java b/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/VolatileStorageDelegate.java deleted file mode 100644 index 27be1f85..00000000 --- a/src/main/java/org/openjdk/jmc/flightrecorder/controlpanel/ui/model/VolatileStorageDelegate.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.flightrecorder.controlpanel.ui.model; - -import java.io.InputStream; - -import org.openjdk.jmc.flightrecorder.configuration.spi.IConfigurationStorageDelegate; - -/** - * Storage delegate for templates that cannot be saved back to where they came from. In other words, - * read only templates. - */ -public class VolatileStorageDelegate implements IConfigurationStorageDelegate { - private static VolatileStorageDelegate LAST_STARTED = new VolatileStorageDelegate( - "last started", false); - private static VolatileStorageDelegate ON_SERVER = new VolatileStorageDelegate( - "on server", false); - private static VolatileStorageDelegate RUNNING_RECORDING = new VolatileStorageDelegate( - "running recording", false); - private static VolatileStorageDelegate WORKING_COPY = new VolatileStorageDelegate( - "working copy", true); - - private final String locationInfo; - private final boolean deleteable; - - public static IConfigurationStorageDelegate getLastStartedDelegate() { - return LAST_STARTED; - } - - public static IConfigurationStorageDelegate getOnServerDelegate() { - return ON_SERVER; - } - - public static IConfigurationStorageDelegate getRunningRecordingDelegate() { - return RUNNING_RECORDING; - } - - public static IConfigurationStorageDelegate getWorkingCopyDelegate() { - return WORKING_COPY; - } - - private VolatileStorageDelegate(String locationInfo, boolean deleteable) { - this.locationInfo = locationInfo; - this.deleteable = deleteable; - } - - @Override - public InputStream getContents() { - return null; - } - - @Override - public boolean isSaveable() { - return false; - } - - @Override - public boolean save(String fileContent) { - return false; - } - - @Override - public boolean isDeletable() { - return deleteable; - } - - @Override - public boolean delete() { - return false; - } - - @Override - public String getLocationInfo() { - return locationInfo; - } - - @Override - public String getLocationPath() { - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ConnectionDescriptorBuilder.java b/src/main/java/org/openjdk/jmc/rjmx/ConnectionDescriptorBuilder.java deleted file mode 100644 index 8d9bd072..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ConnectionDescriptorBuilder.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.net.MalformedURLException; - -import javax.management.remote.JMXServiceURL; - -import org.openjdk.jmc.rjmx.internal.JMXConnectionDescriptor; -import org.openjdk.jmc.ui.common.security.ICredentials; -import org.openjdk.jmc.ui.common.security.InMemoryCredentials; - -/** - * This class hides the complexities of building a default JMX over RMI ConnectionDescriptor in a - * type safe way. It lets you specify various optional arguments, which are all checked upon - * building the descriptor. - */ -public class ConnectionDescriptorBuilder { - - private JMXServiceURL url; - private String hostName; - private String username; - private String password; - private int port = DEFAULT_PORT; - private ICredentials credentials; - - /** - * Port number designator meaning that the default port for the selected protocol should be - * used. It has the value -1. - */ - public final static int DEFAULT_PORT = -1; - - /** - * Creates a new builder initialized to default values. - */ - public ConnectionDescriptorBuilder() { - } - - /** - * Sets the service URL. - * - * @param url - * the {@link JMXServiceURL} to use. If the URL is set it will override any host and - * port settings. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder url(JMXServiceURL url) { - this.url = url; - return this; - } - - /** - * Sets the host name. - * - * @param hostName - * the host name to set. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder hostName(String hostName) { - this.hostName = hostName; - return this; - } - - /** - * Sets the port for the selected protocol. This will be the RMI Registry port for jmxrmi. For - * RMP it will be the management server port. - * - * @param port - * port or {@link ConnectionDescriptorBuilder#DEFAULT_PORT} for the default port for - * the selected protocol. Is {@link ConnectionDescriptorBuilder#DEFAULT_PORT} by - * default. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder port(int port) { - this.port = port; - return this; - } - - /** - * Sets the credentials to use. - * - * @param credentials - * the user credentials to use. Is by default {@code null}. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder credentials(ICredentials credentials) { - this.credentials = credentials; - return this; - } - - /** - * Sets the user name to use. - * - * @param username - * the user name to use. Is by default {@code null}. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder username(String username) { - this.username = username; - return this; - } - - /** - * Sets the user password to use. - * - * @param password - * the user password to use. Is by default {@code null}. - * @return the Builder currently being configured. - */ - public ConnectionDescriptorBuilder password(String password) { - this.password = password; - return this; - } - - /** - * Builds the {@link IConnectionDescriptor}. - * - * @return a freshly created {@link IConnectionDescriptor} initialized as per the builder - * settings. - * @throws IllegalStateException - * if the settings were not sufficient to create a proper - * {@link IConnectionDescriptor}. - */ - public IConnectionDescriptor build() throws IllegalStateException { - if (credentials == null && username != null && password != null) { - credentials = new InMemoryCredentials(username, password); - } - if (url == null && hostName == null) { - throw new IllegalStateException("You must specify either the url or the host!"); //$NON-NLS-1$ - } - if (url == null) { - try { - url = ConnectionToolkit.createServiceURL(hostName, port); - } catch (MalformedURLException e) { - IllegalStateException exception = new IllegalStateException( - "Could not create a proper JMXServiceURL with the provided information."); //$NON-NLS-1$ - exception.initCause(e); - throw exception; - } - } - - return new JMXConnectionDescriptor(url, credentials); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ConnectionException.java b/src/main/java/org/openjdk/jmc/rjmx/ConnectionException.java deleted file mode 100644 index 8db50431..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ConnectionException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.io.IOException; - -/** - * This exception is thrown when an IO related problem occurs. - */ -public class ConnectionException extends IOException { - - private static final long serialVersionUID = -6261767007629093036L; - - /** - * Constructs an exception with the specified detail message. - * - * @param message - * The detail message (which is saved for later retrieval by the - * {@link #getMessage()} method) - */ - public ConnectionException(String message) { - super(message); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java deleted file mode 100644 index dfe5dde1..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java +++ /dev/null @@ -1,449 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryMXBean; -import java.lang.management.OperatingSystemMXBean; -import java.lang.management.RuntimeMXBean; -import java.lang.management.ThreadMXBean; -import java.lang.reflect.UndeclaredThrowableException; -import java.net.MalformedURLException; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.logging.Level; - -import javax.management.JMException; -import javax.management.MBeanServerConnection; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.TabularData; -import javax.management.remote.JMXServiceURL; - -import org.openjdk.jmc.common.version.JavaVMVersionToolkit; -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.rjmx.internal.RJMXConnection; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; - -/** - * Toolkit providing utility methods to retrieve MBean proxy objects, invoke JMX operations and - * query a connection about its properties. - */ -public final class ConnectionToolkit { - - /** - * Object name for the {@link ManagementFactory#RUNTIME_MXBEAN_NAME} constant. - */ - public static final ObjectName RUNTIME_BEAN_NAME = createObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME); - /** - * Object name for the {@link ManagementFactory#MEMORY_MXBEAN_NAME} constant. - */ - public static final ObjectName MEMORY_BEAN_NAME = createObjectName(ManagementFactory.MEMORY_MXBEAN_NAME); - /** - * Object name for the {@link ManagementFactory#THREAD_MXBEAN_NAME} constant. - */ - public static final ObjectName THREAD_BEAN_NAME = createObjectName(ManagementFactory.THREAD_MXBEAN_NAME); - /** - * Object name for the {@link ManagementFactory#OPERATING_SYSTEM_MXBEAN_NAME} constant. - */ - public static final ObjectName OPERATING_SYSTEM_BEAN_NAME = createObjectName( - ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME); - - private ConnectionToolkit() { - throw new IllegalArgumentException("Don't instantiate this toolkit"); //$NON-NLS-1$ - } - - /** - * Creates an object name for an MBean. Hides the fact that a - * {@link MalformedObjectNameException} might be thrown if the passed string has the wrong - * format. - * - * @param name - * name of the object. - * @return the ObjectName - * @throws IllegalArgumentException - * if an object name could not be created from the string - */ - public static ObjectName createObjectName(String name) { - try { - return new ObjectName(name); - } catch (MalformedObjectNameException e) { - // Should not happen - programmer error! - assert (false); - throw new IllegalArgumentException(e.getMessage(), e); - } - } - - /** - * Helper method to retrieve proxy object for platform Memory MXBean - * ({@code "java.lang:type=Memory"}). - * - * @param server - * the connected server - * @return a proxy object or {@code null} if it does not exist. - * @throws IOException - * if a communication problem occurred. - * @see ManagementFactory#newPlatformMXBeanProxy(MBeanServerConnection, String, Class) - */ - public static MemoryMXBean getMemoryBean(MBeanServerConnection server) throws IOException { - return ManagementFactory.newPlatformMXBeanProxy(server, ManagementFactory.MEMORY_MXBEAN_NAME, - MemoryMXBean.class); - } - - /** - * Helper method to retrieve proxy object for platform Runtime MXBean - * ({@code "java.lang:type=Runtime"}). - * - * @param server - * the connected server - * @return a proxy object or {@code null} if it does not exist. - * @throws IOException - * if a communication problem occurred. - * @see ManagementFactory#newPlatformMXBeanProxy(MBeanServerConnection, String, Class) - */ - public static RuntimeMXBean getRuntimeBean(MBeanServerConnection server) throws IOException { - return ManagementFactory.newPlatformMXBeanProxy(server, ManagementFactory.RUNTIME_MXBEAN_NAME, - RuntimeMXBean.class); - } - - /** - * Helper method to retrieve proxy object for platform Memory MXBean - * ({@code "java.lang:type=Threading"}). - * - * @param server - * the connected server - * @return a proxy object or {@code null} if it does not exist. - * @throws IOException - * if a communication problem occurred. - * @see ManagementFactory#newPlatformMXBeanProxy(MBeanServerConnection, String, Class) - */ - public static ThreadMXBean getThreadBean(MBeanServerConnection server) throws IOException { - return ManagementFactory.newPlatformMXBeanProxy(server, ManagementFactory.THREAD_MXBEAN_NAME, - ThreadMXBean.class); - } - - /** - * Helper method to retrieve proxy object for platform Memory MXBean - * ({@code "java.lang:type=OperatingSystem"}). - * - * @param server - * the connected server - * @return a proxy object or {@code null} if it does not exist. - * @throws IOException - * if a communication problem occurred. - * @see ManagementFactory#newPlatformMXBeanProxy(MBeanServerConnection, String, Class) - */ - public static OperatingSystemMXBean getOperatingSystemBean(MBeanServerConnection server) throws IOException { - return ManagementFactory.newPlatformMXBeanProxy(server, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, - OperatingSystemMXBean.class); - } - - /** - * Helper method to invoke MBean operation on a MBean server. Will try to deduce the correct - * method to invoke based on the provided parameters. - * - * @param server - * the MBean server to invoke method on. - * @param on - * the name of the MBean. - * @param operation - * the name of the operation. - * @param parameters - * the parameters for the method invocation. - * @return the object returned by the operation, which represents the result of invoking the - * operation on the MBean specified. - * @throws JMException - * some sort of exception due to unknown MBean or exception thrown in invoked - * method. - * @throws IOException - * if a communication problem occurred when talking to the MBean server. - */ - public static Object invokeOperation( - MBeanServerConnection server, ObjectName on, String operation, Object ... parameters) - throws JMException, IOException { - return server.invoke(on, operation, parameters, extractSignature(parameters)); - } - - /** - * Automatically generates the signature to be used when invoking operations. - * - * @param param - * the parameters for which to get the signature. - * @return the signature matching the parameters. - */ - private static String[] extractSignature(Object[] param) { - String[] sig = new String[param.length]; - for (int i = 0; i < sig.length; i++) { - if (param[i].getClass() == Boolean.class) { - sig[i] = Boolean.TYPE.getName(); - } else if (Number.class.isAssignableFrom(param[i].getClass())) { - try { - sig[i] = ((Class) param[i].getClass().getField("TYPE").get(param[i])).getName(); //$NON-NLS-1$ - } catch (IllegalArgumentException e) { - throw new UndeclaredThrowableException(e); - } catch (SecurityException e) { - throw new UndeclaredThrowableException(e); - } catch (IllegalAccessException e) { - throw new UndeclaredThrowableException(e); - } catch (NoSuchFieldException e) { - throw new UndeclaredThrowableException(e); - } - } else if (CompositeData.class.isAssignableFrom(param[i].getClass())) { - sig[i] = CompositeData.class.getName(); - } else if (TabularData.class.isAssignableFrom(param[i].getClass())) { - sig[i] = TabularData.class.getName(); - } else if (List.class.isAssignableFrom(param[i].getClass())) { - sig[i] = List.class.getName(); - } else { - sig[i] = param[i].getClass().getName(); - } - } - return sig; - } - - /** - * Will attempt to derive the host name from the {@link JMXServiceURL}. If the JXMServiceURL - * uses jmxrmi, the host name will be derived from the information in the JXMServiceURL. - * - * @param url - * the {@link JMXServiceURL} to retrieve the host name from. - * @return the host name. - */ - public static String getHostName(JMXServiceURL url) { - if (url.getHost() == null || "".equals(url.getHost().trim())) { //$NON-NLS-1$ - return deriveHost(url); - } else { - return url.getHost(); - } - } - - /** - * Will attempt to derive the port from the {@link JMXServiceURL}. If the JXMServiceURL uses - * jmxrmi, the port will be derived from the information in the JXMServiceURL. - * - * @param url - * the {@link JMXServiceURL} to derive the port from. - * @return the port number - */ - public static int getPort(JMXServiceURL url) { - if (url.getPort() <= 0) { - return derivePort(url); - } else { - return url.getPort(); - } - } - - /** - * Helper method to try to derive the host name from a standard jmxrmi JMX service URL. - * - * @param url - * service URL. - * @return the host name. - */ - private static String deriveHost(JMXServiceURL url) { - StringTokenizer st = new StringTokenizer(url.getURLPath(), ":/"); //$NON-NLS-1$ - if (st.countTokens() == 5) { - for (int i = 0; i < 2; i++) { - st.nextToken(); - } - String host = st.nextToken(); - // strip dashes - return host; - } - return "unknown"; //$NON-NLS-1$ - } - - /** - * Evil helper method to try to derive the port number from a standard jmxrmi JMX service URL. - * - * @param url - * service URL. - * @return the port number. - */ - private static int derivePort(JMXServiceURL url) { - StringTokenizer st = new StringTokenizer(url.getURLPath(), ":/"); //$NON-NLS-1$ - if (st.countTokens() == 5) { - for (int i = 0; i < 3; i++) { - st.nextToken(); - } - String port = st.nextToken(); - try { - return Integer.parseInt(port); - } catch (NumberFormatException e) { - return -1; - } - } - return 0; - } - - /** - * Creates a "JMX over RMI" or "JMX over RMP" service URL. - * - * @param host - * the host name. - * @param port - * port or {@link ConnectionDescriptorBuilder#DEFAULT_PORT} for the default port for - * the selected protocol - * @return the {@link JMXServiceURL}. - * @throws MalformedURLException - * if the URL could not be created with the provided data. - */ - public static JMXServiceURL createServiceURL(String host, int port) throws MalformedURLException { - int actualPort = (port != ConnectionDescriptorBuilder.DEFAULT_PORT) ? port - : RJMXConnection.VALUE_DEFAULT_REMOTE_PORT_JMX; - return new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ':' + actualPort + "/jmxrmi"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - - /** - * Returns the default port number for the management agent. - * - * @return the default port for the management agent. May vary depending on which JVM version - * the method is executed in. - */ - public static int getDefaultPort() { - return RJMXConnection.VALUE_DEFAULT_REMOTE_PORT_JMX; - } - - /** - * Returns {@code true} if the connection handle is connected to a JRockit, {@code false} - * otherwise. - * - * @param connectionHandle - * the connection handle to check. - * @return {@code true} if the connection handle is connected to a JRockit, {@code false} - * otherwise. - */ - public static boolean isJRockit(IConnectionHandle connectionHandle) { - String vmName = getVMName(connectionHandle); - return JavaVMVersionToolkit.isJRockitJVMName(vmName); - } - - /** - * Returns {@code true} if the connection handle is connected to a HotSpot, {@code false} - * otherwise. This method requires the connection handle to be connected. - * - * @param connectionHandle - * the connection handle to check. - * @return {@code true} if the connection handle is connected to a HotSpot, {@code false} - * otherwise. - */ - public static boolean isHotSpot(IConnectionHandle connectionHandle) { - String vmName = getVMName(connectionHandle); - return vmName != null && JavaVMVersionToolkit.isHotspotJVMName(vmName); - } - - public static boolean isSubstrateVm(IConnectionHandle connectionHandle) { - return getVMName(connectionHandle).equals("Substrate VM"); - } - /** - * Returns {@code true} if the connection handle is associated with an Oracle built JVM, - * {@code false} otherwise. If the information is already present in the {@link JVMDescriptor}, - * this method will not cause any JMXRMI calls. If the information is lacking, an attempt will - * be made to look it up in the connected JVM. If the attempt fails, false will be returned. - * - * @return {@code true} if the connection handle describes an Oracle JVM, or {@code false} - * otherwise or if it could not be determined. - */ - public static boolean isOracle(IConnectionHandle handle) { - JVMDescriptor descriptor = handle.getServerDescriptor().getJvmInfo(); - // This should normally not happen for discovered JVMs, but users can create custom connections - String name = null; - if (descriptor != null) { - name = descriptor.getJvmName(); - } else { - // We try checking if connected - if (handle.isConnected()) { - MBeanServerConnection connection = handle.getServiceOrNull(MBeanServerConnection.class); - if (connection != null) { - try { - name = getRuntimeBean(connection).getVmName(); - } catch (IOException e) { - // Worst case we classify JVM name wrong - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not check if Oracle JVM", e); - } - } - } - } - return name != null && (name.contains("Java HotSpot")); - } - - /** - * This will return true if the java version is above or equal the supplied value. (For example - * 1.7.0_40). - * - * @param connectionHandle - * the connectionHandle to check. - * @param minVersion - * the java version needed. - * @return {@code true} if the version is above or equal the supplied value, {@code true} if no - * version can be obtained from the connection, {@code false} otherwise. - */ - public static boolean isJavaVersionAboveOrEqual(IConnectionHandle connectionHandle, JavaVersion minVersion) { - JavaVersion version = getJavaVersion(connectionHandle); - return version != null ? version.isGreaterOrEqualThan(minVersion) : true; - } - - private static String getVMName(IConnectionHandle connectionHandle) { - MBeanServerConnection connection = connectionHandle.getServiceOrDummy(MBeanServerConnection.class); - try { - // getAttribute may fail if the connection handle - // has just been disconnected by the user, which is not a problem - return getRuntimeBean(connection).getVmName(); - - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.INFO, "Could not check the JVM name!", e); //$NON-NLS-1$ - } - return null; - } - - private static JavaVersion getJavaVersion(IConnectionHandle connectionHandle) { - try { - MBeanServerConnection server = connectionHandle.getServiceOrThrow(MBeanServerConnection.class); - Map serverProps = getRuntimeBean(server).getSystemProperties(); - String javaVersion = serverProps.get("java.version"); //$NON-NLS-1$ - if (javaVersion != null) { - return new JavaVersion(javaVersion); - } - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "System Properties from " + connectionHandle.getDescription() //$NON-NLS-1$ - + " contained no java.version property!"); //$NON-NLS-1$ - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Could not check the java.version from System Properties!", e); //$NON-NLS-1$ - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IConnectionDescriptor.java b/src/main/java/org/openjdk/jmc/rjmx/IConnectionDescriptor.java deleted file mode 100644 index ec654bcb..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IConnectionDescriptor.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.io.IOException; -import java.util.Map; - -import javax.management.remote.JMXServiceURL; - -/** - * Describes a connection. - *

- * It encapsulates the knowledge for how to connect to another JVM. - *

- * The extended properties collection is a set of application specific flags that will be persisted - * with the connection. It is free to use and change at the application's discretion. - *

- * If you need to use the extended properties, please note that the key name space - * {@code org.openjdk.jmc.*} is reserved for JRPG applications. - *

- * The descriptor may opt to resolve its {@link JMXServiceURL} lazily. - */ -public interface IConnectionDescriptor { - - /** - * Returns a JMX service URL based on the settings in the descriptor. Some implementations may - * want to just return a pre-configured service URL, whilst others may want to resolve the URL - * lazily, as resolving it might be quite expensive. - * - * @return the resolved {@link JMXServiceURL}. - * @throws IOException - * since this can be created lazily, potential problems whilst resolving the service - * URL can throw {@link IOException}. - */ - JMXServiceURL createJMXServiceURL() throws IOException; - - /** - * Returns a copy of the JMX environment. - * - * @return the JMX environment. Usually contains credentials and similar. - */ - Map getEnvironment(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IConnectionHandle.java b/src/main/java/org/openjdk/jmc/rjmx/IConnectionHandle.java deleted file mode 100644 index eeab53fd..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IConnectionHandle.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.io.Closeable; - -/** - * A connection handle is a handle to an active connection. It provides services around the - * connection. A connection handle can be injected into a Console page: - * - *

-public class ConnectionExamplePage {
-
-   {@literal @}Inject
-    private IConnectionHandle connectionHandle;
-
-   {@literal @}Inject
-    protected void createPageContent(IManagedForm managedForm) {
-        managedForm.getToolkit().decorateFormHeading(managedForm.getForm().getForm());
-        final Label valueLabel = managedForm.getToolkit().createLabel(
-            managedForm.getForm().getBody(), "", SWT.CENTER);
-        valueLabel.setText("isConnected: " + connectionHandle.isConnected());
-        managedForm.getForm().getBody().setLayout(new FillLayout());
-    }
-}
- * 
- */ -public interface IConnectionHandle extends Closeable { - - /** - * Gets the server descriptor for this connection handle. - * - * @return the server descriptor - */ - IServerDescriptor getServerDescriptor(); - - /** - * Get a service implementation of {@code serviceClass}. - * - * @param - * the service type to look up - * @param serviceClass - * the {@link Class} of the service - * @return either a proper service, or a dummy service that mostly throws exceptions, never - * {@code null}. - * @throws IllegalArgumentException - * if the service argument didn't represent an interface. - */ - T getServiceOrDummy(Class serviceClass) throws IllegalArgumentException; - - /** - * Get a proper service implementation of {@code serviceClass}, or {@code null} if no such - * service could be created or the connection has been closed. - * - * @param - * the service type to look up - * @param serviceClass - * the {@link Class} of the service - * @return a proper service implementing {@code serviceClass}, or {@code null}. - */ - T getServiceOrNull(Class serviceClass); - - /** - * Get a proper service implementation of {@code serviceClass} - * - * @param - * the service type to look up - * @param serviceClass - * the {@link Class} of the service - * @return a proper service implementing {@code serviceClass} - * @throws ConnectionException - * if the connection handle has been closed - * @throws ServiceNotAvailableException - * if the service is not available - */ - T getServiceOrThrow(Class serviceClass) throws ConnectionException, ServiceNotAvailableException; - - /** - * Returns whether there is a service registered for the given type. - * - * @param clazz - * the {@link Class} of the service - * @return {@code true} if the service exist, {@code false} otherwise. - */ - boolean hasService(Class clazz); - - /** - * Return whether this connection is live. - * - * @return {@code true} if this connection is live, {@code false} otherwise. - */ - boolean isConnected(); - - /** - * Returns a description of the connection handle's intended use. - * - * @return the description of the connection handle's intended use. - */ - String getDescription(); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IConnectionListener.java b/src/main/java/org/openjdk/jmc/rjmx/IConnectionListener.java deleted file mode 100644 index 4a5c9f36..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IConnectionListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -/** - * A listener that can be notified when the status of a connection changes - */ -public interface IConnectionListener { - - /** - * @param connection - * the handle to the connection that has changed - */ - void onConnectionChange(IConnectionHandle connection); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IPropertySyntheticAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/IPropertySyntheticAttribute.java deleted file mode 100644 index f7103969..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IPropertySyntheticAttribute.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.util.Map; - -/** - * Defines a client side evaluated attribute which accepts properties defined in the extension. The - * properties callback will be called after the synthetic attribute has been created, but before it - * is available to the MBeanServerConnection. - */ -public interface IPropertySyntheticAttribute extends ISyntheticAttribute { - /** - * Initializes this synthetic attribute with the custom properties from the extension. - * - * @param values - * the map with the properties from the extension. - */ - void setProperties(Map values); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IServerDescriptor.java b/src/main/java/org/openjdk/jmc/rjmx/IServerDescriptor.java deleted file mode 100644 index 09952ed2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IServerDescriptor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import org.openjdk.jmc.rjmx.internal.ServerDescriptor; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; - -/** - * An object describing a server - */ -public interface IServerDescriptor { - - /** - * @return the globally unique ID of the server - */ - String getGUID(); - - /** - * @return the display name of the server - */ - String getDisplayName(); - - /** - * @return an object describing the JVM on which the server is running - */ - JVMDescriptor getJvmInfo(); - - /** - * Creates a new server descriptor with the supplied properties - * - * @param guid - * the globally unique ID of the server - * @param displayName - * the display name of the server - * @param jvmInfo - * an object describing the JVM on which the server is running - * @return the new server descriptor - */ - static IServerDescriptor create(String guid, String displayName, JVMDescriptor jvmInfo) { - return new ServerDescriptor(guid, displayName, jvmInfo); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/IServerHandle.java b/src/main/java/org/openjdk/jmc/rjmx/IServerHandle.java deleted file mode 100644 index 544a74be..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/IServerHandle.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import org.openjdk.jmc.rjmx.internal.ServerHandle; - -/** - * A handle that is used to setup connections to a server. - *

- * Handles can be closed and disposed. Closing a handle closes all its current existing connections. - * Disposing a handle also prevents it from opening new connections. - */ -public interface IServerHandle { - - /** - * Describes the different connection states a server can handle be in. A handle is - * {@link #DISPOSED} if it is invalidated by a graceful dispose action, and {@link #FAILED} if - * it is invalidated for some other reason. If the handle is not disposed it is either - * {@link #CONNECTED} if there is an active connection to the server, or {@link #DISCONNECTED} - * if there is not. - */ - enum State { - DISCONNECTED, CONNECTED, DISPOSED, FAILED; - } - - /** - * @param usage - * A localized string that may be shown to the user, describing why this connection - * was established - * @return A handle representing an open connection to the server - * @throws ConnectionException - * If the connection failed, for example since the server was no longer reachable, - * or this handle was closed. - */ - IConnectionHandle connect(String usage) throws ConnectionException; - - /** - * @param usage - * A localized string that may be shown to the user, describing why this connection - * was established - * @param listener - * A listener that is notified when the status of the connection changes - * @return A handle representing an open connection to the server - * @throws ConnectionException - * If the the connection failed, for example since the server was no longer - * reachable, or this handle was closed. - */ - IConnectionHandle connect(String usage, IConnectionListener listener) throws ConnectionException; - - /** - * Closes all existing connections for this server handle but leaves it in a state which enables - * new invokes of connect. - */ - void close(); - - /** - * Disposes this server handle, closes all connection handles and makes it invalid to use for - * creating new connections. - */ - void dispose(); - - /** - * @return An object describing the server this instance is a handle for - */ - IServerDescriptor getServerDescriptor(); - - /** - * @return The state of this handle - */ - State getState(); - - /** - * Creates a server handle for a possible connection. This descriptor might or might not be - * valid and actually point to a real RJMX server. Used when one wants to connect to an explicit - * server. - * - * @param descriptor - * the descriptor for the handle - * @return the server handle - */ - static IServerHandle create(IConnectionDescriptor descriptor) { - return new ServerHandle(descriptor); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ISyntheticAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/ISyntheticAttribute.java deleted file mode 100644 index b56a2ba2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ISyntheticAttribute.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -/** - * Defines a client side evaluated attribute. These attributes can be mounted in the existing MBean - * tree using the {@code org.openjdk.jmc.rjmx.syntheticattribute} extension point. It is even - * possible to add attributes, and override attributes, in already existing MBeans. Synthetic - * attributes will take precedence. If several synthetic attributes have the same attribute name, - * only one will be registered, and a warning will be logged for the rest. - */ -public interface ISyntheticAttribute { - /** - * Returns the value of the synthetic attribute. - * - * @param connection - * the MBean server to use for resource lookup - * @return the value of the synthetic attribute. - * @throws MBeanException - * Wraps an exception thrown by the MBean's getter. - * @throws ReflectionException - * Wraps an exception thrown while trying to invoke the getter. - */ - Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException; - - /** - * Sets the value of the synthetic attribute. - * - * @param connection - * the MBean server to use for resource lookup - * @param value - * the value to set. - * @throws MBeanException - * Wraps an exception thrown by the MBean's setter. - * @throws ReflectionException - * Wraps an exception thrown while trying to invoke the MBean's setter. - */ - void setValue(MBeanServerConnection connection, Object value) throws MBeanException, ReflectionException; - - /** - * Whether the resources that the synthetic attribute depends on are present. - * - * @param connection - * the MBean server to use for resource lookup - * @return {@code true} if resources are present, {@code false} otherwise - */ - boolean hasResolvedDependencies(MBeanServerConnection connection); - - /** - * Use this method to set up dependencies on notifications. It can also be used to set up - * external timers or other initializations. - * - * @param connection - * the MBean connection that this attribute is used for. - */ - void init(MBeanServerConnection connection); - - /** - * Use this method if you have any cleanup that needs be done when the MBeanServer connection is - * about to be closed down. - */ - void stop(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ISyntheticNotification.java b/src/main/java/org/openjdk/jmc/rjmx/ISyntheticNotification.java deleted file mode 100644 index 89b3d85f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ISyntheticNotification.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import javax.management.MBeanServerConnection; -import javax.management.modelmbean.ModelMBeanNotificationBroadcaster; -import javax.management.openmbean.OpenType; - -/** - * Base interface to implement for synthetic notifications. Used with the - * {@code org.openjdk.jmc.rjmx.syntheticnotification} extension point. - */ -public interface ISyntheticNotification { - - /** - * This method returns the value to include in the notification. - * - * @return the value to include in the notification. - */ - Object getValue(); - - /** - * Override this method if you have any cleanup that needs be done when the MBeanServer - * connection is about to be closed down. - */ - void stop(); - - /** - * Whether the resources that the synthetic notification depends on are present. - * - * @param connection - * the MBean server to use for resource lookup - * @return true if resources are present, false otherwise - */ - boolean hasResolvedDependencies(MBeanServerConnection connection); - - /** - * This method can be overridden to set up dependencies on other notifications. It can also be - * used to set up external timers or any other mechanism that will send notifications. Note that - * no notification will be triggered unless one is explicit created and sent to - * {@link ModelMBeanNotificationBroadcaster#sendNotification(javax.management.Notification)}. It - * is the subclass' responsibility to ensure this happens. - * - * @param connection - * the MBean connection that this notification is used for. - * @param type - * the type of notifications that this synthetic notification is expected to - * generate. - * @param message - * the message that will be provided in the generated notification by default. - */ - void init(MBeanServerConnection connection, String type, String message); - - /** - * This method is used by the framework to inject the broadcaster. - * - * @param broadcaster - * the broadcaster responsible for sending the notifications. - */ - void init(ModelMBeanNotificationBroadcaster broadcaster); - - /** - * This method is used by the framework to access the broadcaster. - * - * @return the broadcaster of this synthetic notification - */ - ModelMBeanNotificationBroadcaster getBroadcaster(); - - /** - * Returns the MBean {@link OpenType} for this synthetic notification. - * - * @return this notifications type - */ - OpenType getValueType(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java deleted file mode 100644 index a6c336dc..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import javax.management.MBeanServerConnection; - -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.rjmx.internal.ServerToolkit; -import org.openjdk.jmc.rjmx.services.internal.HotspotManagementToolkit; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; -import org.openjdk.jmc.ui.common.jvm.JVMType; - -/** - * Checks the JVM capabilities of a connection. - */ -public final class JVMSupportToolkit { - - private JVMSupportToolkit() { - throw new IllegalArgumentException("Don't instantiate this toolkit"); //$NON-NLS-1$ - } - - /** - * Checks if the JVM is supported in respect to console features, and if not, returns a string - * array with title and message - * - * @param connection - * the connection to check - * @return a string array with title and message if the jvm is not supported, otherwise - * {@code null}. - */ - public static String[] checkConsoleSupport(IConnectionHandle connection) { - String title = null; - String message = null; - if (ConnectionToolkit.isJRockit(connection)) { - title = "JRockit Not Supported"; - message = "You are attempting to connect to a JRockit JVM. To connect to a JRockit JVM, please use JRockit Mission Control 4.1 for JRockit R28, and JRockit Mission Control 3.1 for JRockit R27. \nIf you connect to a JRockit, functionality will be limited. \n\nAre you sure you want to continue?"; - } else if (!ConnectionToolkit.isHotSpot(connection)) { - title = "Not a Known JVM"; - message = "You are attempting to connect to an unknown JVM. This will most likely not succeed unless you're running the JMX Console, and even then functionality will be limited. \n\nAre you sure you want to continue?"; - } else if (!ConnectionToolkit.isJavaVersionAboveOrEqual(connection, - JavaVersionSupport.DIAGNOSTIC_COMMANDS_SUPPORTED)) { - title = "Too Old JVM"; - message = "The JVM you are connecting to is not recent enough for full functionality in the JMX Console. For full functionality you need to connect to an Oracle JDK 7u40 or later JVM or an OpenJDK 11+ JVM. Do you still want to connect?"; - } - - if (title != null) { - String[] returnInfo = new String[2]; - returnInfo[0] = title; - returnInfo[1] = message; - return returnInfo; - } - return new String[0]; - } - - /** - * Checks if Flight Recorder is available for use - * - * @param connection - * @return If it is an Oracle JVM or there is a FlightRecorder VM option, then return true. - * Otherwise, return false. This is used for verifying JDK 8 JVMs that are not built - * with JFR enabled, e.g., OpenJDK 8 - */ - public static boolean hasFlightRecorder(IConnectionHandle connection) { - if (ConnectionToolkit.isOracle(connection)) { - return true; - } - MBeanServerConnection server = connection.getServiceOrNull(MBeanServerConnection.class); - try { - HotspotManagementToolkit.getVMOption(server, "FlightRecorder"); - return true; - } catch (Exception e) { // RuntimeMBeanException thrown if FlightRecorder is not present - return false; - } - } - - /** - * Checks if Flight Recorder is disabled. - * - * @param connection - * the connection to check - * @param explicitFlag - * If the flag has to be explicitly disabled on the command line with - * -XX:-FlightRecorder - * @return If explicitFlag is true, then returns true only if Flight Recorder is explicitly - * disabled on the command line. If explicitFlag is false, then returns true if Flight - * Recorder is currently not enabled. - */ - public static boolean isFlightRecorderDisabled(IConnectionHandle connection, boolean explicitFlag) { - try { - MBeanServerConnection server = connection.getServiceOrThrow(MBeanServerConnection.class); - boolean disabled = !Boolean - .parseBoolean(HotspotManagementToolkit.getVMOption(server, "FlightRecorder").toString()); //$NON-NLS-1$ - if (explicitFlag) { - return (disabled && HotspotManagementToolkit.isVMOptionExplicit(server, "FlightRecorder")); //$NON-NLS-1$ - } else { - return disabled; - } - } catch (Exception e) { - return false; - } - } - - /** - * Returns a descriptive error message about why Flight Recorder is unavailable. - * - * @param handle - * the connection to check - * @param shortMessage - * whether to return a short message or not - * @return a descriptive string about why Flight Recorder is unavailable. - */ - public static String getNoFlightRecorderErrorMessage(IConnectionHandle handle, boolean shortMessage) { - if (ConnectionToolkit.isJRockit(handle)) { - return getJfrJRockitNotSupported(shortMessage); - } - if (!ConnectionToolkit.isHotSpot(handle)) { - return getJfrNonHotSpotNotSupported(shortMessage); - } - if (!ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.JFR_ENGINE_SUPPORTED)) { - return getJfrOldHotSpotNotSupported(shortMessage); - } - if (isFlightRecorderDisabled(handle, true)) { - return getJfrDisabled(shortMessage); - } - return getJfrNotEnabled(shortMessage); - } - - /** - * Returns information about whether the server supports Flight Recorder. - * - * @param handle - * the server to check - * @param shortMessage - * whether to return a short message or not - * @return a descriptive string about why Flight Recorder is not supported, or {@code null}. - */ - public static String checkFlightRecorderSupport(IServerHandle handle, boolean shortMessage) { - if (ServerToolkit.getJvmInfo(handle) != null) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(handle); - - if (jvmInfo.getJvmType() == null) { - return null; - } - if (jvmInfo.getJvmType() == JVMType.JROCKIT) { - return getJfrJRockitNotSupported(shortMessage); - } - if (jvmInfo.getJvmType() == JVMType.UNKNOWN) { - return null; - } - if (jvmInfo.getJvmType() != JVMType.HOTSPOT) { - return getJfrNonHotSpotNotSupported(shortMessage); - } - if (jvmInfo.getJavaVersion() == null) { - return null; - } - if (!new JavaVersion(jvmInfo.getJavaVersion()) - .isGreaterOrEqualThan(JavaVersionSupport.JFR_ENGINE_SUPPORTED)) { - return getJfrOldHotSpotNotSupported(shortMessage); - } - if (!new JavaVersion(jvmInfo.getJavaVersion()) - .isGreaterOrEqualThan(JavaVersionSupport.JFR_FULLY_SUPPORTED)) { - return getJfrOldHotSpotNotFullySupported(shortMessage); - } - } - return null; - } - - private static String getJfrNotEnabled(boolean shortMessage) { - return shortMessage ? "Flight Recorder features are not enabled" - : "Flight Recorder features are not enabled. To enable this you need to use an Oracle JDK 7u4 or later JVM started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder or an OpenJDK 11+ JVM."; - } - - private static String getJfrDisabled(boolean shortMessage) { - return shortMessage ? "Flight Recorder is explicitly disabled" - : "Flight Recorder is explicitly disabled. To enable the Flight Recorder, remove -XX:-FlightRecorder from the command line."; - } - - private static String getJfrOldHotSpotNotSupported(boolean shortMessage) { - return shortMessage ? "Flight Recorder is not supported for JVMs with Java versions below 7u4" - : "Flight Recorder is not supported for JVMs with Java versions below 7u4"; - } - - private static String getJfrOldHotSpotNotFullySupported(boolean shortMessage) { - return shortMessage ? "Flight Recorder is not fully supported for JVMs with Java versions below 7u40" - : "Flight Recorder is not fully supported for JVMs with Java versions below 7u40"; - } - - private static String getJfrNonHotSpotNotSupported(boolean shortMessage) { - return shortMessage ? "Flight Recorder is not supported for non HotSpot JVMs" - : "Flight Recorder is not supported for non HotSpot JVMs"; - } - - private static String getJfrJRockitNotSupported(boolean shortMessage) { - return shortMessage ? "JRockit is no longer supported" - : "JRockit is no longer supported"; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/RJMXPlugin.java b/src/main/java/org/openjdk/jmc/rjmx/RJMXPlugin.java deleted file mode 100644 index 6b5ccfea..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/RJMXPlugin.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -import java.util.logging.Logger; - -import org.openjdk.jmc.rjmx.internal.RJMXSingleton; - -/** - * There is one instance of the RJMX plugin available from {@link RJMXPlugin#getDefault()}. The - * plugin provides: - *

    - *
  • access to the connection manager
  • - *
  • access to the description repository
  • - *
  • access to the global services
  • - *
- * Clients may not instantiate or subclass this class. - */ -public final class RJMXPlugin { - - /** - * The plugin identifier. - */ - public static final String PLUGIN_ID = "org.openjdk.jmc.rjmx"; //$NON-NLS-1$ - - /** - * The identifier for the server configuration. - */ - public static final String SERVER_CONFIG_ID = "serverConfig"; //$NON-NLS-1$ - - // The logger. - private final static Logger LOGGER = Logger.getLogger(PLUGIN_ID); - - // The shared instance - private static final RJMXPlugin plugin = new RJMXPlugin(); - - /** - * The default constructor. - */ - private RJMXPlugin() { - } - - - /** - * Returns the shared instance. - * - * @return the shared instance - */ - public static RJMXPlugin getDefault() { - return plugin; - } - - /** - * Returns the logger for RJMX. - * - * @return the {@link Logger} - */ - public Logger getLogger() { - return LOGGER; - } - - /** - * Returns a global RJMX service. Currently there is no way to register new global services. - * - * @param - * the service type to look up - * @param clazz - * the {@link Class} of the service - * @return the service object registered for the given class. - */ - public T getService(Class clazz) { - return RJMXSingleton.getDefault().getService(clazz); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/ServiceNotAvailableException.java b/src/main/java/org/openjdk/jmc/rjmx/ServiceNotAvailableException.java deleted file mode 100644 index 81e847e9..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/ServiceNotAvailableException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx; - -/** - * This exception is thrown when a service is not available. - */ -public class ServiceNotAvailableException extends Exception { - - private static final long serialVersionUID = -5674957382317797765L; - - /** - * Constructs an exception with the specified detail message. - * - * @param message - * The detail message (which is saved for later retrieval by the - * {@link #getMessage()} method) - */ - public ServiceNotAvailableException(String message) { - super(message); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/IActionProviderFactory.java b/src/main/java/org/openjdk/jmc/rjmx/actionprovider/IActionProviderFactory.java deleted file mode 100644 index f342adeb..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/IActionProviderFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.actionprovider; - -import java.util.Collection; - -import org.openjdk.jmc.rjmx.IServerHandle; -import org.openjdk.jmc.ui.common.action.IActionProvider; -import org.openjdk.jmc.ui.common.action.IUserAction; - -/** - * Factory interface that is implemented by contributors to the org.openjdk.jmc.rjmx.actionProvider - * extension point that want to contribute both actions and action providers. - */ -public interface IActionProviderFactory { - - void initialize(IServerHandle serverHandle); - - Collection getActionProviders(); - - Collection getActions(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProvider.java b/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProvider.java deleted file mode 100644 index b330b103..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.actionprovider.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.openjdk.jmc.ui.common.action.IActionProvider; -import org.openjdk.jmc.ui.common.action.IUserAction; - -public class ActionProvider implements IActionProvider { - private final List providers = new ArrayList<>(); - private final List actions = new ArrayList<>(); - - public List getProviders() { - return providers; - } - - @Override - public List getActions() { - return actions; - } - - @Override - public boolean hasChildren() { - return providers.size() > 0; - } - - @Override - public List getChildren() { - return providers; - } - - @Override - public IUserAction getDefaultAction() { - return actions.size() > 0 ? actions.get(0) : null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderGrammar.java b/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderGrammar.java deleted file mode 100644 index d3d8195d..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderGrammar.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.actionprovider.internal; - -public class ActionProviderGrammar { - public static final String EXTENSION_POINT = "org.openjdk.jmc.rjmx.actionProvider"; //$NON-NLS-1$ - public static final String ICON_ATTRIBUTE = "icon"; //$NON-NLS-1$ - public static final String DESCRIPTION_ATTRIBUTE = "description"; //$NON-NLS-1$ - public static final String ID_ATTRIBUTE = "id"; //$NON-NLS-1$ - public static final String LABEL_ATTRIBUTE = "label"; //$NON-NLS-1$ - public static final String FACTORY_ATTRIBUTE = "factory"; //$NON-NLS-1$ - public static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ - public static final String LOCATION_ATTRIBUTE = "location"; //$NON-NLS-1$ - public static final String PRIORITY_ATTRIBUTE = "priority"; //$NON-NLS-1$ - public static final String DOUBLECLICKACTIONINDEX_ATTRIBUTE = "doubleClickActionIndex"; //$NON-NLS-1$ - public static final String EXTENSION_ELEMENT_PROVIDER = "provider"; //$NON-NLS-1$ - public static final String EXTENSION_ELEMENT_PROVIDER_FACTORY = "providerFactory"; //$NON-NLS-1$ - public static final String EXTENSION_ELEMENT_ACTION = "action"; //$NON-NLS-1$ - public static final String EXTENSION_ELEMENT_ADDON = "addon"; //$NON-NLS-1$ -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderRepository.java b/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderRepository.java deleted file mode 100644 index 633d899a..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/actionprovider/internal/ActionProviderRepository.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.actionprovider.internal; - -import org.openjdk.jmc.rjmx.IServerHandle; -import org.openjdk.jmc.ui.common.action.IActionProvider; - -public class ActionProviderRepository { - - public static IActionProvider buildActionProvider(IServerHandle handle) { - ActionProvider ap = new ActionProvider(); - return ap; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorListener.java b/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorListener.java deleted file mode 100644 index 38bb3613..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.descriptorprovider; - -import javax.management.remote.JMXServiceURL; - -import org.openjdk.jmc.common.IDescribable; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IServerDescriptor; - -/** - * The consumer of descriptors provided by the descriptor provider. - */ -public interface IDescriptorListener { - - void onDescriptorDetected( - IServerDescriptor serverDescriptor, String path, JMXServiceURL url, IConnectionDescriptor connectionDescriptor, - IDescribable provider); - - /** - * Callback hook called upon change in the discovered descriptor set. A removed descriptor will - * only be reported once. - * - * @param descriptorId - * the id of the descriptor that was removed. - */ - void onDescriptorRemoved(String descriptorId); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorProvider.java b/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorProvider.java deleted file mode 100644 index c6b77278..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/descriptorprovider/IDescriptorProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.descriptorprovider; - -import org.openjdk.jmc.common.IDescribable; - -/** - * Interface for descriptor providers. - */ -public interface IDescriptorProvider extends IDescribable { - - /** - * Adds a descriptor listener to this IDescriptorProvider. - * - * @param l - * the listener to add. - */ - void addDescriptorListener(IDescriptorListener l); - - /** - * Removes a descriptor listener from this IDescriptorProvider. - * - * @param l - * the listener to remove. - */ - void removeDescriptorListener(IDescriptorListener l); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/DefaultConnectionHandle.java b/src/main/java/org/openjdk/jmc/rjmx/internal/DefaultConnectionHandle.java deleted file mode 100644 index c994bf3c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/DefaultConnectionHandle.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.logging.Level; - -import javax.management.MBeanServerConnection; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.IConnectionListener; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.internal.ServiceFactoryManager; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMRIService; - -/** - * This class represents a connection to a JVM. - * - * @see org.openjdk.jmc.rjmx.internal.RJMXConnection - */ -public class DefaultConnectionHandle implements IConnectionHandle { - - // The services exposed by this IConnectionHandle () - private final Map, Object> services = Collections.synchronizedMap(new LinkedHashMap, Object>()); - - private final String description; - private final RJMXConnection connection; - private final IConnectionListener[] listeners; - - private static final ServiceFactoryManager FACTORY_MANAGER = new ServiceFactoryManager(); - - private volatile Long closeDownThreadId; // Set to -1 when handle is closed - - public DefaultConnectionHandle(RJMXConnection connection, String description, IConnectionListener[] listeners) { - this.connection = connection; - this.description = description; - this.listeners = listeners == null ? new IConnectionListener[0] : listeners; - registerDefaultServices(); - } - - @Override - public IServerDescriptor getServerDescriptor() { - return connection.getServerDescriptor(); - } - - @Override - public boolean isConnected() { - return isOpen() && connection.isConnected(); - } - - private boolean isOpen() { - // Access allowed if we are not closed, or for the closing thread during shutdown - return closeDownThreadId == null || Thread.currentThread().getId() == closeDownThreadId; - } - - @Override - public void close() throws IOException { - synchronized (services) { - if (closeDownThreadId != null) { - // Already closed - return; - } - // Allow disposing services to get other services, but refuse all other - closeDownThreadId = Thread.currentThread().getId(); - shutdownServices(); - closeDownThreadId = -1L; // No more access, refuse all - } - for (IConnectionListener l : listeners) { - try { - l.onConnectionChange(this); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "DefaultConnectionHandle listener " + l + " failed", e); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - - private void shutdownServices() { - Object[] servicesArray = services.values().toArray(); - for (int i = 0; i < servicesArray.length; i++) { - Object service = servicesArray[servicesArray.length - i - 1]; - if (service instanceof IDisposableService) { - try { - ((IDisposableService) service).dispose(); - } catch (RuntimeException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Could not shut down the " + service.getClass().getName() //$NON-NLS-1$ - + " service.", //$NON-NLS-1$ - e); - } - } - } - services.clear(); - } - - /** - * Free external resources. - * - * @see java.lang.Object#finalize() - */ - @Override - protected void finalize() throws Throwable { - // Make sure that external resources are freed upon GC. - close(); - super.finalize(); - } - - @Override - public String toString() { - return description + " - " + connection.toString(); //$NON-NLS-1$ - } - - @Override - public T getServiceOrThrow(Class serviceInterface) throws ConnectionException, ServiceNotAvailableException { - if (isOpen()) { - T service = getService(serviceInterface, false); - if (service != null) { - return service; - } - } else { - throw new ConnectionException("Connection closed!"); //$NON-NLS-1$ - } - throw new ServiceNotAvailableException("Service '" + serviceInterface.getName() + "' not available!"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - @Override - public T getServiceOrDummy(Class serviceInterface) { - if (!serviceInterface.isInterface()) { - /* - * If you get this, you need to call createServiceOrNull() instead and handle the null - * case. (And yes, we want to check this before attempting to create a service. Ideally, - * we would like to check this at compile time, but langtools couldn't come up with a - * good way to do so when we asked. Although JSR 308 and the Checker Framework should - * change that.) - */ - throw new IllegalArgumentException("Will not be able to create dummy implementations of " //$NON-NLS-1$ - + serviceInterface.getName() + " since the service is not an interface"); //$NON-NLS-1$ - } else if (isOpen()) { - return getService(serviceInterface, true); - } else { - return createDummyService(serviceInterface); - } - } - - @Override - public T getServiceOrNull(Class serviceInterface) { - if (isOpen()) { - return getService(serviceInterface, false); - } else { - return null; - } - } - - private T getService(Class serviceInterface, boolean acceptDummy) { - synchronized (services) { - @SuppressWarnings("unchecked") - T service = (T) services.get(serviceInterface); - if (service == null || (ServiceFactoryManager.isDummy(service) && !acceptDummy)) { - service = FACTORY_MANAGER.createService(serviceInterface, this); - if ((service == null) && acceptDummy) { - service = createDummyService(serviceInterface); - } - if (service != null) { - services.put(serviceInterface, service); - } - } - return (acceptDummy || !ServiceFactoryManager.isDummy(service)) ? service : null; - } - } - - private static T createDummyService(Class serviceInterface) throws IllegalArgumentException { - return ServiceFactoryManager.createDummyService(serviceInterface, null); - } - - private synchronized void registerDefaultServices() { - synchronized (services) { - services.put(MBeanServerConnection.class, connection.getMBeanServer()); - services.put(IMBeanHelperService.class, connection); - services.put(IMRIService.class, connection.getMRIService()); - } - } - - @Override - public boolean hasService(Class serviceClass) { - synchronized (services) { - return getServiceOrNull(serviceClass) != null; - } - } - - @Override - public String getDescription() { - return description; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/IDisposableService.java b/src/main/java/org/openjdk/jmc/rjmx/internal/IDisposableService.java deleted file mode 100644 index 351e51fa..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/IDisposableService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -/** - * Interface for services that can be disposed. Implement this interface if you want to release - * resources in your service when the service is released. - */ -public interface IDisposableService { - /** - * Notifies the service that it should be disposed. - */ - void dispose(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/JMXConnectionDescriptor.java b/src/main/java/org/openjdk/jmc/rjmx/internal/JMXConnectionDescriptor.java deleted file mode 100644 index 1c3c9b7b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/JMXConnectionDescriptor.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXServiceURL; -import javax.naming.Context; - -import org.openjdk.jmc.rjmx.ConnectionDescriptorBuilder; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.ui.common.security.ICredentials; -import org.openjdk.jmc.ui.common.security.SecurityException; - -/** - * This is the default implementation of {@link IConnectionDescriptor}. - *

- * The Connection Descriptor encapsulates the knowledge for how to connect to another JVM. The - * connection information is immutable and will not change. - *

- * The extended properties collection is a set of application specific flags that will be persisted - * with the connection. It is free to use and change at the application's discretion. - *

- * If you need to use the extended properties, please note that the key namespace org.openjdk.jmc.* - * is reserved for JRPG applications. - *

- * A DefaultJMXConnectionDescriptor has many different properties that can be set. To facilitate the - * creation of descriptors in an as easy way as possible, an internal builder class is provided. - * Here is an example on how to create a descriptor that will simply communicate using a reference - * to the local platform MBean server: - *

- * Please see {@link ConnectionDescriptorBuilder} for more information on the various options - * available. - */ -public final class JMXConnectionDescriptor implements IConnectionDescriptor { - - /** - * The JMX service URL. - */ - private final JMXServiceURL url; - - private final ICredentials credentials; - - /** - * Full constructor. - */ - public JMXConnectionDescriptor(JMXServiceURL url, ICredentials credentials) { - this.url = url; - this.credentials = credentials; - } - - @Override - public JMXServiceURL createJMXServiceURL() throws IOException { - return url; - } - - @Override - public Map getEnvironment() { - Map env = new HashMap<>(); - try { - String user = ""; //$NON-NLS-1$ - String pwd = ""; //$NON-NLS-1$ - if (credentials != null) { - if (credentials.getUsername() != null) { - user = credentials.getUsername(); - } - if (credentials.getPassword() != null) { - pwd = credentials.getPassword(); - } - } - String[] creArray = new String[2]; - creArray[0] = user; - creArray[1] = pwd; - env.put(JMXConnector.CREDENTIALS, creArray); - - // This is here for properly supporting t3 authentication... - env.put(Context.SECURITY_PRINCIPAL, user); - env.put(Context.SECURITY_CREDENTIALS, pwd); - } catch (SecurityException e) { - throw new RuntimeException(e); - } - return env; - } - - @Override - public String toString() { - return url.toString(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/JMXRMISystemPropertiesProvider.java b/src/main/java/org/openjdk/jmc/rjmx/internal/JMXRMISystemPropertiesProvider.java deleted file mode 100644 index 2e3f8137..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/JMXRMISystemPropertiesProvider.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.util.Properties; -import java.util.logging.Level; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.preferences.JMXRMIPreferences; - -public final class JMXRMISystemPropertiesProvider { - - public static void setup() { - try { - Properties jmxRmiProperties = JMXRMIPreferences.getInstance().getProperties(); - if (jmxRmiProperties != null) { - for (String prop : jmxRmiProperties.stringPropertyNames()) { - Object val = jmxRmiProperties.get(prop); - if (val != null && !val.toString().isEmpty()) { - System.setProperty(prop, val.toString()); - } - } - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.FINE, "Did not load jmxRmiProperties", e); //$NON-NLS-1$ - } - } - - public static void clearJMXRMISystemProperties() { - try { - Properties jmxRmiProperties = JMXRMIPreferences.getInstance().getProperties(); - if (jmxRmiProperties != null) { - for (String prop : jmxRmiProperties.stringPropertyNames()) { - System.clearProperty(prop); - } - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.FINE, "Failed to remove JMXRMI SystemProperties", e); //$NON-NLS-1$ - } - } - - public static boolean isKeyStoreConfigured() { - try { - Properties jmxRmiProperties = JMXRMIPreferences.getInstance().getProperties(); - if (jmxRmiProperties != null) { - int totalPrefCnt = 0; - for (String prop : jmxRmiProperties.stringPropertyNames()) { - Object val = jmxRmiProperties.get(prop); - if (val != null && !val.toString().isEmpty()) { - ++totalPrefCnt; - } - } - if (totalPrefCnt == 4) { - return true; - } - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.FINE, "Did not load jmxRmiProperties", e); //$NON-NLS-1$ - } - return false; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/MBeanOperationWrapper.java b/src/main/java/org/openjdk/jmc/rjmx/internal/MBeanOperationWrapper.java deleted file mode 100644 index efdfb5d6..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/MBeanOperationWrapper.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.Callable; - -import javax.management.MBeanFeatureInfo; -import javax.management.MBeanOperationInfo; -import javax.management.MBeanParameterInfo; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; - -import org.openjdk.jmc.common.util.TypeHandling; -import org.openjdk.jmc.rjmx.services.IOperation; -import org.openjdk.jmc.rjmx.services.IllegalOperandException; -import org.openjdk.jmc.rjmx.services.internal.AbstractOperation; -import org.openjdk.jmc.rjmx.util.internal.SimpleAttributeInfo; - -final class MBeanOperationWrapper extends AbstractOperation { - private static final String IMPACT = ".vmImpact"; //$NON-NLS-1$ - private static final int MAX_DESCRIPTORS = 8; - private static final int MAX_LINE_LENGTH = 100; - private static final String ELLIPSIS_STRING = "..."; //$NON-NLS-1$ - - private final MBeanServerConnection connection; - private final ObjectName objectName; - - private MBeanOperationWrapper(MBeanServerConnection connection, ObjectName objectName, MBeanOperationInfo info) { - super(info.getName(), convertDescription(info), info.getReturnType(), convertArguments(info), - convertImpact(info)); - this.connection = connection; - this.objectName = objectName; - } - - @Override - public Callable getInvocator(final Object ... argVals) throws IllegalOperandException { - List params = getSignature(); - final StringBuilder argString = new StringBuilder("("); //$NON-NLS-1$ - if (argVals.length < params.size()) { - // Argument list is shorter than the signature - throw new IllegalOperandException(params.subList(argVals.length, params.size())); - } - final String[] sig = new String[params.size()]; - for (int i = 0; i < params.size(); i++) { - sig[i] = params.get(i).getType(); - if (argVals[i] != null) { - argString.append(' ').append(describeValue(argVals[i])).append(','); - } else if (TypeHandling.isPrimitive(sig[i])) { - // Argument value of primitive type is null - IllegalOperandException ex = new IllegalOperandException(params.get(i)); - while (++i < params.size()) { - // Check for other attributes with the same error - if (argVals[i] == null && TypeHandling.isPrimitive(params.get(i).getType())) { - ex.addInvalidValue(params.get(i)); - } - } - throw ex; - } - } - if (argString.charAt(argString.length() - 1) == ',') { - argString.deleteCharAt(argString.length() - 1); - } - argString.append(" )"); //$NON-NLS-1$ - - return new Callable() { - - @Override - public Object call() throws Exception { - return connection.invoke(objectName, getName(), argVals, sig); - } - - @Override - public String toString() { - return getName() + argString.toString().replace("\n", "\\n").replace("\r", "\\r"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - }; - } - - static Collection createOperations( - MBeanServerConnection connection, ObjectName objectName, MBeanOperationInfo[] operations) { - List wrappedOperations = new ArrayList<>(); - for (MBeanOperationInfo info : operations) { - wrappedOperations.add(new MBeanOperationWrapper(connection, objectName, info)); - } - return wrappedOperations; - } - - /** - * @return {@code string} if it is not {@code null} and it is not an empty or blank string, - * otherwise {@code defaultString} - */ - private static String asNonNullNorEmptyString(String string, String defaultString) { - return (string != null && string.trim().length() > 0) ? string : defaultString; - } - - private static String describeValue(Object o) { - if (o.getClass().isArray()) { - return o.getClass().getComponentType().getName() + "[" + Array.getLength(o) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } else if (o instanceof String) { - return "\"" + o + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - } else { - return o.toString(); - } - } - - private static OperationImpact convertImpact(MBeanOperationInfo info) { - for (String name : info.getDescriptor().getFieldNames()) { - if (name.endsWith(IMPACT)) { - Object impactField = info.getDescriptor().getFieldValue(name); - if (impactField != null) { - String impact = impactField.toString(); - if (impact.startsWith("Low")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_LOW; - } - if (impact.startsWith("Medium")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_MEDIUM; - } - if (impact.startsWith("High")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_HIGH; - } - } - } - } - return OperationImpact.IMPACT_UNKNOWN; - } - - private static List convertArguments(MBeanOperationInfo info) { - MBeanParameterInfo[] sign = info.getSignature(); - List signature = new ArrayList<>(sign.length); - for (MBeanParameterInfo paramInfo : sign) { - // Use name primarily. Use description as name only if name is null or empty. - String name = asNonNullNorEmptyString(paramInfo.getName(), - asNonNullNorEmptyString(paramInfo.getDescription(), "")); //$NON-NLS-1$ - signature.add(new SimpleAttributeInfo(name, paramInfo.getType(), convertDescription(paramInfo))); - } - return signature; - } - - private static String convertDescription(MBeanFeatureInfo info) { - // FIXME: Building tool tips and descriptors should be unified into a toolkit - StringBuilder sb = new StringBuilder(); - if (info.getDescriptor() != null && info.getDescriptor().getFields() != null) { - String[] fields = info.getDescriptor().getFields(); - if (fields.length > 0) { - // TODO: This is a workaround to get the descriptors to UI-layer. Should be handled using some adaptive mechanism. - sb.append("Descriptor").append(":\n "); //$NON-NLS-1$ - for (int i = 0; i < Math.min(fields.length, MAX_DESCRIPTORS); i++) { - String str = fields[i]; - int cur = 0; - int newLine = 0; - while (cur < str.length() && newLine != -1) { - newLine = str.indexOf('\n', cur); - if (newLine == -1) { - sb.append(shorten(str.substring(cur))).append("\n "); //$NON-NLS-1$ - } else { - sb.append(shorten(str.substring(cur, newLine))).append("\n "); //$NON-NLS-1$ - cur = newLine + 1; - } - } - } - } - } - return shorten(info.getDescription()) + "\n " + sb.toString().trim(); //$NON-NLS-1$ - } - - private static String shorten(String s) { - if (s == null) { - return ""; //$NON-NLS-1$ - } else if (s.length() > MAX_LINE_LENGTH) { - return (s.subSequence(0, MAX_LINE_LENGTH - ELLIPSIS_STRING.length()) + ELLIPSIS_STRING); - } else { - return s; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/MCMBeanServerConnection.java b/src/main/java/org/openjdk/jmc/rjmx/internal/MCMBeanServerConnection.java deleted file mode 100644 index e2b01641..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/MCMBeanServerConnection.java +++ /dev/null @@ -1,589 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.InvalidAttributeValueException; -import javax.management.ListenerNotFoundException; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanNotificationInfo; -import javax.management.MBeanRegistrationException; -import javax.management.MBeanServerConnection; -import javax.management.NotCompliantMBeanException; -import javax.management.NotificationFilter; -import javax.management.NotificationListener; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import javax.management.QueryExp; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.internal.AttributeValueToolkit; -import org.openjdk.jmc.ui.common.util.Environment; - -/** - * Delegating MBean server connection. Provides support for synthetic attributes. - */ -public final class MCMBeanServerConnection implements MBeanServerConnection { - private final SyntheticAttributeRepository attributeRepository; - private final SyntheticNotificationRepository notificationRepository; - private final MBeanServerConnection delegate; - - public MCMBeanServerConnection(MBeanServerConnection delegate) { - this.delegate = delegate; - attributeRepository = new SyntheticAttributeRepository(this); - notificationRepository = new SyntheticNotificationRepository(this); - attributeRepository.initializeFromExtensions(); - notificationRepository.initializeFromExtensions(); - } - - /** - * All MBeans are attempted to be created in the delegate. - */ - @Override - public ObjectInstance createMBean(String className, ObjectName name) - throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, - NotCompliantMBeanException, IOException { - return delegate.createMBean(className, name); - } - - /** - * All MBeans are attempted to be created in the delegate. - */ - @Override - public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) - throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, - NotCompliantMBeanException, InstanceNotFoundException, IOException { - return delegate.createMBean(className, name, loaderName); - } - - /** - * All MBeans are attempted to be created in the delegate. - */ - @Override - public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) - throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, - NotCompliantMBeanException, IOException { - return delegate.createMBean(className, name, params, signature); - } - - /** - * All MBeans are attempted to be created in the delegate. - */ - @Override - public ObjectInstance createMBean( - String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) - throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, - NotCompliantMBeanException, InstanceNotFoundException, IOException { - return delegate.createMBean(className, name, loaderName, params, signature); - } - - /** - * Synthetics cannot be unregistered. - */ - @Override - public void unregisterMBean(ObjectName name) - throws InstanceNotFoundException, MBeanRegistrationException, IOException { - delegate.unregisterMBean(name); - } - - /** - * First attempt to get real object instance. If no joy, try synthetics. - */ - @Override - public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException, IOException { - ObjectInstance instance = delegate.getObjectInstance(name); - if (instance == null) { - instance = attributeRepository.getObjectInstance(name); - } - if (instance == null) { - instance = notificationRepository.getObjectInstance(name); - } - return instance; - } - - @Override - public Set queryMBeans(ObjectName name, QueryExp query) throws IOException { - return unify(delegate.queryMBeans(name, query), - unify(attributeRepository.queryMBeans(name, query), notificationRepository.queryMBeans(name, query))); - } - - @Override - public Set queryNames(ObjectName name, QueryExp query) throws IOException { - return unify(delegate.queryNames(name, query), - unify(attributeRepository.queryNames(name, query), notificationRepository.queryNames(name, query))); - } - - @Override - public boolean isRegistered(ObjectName name) throws IOException { - return delegate.isRegistered(name) || attributeRepository.isRegistered(name) - || notificationRepository.isRegistered(name); - } - - @Override - public Integer getMBeanCount() throws IOException { - return queryNames(null, null).size(); - } - - @Override - public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, - InstanceNotFoundException, ReflectionException, IOException { - if (attributeRepository.hasAttribute(name, attribute)) { - return attributeRepository.getAttribute(name, attribute); - } - return AttributeValueToolkit.getAttribute(delegate, name, attribute); - } - - @Override - public AttributeList getAttributes(ObjectName name, String[] attributes) - throws InstanceNotFoundException, ReflectionException, IOException { - AttributeList resultList = attributeRepository.getExistingAttributes(name, attributes); - if (resultList.size() == attributes.length) { - return resultList; - } - if (resultList.size() > 0) { - attributes = filterFoundAttributes(attributes, resultList); - resultList.addAll(AttributeValueToolkit.getAttributes(delegate, name, Arrays.asList(attributes))); - return resultList; - } - return AttributeValueToolkit.getAttributes(delegate, name, Arrays.asList(attributes)); - } - - private String[] filterFoundAttributes(String[] attributes, AttributeList attributeList) { - // Arrays.asList(...) returns a list that does not support remove(...) - List filteredAttributes = new ArrayList<>(Arrays.asList(attributes)); - for (Object obj : attributeList) { - Attribute attribute = (Attribute) obj; - filteredAttributes.remove(attribute.getName()); - } - attributes = filteredAttributes.toArray(new String[filteredAttributes.size()]); - return attributes; - } - - @Override - public void setAttribute(ObjectName name, Attribute attribute) - throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, - MBeanException, ReflectionException, IOException { - if (attributeRepository.hasAttribute(name, attribute.getName())) { - attributeRepository.setAttribute(name, attribute); - } else { - delegate.setAttribute(name, attribute); - } - } - - @Override - public AttributeList setAttributes(ObjectName name, AttributeList attributes) - throws InstanceNotFoundException, ReflectionException, IOException { - AttributeList resultList = attributeRepository.setExistingAttributes(name, attributes); - if (resultList.size() == attributes.size()) { - return resultList; - } - if (resultList.size() > 0) { - attributes = filterFoundAttributes(attributes, resultList); - resultList.addAll(delegate.setAttributes(name, attributes)); - return resultList; - } - return delegate.setAttributes(name, attributes); - } - - private AttributeList filterFoundAttributes(AttributeList attributes, AttributeList resultList) { - AttributeList filteredAttributes = new AttributeList(); - for (Object obj : attributes) { - boolean add = true; - Attribute attribute = (Attribute) obj; - for (Object result : resultList) { - Attribute resultAttribute = (Attribute) result; - if (attribute.getName().equals(resultAttribute.getName())) { - add = false; - break; - } - } - if (add) { - filteredAttributes.add(attribute); - } - } - return filteredAttributes; - } - - - @Override - public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) - throws InstanceNotFoundException, MBeanException, ReflectionException, IOException { - logInvokeMessage(name, operationName, params); - return delegate.invoke(name, operationName, params, signature); - } - - private void logInvokeMessage(ObjectName name, String operationName, Object[] params) { - if (Environment.isDebug()) { - if (params == null) { - RJMXPlugin.getDefault().getLogger().log(Level.FINE, - String.format("Invoking operation %s on %s", operationName, name)); //$NON-NLS-1$ - } else { - RJMXPlugin.getDefault().getLogger().log(Level.FINE, - String.format("Invoking operation %s on %s, with parameters %s", operationName, name, //$NON-NLS-1$ - toString(params))); - } - } - } - - private Object toString(Object[] params) { - StringBuilder builder = new StringBuilder(); - for (Object o : params) { - builder.append(o.toString()); - builder.append(' '); - } - return builder.toString(); - } - - /** - * Don't have a default domain for synthetics. - */ - @Override - public String getDefaultDomain() throws IOException { - return delegate.getDefaultDomain(); - } - - @Override - public String[] getDomains() throws IOException { - return unify(unify(notificationRepository.getDomains(), attributeRepository.getDomains(), String.class), - delegate.getDomains(), String.class); - } - - @Override - public void addNotificationListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.addNotificationListener(name, listener, filter, handback); - tryRegisteringListener(name, listener, filter, handback); - } else { - delegate.addNotificationListener(name, listener, filter, handback); - } - } - - private void tryRegisteringListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.addNotificationListener(name, listener, filter, handback); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public void addNotificationListener( - ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.addNotificationListener(name, listener, filter, handback); - tryRegisteringListener(name, listener, filter, handback); - } else { - delegate.addNotificationListener(name, listener, filter, handback); - } - } - - private void tryRegisteringListener( - ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.addNotificationListener(name, listener, filter, handback); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public void removeNotificationListener(ObjectName name, ObjectName listener) - throws InstanceNotFoundException, ListenerNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.removeNotificationListener(name, listener); - tryRemoveListener(name, listener); - } else { - delegate.removeNotificationListener(name, listener); - } - } - - private void tryRemoveListener(ObjectName name, ObjectName listener) throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.removeNotificationListener(name, listener); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public void removeNotificationListener( - ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, ListenerNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.removeNotificationListener(name, listener, filter, handback); - tryRemoveListener(name, listener, filter, handback); - } else { - delegate.removeNotificationListener(name, listener, filter, handback); - } - } - - private void tryRemoveListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.removeNotificationListener(name, listener); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public void removeNotificationListener(ObjectName name, NotificationListener listener) - throws InstanceNotFoundException, ListenerNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.removeNotificationListener(name, listener); - tryRemoveListener(name, listener); - } else { - delegate.removeNotificationListener(name, listener); - } - } - - private void tryRemoveListener(ObjectName name, NotificationListener listener) - throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.removeNotificationListener(name, listener); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public void removeNotificationListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, ListenerNotFoundException, IOException { - if (notificationRepository.hasNotification(name)) { - notificationRepository.removeNotificationListener(name, listener, filter, handback); - tryRemoveListener(name, listener, filter, handback); - } else { - delegate.removeNotificationListener(name, listener, filter, handback); - } - } - - private void tryRemoveListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws IOException, InstanceNotFoundException { - try { - if (!delegate.isRegistered(name)) { - return; - } - MBeanNotificationInfo[] infos = delegate.getMBeanInfo(name).getNotifications(); - if (infos != null && infos.length > 0) { - try { - delegate.removeNotificationListener(name, listener); - } catch (Exception e) { - // Silently ignore, veni, vidi and lost. - } - } - } catch (IntrospectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } catch (ReflectionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not add listener!", e); //$NON-NLS-1$ - } - } - - @Override - public MBeanInfo getMBeanInfo(ObjectName name) - throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { - boolean hasSyntheticAttribute = attributeRepository.isRegistered(name); - boolean hasSyntheticNotification = notificationRepository.isRegistered(name); - - if (!hasSyntheticAttribute && !hasSyntheticNotification) { - return delegate.getMBeanInfo(name); - } - - return unifyWithDelegateMBeanInfo(name, unifySyntheticMBeanInfo(name)); - } - - private MBeanInfo unifySyntheticMBeanInfo(ObjectName name) - throws IntrospectionException, InstanceNotFoundException, ReflectionException { - if (!notificationRepository.isRegistered(name)) { - return attributeRepository.getMBeanInfo(name); - } else if (!attributeRepository.isRegistered(name)) { - return notificationRepository.getMBeanInfo(name); - } - return unifyMBeanInfo(notificationRepository.getMBeanInfo(name), attributeRepository.getMBeanInfo(name)); - } - - private MBeanInfo unifyWithDelegateMBeanInfo(ObjectName name, MBeanInfo syntheticMBeanInfo) - throws IOException, InstanceNotFoundException, IntrospectionException, ReflectionException { - if (!delegate.isRegistered(name)) { - return syntheticMBeanInfo; - } - return unifyMBeanInfo(syntheticMBeanInfo, delegate.getMBeanInfo(name)); - } - - private MBeanInfo unifyMBeanInfo(MBeanInfo synthetic, MBeanInfo real) { - String description = real.getDescription(); - if (description == null || description.length() == 0) { - description = synthetic.getDescription(); - } - if (description != null && description.length() > 0) { - description += " [Extended with synthetic attribute(s)]"; //$NON-NLS-1$ - } else { - description = null; - } - String className = real.getClassName(); - return new MBeanInfo(className, description, - unify(synthetic.getAttributes(), real.getAttributes(), MBeanAttributeInfo.class), - real.getConstructors(), real.getOperations(), - unify(synthetic.getNotifications(), real.getNotifications(), MBeanNotificationInfo.class)); - } - - @Override - public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException, IOException { - if (delegate.isRegistered(name)) { - return delegate.isInstanceOf(name, className); - } - if (attributeRepository.isRegistered(name)) { - return attributeRepository.isInstanceOf(name, className); - } - if (notificationRepository.isRegistered(name)) { - return notificationRepository.isInstanceOf(name, className); - } - return delegate.isInstanceOf(name, className); - } - - private T[] unify(T[] masterArray, T[] slaveArray, Class arrayType) { - List unified = new ArrayList<>(masterArray.length + slaveArray.length); - for (T master : masterArray) { - unified.add(master); - } - for (T slave : slaveArray) { - if (!unified.contains(slave)) { - unified.add(slave); - } - } - T[] unifiedArray = createArray(arrayType, unified.size()); - return unified.toArray(unifiedArray); - } - - private T[] createArray(Class componentType, int size) { - @SuppressWarnings("unchecked") - T[] array = (T[]) Array.newInstance(componentType, size); - return array; - } - - private Set unify(Set masterSet, Set slaveSet) { - Set unifiedSet = new HashSet<>(); - unifiedSet.addAll(masterSet); - unifiedSet.addAll(slaveSet); - return unifiedSet; - } - - public void dispose() { - notificationRepository.dispose(); - attributeRepository.dispose(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXConnection.java b/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXConnection.java deleted file mode 100644 index c68bdc8c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXConnection.java +++ /dev/null @@ -1,595 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.net.MalformedURLException; -import java.rmi.UnmarshalException; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; - -import javax.management.AttributeNotFoundException; -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.JMRuntimeException; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerDelegate; -import javax.management.MBeanServerNotification; -import javax.management.MalformedObjectNameException; -import javax.management.Notification; -import javax.management.NotificationListener; -import javax.management.ObjectName; -import javax.management.QueryExp; -import javax.management.ReflectionException; -import javax.management.remote.JMXConnectionNotification; -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; -import javax.rmi.ssl.SslRMIClientSocketFactory; - -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.services.IOperation; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMBeanServerChangeListener; -import org.openjdk.jmc.rjmx.subscription.IMRIService; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.internal.AttributeValueToolkit; -import org.openjdk.jmc.rjmx.subscription.internal.InvoluntaryDisconnectException; -import org.openjdk.jmc.rjmx.subscription.internal.MBeanMRIMetadataDB; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; - -/** - * This class simplifies and hides some of the complexity of connecting to a JVM (supporting JSR-174 - * and JSR-160) using Remote JMX. The RJMXConnection is shared between several - * {@link DefaultConnectionHandle}s, and when the last {@link DefaultConnectionHandle} using the - * JRMXConnection is closed, the RJMXConnection will be automatically closed. - */ -public class RJMXConnection implements Closeable, IMBeanHelperService { - - public static final String KEY_SOCKET_FACTORY = "com.sun.jndi.rmi.factory.socket"; //$NON-NLS-1$ - public static final String KEY_JMXREMOTE_SSL = "com.sun.management.jmxremote.ssl"; //$NON-NLS-1$ - - /** - * The default port JMX - */ - public static final int VALUE_DEFAULT_REMOTE_PORT_JMX = 7091; - - /** - * Default recalibration interval. The server to client timediff is recalibrated every two - * minutes per default. - */ - private static final long VALUE_RECALIBRATION_INTERVAL = 120000; - private static final long REMOTE_START_TIME_UNDEFINED = -1; - private static final AtomicInteger CONNECTION_COUNTER = new AtomicInteger(); - - // The ConnectionDescriptor used to create this RJMXConnection - private final IConnectionDescriptor m_connectionDescriptor; - private final IServerDescriptor m_serverDescriptor; - private final int m_connectionId = CONNECTION_COUNTER.getAndIncrement(); - - // The MBean server connection used for all local and remote communication. - private volatile MCMBeanServerConnection m_server; - - // The underlying JMX connection used when communicating remote. - private JMXConnector m_jmxc; - - private final MBeanMRIMetadataDB m_mbeanDataProvider; - - // Variables used for calibrating the offset to the server clock. - private long m_serverOffset; - private long m_lastRecalibration; - private long m_remoteStartTime = REMOTE_START_TIME_UNDEFINED; - - private boolean m_hasInitializedAllMBeans = false; - private final HashMap m_cachedInfos = new HashMap<>(); - private volatile Set m_cachedMBeanNames = new HashSet<>(); - private final Runnable m_onFailCallback; - private final CopyOnWriteArrayList m_mbeanListeners = new CopyOnWriteArrayList<>(); - private final NotificationListener m_registrationListener = new NotificationListener() { - @Override - public void handleNotification(Notification notification, Object handback) { - if (notification instanceof MBeanServerNotification) { - ObjectName name = ((MBeanServerNotification) notification).getMBeanName(); - if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) { - try { - synchronized (m_cachedInfos) { - getMBeanInfo(name); - if (m_cachedMBeanNames.size() > 0) { - m_cachedMBeanNames.add(name); - } - } - for (IMBeanServerChangeListener l : m_mbeanListeners) { - l.mbeanRegistered(name); - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Could not retrieve MBean information for " + name + '!', e); //$NON-NLS-1$ - } - } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { - synchronized (m_cachedInfos) { - m_cachedInfos.remove(name); - m_cachedMBeanNames.remove(name); - } - for (IMBeanServerChangeListener l : m_mbeanListeners) { - l.mbeanUnregistered(name); - } - } - } - } - }; - - private final NotificationListener m_disconnectListener = new NotificationListener() { - - @Override - public void handleNotification(Notification notification, Object handback) { - if (notification != null && (JMXConnectionNotification.CLOSED.equals(notification.getType()) - || JMXConnectionNotification.FAILED.equals(notification.getType()))) { - close(); - if (m_onFailCallback != null) { - m_onFailCallback.run(); - } - } - } - - }; - - private final Object connectionStateLock = new Object(); - - /** - * Creates a new remote JMX connection to the specified host, using the supplied credentials. If - * password is null or empty, it will be ignored. Will attempt to set up a connection to the - * server immediately. The Constructor will fail if no connection could be established. - * - * @throws MalformedURLException - */ - public RJMXConnection(IConnectionDescriptor connectionDescriptor, IServerDescriptor serverDescriptor, - Runnable onFailCallback) { - if (connectionDescriptor == null) { - throw new IllegalArgumentException("Connection descriptor must not be null!"); //$NON-NLS-1$ - } - if (serverDescriptor == null) { - throw new IllegalArgumentException("Server descriptor must not be null!"); //$NON-NLS-1$ - } - m_onFailCallback = onFailCallback; - m_connectionDescriptor = connectionDescriptor; - m_serverDescriptor = serverDescriptor; - m_mbeanDataProvider = new MBeanMRIMetadataDB(this); - addMBeanServerChangeListener(m_mbeanDataProvider); - } - - public IServerDescriptor getServerDescriptor() { - return m_serverDescriptor; - } - - public IConnectionDescriptor getConnectionDescriptor() { - return m_connectionDescriptor; - } - - /** - * Disconnects the connection from the RJMX server - */ - @Override - public void close() { - synchronized (connectionStateLock) { - if (isConnected()) { - MCMBeanServerConnection tmpServer = m_server; - m_server = null; - tryRemovingListener(tmpServer); - tmpServer.dispose(); - clearCollections(); - if (m_jmxc != null) { - try { - m_jmxc.close(); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.INFO, "Problem when closing connection.", e); //$NON-NLS-1$ - } - m_jmxc = null; - } - } - } - } - - /** - * Sometimes we can fail to remove the unregister listeners from the MBeanConnection, causing - * JMX to keep a reference to this instance. To minimize impact if this happens, we clear all - * collections from data. - */ - private void clearCollections() { - clearCache(); - } - - private void tryRemovingListener(MCMBeanServerConnection tmpServer) { - try { - if (tmpServer != null) { - tmpServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, m_registrationListener); - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Failed to remove unregistration listener! Lost connection?", e); //$NON-NLS-1$ - } - } - - /** - * Returns whether the underlying connector is connected - * - * @return true if the underlying connector is still connected - */ - public boolean isConnected() { - return m_server != null; - } - - @Override - public Set getMBeanNames() throws IOException { - synchronized (m_cachedInfos) { - if (m_cachedMBeanNames.size() == 0) { - MBeanServerConnection server = ensureConnected(); - m_cachedMBeanNames = server.queryNames(null, null); - } - return new HashSet<>(m_cachedMBeanNames); - } - } - - @Override - public HashMap getMBeanInfos() throws IOException { - synchronized (m_cachedInfos) { - initializeMBeanInfos(); - return new HashMap<>(m_cachedInfos); - } - } - - @Override - public MBeanInfo getMBeanInfo(ObjectName mbean) - throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { - synchronized (m_cachedInfos) { - MBeanInfo mbeanInfo = m_cachedInfos.get(mbean); - if (mbeanInfo == null) { - MBeanServerConnection server = ensureConnected(); - mbeanInfo = server.getMBeanInfo(mbean); - if (mbeanInfo != null) { - m_cachedInfos.put(mbean, mbeanInfo); - } - } - return mbeanInfo; - } - } - - @Override - public Object getAttributeValue(MRI attribute) throws AttributeNotFoundException, MBeanException, IOException, - InstanceNotFoundException, ReflectionException { - try { - MBeanServerConnection server = ensureConnected(); - return AttributeValueToolkit.getAttribute(server, attribute); - } catch (JMRuntimeException e) { - throw new MBeanException(e, e.getMessage()); - } - } - - public boolean connect() throws ConnectionException { - JVMDescriptor jvmInfo = getServerDescriptor().getJvmInfo(); - if (jvmInfo != null && jvmInfo.getJavaVersion() != null - && !new JavaVersion(jvmInfo.getJavaVersion()).isGreaterOrEqualThan(JavaVersionSupport.JDK_6)) { - throw new ConnectionException("Too low JDK Version. JDK 1.6 or higher is supported."); //$NON-NLS-1$ - } - synchronized (connectionStateLock) { - if (isConnected()) { - return false; - } - JMXServiceURL url; - try { - url = m_connectionDescriptor.createJMXServiceURL(); - } catch (IOException e1) { - throw new WrappedConnectionException(m_serverDescriptor.getDisplayName(), null, e1); - } - - try { - // Use same convention as Sun. localhost:0 means "VM, monitor thyself!" - String hostName = ConnectionToolkit.getHostName(url); - if (hostName != null && (hostName.equals("localhost")) //$NON-NLS-1$ - && ConnectionToolkit.getPort(url) == 0) { - m_server = new MCMBeanServerConnection(ManagementFactory.getPlatformMBeanServer()); - } else { - establishConnection(url, m_connectionDescriptor.getEnvironment()); - } - tryToAddMBeanNotificationListener(); - m_remoteStartTime = fetchServerStartTime(); - return true; - } catch (Exception e) { - m_server = null; - throw new WrappedConnectionException(m_serverDescriptor.getDisplayName(), url, e); - } - } - } - - @Override - public long getApproximateServerTime(long localTime) { - long startTime = System.currentTimeMillis(); - if ((startTime - m_lastRecalibration) > VALUE_RECALIBRATION_INTERVAL - && m_remoteStartTime != REMOTE_START_TIME_UNDEFINED) { - try { - /* - * FIXME: JMC-4270 - Server time approximation is not reliable. Since JDK-6523160, - * getUptime can no longer be used to derive the current server time. Find some - * other way to do this. - */ - long uptime = ConnectionToolkit.getRuntimeBean(ensureConnected()).getUptime(); - long returnTime = System.currentTimeMillis(); - long localTimeEstimate = (startTime + returnTime) / 2; - m_serverOffset = m_remoteStartTime + uptime - localTimeEstimate; - m_lastRecalibration = returnTime; - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Could not recalibrate server offset", e); //$NON-NLS-1$ - } - } - return localTime + m_serverOffset; - } - - public void clearCache() { - synchronized (m_cachedInfos) { - m_cachedInfos.clear(); - m_cachedMBeanNames.clear(); - m_hasInitializedAllMBeans = false; - } - } - - @Override - public String toString() { - return "RJMX Connection " + m_connectionId + ": " + m_serverDescriptor.getDisplayName(); //$NON-NLS-1$ - } - - @Override - public void removeMBeanServerChangeListener(IMBeanServerChangeListener listener) { - m_mbeanListeners.remove(listener); - } - - @Override - public void addMBeanServerChangeListener(IMBeanServerChangeListener listener) { - m_mbeanListeners.add(listener); - } - - @Override - public Map> getMBeanMetadata(ObjectName mbean) { - return m_mbeanDataProvider.getMBeanData(mbean); - } - - /** - * Returns the IOperations available for the specified MBean. - * - * @param mbean - * the MBean for which to return the information. - * @return the operations that can be invoked on this mbean. - * @throws Exception - * if the connection failed or some other problem occurred when trying create - * operations. - */ - public Collection getOperations(ObjectName mbean) throws Exception { - MBeanServerConnection connection = ensureConnected(); - return MBeanOperationWrapper.createOperations(connection, mbean, - connection.getMBeanInfo(mbean).getOperations()); - } - - IMRIService getMRIService() { - return m_mbeanDataProvider; - } - - /** - * Returns the MBeanServerConnection. Yes, this breaks abstraction a bit, and should only be - * used by the MBeanBrowser. Everybody else should be using subscriptions anyway. - * - * @return the MBeanServerConnection currently in use by this connection. May be null if none is - * currently in use. - */ - MBeanServerConnection getMBeanServer() { - return m_server; - } - - /** - * Returns the bean information for the MBeans matching the domain and query. - * - * @param domain - * the domain for which to retrieve the information. - * @param query - * a query to filter for which MBeans to retrieve the information. - * @return a map with the ObjectNames and their associated MBeanInfos. - * @throws IOException - * if the connection failed or some other IO related problem occurred. - * @throws MalformedObjectNameException - * if a particularly malign (malformatted) domain was specified. - */ - private HashMap getMBeanInfos(String domain, QueryExp query) - throws MalformedObjectNameException, IOException { - MBeanServerConnection server = ensureConnected(); - ObjectName objectName = null; - int skippedMBeanCounter = 0; - if (domain != null) { - objectName = new ObjectName(domain + ":*"); //$NON-NLS-1$ - } - Set names = server.queryNames(objectName, query); - HashMap infos = new HashMap<>(names.size()); - - Iterator iter = names.iterator(); - while (iter.hasNext()) { - ObjectName name = iter.next(); - try { - infos.put(name, getMBeanInfo(name)); - } catch (NullPointerException e) { - /* - * Skip problematic MBeans when connecting. Workaround implemented so that we can - * connect to JBoss 4.2.3. - */ - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Skipping " + name.toString() //$NON-NLS-1$ - + ". Could not retrieve the MBean info for the MBean. Set log level to fine for stacktrace!"); //$NON-NLS-1$ - RJMXPlugin.getDefault().getLogger().log(Level.FINE, e.getMessage(), e); - skippedMBeanCounter++; - } catch (UnmarshalException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Skipping " //$NON-NLS-1$ - + name.toString() - + ". Could not retrieve the MBean info due to marshalling problems. Set log level to fine for stacktrace!"); //$NON-NLS-1$ - RJMXPlugin.getDefault().getLogger().log(Level.FINE, e.getMessage(), e); - skippedMBeanCounter++; - } catch (InstanceNotFoundException e) { - /* - * We may end up here if the MBean was unregistered between the call to - * getMBeanNames and getMBeanInfo(). Should not be very common though. - */ - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Skipping " + name.toString() //$NON-NLS-1$ - + ". It could not be found and may have been unregistered very recently. Set log level to fine to fine for stacktrace!"); //$NON-NLS-1$ - RJMXPlugin.getDefault().getLogger().log(Level.FINE, e.getMessage(), e); - } catch (IntrospectionException e) { - IOException exception = new IOException("Error accessing the bean."); //$NON-NLS-1$ - exception.initCause(e); - throw exception; - } catch (ReflectionException e) { - IOException exception = new IOException("Error accessing the bean."); //$NON-NLS-1$ - exception.initCause(e); - throw exception; - } - } - if (skippedMBeanCounter > 0) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Skipped " + skippedMBeanCounter + " MBeans because of marshalling related issues."); //$NON-NLS-1$ //$NON-NLS-2$ - } - return infos; - } - - /** - * Tries to add a dedicated notification listener that removes unloaded MBeans. - */ - private void tryToAddMBeanNotificationListener() { - try { - ensureConnected().addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, m_registrationListener, null, - null); - } catch (InstanceNotFoundException e) { - // Will typically not happen. - } catch (IOException e) { - // Will typically not happen. - } - } - - /** - * Tries to populate the MBean information cache if it is empty. - * - * @throws IOException - * if the connection failed or some other IO related problem occurred. - */ - private void initializeMBeanInfos() throws IOException { - synchronized (m_cachedInfos) { - if (!m_hasInitializedAllMBeans) { - try { - getMBeanInfos(null, null); - m_hasInitializedAllMBeans = true; - } catch (MalformedObjectNameException e) { - assert (false); // Should not be able to get here! - } - } - } - } - - private long fetchServerStartTime() throws IOException { - try { - return ConnectionToolkit.getRuntimeBean(ensureConnected()).getStartTime(); - } catch (IllegalArgumentException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Could not find the Runtime MBean. You are probably connecting to a custom MBean server. Functionality will be limited.", //$NON-NLS-1$ - e); - return REMOTE_START_TIME_UNDEFINED; - } - } - - /** - * Attempts to establish a connection. If the connection fails due to symptoms indicating the - * registry using SSL, another attempt to connect will be performed, with the required additions - * to the env. - */ - private void establishConnection(JMXServiceURL serviceURL, Map env) throws IOException { - try { - connectJmxConnector(serviceURL, env); - } catch (IOException exception) { - try { - if (env.get(KEY_SOCKET_FACTORY) instanceof SslRMIClientSocketFactory) { - env.remove(KEY_SOCKET_FACTORY); - } else { - env.put(KEY_SOCKET_FACTORY, new SslRMIClientSocketFactory()); - } - connectJmxConnector(serviceURL, env); - } catch (IOException ioe) { - // So we failed even when changing to secure sockets. Original exception was probably spot on... - throw exception; - } - } - m_server = new MCMBeanServerConnection(m_jmxc.getMBeanServerConnection()); - } - - private void connectJmxConnector(JMXServiceURL serviceURL, Map env) throws IOException { - m_jmxc = JMXConnectorFactory.newJMXConnector(serviceURL, env); - m_jmxc.addConnectionNotificationListener(m_disconnectListener, null, null); - // This is a hack to provide SSL properties to the RMI SSL server socket factory using system properties - JMXRMISystemPropertiesProvider.setup(); - // According to javadocs, has to pass env here too (which mSA RMI took literally). - m_jmxc.connect(env); - JMXRMISystemPropertiesProvider.clearJMXRMISystemProperties(); - } - - /** - * Ok, so this method may not be very useful, from a strict synchronization perspective, but at - * least it is now done in ONE place. - * - * @return a MBeanServerConnection, if connected (or at least non-null). - * @throws IOException - * if not connected. - */ - private MBeanServerConnection ensureConnected() throws IOException { - MBeanServerConnection server = m_server; - if (server == null) { - throw new InvoluntaryDisconnectException("Server is disconnected!"); //$NON-NLS-1$ - } - return server; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXSingleton.java b/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXSingleton.java deleted file mode 100644 index 4a17821b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/RJMXSingleton.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.servermodel.IServerModel; -import org.openjdk.jmc.rjmx.servermodel.internal.ServerModel; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProviderService; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.internal.ExtensionMetadataProviderService; -import org.openjdk.jmc.rjmx.subscription.internal.FileMRIMetadataDB; - -/** - * This class contains the service lookup pieces of {@link RJMXPlugin} which likely does not belong - * in a OSGi Bundle Activator. (Almost nothing does.) It was extracted to circumvent activator - * problems (maybe even deadlocks) when starting Mission Control on OS X from the command line with - * an -open argument. Could possibly be replaced with or delegate to OSGi (Declarative) Services. It - * might provide: - *
    - *
  • access to the connection manager
  • - *
  • access to the description repository
  • - *
  • access to the global services
  • - *
- * Clients may not instantiate or subclass this class. - */ -public final class RJMXSingleton { - private static final String PREFERENCE_ATTRIBUTE_METADATA_MANAGER = "AttributeMetadataManager"; //$NON-NLS-1$ - private static final String SERVER_MODEL_PREF = "server_model"; //$NON-NLS-1$ - private static final String TRIGGERS_MODEL_PREF = "triggers_model"; //$NON-NLS-1$ - - // The shared instance - private static final RJMXSingleton INSTANCE = new RJMXSingleton(); - - private final FileMRIMetadataDB metadataManager = buildMetadataManager(); - private final ServerModel serverModel = new ServerModel(); - - /** - * The default constructor. - */ - private RJMXSingleton() { - } - - private static FileMRIMetadataDB buildMetadataManager() { - IMRIMetadataProviderService subService = new ExtensionMetadataProviderService(); - return FileMRIMetadataDB.buildDefault(subService); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static RJMXSingleton getDefault() { - return INSTANCE; - } - - /** - * Returns a global RJMX service. Currently there is no way to register new global services. - * - * @param - * the service type to look up - * @param clazz - * the {@link Class} of an class - * @return the service object registered for the given class. - */ - @SuppressWarnings("unchecked") - public T getService(Class clazz) { - if (clazz == IMRIMetadataService.class) { - return (T) metadataManager; - } - if (clazz == IServerModel.class) { - return (T) serverModel; - } - if (clazz == ServerModel.class) { - return (T) serverModel; - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerDescriptor.java b/src/main/java/org/openjdk/jmc/rjmx/internal/ServerDescriptor.java deleted file mode 100644 index 53b4d7fb..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerDescriptor.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.util.UUID; - -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; -import org.openjdk.jmc.ui.common.labelingrules.NameConverter; - -public class ServerDescriptor implements IServerDescriptor { - private final String guid; - private final String name; - private final JVMDescriptor jvmInfo; - - public ServerDescriptor() { - this(null, null, null); - } - - public ServerDescriptor(String guid, String name, JVMDescriptor jvmInfo) { - this.guid = guid == null ? UUID.randomUUID().toString() : guid; - if (name == null) { - this.name = jvmInfo != null ? NameConverter.getInstance().format(jvmInfo) : this.guid; - } else { - this.name = name; - } - this.jvmInfo = jvmInfo; - } - - public ServerDescriptor(IServerDescriptor sd, String name) { - this(sd.getGUID(), name, sd.getJvmInfo()); - } - - @Override - public String getGUID() { - return guid; - } - - @Override - public String getDisplayName() { - return name; - } - - @Override - public JVMDescriptor getJvmInfo() { - return jvmInfo; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerHandle.java b/src/main/java/org/openjdk/jmc/rjmx/internal/ServerHandle.java deleted file mode 100644 index cc706916..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerHandle.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.openjdk.jmc.common.io.IOToolkit; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.IConnectionListener; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.IServerHandle; - -public final class ServerHandle implements IServerHandle { - - private final List connectionHandles = new ArrayList<>(); - private final RJMXConnection connection; - private final Runnable observer; - private Boolean disposedGracefully; // null if not yet disposed - private final Runnable connectionListener = new Runnable() { - - @Override - public void run() { - disconnect(); - } - }; - private final IConnectionListener connectionHandleListener = new IConnectionListener() { - - @Override - public void onConnectionChange(IConnectionHandle handle) { - if (!handle.isConnected() && removeConnectionHandle(handle)) { - nofifyObserver(); - } - } - }; - - public ServerHandle(IConnectionDescriptor descriptor) { - this(new ServerDescriptor(), descriptor, null); - } - - public ServerHandle(IServerDescriptor server, IConnectionDescriptor descriptor, Runnable observer) { - this.observer = observer; - connection = new RJMXConnection(descriptor, server, connectionListener); - } - - public IConnectionDescriptor getConnectionDescriptor() { - return connection.getConnectionDescriptor(); - } - - @Override - public IServerDescriptor getServerDescriptor() { - return connection.getServerDescriptor(); - } - - public synchronized IConnectionHandle[] getConnectionHandles() { - IConnectionHandle[] handles = new IConnectionHandle[connectionHandles.size()]; - Iterator it = connectionHandles.iterator(); - for (int i = 0; i < handles.length; i++) { - handles[i] = it.next(); - } - return handles; - } - - @Override - public IConnectionHandle connect(String usage) throws ConnectionException { - IConnectionListener[] listeners = new IConnectionListener[] {connectionHandleListener}; - return doConnect(usage, listeners); - } - - @Override - public IConnectionHandle connect(String usage, IConnectionListener listener) throws ConnectionException { - IConnectionListener[] listeners = new IConnectionListener[] {listener, connectionHandleListener}; - return doConnect(usage, listeners); - } - - private IConnectionHandle doConnect(String usage, IConnectionListener[] listeners) throws ConnectionException { - boolean performedConnect; - DefaultConnectionHandle newConnectionHandle; - synchronized (this) { - if (isDisposed()) { - throw new ConnectionException("Server handle is disposed"); //$NON-NLS-1$ - } - performedConnect = connection.connect(); - newConnectionHandle = new DefaultConnectionHandle(connection, usage, listeners); - connectionHandles.add(newConnectionHandle); - } - if (performedConnect) { - nofifyObserver(); - } - return newConnectionHandle; - } - - public void dispose(boolean gracefully) { - synchronized (this) { - if (!isDisposed()) { - disposedGracefully = gracefully; - } - } - disconnect(); - } - - @Override - public void dispose() { - dispose(true); - } - - private synchronized boolean isDisposed() { - return disposedGracefully != null; - } - - private synchronized boolean removeConnectionHandle(IConnectionHandle handle) { - connectionHandles.remove(handle); - if (connectionHandles.size() == 0) { - connection.close(); - return true; - } - return false; - } - - @Override - public void close() { - disconnect(); - } - - private void disconnect() { - for (IConnectionHandle handle : getConnectionHandles()) { - IOToolkit.closeSilently(handle); - } - } - - @Override - public String toString() { - return connection.toString(); - } - - private void nofifyObserver() { - if (observer != null) { - observer.run(); - } - } - - @Override - public synchronized State getState() { - if (isDisposed()) { - return disposedGracefully ? State.DISPOSED : State.FAILED; - } else { - return connection.isConnected() ? State.CONNECTED : State.DISCONNECTED; - } - } - - @Override - protected void finalize() throws Throwable { - disconnect(); - super.finalize(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/internal/ServerToolkit.java deleted file mode 100644 index 9f001617..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/ServerToolkit.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import org.openjdk.jmc.rjmx.IServerHandle; -import org.openjdk.jmc.rjmx.servermodel.IServer; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; - -public class ServerToolkit { - - public static JVMDescriptor getJvmInfo(IServer server) { - if (server != null) { - return getJvmInfo(server.getServerHandle()); - } - return null; - } - - public static JVMDescriptor getJvmInfo(IServerHandle serverHandle) { - if (serverHandle != null) { - if (serverHandle.getServerDescriptor() != null) { - return serverHandle.getServerDescriptor().getJvmInfo(); - } - } - return null; - } - - public static boolean isAttachable(IServerHandle serverHandle) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(serverHandle); - if (jvmInfo != null) { - return jvmInfo.isAttachable(); - } - return false; - } - - public static boolean isUnconnectable(IServerHandle serverHandle) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(serverHandle); - if (jvmInfo != null) { - return jvmInfo.isUnconnectable(); - } - return false; - } - - public static Integer getPid(IServerHandle serverHandle) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(serverHandle); - return jvmInfo == null ? null : jvmInfo.getPid(); - } - - /** - * @return the Java class run, plus any arguments to the java class. - */ - public static String getJavaCommand(IServer server) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(server); - if (jvmInfo != null) { - return jvmInfo.getJavaCommand(); - } - return null; - } - - public static String getDisplayName(IServer server) { - if (server != null) { - return getDisplayName(server.getServerHandle()); - } - return null; - } - - public static String getDisplayName(IServerHandle serverHandle) { - if (serverHandle != null) { - if (serverHandle.getServerDescriptor() != null) { - return serverHandle.getServerDescriptor().getDisplayName(); - } - } - return null; - } - - public static String getJVMArguments(IServer server) { - JVMDescriptor jvmInfo = ServerToolkit.getJvmInfo(server); - if (jvmInfo != null) { - return jvmInfo.getJVMArguments(); - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeEntry.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeEntry.java deleted file mode 100644 index 051f0892..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeEntry.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import org.openjdk.jmc.rjmx.ISyntheticAttribute; -import org.openjdk.jmc.rjmx.subscription.MRI; - -public class SyntheticAttributeEntry { - private final ISyntheticAttribute attribute; - private final MRI descriptor; - private final String description; - private final String type; - private final boolean readable; - private final boolean writeable; - private final boolean isIs; - - public SyntheticAttributeEntry(ISyntheticAttribute attribute, MRI descriptor, String description, String type, - boolean readable, boolean writeable, boolean isIs) { - this.attribute = attribute; - this.descriptor = descriptor; - this.description = description; - this.type = type; - this.readable = readable; - this.writeable = writeable; - this.isIs = isIs; - } - - public ISyntheticAttribute getAttribute() { - return attribute; - } - - public String getName() { - return descriptor.getQualifiedName(); - } - - public String getDescription() { - return description; - } - - public String getType() { - return type; - } - - public boolean isReadable() { - return readable; - } - - public boolean isWriteable() { - return writeable; - } - - public MRI getAttributeDescriptor() { - return descriptor; - } - - public boolean isIs() { - return isIs; - } - - @Override - public String toString() { - return getName() + '[' + type + ", " + flags() + ']'; //$NON-NLS-1$ - } - - private String flags() { - String flags = ""; //$NON-NLS-1$ - if (isReadable()) { - flags += 'R'; - } - if (isWriteable()) { - flags += 'W'; - } - if (isIs()) { - flags += 'I'; - } - return flags; - } - - @Override - public int hashCode() { - return descriptor.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - SyntheticAttributeEntry other = (SyntheticAttributeEntry) obj; - if (descriptor == null) { - if (other.descriptor != null) { - return false; - } - } else if (!descriptor.equals(other.descriptor)) { - return false; - } - return true; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeMBeanEntry.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeMBeanEntry.java deleted file mode 100644 index 9fdc2a22..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeMBeanEntry.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.Descriptor; -import javax.management.DynamicMBean; -import javax.management.ImmutableDescriptor; -import javax.management.InvalidAttributeValueException; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -public class SyntheticAttributeMBeanEntry implements DynamicMBean { - private final Map attributeMap = new HashMap<>(); - private final MBeanServerConnection connection; - - public SyntheticAttributeMBeanEntry(MBeanServerConnection connection) { - this.connection = connection; - } - - public void addSyntheticAttribute(SyntheticAttributeEntry entry) { - attributeMap.put(entry.getAttributeDescriptor().getDataPath(), entry); - } - - public void removeSyntheticAttribute(SyntheticAttributeEntry entry) { - attributeMap.remove(entry.getAttributeDescriptor().getDataPath()); - } - - Collection getSyntheticAttributes() { - return attributeMap.values(); - } - - @Override - public Object getAttribute(String attribute) throws MBeanException, ReflectionException { - return attributeMap.get(attribute).getAttribute().getValue(connection); - } - - @Override - public void setAttribute(Attribute attribute) - throws InvalidAttributeValueException, MBeanException, ReflectionException { - attributeMap.get(attribute.getName()).getAttribute().setValue(connection, attribute.getValue()); - } - - @Override - public AttributeList getAttributes(String[] attributes) { - AttributeList al = new AttributeList(); - for (String attribute : attributes) { - try { - Attribute a = new Attribute(attribute, attributeMap.get(attribute).getAttribute().getValue(connection)); - al.add(a); - } catch (MBeanException e) { - // Skip the attribute that couldn't be obtained. - } catch (ReflectionException e) { - // Skip the attribute that couldn't be obtained. - } - } - return al; - } - - @Override - public AttributeList setAttributes(AttributeList attributes) { - AttributeList result = new AttributeList(); - for (Object a : attributes) { - try { - Attribute attribute = (Attribute) a; - setAttribute(attribute); - result.add(attribute); - } catch (InvalidAttributeValueException e) { - // Skip the attribute that couldn't be obtained. - } catch (MBeanException e) { - // Skip the attribute that couldn't be obtained. - } catch (ReflectionException e) { - // Skip the attribute that couldn't be obtained. - } - } - return result; - } - - @Override - public Object invoke(String actionName, Object[] params, String[] signature) - throws MBeanException, ReflectionException { - throw new IllegalArgumentException("Not implemented yet!"); //$NON-NLS-1$ - } - - @Override - public MBeanInfo getMBeanInfo() { - return new MBeanInfo(getClass().getName(), "Dynamic Synthetic MBean", createAttributeInfos(), null, null, null); //$NON-NLS-1$ - } - - private MBeanAttributeInfo[] createAttributeInfos() { - Collection entries = attributeMap.values(); - MBeanAttributeInfo[] attributeInfos = new MBeanAttributeInfo[entries.size()]; - int i = 0; - for (SyntheticAttributeEntry entry : attributeMap.values()) { - attributeInfos[i++] = createAttributeInfo(entry); - } - return attributeInfos; - } - - private MBeanAttributeInfo createAttributeInfo(SyntheticAttributeEntry entry) { - return new MBeanAttributeInfo(entry.getAttributeDescriptor().getDataPath(), entry.getType(), - entry.getDescription(), entry.isReadable(), entry.isWriteable(), entry.isIs(), createDescriptor()); - } - - private Descriptor createDescriptor() { - return new ImmutableDescriptor("synthetic=true"); //$NON-NLS-1$ - } - - public boolean hasDataPath(String dataPath) { - // FIXME: Perform proper lookup - for (SyntheticAttributeEntry entry : attributeMap.values()) { - if (entry.getAttributeDescriptor().getDataPath().equals(dataPath)) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeRepository.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeRepository.java deleted file mode 100644 index 7652fbe0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticAttributeRepository.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.InvalidAttributeValueException; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanServer; -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerFactory; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import javax.management.QueryExp; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.IPropertySyntheticAttribute; -import org.openjdk.jmc.rjmx.ISyntheticAttribute; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.internal.AttributeValueToolkit; -import org.openjdk.jmc.rjmx.subscription.internal.DeadlockedThreadCountAttribute; -import org.openjdk.jmc.rjmx.subscription.internal.DivisionAttribute; -import org.openjdk.jmc.rjmx.subscription.internal.HotSpotLastGcAttribute; -import org.openjdk.jmc.rjmx.subscription.internal.HotSpotLiveSetAttribute; -import org.openjdk.jmc.rjmx.subscription.internal.LongDifferenceAttribute; -import org.openjdk.jmc.rjmx.subscription.internal.MonitoredDeadlockedThreadCountAttribute; - -/** - * Contains all the synthetic attributes. - */ -public final class SyntheticAttributeRepository { - - private final Map mbeans = new HashMap<>(); - private final MBeanServer server = MBeanServerFactory.newMBeanServer(); - private final MBeanServerConnection compoundServer; - - public SyntheticAttributeRepository(MBeanServerConnection compoundServer) { - this.compoundServer = compoundServer; - } - - void initializeFromExtensions() { - - List attributeCandidates = new ArrayList<>(); - - ISyntheticAttribute attribute = new LongDifferenceAttribute(); - MRI descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=Memory/FreeHeapMemory"); - Map properties = new HashMap<>(); - properties.put("minuend", "attribute://java.lang:type=Memory/HeapMemoryUsage/committed"); - properties.put("subtrahend", "attribute://java.lang:type=Memory/HeapMemoryUsage/used"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "long", true, false, false)); - - attribute = new LongDifferenceAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=Memory/FreeNonHeapMemory"); - properties = new HashMap<>(); - properties.put("minuend", "attribute://java.lang:type=Memory/NonHeapMemoryUsage/committed"); - properties.put("subtrahend", "attribute://java.lang:type=Memory/NonHeapMemoryUsage/used"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "long", true, false, false)); - - attribute = new DivisionAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=Memory/HeapMemoryUsagePercent"); - properties = new HashMap<>(); - properties.put("dividend", "attribute://java.lang:type=Memory/HeapMemoryUsage/used"); - properties.put("divisor", "attribute://java.lang:type=Memory/HeapMemoryUsage/committed"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "double", true, false, false)); - - attribute = new DivisionAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=OperatingSystem/PhysicalMemoryUsagePercent"); - properties = new HashMap<>(); - properties.put("dividend", "attribute://java.lang:type=OperatingSystem/UsedPhysicalMemorySize"); - properties.put("divisor", "attribute://java.lang:type=OperatingSystem/TotalPhysicalMemorySize"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "double", true, false, false)); - - attribute = new LongDifferenceAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=OperatingSystem/UsedPhysicalMemorySize"); - properties = new HashMap<>(); - properties.put("minuend", "attribute://java.lang:type=OperatingSystem/TotalPhysicalMemorySize"); - properties.put("subtrahend", "attribute://java.lang:type=OperatingSystem/FreePhysicalMemorySize"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "long", true, false, false)); - - attribute = new LongDifferenceAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=OperatingSystem/UsedSwapSpaceSize"); - properties = new HashMap<>(); - properties.put("minuend", "attribute://java.lang:type=OperatingSystem/TotalSwapSpaceSize"); - properties.put("subtrahend", "attribute://java.lang:type=OperatingSystem/FreeSwapSpaceSize"); - ((IPropertySyntheticAttribute) attribute).setProperties(properties); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "long", true, false, false)); - - attribute = new DeadlockedThreadCountAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=Threading/DeadlockedThreadCount"); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "int", true, false, false)); - - attribute = new MonitoredDeadlockedThreadCountAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://java.lang:type=Threading/MonitoredDeadlockedThreadCount"); - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, null, "int", true, false, false)); - - attribute = new HotSpotLiveSetAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://com.sun.management:type=GarbageCollectionAggregator/HeapLiveSet"); - String description = "The remaining heap memory after the last major GC, measured in percent of committed heap."; - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, description, "double", true, false, false)); - - attribute = new HotSpotLastGcAttribute(); - descriptor = MRI.createFromQualifiedName("attribute://com.sun.management:type=GarbageCollectionAggregator/LastGcInfo"); - description = "Information from the last time a garbage collection took place."; - attributeCandidates.add(new SyntheticAttributeEntry(attribute, descriptor, description, "javax.management.openmbean.CompositeData", true, false, false)); - - boolean hasResolved = true; - while (!attributeCandidates.isEmpty() && hasResolved) { - hasResolved = false; - Iterator iterator = attributeCandidates.iterator(); - while (iterator.hasNext()) { - SyntheticAttributeEntry candidate = iterator.next(); - if (candidate.getAttribute().hasResolvedDependencies(compoundServer)) { - hasResolved = true; - iterator.remove(); - candidate.getAttribute().init(compoundServer); - registerEntry(candidate); - } - } - } - } - - private void registerEntry(SyntheticAttributeEntry attributeEntry) { - ObjectName objectName = attributeEntry.getAttributeDescriptor().getObjectName(); - SyntheticAttributeMBeanEntry entry = mbeans.get(objectName); - if (entry == null) { - entry = new SyntheticAttributeMBeanEntry(compoundServer); - try { - server.registerMBean(entry, objectName); - mbeans.put(objectName, entry); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, - "Could not register MBean for synthetic attribute!", e); //$NON-NLS-1$ - } - } - entry.addSyntheticAttribute(attributeEntry); - } - - public String[] getDomains() { - return server.getDomains(); - } - - public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException { - return server.getObjectInstance(name); - } - - public Set queryMBeans(ObjectName name, QueryExp query) { - return server.queryMBeans(name, query); - } - - public Set queryNames(ObjectName name, QueryExp query) { - return server.queryNames(name, query); - } - - public boolean isRegistered(ObjectName name) { - return server.isRegistered(name); - } - - public Integer getMBeanCount() { - return server.getMBeanCount(); - } - - public boolean hasAttribute(ObjectName name, String dataPath) { - SyntheticAttributeMBeanEntry entry = mbeans.get(name); - if (entry == null) { - return false; - } - return entry.hasDataPath(dataPath); - } - - public MBeanInfo getMBeanInfo(ObjectName name) - throws IntrospectionException, InstanceNotFoundException, ReflectionException { - return server.getMBeanInfo(name); - } - - public Object getAttribute(ObjectName name, String attribute) throws AttributeNotFoundException, - InstanceNotFoundException, MBeanException, ReflectionException, IOException { - return AttributeValueToolkit.getAttribute(server, name, attribute); - } - - public AttributeList getExistingAttributes(ObjectName name, String[] attributes) - throws InstanceNotFoundException, ReflectionException, IOException { - List syntheticAttributes = new ArrayList<>(); - for (String attribute : attributes) { - if (hasAttribute(name, attribute)) { - syntheticAttributes.add(attribute); - } - } - if (syntheticAttributes.size() > 0) { - return AttributeValueToolkit.getAttributes(server, name, syntheticAttributes); - } - return new AttributeList(); - } - - public void setAttribute(ObjectName name, Attribute attribute) - throws InstanceNotFoundException, InvalidAttributeValueException, AttributeNotFoundException, - ReflectionException, MBeanException, IOException { - server.setAttribute(name, attribute); - } - - public AttributeList setExistingAttributes(ObjectName name, AttributeList attributes) - throws InstanceNotFoundException, ReflectionException, IOException { - AttributeList existingAttributes = new AttributeList(); - for (Object obj : attributes) { - Attribute attribute = (Attribute) obj; - if (hasAttribute(name, attribute.getName())) { - existingAttributes.add(attribute); - } - } - if (existingAttributes.size() > 0) { - return server.setAttributes(name, existingAttributes); - } - return new AttributeList(); - } - - public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException { - return server.isInstanceOf(name, className); - } - - public void dispose() { - for (SyntheticAttributeMBeanEntry mbeanEntry : mbeans.values()) { - for (SyntheticAttributeEntry entry : mbeanEntry.getSyntheticAttributes()) { - try { - entry.getAttribute().stop(); - } catch (Throwable t) { - // silently ignore - } - } - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationEntry.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationEntry.java deleted file mode 100644 index 16ba284b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationEntry.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import org.openjdk.jmc.rjmx.ISyntheticNotification; -import org.openjdk.jmc.rjmx.subscription.MRI; - -public class SyntheticNotificationEntry { - private ISyntheticNotification notification; - private final MRI descriptor; - private final String description; - private final String type; - private final String message; - - public SyntheticNotificationEntry(ISyntheticNotification notification, MRI descriptor, String description, - String type, String message) { - this.notification = notification; - this.descriptor = descriptor; - this.description = description; - this.type = type; - this.message = message; - } - - public void setNotification(ISyntheticNotification notification) { - this.notification = notification; - } - - public ISyntheticNotification getNotification() { - return notification; - } - - public String getName() { - return descriptor.getQualifiedName(); - } - - public String getDescription() { - return description; - } - - public String getType() { - return type; - } - - public MRI getNotificationDescriptor() { - return descriptor; - } - - public String getMessage() { - return message; - } - - @Override - public String toString() { - return getName() + '[' + type + ']'; - } - - @Override - public int hashCode() { - return descriptor.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - SyntheticNotificationEntry other = (SyntheticNotificationEntry) obj; - if (descriptor == null) { - if (other.descriptor != null) { - return false; - } - } else if (!descriptor.equals(other.descriptor)) { - return false; - } - return true; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationMBean.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationMBean.java deleted file mode 100644 index 0fe47f05..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationMBean.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import javax.management.Descriptor; -import javax.management.JMX; -import javax.management.MBeanException; -import javax.management.MBeanNotificationInfo; -import javax.management.Notification; -import javax.management.RuntimeOperationsException; -import javax.management.modelmbean.ModelMBeanInfoSupport; -import javax.management.modelmbean.ModelMBeanNotificationInfo; -import javax.management.modelmbean.RequiredModelMBean; - -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * This MBean is used to forward notifications from the notification MBean repository. It is also - * responsible to return proper metadata regarding the available notifications. - */ -public class SyntheticNotificationMBean extends RequiredModelMBean { - - public SyntheticNotificationMBean(SyntheticNotificationEntry[] entries) - throws RuntimeOperationsException, MBeanException { - super(); - initializeModelMBeanInfo(entries); - } - - private void initializeModelMBeanInfo(SyntheticNotificationEntry[] entries) { - try { - setModelMBeanInfo(new ModelMBeanInfoSupport((this.getClass().getName()), "Synthetic notification.", null, //$NON-NLS-1$ - null, null, createNotificationInfo(entries))); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Could not setup synthetic notification MBean!", e); //$NON-NLS-1$ - } - } - - private ModelMBeanNotificationInfo[] createNotificationInfo(SyntheticNotificationEntry[] entries) { - List list = new ArrayList<>(); - for (SyntheticNotificationEntry entry : entries) { - ModelMBeanNotificationInfo notificationInfo = createNotificationInfo(entry); - Descriptor descriptorCopy = notificationInfo.getDescriptor(); - descriptorCopy.setField(JMX.OPEN_TYPE_FIELD, entry.getNotification().getValueType()); - notificationInfo.setDescriptor(descriptorCopy); - list.add(notificationInfo); - } - return list.toArray(new ModelMBeanNotificationInfo[list.size()]); - } - - private ModelMBeanNotificationInfo createNotificationInfo(SyntheticNotificationEntry entry) { - return new ModelMBeanNotificationInfo(new String[] {entry.getNotificationDescriptor().getDataPath()}, - Notification.class.getName(), entry.getDescription()); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationRepository.java b/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationRepository.java deleted file mode 100644 index eb501d10..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/SyntheticNotificationRepository.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.ListenerNotFoundException; -import javax.management.MBeanInfo; -import javax.management.MBeanServer; -import javax.management.MBeanServerConnection; -import javax.management.MBeanServerFactory; -import javax.management.NotificationFilter; -import javax.management.NotificationListener; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import javax.management.QueryExp; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.ISyntheticNotification; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.internal.HotSpotGcNotification; - -public class SyntheticNotificationRepository { - private final Map> mbeans = new HashMap<>(); - private final MBeanServer server = MBeanServerFactory.newMBeanServer(); - private final MBeanServerConnection compoundServer; - - public SyntheticNotificationRepository(MBeanServerConnection compoundServer) { - this.compoundServer = compoundServer; - } - - public String[] getDomains() { - return server.getDomains(); - } - - public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException { - return server.getObjectInstance(name); - } - - public Set queryMBeans(ObjectName name, QueryExp query) { - return server.queryMBeans(name, query); - } - - public Set queryNames(ObjectName name, QueryExp query) { - return server.queryNames(name, query); - } - - public boolean isRegistered(ObjectName name) { - return server.isRegistered(name); - } - - public Integer getMBeanCount() { - return server.getMBeanCount(); - } - - public boolean hasNotification(ObjectName name) { - Set entries = mbeans.get(name); - return entries != null; - } - - public MBeanInfo getMBeanInfo(ObjectName name) - throws IntrospectionException, InstanceNotFoundException, ReflectionException { - return server.getMBeanInfo(name); - } - - public void addNotificationListener( - ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, IOException { - server.addNotificationListener(name, listener, filter, handback); - } - - public void addNotificationListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException { - server.addNotificationListener(name, listener, filter, handback); - } - - public void removeNotificationListener(ObjectName name, ObjectName listener) - throws InstanceNotFoundException, ListenerNotFoundException { - server.removeNotificationListener(name, listener); - } - - public void removeNotificationListener( - ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, ListenerNotFoundException { - server.removeNotificationListener(name, listener, filter, handback); - } - - public void removeNotificationListener(ObjectName name, NotificationListener listener) - throws InstanceNotFoundException, ListenerNotFoundException { - server.removeNotificationListener(name, listener); - } - - public void removeNotificationListener( - ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) - throws InstanceNotFoundException, ListenerNotFoundException { - server.removeNotificationListener(name, listener, filter, handback); - } - - void initializeFromExtensions() { - List notificationCandidates = new ArrayList<>(); - - ISyntheticNotification notification = new HotSpotGcNotification(); - MRI descriptor = MRI.createFromQualifiedName("notification://com.sun.management:type=GarbageCollectionAggregator/com.sun.management.gc.notification"); - String description = "Sends an event every time a garbage collection has taken place."; - String type = "javax.management.openmbean.CompositeData"; - notificationCandidates.add(new SyntheticNotificationEntry(notification, descriptor, description, type, "")); - - boolean hasResolved = true; - while (!notificationCandidates.isEmpty() && hasResolved) { - hasResolved = false; - Iterator iterator = notificationCandidates.iterator(); - while (iterator.hasNext()) { - SyntheticNotificationEntry candidate = iterator.next(); - if (candidate.getNotification().hasResolvedDependencies(compoundServer)) { - hasResolved = true; - iterator.remove(); - registerEntry(candidate); - } - } - } - registerMBeans(); - } - - private void registerMBeans() { - for (Entry> notificationEntry : mbeans.entrySet()) { - ObjectName objectName = notificationEntry.getKey(); - try { - SyntheticNotificationMBean mbean = createMBean(objectName); - for (SyntheticNotificationEntry entry : notificationEntry.getValue()) { - entry.getNotification().init(mbean); - entry.getNotification().init(compoundServer, entry.getNotificationDescriptor().getDataPath(), - entry.getMessage()); - } - - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, - "Failed to register synthetic notification mbean " + objectName.toString(), e); //$NON-NLS-1$ - } - } - } - - private SyntheticNotificationMBean createMBean(ObjectName name) throws Exception { - Set entries = mbeans.get(name); - SyntheticNotificationMBean mbean = new SyntheticNotificationMBean( - entries.toArray(new SyntheticNotificationEntry[entries.size()])); - server.registerMBean(mbean, name); - return mbean; - } - - private void registerEntry(SyntheticNotificationEntry entry) { - Set notificationEntries = mbeans - .get(entry.getNotificationDescriptor().getObjectName()); - if (notificationEntries == null) { - notificationEntries = new HashSet<>(); - mbeans.put(entry.getNotificationDescriptor().getObjectName(), notificationEntries); - } - notificationEntries.add(entry); - } - - public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException { - return server.isInstanceOf(name, className); - } - - public void dispose() { - for (Set notificationEntrySet : mbeans.values()) { - for (SyntheticNotificationEntry entry : notificationEntrySet) { - try { - entry.getNotification().stop(); - } catch (Throwable t) { - // silently ignore - } - } - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/internal/WrappedConnectionException.java b/src/main/java/org/openjdk/jmc/rjmx/internal/WrappedConnectionException.java deleted file mode 100644 index ef00fe57..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/internal/WrappedConnectionException.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.internal; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.MalformedURLException; -import java.net.UnknownHostException; -import java.security.GeneralSecurityException; - -import javax.management.remote.JMXServiceURL; -import javax.naming.NameNotFoundException; -import javax.naming.NoInitialContextException; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; - -public class WrappedConnectionException extends ConnectionException { - - private final JMXServiceURL url; - private final String serverName; - - public WrappedConnectionException(String serverName, JMXServiceURL url, Exception cause) { - super(cause.getMessage()); - initCause(cause); // yes, still 1.4 compatible - this.url = url; - this.serverName = serverName; - - } - - @Override - public String getLocalizedMessage() { - Throwable cause = getCause(); - Throwable rootCause = cause; - while (rootCause.getCause() != null) { - rootCause = rootCause.getCause(); - } - - String hostName = url != null ? ConnectionToolkit.getHostName(url) : "Unresolved"; - String protocol = url != null ? url.getProtocol() : "Unresolved"; - - if (rootCause instanceof UnknownHostException) { - return String.format("Could not determine IP address for %s", hostName); - } - if (rootCause instanceof NameNotFoundException) { - return String.format("Name cannot be found for %s. Please check the Service URL (%s).", serverName, url); - } - if (rootCause instanceof MalformedURLException) { - return String.format("The URL for %s is not in a valid format. Please check the Service URL (%s).", serverName, url); - } - if (rootCause instanceof NoInitialContextException) { - return String.format("Unable to create initial context for %s. Please check the Service URL (%s).", serverName, url); - } - if (protocol.equals("msarmi")) { //$NON-NLS-1$ - return String.format("Unable to connect with msarmi protocol for %s, using Service URL %s. Verify that you have entered the correct password.", serverName, url); - } - if (rootCause instanceof SecurityException || rootCause instanceof GeneralSecurityException) { - return String.format("Unable to resolve the connection credentials for %s. Problem was: %s", serverName, - rootCause.getLocalizedMessage()); - } - if ("com.sun.tools.attach.AttachNotSupportedException".equals(rootCause //$NON-NLS-1$ - .getClass().getName())) { - return String.format("Attaching to the local JVM %s is not supported: %s", serverName, - rootCause.getLocalizedMessage()); - } - return String.format("Could not connect to %s. Make sure the JVM is running and that you are using the correct protocol in the Service URL (%s).", serverName, url); - } - - @Override - public String toString() { - return ConnectionException.class.getName() + " caused by " + getCause().toString(); //$NON-NLS-1$ - } - - private void writeObject(ObjectOutputStream oos) throws IOException { - throw new IOException("You should not serialize instances of " + getClass().getName()); //$NON-NLS-1$ - } - - private void readObject(ObjectInputStream ois) throws IOException { - throw new IOException("You should not serialize instances of " + getClass().getName()); //$NON-NLS-1$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/preferences/JMXRMIPreferences.java b/src/main/java/org/openjdk/jmc/rjmx/preferences/JMXRMIPreferences.java deleted file mode 100644 index 828fa072..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/preferences/JMXRMIPreferences.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.preferences; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Properties; - -import org.openjdk.jmc.ui.common.security.SecurelyStoredByteArray; - -public class JMXRMIPreferences extends SecurelyStoredByteArray { - - public static final String PROPERTY_KEY_KEYSTORE = "javax.net.ssl.keyStore"; //$NON-NLS-1$ - public static final String PROPERTY_KEY_TRUSTSTORE = "javax.net.ssl.trustStore"; //$NON-NLS-1$ - public static final String PROPERTY_KEY_KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword"; //$NON-NLS-1$ - public static final String PROPERTY_KEY_TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword"; //$NON-NLS-1$ - - private static final JMXRMIPreferences INSTANCE = new JMXRMIPreferences(); - - private Properties cache; - - private JMXRMIPreferences() { - super("org.openjdk.jmc.rjmx.preferences.SslPreferences"); //$NON-NLS-1$ - } - - public static JMXRMIPreferences getInstance() { - return INSTANCE; - } - - @Override - public void set(byte ... value) throws Exception { - super.set(value); - buildCache(value); - } - - public Properties getProperties() throws Exception { - synchronized (this) { - if (cache != null) { - return cache; - } - } - byte[] bytes = get(); - if (bytes != null) { - return buildCache(bytes); - } - return null; - } - - @Override - public void remove() throws Exception { - super.remove(); - setCache(null); - } - - private Properties buildCache(byte[] value) throws IOException { - Properties props = new Properties(); - props.load(new ByteArrayInputStream(value)); - return setCache(props); - } - - private synchronized Properties setCache(Properties props) { - cache = props; - return props; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/preferences/PreferencesKeys.java b/src/main/java/org/openjdk/jmc/rjmx/preferences/PreferencesKeys.java deleted file mode 100644 index 148b0657..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/preferences/PreferencesKeys.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.preferences; - -import java.io.File; - -import org.openjdk.jmc.ui.common.CorePlugin; - -/** - * Preference keys and default values - */ -public class PreferencesKeys { - /** Update interval for attribute subscriptions */ - public static final String PROPERTY_UPDATE_INTERVAL = "org.openjdk.jmc.console.preferences.updateinterval"; //$NON-NLS-1$ - public static final int DEFAULT_UPDATE_INTERVAL = 1000; - - /** Default value of retained event values for subscriptions */ - public static final String PROPERTY_RETAINED_EVENT_VALUES = "rjmx.events.retained"; //$NON-NLS-1$ - public static final int DEFAULT_RETAINED_EVENT_VALUES = 7 * 24 * 3600; - - public static final String PROPERTY_MAIL_SERVER = "rjmx.smtp.server"; //$NON-NLS-1$ - public static final String PROPERTY_MAIL_SERVER_PORT = "rjmx.smtp.server.port"; //$NON-NLS-1$ - public static final String PROPERTY_MAIL_SERVER_SECURE = "rjmx.smtp.server.secure"; //$NON-NLS-1$ - public static final String PROPERTY_MAIL_SERVER_STARTTLS_ENCRYPTION = "rjmx.smtp.server.starttls.encryption"; //$NON-NLS-1$ - public static final String PROPERTY_MAIL_SERVER_CREDENTIALS = "rjmx.smtp.server.credentials"; //$NON-NLS-1$ - public static final String DEFAULT_MAIL_SERVER = "mail.example.org"; //$NON-NLS-1$ - public static final int DEFAULT_MAIL_SERVER_PORT = 25; - public static final boolean DEFAULT_MAIL_SERVER_SECURE = false; - public static final boolean DEFAULT_MAIL_SERVER_STARTTLS_ENCRYPTION = false; - public static final String DEFAULT_MAIL_SERVER_USER = ""; //$NON-NLS-1$ - public static final String DEFAULT_MAIL_SERVER_PASSWORD = ""; //$NON-NLS-1$ - public static final String DEFAULT_MAIL_SERVER_CREDENTIALS = ""; //$NON-NLS-1$ - - // Persistence - public static final String PROPERTY_PERSISTENCE_LOG_ROTATION_LIMIT_KB = "rjmx.services.persistence.log.rotation.limit"; //$NON-NLS-1$ - public static final long DEFAULT_PERSISTENCE_LOG_ROTATION_LIMIT_KB = 100; - public static final String PROPERTY_PERSISTENCE_DIRECTORY = "rjmx.services.persistence.directory"; //$NON-NLS-1$ - - public static final String PROPERTY_LIST_AGGREGATE_SIZE = "rjmx.internal.listAggregateSize"; //$NON-NLS-1$ - public static final int DEFAULT_LIST_AGGREGATE_SIZE = 40; -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IDiscoveryInfo.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/IDiscoveryInfo.java deleted file mode 100644 index a46f9c1f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IDiscoveryInfo.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel; - -import org.openjdk.jmc.common.IDescribable; - -/** - * Provides information on how and when an IServer was discovered - */ -public interface IDiscoveryInfo { - - IDescribable getProvider(); - - long getDiscoveredTimestamp(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServer.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServer.java deleted file mode 100644 index e59c4666..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServer.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.IServerHandle; -import org.openjdk.jmc.ui.common.action.IActionProvider; - -/** - * Represents a particular (potentially remote) server that can be connected to - */ -public interface IServer { - - /** - * @return Information on the discovery of this server, or {@code null} if the server was not - * discovered - */ - IDiscoveryInfo getDiscoveryInfo(); - - /** - * @return A handle used to connect to this server - */ - IServerHandle getServerHandle(); - - /** - * @return A tree of actions that can be performed on this server - */ - IActionProvider getActionProvider(); - - /** - * @return All connections that are currently open to this server - */ - IConnectionHandle[] getConnectionHandles(); - - /** - * Invalidates all currently existing {@link IServerHandle} to this server - */ - void reset(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServerModel.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServerModel.java deleted file mode 100644 index 40b343be..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/IServerModel.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel; - -import org.openjdk.jmc.ui.common.tree.IArray; - -/** - * A container with all available servers - */ -public interface IServerModel extends IArray { - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/DiscoveryInfo.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/DiscoveryInfo.java deleted file mode 100644 index cc006915..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/DiscoveryInfo.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel.internal; - -import org.openjdk.jmc.common.IDescribable; -import org.openjdk.jmc.rjmx.servermodel.IDiscoveryInfo; - -class DiscoveryInfo implements IDiscoveryInfo { - - IDescribable provider; - long discoveryTime = System.currentTimeMillis(); - - DiscoveryInfo(IDescribable provider) { - this.provider = provider; - } - - @Override - public IDescribable getProvider() { - return provider; - } - - @Override - public long getDiscoveredTimestamp() { - return discoveryTime; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ModelPersistence.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ModelPersistence.java deleted file mode 100644 index 1182cde0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ModelPersistence.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel.internal; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.remote.JMXServiceURL; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.openjdk.jmc.common.util.XmlToolkit; -import org.openjdk.jmc.rjmx.ConnectionDescriptorBuilder; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.internal.ServerDescriptor; -import org.openjdk.jmc.ui.common.security.ICredentials; -import org.openjdk.jmc.ui.common.security.PersistentCredentials; -import org.openjdk.jmc.ui.common.security.SecurityException; -import org.openjdk.jmc.ui.common.security.SecurityManagerFactory; - -class ModelPersistence { - - final static String SERVER_CREDENTIALS_FAMILY = "org.openjdk.jmc.rjmx.servermodel.ModelPersistence"; //$NON-NLS-1$ - private final static String XML_COMPONENT_TAG = "server"; //$NON-NLS-1$ - private final static String XML_ELEMENT_SERVER_NAME = "server_name"; //$NON-NLS-1$ - private final static String XML_ELEMENT_SERVER_PATH = "server_path"; //$NON-NLS-1$ - private final static String XML_ELEMENT_JMX_SERVICE_URL = "jmx_service_url"; //$NON-NLS-1$ - private final static String XML_ELEMENT_CREDENTIALS_ID = "credentials_id"; //$NON-NLS-1$ - private final static String XML_ELEMENT_UID = "uid"; //$NON-NLS-1$ - private final static String XML_ROOT_TAG = "server_model"; //$NON-NLS-1$ - private final static Server[] EMPTY = new Server[] {}; - - /** - * Stores the current settings to persistent storage. - * - * @throws IOException - * @throws SecurityException - */ - synchronized static Document export(boolean exportForTransfer, Server ... servers) throws Exception { - Document doc = XmlToolkit.createNewDocument(XML_ROOT_TAG); - Element repoRoot = doc.getDocumentElement(); - Set credentialIds = new HashSet<>(); - for (Server s : servers) { - exportToXml(s, repoRoot, exportForTransfer, credentialIds); - } - if (!exportForTransfer) { - SecurityManagerFactory.getSecurityManager().clearFamily(SERVER_CREDENTIALS_FAMILY, credentialIds); - } - return doc; - } - - private static void exportToXml(Server me, Element parentNode, boolean exportForTransfer, Set credentialIds) - throws SecurityException { - if (me != null && me.getDiscoveryInfo() == null) { - Element connectionNode = XmlToolkit.createElement(parentNode, XML_COMPONENT_TAG); - IServerDescriptor descriptor = me.getServerHandle().getServerDescriptor(); - if (!exportForTransfer) { - XmlToolkit.setSetting(connectionNode, XML_ELEMENT_UID, descriptor.getGUID()); - } - XmlToolkit.setSetting(connectionNode, XML_ELEMENT_JMX_SERVICE_URL, me.getConnectionUrl().toString()); - XmlToolkit.setSetting(connectionNode, XML_ELEMENT_SERVER_NAME, descriptor.getDisplayName()); - XmlToolkit.setSetting(connectionNode, XML_ELEMENT_SERVER_PATH, me.getPath()); - if (!exportForTransfer && me.getCredentials() != null) { - String storedCredentialsId = me.getCredentials().getExportedId(); - if (storedCredentialsId != null) { - XmlToolkit.setSetting(connectionNode, XML_ELEMENT_CREDENTIALS_ID, storedCredentialsId); - credentialIds.add(storedCredentialsId); - } - } - } - } - - /** - * Loads the current settings from persistent storage. - */ - synchronized static Server[] loadSettings(Document doc) throws IOException { - try { - Element root = doc.getDocumentElement(); - if (root.getTagName().equals(XML_ROOT_TAG)) { - return loadServersFromXml(root); - } else { - throw new IOException(); - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Problem initializing from browser settings", e); //$NON-NLS-1$ - } - return EMPTY; - } - - private static Server loadServerFromXml(Element node) throws MalformedURLException { - JMXServiceURL url = new JMXServiceURL(XmlToolkit.getSetting(node, XML_ELEMENT_JMX_SERVICE_URL, null)); - String guid = XmlToolkit.getSetting(node, XML_ELEMENT_UID, null); - String credentialsId = XmlToolkit.getSetting(node, XML_ELEMENT_CREDENTIALS_ID, null); - ICredentials c = credentialsId == null ? null : new PersistentCredentials(credentialsId); - String name = XmlToolkit.getSetting(node, XML_ELEMENT_SERVER_NAME, null); - String path = XmlToolkit.getSetting(node, XML_ELEMENT_SERVER_PATH, null); - IServerDescriptor sd = new ServerDescriptor(guid, name, null); - IConnectionDescriptor cd = new ConnectionDescriptorBuilder().url(url).credentials(c).build(); - return new Server(path, url, c, null, sd, cd); - } - - private static Server[] loadServersFromXml(Element node) { - List servers = new ArrayList<>(); - for (Element e : XmlToolkit.getChildElementsByTag(node, XML_COMPONENT_TAG)) { - try { - servers.add(loadServerFromXml(e)); - } catch (MalformedURLException e1) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Problem loading server from element " + e, e1); //$NON-NLS-1$ - } - } - return servers.toArray(new Server[servers.size()]); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/Server.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/Server.java deleted file mode 100644 index 0d133f31..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/Server.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel.internal; - -import java.util.function.Consumer; -import java.util.logging.Level; - -import javax.management.remote.JMXServiceURL; - -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.actionprovider.internal.ActionProviderRepository; -import org.openjdk.jmc.rjmx.internal.ServerDescriptor; -import org.openjdk.jmc.rjmx.internal.ServerHandle; -import org.openjdk.jmc.rjmx.servermodel.IDiscoveryInfo; -import org.openjdk.jmc.rjmx.servermodel.IServer; -import org.openjdk.jmc.ui.common.action.IActionProvider; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; -import org.openjdk.jmc.ui.common.labelingrules.NameConverter; -import org.openjdk.jmc.ui.common.resource.IImageResource; -import org.openjdk.jmc.ui.common.resource.Resource; -import org.openjdk.jmc.ui.common.security.ICredentials; -import org.openjdk.jmc.ui.common.util.ICopyable; - -public class Server implements IServer, ICopyable, IImageResource { - private final ICredentials credentials; - private final IDiscoveryInfo discoveryInfo; - private final JMXServiceURL url; - private final Resource imageResource; - private IActionProvider actionProvider; - private String path; - private ServerHandle serverHandle; - private Consumer observer; - private final Runnable listener = new Runnable() { - - @Override - public void run() { - Consumer o = getObserver(); - if (o != null) { - try { - o.accept(Server.this); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Notify Server observer " + o + " failed", //$NON-NLS-1$ //$NON-NLS-2$ - e); - } - } - } - }; - - public Server(String path, JMXServiceURL url, ICredentials credentials, IDiscoveryInfo discoveryInfo, - IServerDescriptor serverDesc, IConnectionDescriptor connector) { - this.discoveryInfo = discoveryInfo; - this.credentials = credentials; - this.path = path; - this.url = url; - JVMDescriptor jvmInfo = serverDesc.getJvmInfo(); - imageResource = jvmInfo != null ? NameConverter.getInstance().getImageResource(jvmInfo) : null; - serverHandle = new ServerHandle(serverDesc, connector, listener); - actionProvider = ActionProviderRepository.buildActionProvider(serverHandle); - } - - synchronized void setObserver(Consumer observer) { - this.observer = observer; - } - - private synchronized Consumer getObserver() { - return observer; - } - - @Override - public IDiscoveryInfo getDiscoveryInfo() { - return discoveryInfo; - } - - public ICredentials getCredentials() { - return credentials; - } - - public synchronized void setPath(String path) { - this.path = path; - } - - public synchronized String getPath() { - return path; - } - - @Override - public synchronized ServerHandle getServerHandle() { - return serverHandle; - } - - @Override - public synchronized IActionProvider getActionProvider() { - return actionProvider; - } - - @Override - public synchronized IConnectionHandle[] getConnectionHandles() { - return serverHandle.getConnectionHandles(); - } - - @Override - public boolean isCopyable() { - return url != null; - } - - public JMXServiceURL getConnectionUrl() { - return url; - } - - @Override - public synchronized Object copy() { - IServerDescriptor originalSd = serverHandle.getServerDescriptor(); - IServerDescriptor desc = new ServerDescriptor(null, originalSd.getDisplayName(), originalSd.getJvmInfo()); - return new Server(path, url, credentials, null, desc, serverHandle.getConnectionDescriptor()); - } - - @Override - public void reset() { - ServerHandle oldHandle; - synchronized (this) { - oldHandle = serverHandle; - serverHandle = new ServerHandle(oldHandle.getServerDescriptor(), oldHandle.getConnectionDescriptor(), - listener); - actionProvider = ActionProviderRepository.buildActionProvider(serverHandle); - } - oldHandle.dispose(true); - } - - @Override - public Resource getImageResource() { - return imageResource; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ServerModel.java b/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ServerModel.java deleted file mode 100644 index 64b4bc9b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/servermodel/internal/ServerModel.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.servermodel.internal; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Observable; - -import javax.management.remote.JMXServiceURL; - -import org.openjdk.jmc.common.IDescribable; -import org.openjdk.jmc.rjmx.ConnectionDescriptorBuilder; -import org.openjdk.jmc.rjmx.IConnectionDescriptor; -import org.openjdk.jmc.rjmx.IServerDescriptor; -import org.openjdk.jmc.rjmx.descriptorprovider.IDescriptorListener; -import org.openjdk.jmc.rjmx.servermodel.IServer; -import org.openjdk.jmc.rjmx.servermodel.IServerModel; -import org.w3c.dom.Document; - -public final class ServerModel extends Observable implements IServerModel { - private static final String EXTENSIONPOINT_DESCRIPTORPROVIDER = "descriptorProvider"; //$NON-NLS-1$ - private final Map elements = new HashMap<>(); - - private final IDescriptorListener descriptorListener = new IDescriptorListener() { - - @Override - public void onDescriptorRemoved(String descriptorId) { - Server removedEntry = doRemove(descriptorId); - if (removedEntry != null) { - removedEntry.getServerHandle().dispose(false); - modelChanged(null); - } - } - - @Override - public void onDescriptorDetected( - IServerDescriptor sd, String path, JMXServiceURL url, IConnectionDescriptor cd, IDescribable provider) { - cd = cd != null ? cd : new ConnectionDescriptorBuilder().url(url).build(); - insert(new Server(path, url, null, new DiscoveryInfo(provider), sd, cd)); - } - - }; - - public ServerModel() { - setUpDiscoveryListeners(); - } - - @Override - public synchronized boolean isEmpty() { - return elements.size() > 0; - } - - @Override - public synchronized Server[] elements() { - Collection serverCollection = elements.values(); - Server[] servers = new Server[serverCollection.size()]; - Iterator it = serverCollection.iterator(); - for (int i = 0; i < servers.length; i++) { - servers[i] = it.next(); - } - return servers; - } - - public void remove(IServer ... servers) { - for (IServer is : servers) { - Server server = doRemove(is.getServerHandle().getServerDescriptor().getGUID()); - if (server != null) { - server.getServerHandle().dispose(true); - } - } - modelChanged(null); - } - - private synchronized Server doRemove(String guid) { - return elements.remove(guid); - } - - private synchronized Server doAdd(Server server) { - return elements.put(server.getServerHandle().getServerDescriptor().getGUID(), server); - } - - public void insert(Server ... servers) { - for (Server server : servers) { - Server oldEntry = doAdd(server); - if (oldEntry != server) { - server.setObserver(this::modelChanged); - if (oldEntry != null) { - oldEntry.getServerHandle().dispose(true); - } - } - } - modelChanged(null); - } - - void modelChanged(Server element) { - setChanged(); - notifyObservers(element); - } - - public Document exportServers(Server ... servers) throws Exception { - if (servers.length == 0) { - return ModelPersistence.export(false, elements()); - } else { - return ModelPersistence.export(true, servers); - } - - } - - public void importServers(Document doc) throws IOException { - insert(ModelPersistence.loadSettings(doc)); - } - - private void setUpDiscoveryListeners() { - // None registered - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeInfo.java b/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeInfo.java deleted file mode 100644 index f4b03232..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -// FIXME: Use generics in this interface (and dependent IAttribute and IOperation interfaces) when needed. getType should return Class etc. -public interface IAttributeInfo { - - public String getDescription(); - - public String getName(); - - /** - * @return the type of the attribute, possible {@code null}. - */ - public String getType(); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorage.java b/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorage.java deleted file mode 100644 index 7b39ac78..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorage.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import java.util.List; - -import org.openjdk.jmc.ui.common.util.IObservable; - -public interface IAttributeStorage extends IObservable { - - List getDataSeries(); - - long getDataStart(); - - long getDataEnd(); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorageService.java b/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorageService.java deleted file mode 100644 index 68d26dba..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IAttributeStorageService.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import org.openjdk.jmc.rjmx.subscription.MRI; - -public interface IAttributeStorageService { - - IAttributeStorage getAttributeStorage(MRI attributeDescriptor); - - int getRetainedLength(MRI attributeDescriptor); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/ICommercialFeaturesService.java b/src/main/java/org/openjdk/jmc/rjmx/services/ICommercialFeaturesService.java deleted file mode 100644 index f31cd4d3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/ICommercialFeaturesService.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -/** - * This service is used to control the enablement of the commercial features in Hotspot. - */ -public interface ICommercialFeaturesService { - - /** - * @return true if the commercial features are enabled, or false if they are disabled. - */ - boolean isCommercialFeaturesEnabled(); - - /** - * This method is used to enable the commercial features. Note that some implementations may not - * support switching on the commercial features dynamically. If the operation fails, the - * exception message may provide more information about why the operation failed. - * - * @throws Exception - * if changing the state was not successful. - */ - void enableCommercialFeatures() throws Exception; - - /** - * @return true if there are commercial features available, or false if this JVM doesn't have - * commercial features. - */ - boolean hasCommercialFeatures(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IDiagnosticCommandService.java b/src/main/java/org/openjdk/jmc/rjmx/services/IDiagnosticCommandService.java deleted file mode 100644 index 31c42cf2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IDiagnosticCommandService.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import java.util.Collection; - -public interface IDiagnosticCommandService { - - /** - * Returns the available diagnostic commands - * - * @return the IOperations that can be invoked. - * @throws Exception - * if the connection failed or some other problem occurred when trying create - * operations. - */ - Collection getOperations() throws Exception; - - /** - * Runs the specified diagnostic command. - * - * @param arg - * the diagnostic command and the relevant arguments, in jrcmd format. - * @return the result, if one was returned. - * @throws Exception - * if the operation execution was not successful - */ - String runCtrlBreakHandlerWithResult(String arg) throws Exception; -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IDummyService.java b/src/main/java/org/openjdk/jmc/rjmx/services/IDummyService.java deleted file mode 100644 index 9972caa9..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IDummyService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -/** - * Marker interface used to designate service implementations that doesn't really provide the - * service but whose methods mostly throws exceptions or returns false. This interface exist so that - * clients that wants to check if there is a real service should be able to do so. - *

- * Yes, this could in principle be a runtime annotation instead, but then it couldn't be applied to - * dynamic proxies, which we currently use to construct dummy services on the fly. - */ -public interface IDummyService { -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IOperation.java b/src/main/java/org/openjdk/jmc/rjmx/services/IOperation.java deleted file mode 100644 index fc6cb1ce..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IOperation.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import java.util.List; -import java.util.concurrent.Callable; - -public interface IOperation { - public enum OperationImpact { - IMPACT_LOW, IMPACT_MEDIUM, IMPACT_HIGH, IMPACT_UNKNOWN - } - - public String getName(); - - public String getDescription(); - - public String getReturnType(); - - public List getSignature(); - - public OperationImpact getImpact(); - - public Callable getInvocator(Object ... argumentValues) throws IllegalOperandException; -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/IServiceFactory.java deleted file mode 100644 index a4a6092a..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IServiceFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; - -public interface IServiceFactory { - /** - * Create an instance of the service as based on {@code handle}. Normally, a service should only - * be returned if it is likely that this factory provides the best service for the given - * {@code handle}. Otherwise, null shall be returned. However, there might currently be - * circumstances where dummy services could be returned. In this case, they must also implement - * the marker interface {@link IDummyService}, so that they can be skipped when looking for - * proper services. - * - * @param handle - * @return a proper service, a dummy service, or null. - * @throws ConnectionException - * @throws ServiceNotAvailableException - */ - T getServiceInstance(IConnectionHandle handle) throws ConnectionException, ServiceNotAvailableException; - - Class getServiceType(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/IllegalOperandException.java b/src/main/java/org/openjdk/jmc/rjmx/services/IllegalOperandException.java deleted file mode 100644 index fbd32cd3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/IllegalOperandException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -public class IllegalOperandException extends Exception { - - private static final long serialVersionUID = -5931300867637843266L; - private final Set invalidValues; - - public IllegalOperandException(IAttributeInfo invalidValue) { - invalidValues = new HashSet<>(); - invalidValues.add(invalidValue); - } - - public IllegalOperandException(Collection invalidValues) { - this.invalidValues = new HashSet<>(invalidValues); - } - - public Set getInvalidValues() { - return invalidValues; - } - - public void addInvalidValue(IAttributeInfo invalidValues) { - this.invalidValues.add(invalidValues); - } - - private void writeObject(ObjectOutputStream oos) throws IOException { - throw new IOException("You should not serialize instances of " + getClass().getName()); //$NON-NLS-1$ - } - - private void readObject(ObjectInputStream ois) throws IOException { - throw new IOException("You should not serialize instances of " + getClass().getName()); //$NON-NLS-1$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/MRIDataSeries.java b/src/main/java/org/openjdk/jmc/rjmx/services/MRIDataSeries.java deleted file mode 100644 index e321b7f1..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/MRIDataSeries.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services; - -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.ui.common.xydata.DataSeries; -import org.openjdk.jmc.ui.common.xydata.ITimestampedData; - -public interface MRIDataSeries extends DataSeries { - - MRI getAttribute(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/AbstractOperation.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/AbstractOperation.java deleted file mode 100644 index cbc75d2c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/AbstractOperation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import java.util.List; - -import org.openjdk.jmc.rjmx.services.IAttributeInfo; -import org.openjdk.jmc.rjmx.services.IOperation; - -public abstract class AbstractOperation implements IOperation { - - private final String name; - private final String desc; - private final String ret; - private final List signature; - private final OperationImpact impact; - - public AbstractOperation(String name, String desc, String ret, List signature, OperationImpact impact) { - this.name = name; - this.ret = ret; - this.desc = desc; - this.signature = signature; - this.impact = impact; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getDescription() { - return desc; - } - - @Override - public String getReturnType() { - return ret; - } - - @Override - public List getSignature() { - return signature; - } - - @Override - public OperationImpact getImpact() { - return impact; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/AttributeStorageServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/AttributeStorageServiceFactory.java deleted file mode 100644 index fbc5b319..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/AttributeStorageServiceFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IAttributeStorageService; -import org.openjdk.jmc.rjmx.services.IServiceFactory; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.storage.internal.DefaultAttributeStorageService; - -public class AttributeStorageServiceFactory implements IServiceFactory { - - @Override - public IAttributeStorageService getServiceInstance(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - return new DefaultAttributeStorageService(handle.getServiceOrThrow(ISubscriptionService.class)); - } - - @Override - public Class getServiceType() { - return IAttributeStorageService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/CommercialFeaturesServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/CommercialFeaturesServiceFactory.java deleted file mode 100644 index 4e79f19c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/CommercialFeaturesServiceFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.common.version.JavaVersion; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService; -import org.openjdk.jmc.rjmx.services.IServiceFactory; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; - -public class CommercialFeaturesServiceFactory implements IServiceFactory { - - @Override - public ICommercialFeaturesService getServiceInstance(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - // Optimization - using already available information instead of doing more round trips. - // It's always a bit precarious to look at version instead of capability, but in this case - // it should be safe - the commercial features flag is not coming back - JVMDescriptor descriptor = handle.getServerDescriptor().getJvmInfo(); - if (descriptor != null) { - JavaVersion version = new JavaVersion(descriptor.getJavaVersion()); - if (version.getMajorVersion() >= 11) { - return new NoCommercialFeaturesService(); - } - } - return new HotSpot23CommercialFeaturesService(handle); - } - - @Override - public Class getServiceType() { - return ICommercialFeaturesService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/DiagnosticCommandServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/DiagnosticCommandServiceFactory.java deleted file mode 100644 index 5709ad9c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/DiagnosticCommandServiceFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import javax.management.MBeanServerConnection; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IDiagnosticCommandService; -import org.openjdk.jmc.rjmx.services.IServiceFactory; - -public class DiagnosticCommandServiceFactory implements IServiceFactory { - - @Override - public IDiagnosticCommandService getServiceInstance(IConnectionHandle handle) - throws ServiceNotAvailableException, ConnectionException { - return new HotSpot24DiagnosticCommandService(handle.getServiceOrThrow(MBeanServerConnection.class)); - } - - @Override - public Class getServiceType() { - return IDiagnosticCommandService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java deleted file mode 100644 index fbab0390..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import javax.management.MBeanServerConnection; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService; -import org.openjdk.jmc.rjmx.services.IDiagnosticCommandService; -import javax.management.ObjectName; - -public class HotSpot23CommercialFeaturesService implements ICommercialFeaturesService { - private final static String UNLOCK_COMMERCIAL_FEATURES_FLAG = "UnlockCommercialFeatures"; //$NON-NLS-1$ - private final static String UNLOCK_COMMAND = "VM.unlock_commercial_features"; //$NON-NLS-1$ - private final MBeanServerConnection server; - private final IDiagnosticCommandService dcs; - private final static String JDK_MANAGEMENT_JFR_MBEAN_NAME = "jdk.management.jfr:type=FlightRecorder"; //$NON-NLS-1$ - - public HotSpot23CommercialFeaturesService(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - server = handle.getServiceOrThrow(MBeanServerConnection.class); - dcs = handle.getServiceOrNull(IDiagnosticCommandService.class); - try { - HotspotManagementToolkit.getVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG); // Will fail if option is not available - } catch (Exception e) { - // Commercial Feature option is not available but Flight Recorder is. - if (!isJfrMBeanAvailable()) { - throw new ServiceNotAvailableException(""); //$NON-NLS-1$ - } - } - } - - @Override - public boolean isCommercialFeaturesEnabled() { - try { - return ((String) HotspotManagementToolkit.getVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG)) - .contains("true"); //$NON-NLS-1$ - } catch (Exception e) { - return false; - } - } - - @Override - public void enableCommercialFeatures() throws Exception { - if (dcs != null) { - dcs.runCtrlBreakHandlerWithResult(UNLOCK_COMMAND); - } - if (!isCommercialFeaturesEnabled()) { - HotspotManagementToolkit.setVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG, "true"); //$NON-NLS-1$ - } - } - - private boolean isJfrMBeanAvailable() { - try { - getJfrMBeanObjectName(); - return true; - } catch (Exception e) { - return false; - } - } - - private ObjectName getJfrMBeanObjectName() throws Exception { - ObjectName candidateObjectName = ConnectionToolkit.createObjectName(JDK_MANAGEMENT_JFR_MBEAN_NAME); - server.getMBeanInfo(candidateObjectName); - return candidateObjectName; - } - - @Override - public boolean hasCommercialFeatures() { - return true; - } -} \ No newline at end of file diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot24DiagnosticCommandService.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot24DiagnosticCommandService.java deleted file mode 100644 index 1c96c13a..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot24DiagnosticCommandService.java +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; - -import javax.management.Descriptor; -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanOperationInfo; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IDiagnosticCommandService; -import org.openjdk.jmc.rjmx.services.IOperation.OperationImpact; -import org.openjdk.jmc.rjmx.services.IllegalOperandException; -import org.openjdk.jmc.rjmx.util.internal.SimpleAttributeInfo; - -public class HotSpot24DiagnosticCommandService implements IDiagnosticCommandService { - - private static final ObjectName DIAGNOSTIC_BEAN = ConnectionToolkit - .createObjectName("com.sun.management:type=DiagnosticCommand"); //$NON-NLS-1$ - private static final String OPERATION_UPDATE = "update"; //$NON-NLS-1$ - private final MBeanServerConnection m_mbeanServer; - private final Map commandNameToOperation = new HashMap<>(); - private Collection operations; - - private static final String IMPACT = "dcmd.vmImpact"; //$NON-NLS-1$ - private static final String NAME = "dcmd.name"; //$NON-NLS-1$ - private static final String DESCRIPTION = "dcmd.description"; //$NON-NLS-1$ -// private final static String HELP = "dcmd.help"; //$NON-NLS-1$ - private static final String ARGUMENTS = "dcmd.arguments"; //$NON-NLS-1$ - private static final String ARGUMENT_NAME = "dcmd.arg.name"; //$NON-NLS-1$ - private static final String ARGUMENT_DESCRIPTION = "dcmd.arg.description"; //$NON-NLS-1$ - private static final String ARGUMENT_MANDATORY = "dcmd.arg.isMandatory"; //$NON-NLS-1$ - private static final String ARGUMENT_TYPE = "dcmd.arg.type"; //$NON-NLS-1$ - private static final String ARGUMENT_OPTION = "dcmd.arg.isOption"; //$NON-NLS-1$ - private static final String ARGUMENT_MULITPLE = "dcmd.arg.isMultiple"; //$NON-NLS-1$ - - private static List extractSignature(Descriptor args) { - if (args != null) { - String[] argNames = args.getFieldNames(); - List parameters = new ArrayList<>(argNames.length); - for (String argName : argNames) { - Descriptor arg = (Descriptor) args.getFieldValue(argName); - parameters.add(new DiagnosticCommandParameter(arg)); - } - return parameters; - } else { - return Collections.emptyList(); - } - } - - private static OperationImpact extractImpact(Descriptor d) { - String impact = d.getFieldValue(IMPACT).toString(); - if (impact.startsWith("Low")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_LOW; - } - if (impact.startsWith("Medium")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_MEDIUM; - } - if (impact.startsWith("High")) { //$NON-NLS-1$ - return OperationImpact.IMPACT_HIGH; - } - return OperationImpact.IMPACT_UNKNOWN; - } - - private static String extractType(Descriptor d) { - boolean isMultiple = Boolean.parseBoolean(d.getFieldValue(ARGUMENT_MULITPLE).toString()); - String typeName = d.getFieldValue(ARGUMENT_TYPE).toString(); - if (isMultiple) { - if (typeName.equals("STRING SET")) { //$NON-NLS-1$ - return String[].class.getName(); - } else { - return typeName.toLowerCase().replace(' ', '_') + '*'; - } - } - if (typeName.equals("BOOLEAN")) { //$NON-NLS-1$ - return Boolean.class.getName(); - } else if (typeName.equals("STRING") || typeName.equals("NANOTIME") || typeName.equals("MEMORY SIZE")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - return String.class.getName(); - } else if (typeName.equals("JLONG")) { //$NON-NLS-1$ - return Long.class.getName(); - } else { - return typeName.toLowerCase().replace(' ', '_'); - } - } - - private static String extractDescription(Descriptor d) { - // FIXME: Argument descriptions for JFR operations contains \" that should be ". Workaround for now. - String desc = d.getFieldValue(ARGUMENT_DESCRIPTION).toString().trim().replaceAll("\\\\\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$ - return desc.length() > 0 ? desc : d.getFieldValue(ARGUMENT_NAME).toString().trim(); - } - - private static class ArgumentBuilder { - private final List arguments = new ArrayList<>(); - - public void appendArgument(Object value, DiagnosticCommandParameter parameterInfo) - throws IllegalOperandException { - if (parameterInfo.isMultiple) { - if (value.getClass().isArray()) { - for (Object o : ((Object[]) value)) { - appendValue(o, parameterInfo); - } - } else { - throw new IllegalOperandException(parameterInfo); - } - } else { - appendValue(value, parameterInfo); - } - } - - private void appendValue(Object value, DiagnosticCommandParameter parameterInfo) - throws IllegalOperandException { - StringBuilder sb = new StringBuilder(); - if (parameterInfo.isOption) { - sb.append(parameterInfo.parameterName).append('='); - } - String stringValue = String.valueOf(value); - if (stringValue.indexOf('"') >= 0) { - throw new IllegalOperandException(parameterInfo); - } else if (stringValue.indexOf(' ') >= 0) { - sb.append('"').append(stringValue).append('"'); - } else { - sb.append(stringValue); - } - arguments.add(sb.toString()); - } - - public String[] asArray() { - return arguments.toArray(new String[arguments.size()]); - } - } - - private static class DiagnosticCommandParameter extends SimpleAttributeInfo { - private final boolean isOption; - private final boolean isMultiple; - private final boolean isRequired; - private final String parameterName; - - public DiagnosticCommandParameter(Descriptor d) { - super(d.getFieldValue(ARGUMENT_NAME).toString(), extractType(d), extractDescription(d)); - parameterName = d.getFieldValue(ARGUMENT_NAME).toString(); - isOption = Boolean.parseBoolean(d.getFieldValue(ARGUMENT_OPTION).toString()); - isMultiple = Boolean.parseBoolean(d.getFieldValue(ARGUMENT_MULITPLE).toString()); - isRequired = Boolean.parseBoolean(d.getFieldValue(ARGUMENT_MANDATORY).toString()); - RJMXPlugin.getDefault().getLogger() - .finest("DiagnosticCommandArg created: " + getType() + ' ' + getName() + ' ' + getDescription() //$NON-NLS-1$ - + (isRequired ? " isRequired" : "") //$NON-NLS-1$ //$NON-NLS-2$ - + (isOption ? " isOption" : "") + (isMultiple ? " isMultiple" : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - - } - - private class DiagnosticCommand extends AbstractOperation { - - public DiagnosticCommand(Descriptor d, String returnType) { - super(d.getFieldValue(NAME).toString(), d.getFieldValue(DESCRIPTION).toString(), returnType, - extractSignature((Descriptor) d.getFieldValue(ARGUMENTS)), extractImpact(d)); - RJMXPlugin.getDefault().getLogger() - .finest("DiagnosticCommand created: " + getName() + ' ' + getReturnType() + ' ' + getImpact()); //$NON-NLS-1$ - } - - @Override - public Callable getInvocator(Object ... argValues) throws IllegalOperandException { - ArgumentBuilder ab = new ArgumentBuilder(); - List args = getSignature(); - for (int i = 0; i < args.size(); i++) { - if (i >= argValues.length || argValues[i] == null) { - if (args.get(i).isRequired) { - // Argument value is required but not provided - IllegalOperandException ex = new IllegalOperandException(args.get(i)); - while (++i < args.size()) { - // Check for other attributes with the same error - if (args.get(i).isRequired) { - ex.addInvalidValue(args.get(i)); - } - } - throw ex; - } else { - continue; - } - } - ab.appendArgument(argValues[i], args.get(i)); - } - final String[] arguments = ab.asArray(); - return new Callable() { - - @Override - public Object call() throws Exception { - return execute(arguments); - } - - @Override - public String toString() { - return getName() + ' ' + asString(arguments); - } - }; - } - - private String asString(String[] array) { - StringBuilder sb = new StringBuilder(); - if (array != null) { - for (int i = 0; i < array.length; i += 1) { - sb.append(array[i]); - if (i + 1 < array.length) { - sb.append(' '); - } - } - } - return sb.toString(); - } - - private String execute(String[] arguments) - throws InstanceNotFoundException, MBeanException, ReflectionException, IOException { - String operation = commandNameToOperation.get(getName()); - RJMXPlugin.getDefault().getLogger() - .fine("Running " + getName() + " |" + operation + '|' + asString(arguments) + '|'); //$NON-NLS-1$ //$NON-NLS-2$ - if (operation == null) { - throw new RuntimeException("Unavailable diagnostic command " + getName() + '!'); //$NON-NLS-1$ - } - if (getSignature().size() > 0) { - return (String) m_mbeanServer.invoke(DIAGNOSTIC_BEAN, operation, new Object[] {arguments}, - new String[] {String[].class.getName()}); - } else { - return (String) m_mbeanServer.invoke(DIAGNOSTIC_BEAN, operation, new Object[0], new String[0]); - } - } - - } - - public HotSpot24DiagnosticCommandService(MBeanServerConnection server) throws ServiceNotAvailableException { - m_mbeanServer = server; - try { - refreshOperations(); - } catch (Exception e) { - throw new ServiceNotAvailableException("Unable to retrieve diagnostic commands!"); //$NON-NLS-1$ - } - } - - @Override - public synchronized Collection getOperations() throws Exception { - refreshOperations(); - return operations; - } - - private void refreshOperations() throws Exception { - RJMXPlugin.getDefault().getLogger().finer("Refreshing diagnostic operations"); //$NON-NLS-1$ - MBeanInfo info = m_mbeanServer.getMBeanInfo(DIAGNOSTIC_BEAN); - operations = new ArrayList<>(info.getOperations().length); - commandNameToOperation.clear(); - for (MBeanOperationInfo oper : info.getOperations()) { - if (!oper.getName().equals(OPERATION_UPDATE)) { - Descriptor descriptor = oper.getDescriptor(); - DiagnosticCommand c = new DiagnosticCommand(descriptor, oper.getReturnType()); - operations.add(c); - commandNameToOperation.put(c.getName(), oper.getName()); - } - } - } - - @Override - public String runCtrlBreakHandlerWithResult(String command) throws Exception { - int index = command.indexOf(' '); - if (index > 0) { - String operationName = command.substring(0, index); - return findDiagnosticCommand(operationName).execute(splitArguments(command.substring(index + 1).trim())); - } else { - return findDiagnosticCommand(command).execute(null); - } - } - - private String[] splitArguments(String commandArguments) { - List arguments = new ArrayList<>(); - StringBuilder argument = new StringBuilder(); - boolean inCitation = false; - for (char c : commandArguments.toCharArray()) { - if (inCitation) { - if (c == '"') { - inCitation = false; - } - argument.append(c); - } else { - if (Character.isWhitespace(c)) { - if (argument.length() > 0) { - arguments.add(argument.toString()); - argument = new StringBuilder(); - } - } else { - if (c == '"') { - inCitation = true; - } - argument.append(c); - } - } - } - if (argument.length() > 0) { - arguments.add(argument.toString()); - } - return arguments.toArray(new String[arguments.size()]); - } - - private synchronized DiagnosticCommand findDiagnosticCommand(String operationName) throws Exception { - for (DiagnosticCommand op : operations) { - if (op.getName().equals(operationName)) { - return op; - } - } - throw new IllegalArgumentException("Unavailable diagnostic command " + operationName + '!'); //$NON-NLS-1$ - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotspotManagementToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotspotManagementToolkit.java deleted file mode 100644 index 8b1f6550..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotspotManagementToolkit.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import java.io.IOException; - -import javax.management.InstanceAlreadyExistsException; -import javax.management.JMException; -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.rjmx.ConnectionToolkit; - -public final class HotspotManagementToolkit { - - private final static String MC_BEAN_CLASS = "com.sun.management.MissionControl"; //$NON-NLS-1$ - private final static ObjectName MC_BEAN_NAME = ConnectionToolkit - .createObjectName("com.sun.management:type=MissionControl"); //$NON-NLS-1$ - private final static ObjectName HS_DIAGNOSTICS_BEAN_NAME = ConnectionToolkit - .createObjectName("com.sun.management:type=HotSpotDiagnostic"); //$NON-NLS-1$ - private final static String OPERATION_GET_VM_OPTION = "getVMOption"; //$NON-NLS-1$ - private final static String OPERATION_SET_VM_OPTION = "setVMOption"; //$NON-NLS-1$ - private final static String OPERATION_REGISTER_MBEANS = "registerMBeans"; //$NON-NLS-1$ - private final static String PARAMETER_STRING = String.class.getName(); - private final static String EXPLICIT_FLAG = "VM_CREATION"; //$NON-NLS-1$ - - public static void setVMOption(MBeanServerConnection server, String flag, String value) throws Exception { - server.invoke(HS_DIAGNOSTICS_BEAN_NAME, OPERATION_SET_VM_OPTION, new Object[] {flag, value}, - new String[] {PARAMETER_STRING, PARAMETER_STRING}); - } - - public static Object getVMOption(MBeanServerConnection server, String flag) throws Exception { - CompositeData data = (CompositeData) server.invoke(HS_DIAGNOSTICS_BEAN_NAME, OPERATION_GET_VM_OPTION, - new Object[] {flag}, new String[] {PARAMETER_STRING}); - return data.get("value"); //$NON-NLS-1$ - } - - public static boolean isVMOptionExplicit(MBeanServerConnection server, String flag) throws Exception { - CompositeData data = (CompositeData) server.invoke(HS_DIAGNOSTICS_BEAN_NAME, OPERATION_GET_VM_OPTION, - new Object[] {flag}, new String[] {PARAMETER_STRING}); - return data.get("origin").equals(EXPLICIT_FLAG); //$NON-NLS-1$ - } - - public static void registerMBeans(MBeanServerConnection server) throws JMException, IOException { - try { - server.createMBean(MC_BEAN_CLASS, MC_BEAN_NAME); - } catch (InstanceAlreadyExistsException iaee) { - // Ok, it already exists. - } catch (MBeanException mbe) { - // This catch is a workaround for https://github.com/javaee/glassfish/issues/20686 - if (mbe.getTargetException() instanceof InstanceAlreadyExistsException) { - // Ok, it already exists. - } else { - throw mbe; - } - } - server.invoke(MC_BEAN_NAME, OPERATION_REGISTER_MBEANS, new Object[0], new String[0]); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/MRIMetadataServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/MRIMetadataServiceFactory.java deleted file mode 100644 index 595b08a3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/MRIMetadataServiceFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IServiceFactory; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.internal.DefaultMRIMetadataService; - -public class MRIMetadataServiceFactory implements IServiceFactory { - - @Override - public IMRIMetadataService getServiceInstance(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - return new DefaultMRIMetadataService(handle); - } - - @Override - public Class getServiceType() { - return IMRIMetadataService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/NoCommercialFeaturesService.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/NoCommercialFeaturesService.java deleted file mode 100644 index 2050cf34..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/NoCommercialFeaturesService.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService; - -/** - * Used by JVMs with no commercial features, e.g. OpenJDK 8 and JDK 11+ JVMs. - */ -public class NoCommercialFeaturesService implements ICommercialFeaturesService { - - @Override - public boolean isCommercialFeaturesEnabled() { - return true; - } - - @Override - public void enableCommercialFeatures() throws Exception { - // Noop - } - - @Override - public boolean hasCommercialFeatures() { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceEntry.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceEntry.java deleted file mode 100644 index f9f5fafd..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceEntry.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.rjmx.services.IServiceFactory; - -class ServiceEntry { - private final IServiceFactory serviceFactory; - private final String name; - private final String description; - - public ServiceEntry(IServiceFactory serviceFactory, String name, String description) { - this.serviceFactory = serviceFactory; - this.name = name; - this.description = description; - } - - public IServiceFactory getServiceFactory() { - return serviceFactory; - } - - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public Class getServiceClass() { - return serviceFactory.getServiceType(); - } - - @Override - public int hashCode() { - return getServiceClass().getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ServiceEntry other = (ServiceEntry) obj; - if (getServiceClass() == null) { - return (other.getServiceClass() == null); - } else if (!getServiceClass().equals(other.getServiceClass())) { - return false; - } - return true; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceFactoryManager.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceFactoryManager.java deleted file mode 100644 index 5648f3b9..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/ServiceFactoryManager.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.services.IDummyService; - -/** - * Manager for service factories. - */ -@SuppressWarnings("nls") -public class ServiceFactoryManager { - private final static String EXTENSION_POINT = "org.openjdk.jmc.rjmx.service"; - private final static String EXTENSION_ELEMENT_SERVICE = "service"; - private final static String EXTENSION_ATTRIBUTE_FACTORY = "factory"; - private final static String EXTENSION_ATTRIBUTE_NAME = "name"; - private final static String EXTENSION_ATTRIBUTE_DESCRIPTION = "description"; - - private final static Map, Collection>> factoryMap = new HashMap<>(); - - private static class UnsupportedInvocationHandler implements InvocationHandler { - private final Throwable cause; - - public UnsupportedInvocationHandler(Throwable cause) { - this.cause = cause; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - String msg; - if ((cause != null) && (cause.getMessage() != null)) { - msg = cause.getMessage(); - } else { - msg = "Does not support method " + method.getName(); - } - throw new UnsupportedOperationException(msg, cause); - } - } - - public ServiceFactoryManager() { - initializeFromExtensions(); - } - - private Logger getLogger() { - return RJMXPlugin.getDefault().getLogger(); - } - - @SuppressWarnings("unchecked") - public static T createDummyService(Class serviceInterface, Throwable cause) { - Class[] interfaces = new Class[] {serviceInterface, IDummyService.class}; - ClassLoader cl = serviceInterface.getClassLoader(); - return (T) Proxy.newProxyInstance(cl == null ? IDummyService.class.getClassLoader() : cl, interfaces, - new UnsupportedInvocationHandler(cause)); - } - - /** - * Create a service instance of {@code serviceClass}. Normally only proper services or null will - * be returned, but there are two exceptional cases in which dummy services will be returned: - *
    - *
  • If no proper service could be created, but some service factory provided a dummy service, - * this will be returned.
  • - *
  • If neither a proper nor a dummy service was provided, but some service factory threw an - * exception (and {@code serviceClass} denotes an interface), a dummy service will be - * constructed. This dummy service will use the thrown exception as the cause of the - * {@link UnsupportedOperationException}s that its methods will throw. - *
- * - * @param serviceClass - * @param handle - * @return A service instance of {@code serviceClass}, or a dummy service. - */ - public T createService(Class serviceClass, IConnectionHandle handle) { - T firstDummyService = null; - Exception firstException = null; - - for (ServiceEntry entry : getFactoriesFor(serviceClass)) { - try { - T service = entry.getServiceFactory().getServiceInstance(handle); - if (service != null) { - if (!isDummy(service)) { - return service; - } - if (firstDummyService == null) { - firstDummyService = service; - } - } - } catch (Exception e) { - if (firstException == null) { - firstException = e; - } - getLogger().log(Level.FINE, "Could not create service!", e); - } - } - - if ((firstDummyService == null) && (firstException != null) && serviceClass.isInterface()) { - try { - firstDummyService = createDummyService(serviceClass, firstException); - } catch (Exception e) { - // Just log and ignore. - getLogger().log(Level.FINE, "Could not create dummy service to wrap exception!", e); - } - } - - return firstDummyService; - } - - public static boolean isDummy(Object service) { - return service instanceof IDummyService; - } - - @SuppressWarnings("unchecked") - private Collection> getFactoriesFor(Class clazz) { - Collection> factories = (Collection>) factoryMap.get(clazz); - if (factories == null) { - factories = Collections.emptyList(); - } - return factories; - } - - // FIXME: Suggested improvement to service factories. Might not give enough benefits to be worth the effort. -// public boolean hasService(Class serviceClass, IConnectionHandle handle) { -// for (ServiceEntry entry : getFactoriesFor(serviceClass)) { -// if (entry.getServiceFactory().canCreateService(serviceClass, handle)) { -// return true; -// } -// } -// return false; -// } - - private void initializeFromExtensions() { - registerService(new ServiceEntry<>(new DiagnosticCommandServiceFactory(), - "Diagnostic Commands", - "Diagnostic Commands")); - registerService(new ServiceEntry<>(new SubscriptionServiceFactory(), - "Subscription Engine", - "Service for controlling the client side attribute subscription engine")); - registerService(new ServiceEntry<>(new MRIMetadataServiceFactory(), - "Attribute Info", - "Service for getting attribute subscription related information and metadata")); - registerService(new ServiceEntry<>(new AttributeStorageServiceFactory(), - "Attribute Storage", - "Service for storing attribute values")); - registerService(new ServiceEntry<>(new CommercialFeaturesServiceFactory(), - "Commercial Features", - "Service for checking and enabling the state of the commercial features in hotspot.")); - // Skipping PersistenceServiceFactory - } - - private void registerService(ServiceEntry entry) { - Class serviceClass = entry.getServiceClass(); - Collection> factories; - // HINT: A little convoluted to avoid suppressing "unchecked" warnings here. - if (factoryMap.containsKey(serviceClass)) { - factories = getFactoriesFor(entry.getServiceClass()); - } else { - factories = new ArrayList<>(); - factoryMap.put(entry.getServiceClass(), factories); - } - factories.add(entry); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/internal/SubscriptionServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/internal/SubscriptionServiceFactory.java deleted file mode 100644 index 47bc43ba..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/internal/SubscriptionServiceFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.internal; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IServiceFactory; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.internal.DefaultAttributeSubscriptionService; - -public class SubscriptionServiceFactory implements IServiceFactory { - - @Override - public ISubscriptionService getServiceInstance(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - return new DefaultAttributeSubscriptionService(handle); - } - - @Override - public Class getServiceType() { - return ISubscriptionService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderException.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderException.java deleted file mode 100644 index fa9f1b86..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr; - -/** - * Exception thrown when {@link IFlightRecorderService} operations fail. - */ -public class FlightRecorderException extends Exception { - private static final long serialVersionUID = -6818343566212416982L; - - public FlightRecorderException(String message, Throwable cause) { - super(message, cause); - } - - public FlightRecorderException(String message) { - super(message); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderToolkit.java deleted file mode 100644 index f94dd899..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/FlightRecorderToolkit.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr; - -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS; -import static org.openjdk.jmc.common.unit.UnitLookup.MILLISECOND; - -import java.util.List; - -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor.RecordingState; - -/** - * Helper methods to facilitate the use of the {@link IFlightRecorderService}. - */ -public final class FlightRecorderToolkit { - private FlightRecorderToolkit() { - throw new AssertionError("Not to be instantiated!"); //$NON-NLS-1$ - } - - /** - * Will return the first descriptor matching the name. Since there is usually very few - * recordings available, we just do a linear search. - * - * @param name - * the name to look for. - * @param descriptors - * the descriptors to search. - * @return the matching descriptor, or null if none was found. - */ - public static IRecordingDescriptor getDescriptorByName(List descriptors, String name) { - if (name == null) { - return null; - } - for (IRecordingDescriptor descriptor : descriptors) { - if (name.equals(descriptor.getName())) { - return descriptor; - } - } - return null; - } - - /** - * Will return the first descriptor matching the id. Since there is usually very few recordings - * available, we just do a linear search. - * - * @param id - * the id to look for. - * @param descriptors - * the descriptors to search. - * @return the matching descriptor, or null if none was found. - */ - public static IRecordingDescriptor getDescriptorByID(IRecordingDescriptor[] descriptors, Integer id) { - if (id == null) { - return null; - } - for (IRecordingDescriptor descriptor : descriptors) { - if (id.intValue() == descriptor.getId().intValue()) { - return descriptor; - } - } - return null; - } - - /** - * Will return the descriptor that covers the largest part of the desired time range, prefers - * running recordings over stopped recordings. - * - * @param descriptors - * The descriptors to search - * @param timerange - * The desired time range in milliseconds - * @return The best matching descriptor or null if none was found. - */ - public static IRecordingDescriptor getDescriptorByTimerange( - List descriptors, IQuantity timerange) { - IRecordingDescriptor descriptor = null; - descriptor = getDescriptorByTimerange(descriptors, timerange, IRecordingDescriptor.RecordingState.RUNNING); - if (descriptor == null) { - descriptor = getDescriptorByTimerange(descriptors, timerange, IRecordingDescriptor.RecordingState.STOPPED); - } - return descriptor; - } - - private static IRecordingDescriptor getDescriptorByTimerange( - List descriptors, IQuantity timerange, RecordingState recordingState) { - if (timerange == null) { - return null; - } - long now = System.currentTimeMillis(); - long desiredStartTime = now - timerange.clampedLongValueIn(MILLISECOND); - long bestStartTime = Long.MAX_VALUE; - IRecordingDescriptor bestMatchingDescriptor = null; - for (IRecordingDescriptor descriptor : descriptors) { - if (descriptor.getState() == recordingState) { - long dataStartTime = Long.MAX_VALUE; - IQuantity dataStart = descriptor.getDataStartTime(); - if (dataStart != null) { - dataStartTime = dataStart.clampedLongValueIn(EPOCH_MS); - if (dataStartTime <= desiredStartTime) { - return descriptor; - } - } else { - // Generate a synthetic data start time - IQuantity recordingStart = descriptor.getStartTime(); - if (recordingStart != null) { - dataStartTime = recordingStart.clampedLongValueIn(EPOCH_MS); - // FIXME: Also take max size into account? - long maxAge = descriptor.getMaxAge().clampedLongValueIn(MILLISECOND); - if (maxAge > 0) { - dataStartTime = Math.max(dataStartTime, now - maxAge); - } - } else if (bestMatchingDescriptor == null) { - // Last resort choice - bestMatchingDescriptor = descriptor; - } - } - if (dataStartTime < bestStartTime) { - bestMatchingDescriptor = descriptor; - bestStartTime = dataStartTime; - } - } - } - return bestMatchingDescriptor; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IEventTypeInfo.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IEventTypeInfo.java deleted file mode 100644 index 49abde50..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IEventTypeInfo.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr; - -import java.util.Map; - -import org.openjdk.jmc.common.IDescribable; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; - -/** - * Interface to expose additional information of an event type, like a human readable name. This - * should not include implementation details. - */ -public interface IEventTypeInfo extends IDescribable { - /** - * The persistable identifier for the event type that this instance contains information about. - */ - IEventTypeID getEventTypeID(); - - /** - * A human readable categorization for this event type. (This does not include the event type - * itself.) It may be an empty array, but never {@code null}. - */ - String[] getHierarchicalCategory(); - - /** - * A human readable label for this event type. - */ - @Override - String getName(); - - /** - * A human readable description for this event type. May be {@code null}. - */ - @Override - String getDescription(); - - /** - * Get the names and constraints of the parameters accepted by this event type. - */ - Map> getOptionDescriptors(); - - /** - * Get info about any option with the given key. - * - * @param optionKey - * an unqualified option key, such as from {@link EventOptionID#getOptionKey()} - * @return option info or {@code null} - */ - IOptionDescriptor getOptionInfo(String optionKey); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IFlightRecorderService.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IFlightRecorderService.java deleted file mode 100644 index a59724d2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IFlightRecorderService.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr; - -import java.io.InputStream; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPInputStream; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.flightrecorder.configuration.IRecorderConfigurationService; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder; -import org.openjdk.jmc.rjmx.IConnectionHandle; - -/** - * This is the interface for the JDK Flight Recorder controller. - *

- * Implementation, if available, can be retrieved from an - * {@link IConnectionHandle#getServiceOrNull(Class)} - */ -public interface IFlightRecorderService extends IRecorderConfigurationService { - /** - * Returns the available JDK Flight Recorder recordings. The immutable descriptor represents - * the state at the time the method was called. To get an updated representation the method must - * be called again. - * - * @return the available Flight Recording recordings. - * @throws FlightRecorderException - */ - List getAvailableRecordings() throws FlightRecorderException; - - /** - * Get a recording that best represents all the previously recorded data. - * - * @return a recording descriptor. - * @throws FlightRecorderException - */ - IRecordingDescriptor getSnapshotRecording() throws FlightRecorderException; - - /** - * Returns the updated recording descriptor for the specified recording. - * - * @param descriptor - * the recording for which to get the recording descriptor. - * @return the recording descriptor for the specified recording id. - */ - IRecordingDescriptor getUpdatedRecordingDescription(IRecordingDescriptor descriptor) throws FlightRecorderException; - - /** - * Starts a new JDK Flight Recorder recording. - * - * @param recordingOptions - * the recording options. Use {@link RecordingOptionsBuilder} to create. - * @param eventOptions - * the event options. - * @return the {@link IRecordingDescriptor} representing the started recording. - * @throws FlightRecorderException - * if there was a problem starting the recording. - */ - IRecordingDescriptor start(IConstrainedMap recordingOptions, IConstrainedMap eventOptions) - throws FlightRecorderException; - - /** - * Stops the recording represented by the {@link IRecordingDescriptor}. - * - * @param descriptor - * the recording to stop. - * @throws FlightRecorderException - * if there was a problem stopping the recording. - */ - void stop(IRecordingDescriptor descriptor) throws FlightRecorderException; - - /** - * Closes the recording represented by the {@link IRecordingDescriptor}. A closed recording will - * no longer be listed among the available recordings. It's corresponding MBean will be removed. - * - * @param descriptor - * the recording to close. - * @throws FlightRecorderException - * if there was a problem closing the recording. - */ - void close(IRecordingDescriptor descriptor) throws FlightRecorderException; - - /** - * Returns the descriptors for the available recording options. - * - * @return the available recording option descriptors. - * @throws FlightRecorderException - * if there was a problem retrieving the recording options. - */ - Map> getAvailableRecordingOptions() throws FlightRecorderException; - - /** - * Returns the recording options for the specified recording. Note that options can be changed - * over time. The {@link IConstrainedMap} is immutable - call again to get the updated settings - * for a particular recording. - * - * @param recording - * the recording for which to retrieve the recording options. - * @return the {@link IConstrainedMap} for the specified recording. - * @throws FlightRecorderException - * if there was a problem retrieving the options. - */ - IConstrainedMap getRecordingOptions(IRecordingDescriptor recording) throws FlightRecorderException; - - /** - * @return the metadata for all known event types. - * @throws FlightRecorderException - * if there was a problem retrieving the metadata. - */ - Collection getAvailableEventTypes() throws FlightRecorderException; - - /** - * @return a mapping from event type id to info - * @throws FlightRecorderException - * if there was a problem retrieving the metadata. - */ - Map getEventTypeInfoMapByID() throws FlightRecorderException; - - /** - * Returns the currently active settings for all event types, if the JDK Flight Recorder - * version supports this notion. Otherwise, empty settings will be returned. - * - * @return the current settings for the event types. - * @throws FlightRecorderException - * if there was a problem retrieving the settings. - */ - IConstrainedMap getCurrentEventTypeSettings() throws FlightRecorderException; - - /** - * Returns the event settings for the specified recording. - * - * @param recording - * the recording for which to return the settings. - * @return the event settings for the specified recording. - * @throws FlightRecorderException - */ - IConstrainedMap getEventSettings(IRecordingDescriptor recording) throws FlightRecorderException; - - /** - * Opens a stream from the specified recording. Will read all available data. The content of the - * stream is gzipped. You would normally want to wrap it in a {@link GZIPInputStream}. - * - * @param descriptor - * the recording from which to retrieve the data. - * @param removeOnClose - * whether the recording should be removed when the stream is closed or not - * @return an input stream from which to read the recording data. - * @throws FlightRecorderException - * if there was a problem reading the recording data. - */ - InputStream openStream(IRecordingDescriptor descriptor, boolean removeOnClose) throws FlightRecorderException; - - /** - * Opens a stream from the specified recording between the specified times. The content of the - * stream is gzipped. You would normally want to wrap it in a {@link GZIPInputStream}. - *

- * Note that the dates should be in server side time. Special care should be taken to make sure - * that server side timestamps are used. - * - * @param descriptor - * the recording from which to retrieve the data. - * @param startTime - * the start time. - * @param endTime - * the end time. - * @param removeOnClose - * whether the recording should be removed when the stream is closed or not - * @return an input stream from which to read the recording data. - * @throws FlightRecorderException - * if there was a problem reading the recording data. - */ - InputStream openStream( - IRecordingDescriptor descriptor, IQuantity startTime, IQuantity endTime, boolean removeOnClose) - throws FlightRecorderException; - - /** - * Opens a stream from the specified recording for the past "time" milliseconds. The content of - * the stream is gzipped. You would normally want to wrap it in a {@link GZIPInputStream}. - * - * @param descriptor - * the recording from which to retrieve the data. - * @param lastPartDuration - * the duration of data to retrieve. - * @param removeOnClose - * whether the recording should be removed when the stream is closed or not - * @return an input stream from which to read the recording data. - * @throws FlightRecorderException - * if there was a problem reading the recording data. - */ - InputStream openStream(IRecordingDescriptor descriptor, IQuantity lastPartDuration, boolean removeOnClose) - throws FlightRecorderException; - - /** - * @return the server templates for event settings found on the server. - */ - List getServerTemplates() throws FlightRecorderException; - - /** - * Updates the event options for the specified descriptor. - * - * @param descriptor - * the recording to update the event options for. - * @param options - * the new, overriding, event options. If null, the current options will be used. - */ - void updateEventOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException; - - /** - * Updates the recording options for the specified recording. - * - * @param descriptor - * the recording to update the event settings for. - * @param options - * the new options to set. - */ - void updateRecordingOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException; - - /** - * @return true if the flight recorder is enabled, false otherwise. - */ - boolean isEnabled(); - - /** - * Enables the recorder - * - * @throws FlightRecorderException - * if there was a problem to enable the recorder - */ - void enable() throws FlightRecorderException; -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IRecordingDescriptor.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IRecordingDescriptor.java deleted file mode 100644 index fbf3f6b2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/IRecordingDescriptor.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr; - -import java.util.Map; - -import javax.management.ObjectName; - -import org.openjdk.jmc.common.unit.IQuantity; - -/** - * Interface that describe a JDK Flight Recorder recording. - */ -public interface IRecordingDescriptor { - /** - * Defines the possible states a recording can be in. {@link RecordingState#CREATED} - * {@link RecordingState#RUNNING} {@link RecordingState#STOPPED} - */ - public enum RecordingState { - /** - * The Recording has been created but not yet started. - */ - CREATED, - /** - * The recording is running, i.e. it has been started, but not yet stopped. - */ - RUNNING, - /** - * The recording has been started, and is stopping, but has not fully completed. - */ - STOPPING, - /** - * The recording has been started, and then stopped. Either because the recording duration - * timed out, or because it was forced to stop. - */ - STOPPED - } - - /** - * Returns the id value of the recording. - * - * @return the id value of the recording. - */ - Long getId(); - - /** - * Returns the symbolic name of the recording. - * - * @return the symbolic name of the recording. - */ - String getName(); - - /** - * Returns the state of the recording when this {@link IRecordingDescriptor} was created. - * - * @return the state of the recording when this {@link IRecordingDescriptor} was created. - */ - RecordingState getState(); - - /** - * Returns a Map<String, Object> with values that describes the various options in the - * recording. Options can, for instance, be duration and destFile. - * - * @return a Map<String, Object> with values that describes the various options in the - * recording. - */ - Map getOptions(); - - /** - * Returns the object name used to locate the MBean that is used to manage this recording. - * - * @return the object name used to locate the MBean that is used to manage this recording. - */ - ObjectName getObjectName(); - - /** - * Returns the data start time for this recording. - * - * @return the data start time for the recording - */ - public IQuantity getDataStartTime(); - - /** - * Returns the data end time for this recording. - * - * @return the data end time for the recording - */ - public IQuantity getDataEndTime(); - - /** - * Returns the start time for this recording. - * - * @return the start time for this recording, or null if not available - */ - public IQuantity getStartTime(); - - /** - * Returns the duration the recording was created with. - * - * @return the duration of the recording in ms (0 means continuous), or -1 if unavailable - */ - public IQuantity getDuration(); - - /** - * Returns the recording was created as continuous or not. - * - * @return true if the recording was created continuous, or false if not - */ - public boolean isContinuous(); - - /** - * Returns whether the recording is stored to disk. - * - * @return true if the recording is stored to disk, false otherwise - */ - public boolean getToDisk(); - - /** - * Returns the recordings maximum size. - * - * @return the maximum size of the recording - */ - public IQuantity getMaxSize(); - - /** - * Returns the recordings maximum event age. - * - * @return the maximum event age of the recording - */ - public IQuantity getMaxAge(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventOptionsToolkitV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventOptionsToolkitV1.java deleted file mode 100644 index f255e463..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventOptionsToolkitV1.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions.EVENT_OPTIONS_BY_KEY_V1; -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions.KEY_ENABLED; -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions.KEY_PERIOD; -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions.KEY_STACKTRACE; -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions.KEY_THRESHOLD; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; - -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * Toolkit for marshalling JFR 1.0 (JDK7/8) event options. - */ -public final class EventOptionsToolkitV1 { - private final static String KEY_ID = "id"; //$NON-NLS-1$ - private final static String KEY_STACKTRACE_SERVER = "stacktrace"; //$NON-NLS-1$ - private final static String KEY_PERIOD_SERVER = "requestPeriod"; //$NON-NLS-1$ - - private final static Map> CONVERTERS_BY_EVENT_OPTION_KEY; - private final static Map CAPABILITY_KEYS_BY_OPTION_KEY; - - private final static String[] SERVER_NAMES = new String[] {KEY_ID, KEY_THRESHOLD, KEY_STACKTRACE_SERVER, - KEY_PERIOD_SERVER, KEY_ENABLED}; - private final static OpenType[] OPEN_TYPES = new OpenType[] {SimpleType.INTEGER, SimpleType.LONG, - SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.BOOLEAN}; - - public final static CompositeType OPTIONS_COMPOSITE_TYPE; - - static { - Map> converters = new LinkedHashMap<>(); - Map capabilities = new HashMap<>(); - - converters.put(KEY_THRESHOLD, OpenTypeConverter.NANOSECONDS); - capabilities.put(KEY_THRESHOLD, "isTimed"); //$NON-NLS-1$ - - converters.put(KEY_STACKTRACE, OpenTypeConverter.BOOLEAN); - capabilities.put(KEY_STACKTRACE, "isStackTraceAvailable"); //$NON-NLS-1$ - - converters.put(KEY_PERIOD, OpenTypeConverter.MILLIS_PERIODICITY); - capabilities.put(KEY_PERIOD, "isRequestable"); //$NON-NLS-1$ - - converters.put(KEY_ENABLED, OpenTypeConverter.BOOLEAN); - - CONVERTERS_BY_EVENT_OPTION_KEY = converters; - CAPABILITY_KEYS_BY_OPTION_KEY = capabilities; - OPTIONS_COMPOSITE_TYPE = generateOptionsType(); - } - - @SuppressWarnings("nls") - private static CompositeType generateOptionsType() { - try { - return new CompositeType("EventOptions", "Event Options", SERVER_NAMES, SERVER_NAMES, OPEN_TYPES); - } catch (Exception e) { - // Will not ever happen! - } - return null; - } - - @SuppressWarnings("nls") - private EventOptionsToolkitV1() { - throw new AssertionError("Not to be instantiated!"); - } - - /** - * This helper does the ad-hoc mapping from capabilities to parameter names and constraints. The - * capabilities are used to check for which parameters are actually accepted. The parameter - * space to check is currently static - we can't get this data from the server today. - * - * @param capabilities - * the capabilities {@link Map} from the event type that describes (in an ad-hoc way) - * which parameters are accepted. - * @return the names and constraints for the parameters that actually are accepted. - */ - public static Map> getConfigurableOptions(CompositeData data) { - Map> optionMap = new HashMap<>(); - for (Entry> entry : EVENT_OPTIONS_BY_KEY_V1.entrySet()) { - String capKey = CAPABILITY_KEYS_BY_OPTION_KEY.get(entry.getKey()); - if ((capKey == null) || Boolean.TRUE.equals(data.get(capKey))) { - optionMap.put(entry.getKey(), entry.getValue()); - } - } - return optionMap; - } - - /** - * Converts the event settings to a list of composite data, usable by the MBean API. - * - * @throws OpenDataException - */ - public static List encodeAllEventSettings( - Collection availableEventTypes, IConstrainedMap settings) - throws OpenDataException { - List eventSettings = new ArrayList<>(); - for (EventTypeMetadataV1 eventType : availableEventTypes) { - Object[] values = new Object[] {eventType.getId(), -1L, Boolean.FALSE, -1L, Boolean.FALSE}; - int i = 1; - for (Entry> entry : CONVERTERS_BY_EVENT_OPTION_KEY.entrySet()) { - // Only change options the event type is supposed to have. - if (eventType.getOptionInfo(entry.getKey()) != null) { - EventOptionID optionID = new EventOptionID(eventType.getEventTypeID(), entry.getKey()); - Object value = settings.get(optionID); - // FIXME: Check exact semantics of JFR 1.0 here, when to override (0 vs. -1). - if (value != null) { - try { - values[i] = RecordingOptionsToolkitV1.toOpenTypeWithCast(entry.getValue(), value); - } catch (QuantityConversionException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, e.getMessage(), e); - } - } - } - i++; - } - eventSettings.add(new CompositeDataSupport(OPTIONS_COMPOSITE_TYPE, SERVER_NAMES, values)); - } - return eventSettings; - } - - /** - * Adds options from the composite data to the constrained map, filtered by the given event type - * metadata. - */ - @SuppressWarnings("nls") - public static void addOptionsToV1( - IMutableConstrainedMap options, EventTypeMetadataV1 eventType, CompositeData data) { - for (String serverKey : data.getCompositeType().keySet()) { - String localKey = serverKey; - if (serverKey.equals(KEY_PERIOD_SERVER)) { - localKey = KEY_PERIOD; - } else if (localKey.equals(KEY_STACKTRACE_SERVER)) { - localKey = KEY_STACKTRACE; - } - IOptionDescriptor optionInfo = eventType.getOptionInfo(localKey); - OpenTypeConverter converter = CONVERTERS_BY_EVENT_OPTION_KEY.get(localKey); - if ((optionInfo != null) && (converter != null)) { - assert optionInfo.getConstraint() == converter.constraint; - EventOptionID optionID = new EventOptionID(eventType.getEventTypeID(), localKey); - try { - putWithCast(options, optionID, converter, data.get(serverKey)); - } catch (QuantityConversionException e) { - // This should not happen - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Problem with value for option " + optionID, - e); - } - } - } - } - - /** - * @throws QuantityConversionException - */ - static void putWithCast( - IMutableConstrainedMap map, K key, OpenTypeConverter converter, Object openValue) - throws QuantityConversionException { - T value = converter.fromOpenType(converter.getType().cast(openValue)); - map.put(key, converter.constraint, value); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV1.java deleted file mode 100644 index f3d8da67..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV1.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; - -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV1; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; - -/** - * Provides information about an event type. - */ -public final class EventTypeMetadataV1 implements IEventTypeInfo { - private final Integer id; - private final EventTypeIDV1 eventTypeID; - private final String label; - private final String description; - private final Map> optionInfoByKey; - private String[] hierarchy; - - public EventTypeMetadataV1(Integer id, EventTypeIDV1 eventTypeID, String label, String description, - Map> optionInfoByKey) { - this.id = id; - this.eventTypeID = eventTypeID; - this.label = label; - this.description = description; - this.optionInfoByKey = Collections.unmodifiableMap(optionInfoByKey); - - String[] fallback = eventTypeID.getFallbackHierarchy(); - if (fallback != null && fallback.length > 1) { - hierarchy = Arrays.copyOf(fallback, fallback.length - 1); - } - } - - public Integer getId() { - return id; - } - - public String getPath() { - return eventTypeID.getRelativeKey(); - } - - @Override - public String[] getHierarchicalCategory() { - return hierarchy; - } - - @Override - public EventTypeIDV1 getEventTypeID() { - return eventTypeID; - } - - @Override - public String getName() { - return label; - } - - @Override - public String getDescription() { - return description; - } - - /** - * Get the names and constraints of the parameters accepted by this event type. - */ - @Override - public Map> getOptionDescriptors() { - return optionInfoByKey; - } - - @Override - public IOptionDescriptor getOptionInfo(String optionKey) { - return optionInfoByKey.get(optionKey); - } - - @Override - @SuppressWarnings("nls") - public String toString() { - return "EventTypeMetadataV1 [type=" + eventTypeID + ", id=" + id + ", label=" + label + ", options=" - + optionInfoByKey.keySet() + ']'; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV2.java deleted file mode 100644 index d9b2d941..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/EventTypeMetadataV2.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV2; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; - -/** - * Provides information about an event type for JFR 2.0. - */ -public final class EventTypeMetadataV2 implements IEventTypeInfo { - private static final String JFR_SETTINGS_PERIOD = "com.oracle.jfr.settings.Period"; //$NON-NLS-1$ - private final Long id; - private final EventTypeIDV2 eventTypeID; - private final String label; - private final String description; - private final String[] category; - private final Map> optionInfoByKey; - - @SuppressWarnings("nls") - private static OptionInfo optionInfoFrom(CompositeData data) { - String label = (String) data.get("label"); - String description = (String) data.get("description"); - String contentType = (String) data.get("contentType"); - String defaultValue = (String) data.get("defaultValue"); - - final String jfrPkg = "jdk.jfr."; - final String jfrPeriod = jfrPkg + "Period"; - final String jfrFlag = jfrPkg + "Flag"; - if (contentType == null) { - /* - * This is the best way JFR currently wants to communicate which "content type" this is. - * Doing this separately from the below check to skip the printout - */ - String typeName = (String) data.get("typeName"); - if (JFR_SETTINGS_PERIOD.equals(typeName)) { - contentType = jfrPeriod; - } - if (contentType != null) { - FlightRecorderServiceV2.LOGGER.fine("Inferred content type '" + contentType + "' for option " + label); - } - } - if (contentType == null) { - // FIXME: Remove this, as something similar already is in CommonConstraints. - // Patch for beta builds of JFR.next without content types for everything. (Hopefully fixed by release.) - String key = (String) data.get("name"); - if ("period".equals(key)) { - contentType = jfrPeriod; - } else if ("true".equals(defaultValue) || "false".equals(defaultValue)) { - contentType = jfrFlag; - } - if (contentType != null) { - FlightRecorderServiceV2.LOGGER - .warning("Inferred content type '" + contentType + "' for option " + label); - } - } - IConstraint constraint = CommonConstraints.forContentTypeV2(contentType, defaultValue); - return optionInfoFrom(label, description, constraint, contentType, defaultValue); - } - - private static OptionInfo optionInfoFrom( - String label, String description, IConstraint constraint, String jdkContentType, - String defaultPersistedValue) { - T defaultValue; - try { - defaultValue = constraint.parsePersisted(defaultPersistedValue); - } catch (QuantityConversionException e) { - // Should not happen here. If it does, it has already been detected and then T can only be String. - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, e.getMessage(), e); - @SuppressWarnings("unchecked") - T strDef = (T) ""; - defaultValue = strDef; - } - return new OptionInfo<>(label, description, constraint, defaultValue); - } - - @SuppressWarnings("nls") - static EventTypeMetadataV2 from(CompositeData data) { - Long id = (Long) data.get("id"); - String name = (String) data.get("name"); - String label = (String) data.get("label"); - String description = (String) data.get("description"); - String[] category = (String[]) data.get("categoryNames"); - - CompositeData[] settings = (CompositeData[]) data.get("settingDescriptors"); - EventTypeIDV2 eventTypeID = new EventTypeIDV2(name); - Map> infoMap = new HashMap<>(settings.length); - for (CompositeData setting : settings) { - String key = (String) setting.get("name"); - OptionInfo info = optionInfoFrom(setting); - infoMap.put(key, info); - } - return new EventTypeMetadataV2(id, eventTypeID, label, description, category, infoMap); - } - - EventTypeMetadataV2(Long id, EventTypeIDV2 eventTypeID, String label, String description, String[] category, - Map> optionInfoMap) { - this.id = id; - this.eventTypeID = eventTypeID; - this.label = label; - this.description = description; - this.category = category; - optionInfoByKey = Collections.unmodifiableMap(optionInfoMap); - } - - public Long getId() { - return id; - } - - @Override - public String[] getHierarchicalCategory() { - return category; - } - - @Override - public EventTypeIDV2 getEventTypeID() { - return eventTypeID; - } - - @Override - public String getName() { - return label; - } - - @Override - public String getDescription() { - return description; - } - - /** - * Get the names and constraints of the parameters accepted by this event type. - */ - @Override - public Map> getOptionDescriptors() { - return optionInfoByKey; - } - - @Override - public IOptionDescriptor getOptionInfo(String optionKey) { - return optionInfoByKey.get(optionKey); - } - - @Override - @SuppressWarnings("nls") - public String toString() { - return "EventTypeMetadataV2 [type=" + eventTypeID + ", id=" + id + ", category=" + String.join(" / ", category) - + ", label=" + label + ", options=" + optionInfoByKey.keySet() + ']'; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/ExcludingEventOptionMapper.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/ExcludingEventOptionMapper.java deleted file mode 100644 index f63328de..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/ExcludingEventOptionMapper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.util.Map; -import java.util.Set; - -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventOptionDescriptorMapper; - -public class ExcludingEventOptionMapper extends EventOptionDescriptorMapper { - private final Set excludedTypes; - - public ExcludingEventOptionMapper(Set excludedTypes, - Class typeClass, Map> map) { - super(typeClass, map, true); - this.excludedTypes = excludedTypes; - } - - @Override - public IOptionDescriptor get(EventOptionID key) { - return excludedTypes.contains(key.getEventTypeID()) ? OptionInfo.DISALLOWED_OPTION : super.get(key); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV1.java deleted file mode 100644 index 320ad78f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV1.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.io.IOException; - -import javax.management.InstanceNotFoundException; -import javax.management.JMException; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.services.internal.HotspotManagementToolkit; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * Helper class for facilitating communication with the FlightRecorderMBean. This class works with - * R28 and HotSpot 7u4. - */ -final class FlightRecorderCommunicationHelperV1 implements IFlightRecorderCommunicationHelper { - private final MBeanServerConnection server; - private final static ObjectName JFR_MBEAN_OBJECT_NAME = ConnectionToolkit - .createObjectName("com.oracle.jrockit:type=FlightRecorder"); //$NON-NLS-1$ - - public FlightRecorderCommunicationHelperV1(MBeanServerConnection server) { - this.server = server; - } - - @Override - public Object getAttribute(String attribute) throws FlightRecorderException { - try { - try { - return getJfrAttribute(attribute); - } catch (InstanceNotFoundException e) { - HotspotManagementToolkit.registerMBeans(server); - return getJfrAttribute(attribute); - } - } catch (IOException e) { - throw new FlightRecorderException("Could not retrieve the attribute " + attribute + '!', e); //$NON-NLS-1$ - } catch (JMException e) { - throw new FlightRecorderException("Could not retrieve the attribute " + attribute + '!', e); //$NON-NLS-1$ - } - } - - private Object getJfrAttribute(String attribute) throws JMException, IOException { - return server.getAttribute(JFR_MBEAN_OBJECT_NAME, attribute); - } - - @Override - public Object invokeOperation(String name, Object ... parameters) throws IOException, FlightRecorderException { - try { - try { - return invokeJfrOperation(name, parameters); - } catch (InstanceNotFoundException e) { - HotspotManagementToolkit.registerMBeans(server); - return invokeJfrOperation(name, parameters); - } - } catch (JMException e) { - IOException throwMe = new IOException(e.getMessage()); - throwMe.initCause(e); - throw throwMe; - } - } - - private Object invokeJfrOperation(String operation, Object ... parameters) throws JMException, IOException { - return ConnectionToolkit.invokeOperation(server, JFR_MBEAN_OBJECT_NAME, operation, parameters); - } - - @Override - public void closeRecording(IRecordingDescriptor descriptor) throws FlightRecorderException { - try { - invokeOperation("close", descriptor.getObjectName()); //$NON-NLS-1$ - } catch (Exception e) { - throw new FlightRecorderException("Could not close the recording!", e); //$NON-NLS-1$ - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV2.java deleted file mode 100644 index 903c45fa..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderCommunicationHelperV2.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.io.IOException; -import java.text.MessageFormat; - -import javax.management.JMException; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * Helper class for facilitating communication with the FlightRecorderMBean. This class works with - * R28 and HotSpot 7u4. - */ -// FIXME: If the invoke operation and the MBean name is folded into the IFlightRecorderService implementations then we can avoid having two versions of this class -final class FlightRecorderCommunicationHelperV2 implements IFlightRecorderCommunicationHelper { - private final MBeanServerConnection server; - private final ObjectName jfr2MBeanObjectName; - private final static String JFR2_MBEAN_OBJECT_NAME_OLD = "jdk.jfr.management:type=FlightRecorder"; //$NON-NLS-1$ - private final static String JFR2_MBEAN_OBJECT_NAME = "jdk.management.jfr:type=FlightRecorder"; //$NON-NLS-1$ - - public FlightRecorderCommunicationHelperV2(MBeanServerConnection server) throws ServiceNotAvailableException { - this.server = server; - jfr2MBeanObjectName = getJfrMBeanObjectName(server); - } - - @Override - public Object getAttribute(String attribute) throws FlightRecorderException { - try { - return getJfrAttribute(attribute); - } catch (IOException e) { - throw new FlightRecorderException("Could not retrieve the attribute " + attribute + '!', e); //$NON-NLS-1$ - } catch (JMException e) { - throw new FlightRecorderException("Could not retrieve the attribute " + attribute + '!', e); //$NON-NLS-1$ - } - } - - private Object getJfrAttribute(String attribute) throws JMException, IOException { - return server.getAttribute(jfr2MBeanObjectName, attribute); - } - - @Override - public Object invokeOperation(String name, Object ... parameters) throws IOException, FlightRecorderException { - try { - return invokeJfrOperation(name, parameters); - } catch (JMException e) { - IOException throwMe = new IOException(e.getMessage()); - throwMe.initCause(e); - throw throwMe; - } - } - - private Object invokeJfrOperation(String operation, Object ... parameters) throws JMException, IOException { - return ConnectionToolkit.invokeOperation(server, jfr2MBeanObjectName, operation, parameters); - } - - @Override - public void closeRecording(IRecordingDescriptor descriptor) throws FlightRecorderException { - try { - invokeOperation("closeRecording", descriptor.getId()); //$NON-NLS-1$ - } catch (Exception e) { - throw new FlightRecorderException("Could not close the recording!", e); //$NON-NLS-1$ - } - } - - public static boolean isAvailable(IConnectionHandle handle) { - try { - MBeanServerConnection connection = handle.getServiceOrThrow(MBeanServerConnection.class); - getJfrMBeanObjectName(connection); - return true; - } catch (Exception e) { - return false; - } - } - - private static ObjectName getJfrMBeanObjectName(MBeanServerConnection server) throws ServiceNotAvailableException { - /* - * FlightRecorder MXBean name was changed during JDK9 development. Handling both the old and - * the new name. Can consider removing this later. - */ - try { - ObjectName candidate2ObjectName = ConnectionToolkit.createObjectName(JFR2_MBEAN_OBJECT_NAME); - server.getMBeanInfo(candidate2ObjectName); - return candidate2ObjectName; - } catch (Exception e) { - } - try { - ObjectName candidate1ObjectName = ConnectionToolkit.createObjectName(JFR2_MBEAN_OBJECT_NAME_OLD); - server.getMBeanInfo(candidate1ObjectName); - return candidate1ObjectName; - } catch (Exception e) { - throw new ServiceNotAvailableException( - MessageFormat.format("FlightRecorder MXBean not available, tried {0} and {1}", //$NON-NLS-1$ - JFR2_MBEAN_OBJECT_NAME, JFR2_MBEAN_OBJECT_NAME_OLD)); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceFactory.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceFactory.java deleted file mode 100644 index 2900f9d2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceFactory.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IServiceFactory; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; - -public class FlightRecorderServiceFactory implements IServiceFactory { - - @Override - public IFlightRecorderService getServiceInstance(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - if (FlightRecorderServiceV2.isAvailable(handle)) { - return new FlightRecorderServiceV2(handle); - } - return new FlightRecorderServiceV1(handle); - } - - @Override - public Class getServiceType() { - return IFlightRecorderService.class; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java deleted file mode 100644 index 222854a0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS; -import static org.openjdk.jmc.common.unit.UnitLookup.toDate; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.OpenDataException; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.ITypedQuantity; -import org.openjdk.jmc.common.unit.LinearUnit; -import org.openjdk.jmc.common.unit.SimpleConstrainedMap; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.flightrecorder.configuration.ConfigurationToolkit; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.flightrecorder.configuration.events.SchemaVersion; -import org.openjdk.jmc.flightrecorder.configuration.internal.DefaultValueMap; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV1; -import org.openjdk.jmc.flightrecorder.configuration.internal.IMapper; -import org.openjdk.jmc.flightrecorder.configuration.internal.KnownRecordingOptions; -import org.openjdk.jmc.flightrecorder.configuration.internal.ValidationToolkit; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.JVMSupportToolkit; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderToolkit; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; - -public class FlightRecorderServiceV1 implements IFlightRecorderService { - final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.services.jfr"); //$NON-NLS-1$ - private final static IMapper> DISALLOW_MAPPER = new IMapper>() { - @Override - public IOptionDescriptor get(EventOptionID key) { - return OptionInfo.DISALLOWED_OPTION; - } - }; - - // FIXME: This is a very long time span used to find the longest recording. We could remove the need for this constant by changing the code that uses it. - private static final ITypedQuantity MAX_REQUIRED_RECORDING_DURATION = UnitLookup.YEAR.quantity(10); - - private final IFlightRecorderCommunicationHelper helper; - private long eventTypeMetaNextUpdate; - private List eventTypeMetas; - private Map eventTypeMetaByInt; - private Map eventTypeInfoById; - // Optimization to do less JMX invocations. If, against all odds, it gets disabled, - // after having been enabled, we get an exception, and will handle things there. - private boolean wasEnabled; - private final ICommercialFeaturesService cfs; - private final IMBeanHelperService mbhs; - private final String serverId; - - @Override - public String getVersion() { - return "1.0"; //$NON-NLS-1$ - } - - private boolean isDynamicFlightRecorderSupported(IConnectionHandle handle) { - return ConnectionToolkit.isHotSpot(handle) - && ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED); - } - - private boolean isFlightRecorderDisabled(IConnectionHandle handle) { - if (cfs != null) { - return !cfs.isCommercialFeaturesEnabled() || JVMSupportToolkit.isFlightRecorderDisabled(handle, false); - } else { - return true; - } - } - - public FlightRecorderServiceV1(IConnectionHandle handle) throws ConnectionException, ServiceNotAvailableException { - cfs = handle.getServiceOrThrow(ICommercialFeaturesService.class); - if (!isDynamicFlightRecorderSupported(handle) && isFlightRecorderDisabled(handle)) { - throw new ServiceNotAvailableException(""); //$NON-NLS-1$ - } - if (JVMSupportToolkit.isFlightRecorderDisabled(handle, true)) { - throw new ServiceNotAvailableException(""); //$NON-NLS-1$ - } - helper = new FlightRecorderCommunicationHelperV1(handle.getServiceOrThrow(MBeanServerConnection.class)); - mbhs = handle.getServiceOrThrow(IMBeanHelperService.class); - serverId = handle.getServerDescriptor().getGUID(); - } - - @Override - public void stop(IRecordingDescriptor descriptor) throws FlightRecorderException { - stop(descriptor.getObjectName()); - } - - private void stop(ObjectName objectName) throws FlightRecorderException { - try { - helper.invokeOperation("stop", objectName); //$NON-NLS-1$ - } catch (Exception e) { - throw new FlightRecorderException("Could not stop the recording!", e); //$NON-NLS-1$ - } - } - - @Override - public void close(IRecordingDescriptor descriptor) throws FlightRecorderException { - helper.closeRecording(descriptor); - } - - @Override - public IRecordingDescriptor start( - IConstrainedMap recordingOptions, IConstrainedMap eventOptions) - throws FlightRecorderException { - try { - validateOptions(recordingOptions); - String name = RecordingOptionsToolkitV1.getName(recordingOptions); - ObjectName recording = (ObjectName) helper.invokeOperation("createRecording", name); //$NON-NLS-1$ - helper.invokeOperation("setRecordingOptions", recording, //$NON-NLS-1$ - RecordingOptionsToolkitV1.getRecordingOptions(recordingOptions)); - if (eventOptions != null) { - updateEventOptions(recording, eventOptions); - } - helper.invokeOperation("start", recording); //$NON-NLS-1$ - for (IRecordingDescriptor descriptor : getAvailableRecordings()) { - if (recording.equals(descriptor.getObjectName())) { - return descriptor; - } - } - } catch (Exception e) { - throw new FlightRecorderException("Could not start the recording!", e); //$NON-NLS-1$ - } - return null; - } - - @Override - public IDescribedMap getDefaultRecordingOptions() { - return KnownRecordingOptions.OPTION_DEFAULTS_V1; - } - - @Override - public IConstrainedMap getRecordingOptions(IRecordingDescriptor recording) throws FlightRecorderException { - try { - return getRecordingOptions(recording.getObjectName()); - } catch (Exception e) { - throw new FlightRecorderException("Could not retrieve recording options.", e); //$NON-NLS-1$ - } - } - - private IConstrainedMap getRecordingOptions(ObjectName name) throws FlightRecorderException, IOException { - return RecordingOptionsToolkitV1 - .toRecordingOptions((CompositeData) helper.invokeOperation("getRecordingOptions", name)); //$NON-NLS-1$ - } - - @Override - public IConstrainedMap getEventSettings(IRecordingDescriptor recording) - throws FlightRecorderException { - try { - Map map = getEventTypeByIntMap(); - @SuppressWarnings("unchecked") - List compositeList = (List) helper.invokeOperation("getEventSettings", //$NON-NLS-1$ - recording.getObjectName()); - return toEventOptionMap(map, compositeList); - } catch (Exception e) { - FlightRecorderException flr = new FlightRecorderException( - "Could not retrieve recording options for recording " + recording.getName() + '.'); //$NON-NLS-1$ - flr.initCause(e); - throw flr; - } - } - - // FIXME: This should _really_ be retrieved from the server, but the server API does not allow that at the moment. - @Override - public Map> getAvailableRecordingOptions() throws FlightRecorderException { - return RecordingOptionsToolkitV1.getAvailableRecordingOptions(); - } - - @Override - public String toString() { - return helper.toString(); - } - - @Override - public InputStream openStream(IRecordingDescriptor descriptor, boolean removeOnClose) - throws FlightRecorderException { - IRecordingDescriptor streamDescriptor = descriptor; - boolean clone = isStillRunning(descriptor); - if (clone) { - streamDescriptor = clone(descriptor); - } - return new JfrRecordingInputStreamV1(helper, streamDescriptor, clone | removeOnClose); - } - - @Override - public InputStream openStream( - IRecordingDescriptor descriptor, IQuantity startTime, IQuantity endTime, boolean removeOnClose) - throws FlightRecorderException { - IRecordingDescriptor streamDescriptor = descriptor; - boolean clone = isStillRunning(descriptor); - if (clone) { - streamDescriptor = clone(descriptor); - } - return new JfrRecordingInputStreamV1(helper, streamDescriptor, toDate(startTime), toDate(endTime), - clone | removeOnClose); - } - - @Override - public Collection getAvailableEventTypes() throws FlightRecorderException { - return updateEventTypeMetadataMaps(true); - } - - @Override - public List getAvailableRecordings() throws FlightRecorderException { - @SuppressWarnings("unchecked") - List attribute = (List) helper.getAttribute("Recordings"); //$NON-NLS-1$ - List recordings = new ArrayList<>(); - for (CompositeData data : attribute) { - recordings.add(RecordingDescriptorToolkitV1.createRecordingDescriptor(serverId, data)); - } - return Collections.unmodifiableList(recordings); - } - - @Override - public IRecordingDescriptor getSnapshotRecording() throws FlightRecorderException { - return FlightRecorderToolkit.getDescriptorByTimerange(getAvailableRecordings(), - MAX_REQUIRED_RECORDING_DURATION); - } - - @Override - public IConstrainedMap getCurrentEventTypeSettings() throws FlightRecorderException { - Map byIntMap = getEventTypeByIntMap(); - @SuppressWarnings("unchecked") - List compositeList = (List) helper.getAttribute("EventSettings"); //$NON-NLS-1$ - return toEventOptionMap(byIntMap, compositeList); - } - - @Override - public IDescribedMap getDefaultEventOptions() { - try { - updateEventTypeMetadataMaps(true); - // FIXME: Calculate this in the updateEventTypeMetadataMaps() method as for V2? - Map> optionInfoById = new HashMap<>(); - for (Entry typeEntry : eventTypeInfoById.entrySet()) { - for (Entry> optionEntry : typeEntry.getValue().getOptionDescriptors() - .entrySet()) { - EventOptionID optionID = new EventOptionID(typeEntry.getKey(), optionEntry.getKey()); - optionInfoById.put(optionID, optionEntry.getValue()); - } - } - return new DefaultValueMap<>(optionInfoById, DISALLOW_MAPPER); - } catch (FlightRecorderException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Couldn't get default event options", e); //$NON-NLS-1$ - return ConfigurationToolkit.getEventOptions(SchemaVersion.V1); - } - } - - @Override - public IRecordingDescriptor getUpdatedRecordingDescription(IRecordingDescriptor descriptor) - throws FlightRecorderException { - return getUpdatedRecordingDescriptor(descriptor.getObjectName()); - } - - @Override - public List getServerTemplates() throws FlightRecorderException { - @SuppressWarnings("unchecked") - List compositeData = (List) helper.getAttribute("AvailablePresets"); //$NON-NLS-1$ - return RecordingTemplateToolkit.getServerTemplatesV1(compositeData); - } - - @Override - public void updateEventOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException { - try { - updateEventOptions(descriptor.getObjectName(), options); - } catch (Exception e) { - throw new FlightRecorderException("Failed updating the event options for " + descriptor.getName(), e); //$NON-NLS-1$ - } - } - - private IRecordingDescriptor getUpdatedRecordingDescriptor(ObjectName name) throws FlightRecorderException { - // getRecordingOptions doesn't quite contain all we need, so retrieve - // everything and filter out what we need... - return RecordingDescriptorToolkitV1.getRecordingByDescriptor(name, getAvailableRecordings()); - } - - private void validateOptions(IConstrainedMap recordingOptions) throws FlightRecorderException { - try { - ValidationToolkit.validate(recordingOptions); - } catch (Exception e) { - throw new FlightRecorderException("Could not validate options!\n" + e.getMessage()); //$NON-NLS-1$ - } - } - - @Override - public Map getEventTypeInfoMapByID() - throws FlightRecorderException { - updateEventTypeMetadataMaps(false); - return eventTypeInfoById; - } - - private Map getEventTypeByIntMap() throws FlightRecorderException { - updateEventTypeMetadataMaps(false); - return eventTypeMetaByInt; - } - - private Collection updateEventTypeMetadataMaps(boolean force) throws FlightRecorderException { - long timestamp = System.currentTimeMillis(); - if (force || (timestamp > eventTypeMetaNextUpdate)) { - - @SuppressWarnings("unchecked") - List compositeList = (List) helper.getAttribute("EventDescriptors"); //$NON-NLS-1$ - - List metadataList = new ArrayList<>(compositeList.size()); - Map byInt = new HashMap<>(); - Map byId = new HashMap<>(); - for (CompositeData data : compositeList) { - try { - EventTypeMetadataV1 element = toEventMetaDataV1(data); - metadataList.add(element); - byInt.put(element.getId(), element); - byId.put(element.getEventTypeID(), element); - } catch (URISyntaxException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Could not create event metadata for composite data!", e); //$NON-NLS-1$ - } - } - - // Do not update more often than every minute. - // FIXME: Use JMX notifications instead? - eventTypeMetaNextUpdate = timestamp + 60 * 1000; - eventTypeMetas = Collections.unmodifiableList(metadataList); - eventTypeMetaByInt = Collections.unmodifiableMap(byInt); - eventTypeInfoById = Collections.unmodifiableMap(byId); - } - return eventTypeMetas; - } - - private boolean isStillRunning(IRecordingDescriptor descriptor) throws FlightRecorderException { - IRecordingDescriptor updatedDescriptor = getUpdatedRecordingDescription(descriptor); - return updatedDescriptor != null - && IRecordingDescriptor.RecordingState.RUNNING.equals(updatedDescriptor.getState()); - } - - // creates a stopped clone - private IRecordingDescriptor clone(IRecordingDescriptor descriptor) throws FlightRecorderException { - try { - ObjectName name = (ObjectName) helper.invokeOperation("cloneRecording", //$NON-NLS-1$ - descriptor.getObjectName(), "Clone of " + descriptor.getName(), Boolean.TRUE); //$NON-NLS-1$ - return getUpdatedRecordingDescriptor(name); - } catch (IOException e) { - throw new FlightRecorderException("Could not clone the " + descriptor.getName() + " recording ", e); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - private void updateEventOptions(ObjectName recording, IConstrainedMap eventOptions) - throws OpenDataException, IOException, FlightRecorderException { - helper.invokeOperation("updateEventSettings", recording, //$NON-NLS-1$ - EventOptionsToolkitV1.encodeAllEventSettings(getAvailableEventTypes(), eventOptions)); - } - - @Override - public void updateRecordingOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException { - validateOptions(options); - try { - helper.invokeOperation("setRecordingOptions", descriptor.getObjectName(), //$NON-NLS-1$ - RecordingOptionsToolkitV1.getRecordingOptions(options)); - } catch (Exception e) { - throw new FlightRecorderException("Failed updating the recording options for " + descriptor.getName(), e); //$NON-NLS-1$ - } - } - - @Override - public InputStream openStream(IRecordingDescriptor descriptor, IQuantity lastPartDuration, boolean removeOnClose) - throws FlightRecorderException { - /* - * FIXME: JMC-4270 - Server time approximation is not reliable. Can perhaps get a better - * time by cloning the recording and getting the end time from there like in the commented - * out code below. - */ -// IRecordingDescriptor streamDescriptor = descriptor; -// boolean clone = isStillRunning(descriptor); -// if (clone) { -// streamDescriptor = clone(descriptor); -// } -// IQuantity endTime = streamDescriptor.getDataEndTime(); -// IQuantity startTime = endTime.subtract(lastPartDuration); -// return new JfrRecordingInputStreamV1(helper, streamDescriptor, toDate(startTime), toDate(endTime), clone | removeOnClose); - - long serverTime = mbhs.getApproximateServerTime(System.currentTimeMillis()); - IQuantity endDate = EPOCH_MS.quantity(serverTime); - IQuantity startDate = endDate.subtract(lastPartDuration); - return openStream(descriptor, startDate, endDate, removeOnClose); - } - - @Override - public boolean isEnabled() { - if (!wasEnabled) { - boolean isEnabled = cfs.isCommercialFeaturesEnabled(); - if (isEnabled) { - wasEnabled = true; - } - return isEnabled; - } else { - return wasEnabled; - } - } - - @Override - public void enable() throws FlightRecorderException { - try { - cfs.enableCommercialFeatures(); - } catch (Exception e) { - throw new FlightRecorderException("Failed to enable commercial features", e); //$NON-NLS-1$ - } - } - - /** - * @param typeByInt - * a map from {@link Integer} to {@link EventTypeMetadataV1}. - * @param compositeDatas - * a list of composite data representing the actual settings. - * @return the event type settings. - */ - @SuppressWarnings("nls") - private static IConstrainedMap toEventOptionMap( - Map typeByInt, List compositeDatas) { - SimpleConstrainedMap options = new SimpleConstrainedMap<>(); - for (CompositeData data : compositeDatas) { - Integer intID = (Integer) data.get("id"); - EventTypeMetadataV1 metadata = typeByInt.get(intID); - EventOptionsToolkitV1.addOptionsToV1(options, metadata, data); - } - return options; - } - - @SuppressWarnings("nls") - public static EventTypeMetadataV1 toEventMetaDataV1(CompositeData data) throws URISyntaxException { - String uri = (String) data.get("uri"); - Integer id = (Integer) data.get("id"); - String path = (String) data.get("path"); - String label = (String) data.get("name"); - String description = (String) data.get("description"); - // For now, verify URI correctness, as before. - new URI(uri); - // NOTE: Assuming that uri ends in path. - assert uri.endsWith(path); - EventTypeIDV1 eventTypeID = new EventTypeIDV1(uri, uri.length() - path.length()); - return new EventTypeMetadataV1(id, eventTypeID, label, description, - EventOptionsToolkitV1.getConfigurableOptions(data)); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java deleted file mode 100644 index d529e973..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS; -import static org.openjdk.jmc.common.unit.UnitLookup.toDate; -import static org.openjdk.jmc.rjmx.services.jfr.internal.RecordingOptionsToolkitV2.toTabularData; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.management.MBeanServerConnection; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.TabularData; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IDescribedMap; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.flightrecorder.configuration.ConfigurationToolkit; -import org.openjdk.jmc.flightrecorder.configuration.OptionInfo; -import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; -import org.openjdk.jmc.flightrecorder.configuration.events.SchemaVersion; -import org.openjdk.jmc.flightrecorder.configuration.internal.DefaultValueMap; -import org.openjdk.jmc.flightrecorder.configuration.internal.EventTypeIDV2; -import org.openjdk.jmc.flightrecorder.configuration.internal.KnownEventOptions; -import org.openjdk.jmc.flightrecorder.configuration.internal.KnownRecordingOptions; -import org.openjdk.jmc.flightrecorder.configuration.internal.ValidationToolkit; -import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder; -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.ConnectionToolkit; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.JVMSupportToolkit; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; - -public class FlightRecorderServiceV2 implements IFlightRecorderService { - final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.services.jfr"); //$NON-NLS-1$ - final private FlightRecorderCommunicationHelperV2 helper; - private long eventTypeMetaNextUpdate; - private List eventTypeMetas; - private Map eventTypeInfoById; - private Map> optionInfoById; - // Optimization to do less JMX invocations. If, against all odds, it gets disabled, - // after having been enabled, we get an exception, and will handle things there. - private boolean wasEnabled; - private final ICommercialFeaturesService cfs; - private final IMBeanHelperService mbhs; - private final String serverId; - private final IConnectionHandle connection; - - @Override - public String getVersion() { - return "2.0"; //$NON-NLS-1$ - } - - private boolean isDynamicFlightRecorderSupported(IConnectionHandle handle) { - // All OpenJDK versions of JFR support dynamic enablement of JFR, so if there are no commercial features in play - // all is A-OK. - if (ConnectionToolkit.isSubstrateVm(handle)){ - // JFR may not have been built into the native image. Check that FlightRecorderMXBean is accessible from the MBean server. - return isAvailable(handle); - } - - return !cfs.hasCommercialFeatures() || (ConnectionToolkit.isHotSpot(handle) - && ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED)); - } - - private boolean isFlightRecorderDisabled(IConnectionHandle handle) { - if (ConnectionToolkit.isSubstrateVm(handle)){ - // For SVM commercial features may be available but disabled and JFR is still enabled - return !isAvailable(handle); - } else if (cfs != null && cfs.hasCommercialFeatures()) { - return !cfs.isCommercialFeaturesEnabled() || JVMSupportToolkit.isFlightRecorderDisabled(handle, false); - } else { - return JVMSupportToolkit.isFlightRecorderDisabled(handle, false); - } - } - - public static boolean isAvailable(IConnectionHandle handle) { - return FlightRecorderCommunicationHelperV2.isAvailable(handle); - } - - public FlightRecorderServiceV2(IConnectionHandle handle) throws ConnectionException, ServiceNotAvailableException { - cfs = handle.getServiceOrThrow(ICommercialFeaturesService.class); - - if (!isDynamicFlightRecorderSupported(handle) && isFlightRecorderDisabled(handle)) { - throw new ServiceNotAvailableException(""); //$NON-NLS-1$ - } - if (!ConnectionToolkit.isSubstrateVm(handle) && JVMSupportToolkit.isFlightRecorderDisabled(handle, true)) { - throw new ServiceNotAvailableException(""); //$NON-NLS-1$ - } - connection = handle; - helper = new FlightRecorderCommunicationHelperV2(handle.getServiceOrThrow(MBeanServerConnection.class)); - mbhs = handle.getServiceOrThrow(IMBeanHelperService.class); - serverId = handle.getServerDescriptor().getGUID(); - } - - @Override - public void stop(IRecordingDescriptor descriptor) throws FlightRecorderException { - stop(descriptor.getId()); - } - - private void stop(Long id) throws FlightRecorderException { - try { - helper.invokeOperation("stopRecording", id); //$NON-NLS-1$ - } catch (Exception e) { - throw new FlightRecorderException("Could not stop the recording!", e); //$NON-NLS-1$ - } - } - - @Override - public void close(IRecordingDescriptor descriptor) throws FlightRecorderException { - helper.closeRecording(descriptor); - } - - @Override - public IRecordingDescriptor start( - IConstrainedMap recordingOptions, IConstrainedMap eventOptions) - throws FlightRecorderException { - Long id; - try { - validateOptions(recordingOptions); - id = (Long) helper.invokeOperation("newRecording"); //$NON-NLS-1$ - } catch (Exception e) { - throw new FlightRecorderException("Could not create a recording!", e); //$NON-NLS-1$ - } - try { - updateRecordingOptions(id, recordingOptions); - if (eventOptions != null) { - updateEventOptions(id, eventOptions); - } - helper.invokeOperation("startRecording", id); //$NON-NLS-1$ - return getUpdatedRecordingDescriptor(id); - } catch (Exception e) { - try { - helper.invokeOperation("closeRecording", id); //$NON-NLS-1$ - } catch (IOException ioe) { - e.addSuppressed(ioe); - throw new FlightRecorderException( - "Could not start the recording! Could not remove the unstarted recording.", e); //$NON-NLS-1$ - } - throw new FlightRecorderException("Could not start the recording! Removed the unstarted recording.", e); //$NON-NLS-1$ - } - } - - private IMutableConstrainedMap getEmptyRecordingOptions() { - return ConfigurationToolkit.getRecordingOptions(JavaVersionSupport.JDK_9).emptyWithSameConstraints(); - } - - @Override - public IDescribedMap getDefaultRecordingOptions() { - return KnownRecordingOptions.OPTION_DEFAULTS_V2; - } - - @Override - public IConstrainedMap getRecordingOptions(IRecordingDescriptor recording) throws FlightRecorderException { - try { - return getRecordingOptions(recording.getId()); - } catch (Exception e) { - throw new FlightRecorderException("Could not retrieve recording options.", e); //$NON-NLS-1$ - } - } - - private IConstrainedMap getRecordingOptions(Long id) throws FlightRecorderException, IOException { - IMutableConstrainedMap options = getEmptyRecordingOptions(); - for (Object o : ((TabularData) helper.invokeOperation("getRecordingOptions", id)).values()) { //$NON-NLS-1$ - CompositeData row = (CompositeData) o; - String key = (String) row.get("key"); //$NON-NLS-1$ - String value = (String) row.get("value"); //$NON-NLS-1$ - IConstraint constraint = RecordingOptionsToolkitV2.getRecordingOptionConstraint(key); - // FIXME: Use generic string constraint if nothing better was found. - if (constraint != null) { - try { - options.putPersistedString(key, constraint, value); - } catch (QuantityConversionException e) { - // Shouldn't happen, but I want to know if it does. - LOGGER.log(Level.FINE, "Recording option conversion problem", e); //$NON-NLS-1$ - } - } - } - return options; - } - - @Override - public IConstrainedMap getEventSettings(IRecordingDescriptor recording) - throws FlightRecorderException { - try { - TabularData tabularData = (TabularData) helper.invokeOperation("getRecordingSettings", //$NON-NLS-1$ - recording.getId()); - IMutableConstrainedMap settings = getDefaultEventOptions().emptyWithSameConstraints(); - for (Object row : tabularData.values()) { - CompositeData data = (CompositeData) row; - String key = (String) data.get("key"); //$NON-NLS-1$ - String value = (String) data.get("value"); //$NON-NLS-1$ - int hashPos = key.lastIndexOf('#'); - if (hashPos > 0) { - // FIXME: Deal with numerically specified event type (instance). - EventTypeIDV2 type = new EventTypeIDV2(key.substring(0, hashPos)); - EventOptionID option = new EventOptionID(type, key.substring(hashPos + 1)); - // FIXME: Try/catch and ignore? - settings.putPersistedString(option, value); - } - } - return settings; - } catch (Exception e) { - FlightRecorderException flr = new FlightRecorderException( - "Could not retrieve recording options for recording " + recording.getName() + '.'); //$NON-NLS-1$ - flr.initCause(e); - throw flr; - } - } - - // FIXME: This should _really_ be retrieved from the server, but the server API does not allow that at the moment. - @Override - public Map> getAvailableRecordingOptions() throws FlightRecorderException { - return RecordingOptionsToolkitV2.getAvailableRecordingOptions(); - } - - @Override - public String toString() { - return helper.toString(); - } - - @Override - public InputStream openStream(IRecordingDescriptor descriptor, boolean removeOnClose) - throws FlightRecorderException { - IRecordingDescriptor streamDescriptor = descriptor; - boolean clone = isStillRunning(descriptor); - if (clone) { - streamDescriptor = clone(descriptor); - } - return new JfrRecordingInputStreamV2(helper, streamDescriptor, clone | removeOnClose); - } - - @Override - public InputStream openStream( - IRecordingDescriptor descriptor, IQuantity startTime, IQuantity endTime, boolean removeOnClose) - throws FlightRecorderException { - IRecordingDescriptor streamDescriptor = descriptor; - boolean clone = isStillRunning(descriptor); - if (clone) { - streamDescriptor = clone(descriptor); - } - return new JfrRecordingInputStreamV2(helper, streamDescriptor, toDate(startTime), toDate(endTime), - clone | removeOnClose); - } - - @Override - public Collection getAvailableEventTypes() throws FlightRecorderException { - return updateEventTypeMetadataMaps(true); - } - - @Override - public List getAvailableRecordings() throws FlightRecorderException { - CompositeData[] attribute = (CompositeData[]) helper.getAttribute("Recordings"); //$NON-NLS-1$ - List recordings = new ArrayList<>(); - for (CompositeData data : attribute) { - recordings.add(new RecordingDescriptorV2(serverId, data)); - } - return Collections.unmodifiableList(recordings); - } - - @Override - public IRecordingDescriptor getSnapshotRecording() throws FlightRecorderException { - try { - Long id = (Long) helper.invokeOperation("takeSnapshot", new Object[0]); //$NON-NLS-1$ - return getUpdatedRecordingDescriptor(id); - } catch (Exception e) { - throw new FlightRecorderException("Could not take a snapshot of the flight recorder", e); //$NON-NLS-1$ - } - } - - @Override - public IDescribedMap getCurrentEventTypeSettings() throws FlightRecorderException { - updateEventTypeMetadataMaps(true); - return new DefaultValueMap<>(optionInfoById, new ExcludingEventOptionMapper(eventTypeInfoById.keySet(), - EventTypeIDV2.class, KnownEventOptions.EVENT_OPTIONS_BY_KEY_V2)); - } - - @Override - public IDescribedMap getDefaultEventOptions() { - try { - return getCurrentEventTypeSettings(); - } catch (FlightRecorderException e) { - LOGGER.log(Level.WARNING, "Couldn't get event settings", e); //$NON-NLS-1$ - return ConfigurationToolkit.getEventOptions(SchemaVersion.V2); - } - } - - @Override - public IRecordingDescriptor getUpdatedRecordingDescription(IRecordingDescriptor descriptor) - throws FlightRecorderException { - return getUpdatedRecordingDescriptor(descriptor.getId()); - } - - @Override - public List getServerTemplates() throws FlightRecorderException { - CompositeData[] compositeData = (CompositeData[]) helper.getAttribute("Configurations"); //$NON-NLS-1$ - return RecordingTemplateToolkit.getServerTemplatesV2(compositeData); - } - - @Override - public void updateEventOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException { - try { - updateEventOptions(descriptor.getId(), options); - } catch (Exception e) { - throw new FlightRecorderException("Failed updating the event options for " + descriptor.getName(), e); //$NON-NLS-1$ - } - } - - private IRecordingDescriptor getUpdatedRecordingDescriptor(Long id) throws FlightRecorderException { - // getRecordingOptions doesn't quite contain all we need, so retrieve - // everything and filter out what we need... - for (IRecordingDescriptor recording : getAvailableRecordings()) { - if (id.equals(recording.getId())) { - return recording; - } - } - return null; - } - - private void validateOptions(IConstrainedMap recordingOptions) throws FlightRecorderException { - try { - ValidationToolkit.validate(recordingOptions); - } catch (Exception e) { - throw new FlightRecorderException("Could not validate options!\n" + e.getMessage()); //$NON-NLS-1$ - } - } - - @Override - public Map getEventTypeInfoMapByID() throws FlightRecorderException { - updateEventTypeMetadataMaps(false); - return eventTypeInfoById; - } - - private Collection updateEventTypeMetadataMaps(boolean force) throws FlightRecorderException { - long timestamp = System.currentTimeMillis(); - if (force || (timestamp > eventTypeMetaNextUpdate)) { - - CompositeData[] compositeList = (CompositeData[]) helper.getAttribute("EventTypes"); //$NON-NLS-1$ - - List metadataList = new ArrayList<>(compositeList.length); - Map byId = new HashMap<>(); - Map> optionById = new HashMap<>(); - for (CompositeData data : compositeList) { - EventTypeMetadataV2 typeInfo = EventTypeMetadataV2.from(data); - metadataList.add(typeInfo); - EventTypeIDV2 typeID = typeInfo.getEventTypeID(); - byId.put(typeID, typeInfo); - for (Entry> entry : typeInfo.getOptionDescriptors().entrySet()) { - optionById.put(new EventOptionID(typeID, entry.getKey()), entry.getValue()); - } - } - - // Do not update more often than every minute. - // FIXME: Use JMX notifications instead? - eventTypeMetaNextUpdate = timestamp + 60 * 1000; - eventTypeMetas = Collections.unmodifiableList(metadataList); - eventTypeInfoById = Collections.unmodifiableMap(byId); - optionInfoById = Collections.unmodifiableMap(optionById); - } - return eventTypeMetas; - } - - private boolean isStillRunning(IRecordingDescriptor descriptor) throws FlightRecorderException { - IRecordingDescriptor updatedDescriptor = getUpdatedRecordingDescription(descriptor); - return updatedDescriptor != null - && IRecordingDescriptor.RecordingState.RUNNING.equals(updatedDescriptor.getState()); - } - - // creates a stopped clone - private IRecordingDescriptor clone(IRecordingDescriptor descriptor) throws FlightRecorderException { - try { - Long id = (Long) helper.invokeOperation("cloneRecording", //$NON-NLS-1$ - descriptor.getId(), Boolean.TRUE); - IMutableConstrainedMap options = getEmptyRecordingOptions(); - options.put(RecordingOptionsBuilder.KEY_NAME, - String.format("Clone of %s", descriptor.getName())); - helper.invokeOperation("setRecordingOptions", id, toTabularData(options)); //$NON-NLS-1$ - return getUpdatedRecordingDescriptor(id); - } catch (Exception e) { - throw new FlightRecorderException("Could not clone the " + descriptor.getName() + " recording ", e); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - private void updateEventOptions(Long id, IConstrainedMap options) - throws OpenDataException, IOException, FlightRecorderException { - helper.invokeOperation("setRecordingSettings", id, //$NON-NLS-1$ - toTabularData(options)); - } - - @Override - public void updateRecordingOptions(IRecordingDescriptor descriptor, IConstrainedMap options) - throws FlightRecorderException { - validateOptions(options); - // Currently (2016-06-01), in some states, JFR complains about the presence of certain - // options even if unchanged. So, just send the delta. - IConstrainedMap current = getRecordingOptions(descriptor); - IConstrainedMap deltaOptions = ConfigurationToolkit.extractDelta(options, current); - try { - updateRecordingOptions(descriptor.getId(), deltaOptions); - } catch (Exception e) { - throw new FlightRecorderException("Failed updating the recording options for " + descriptor.getName(), e); //$NON-NLS-1$ - } - } - - private void updateRecordingOptions(Long id, IConstrainedMap options) - throws OpenDataException, IOException, FlightRecorderException { - helper.invokeOperation("setRecordingOptions", id, //$NON-NLS-1$ - toTabularData(options)); - } - - @Override - public InputStream openStream(IRecordingDescriptor descriptor, IQuantity lastPartDuration, boolean removeOnClose) - throws FlightRecorderException { - /* - * FIXME: JMC-4270 - Server time approximation is not reliable. Can perhaps get a better - * time by cloning the recording and getting the end time from there like in the commented - * out code below. - */ -// IRecordingDescriptor streamDescriptor = descriptor; -// boolean clone = isStillRunning(descriptor); -// if (clone) { -// streamDescriptor = clone(descriptor); -// } -// IQuantity endTime = streamDescriptor.getDataEndTime(); -// IQuantity startTime = endTime.subtract(lastPartDuration); -// return new JfrRecordingInputStreamV2(helper, streamDescriptor, toDate(startTime), toDate(endTime), clone | removeOnClose); - - long serverTime = mbhs.getApproximateServerTime(System.currentTimeMillis()); - IQuantity endDate = EPOCH_MS.quantity(serverTime); - IQuantity startDate = endDate.subtract(lastPartDuration); - return openStream(descriptor, startDate, endDate, removeOnClose); - } - - @Override - public boolean isEnabled() { - if (!wasEnabled) { - boolean isEnabled = cfs.hasCommercialFeatures() ? cfs.isCommercialFeaturesEnabled() - : isAvailable(connection); - if (isEnabled) { - wasEnabled = true; - } - return isEnabled; - } else { - return wasEnabled; - } - } - - @Override - public void enable() throws FlightRecorderException { - try { - cfs.enableCommercialFeatures(); - } catch (Exception e) { - throw new FlightRecorderException("Failed to enable commercial features", e); //$NON-NLS-1$ - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/IFlightRecorderCommunicationHelper.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/IFlightRecorderCommunicationHelper.java deleted file mode 100644 index a8019226..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/IFlightRecorderCommunicationHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.io.IOException; - -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -interface IFlightRecorderCommunicationHelper { - - Object getAttribute(String attribute) throws FlightRecorderException; - - Object invokeOperation(String name, Object ... parameters) throws IOException, FlightRecorderException; - - void closeRecording(IRecordingDescriptor descriptor) throws FlightRecorderException; - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV1.java deleted file mode 100644 index c294c7ba..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV1.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.logging.Level; - -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * Class representing an {@link InputStream} from an IRecordingDescriptor between two dates. - */ -public final class JfrRecordingInputStreamV1 extends InputStream { - private final static String OPEN_STREAM = "openStream"; //$NON-NLS-1$ - private final static String READ_STREAM = "readStream"; //$NON-NLS-1$ - private final static String CLOSE_STREAM = "closeStream"; //$NON-NLS-1$ - // FIXME: This seems to have no advantage over using null. Remove! - private final static Long UNKNOWN_STREAM = Long.valueOf(-1L); - - private final IRecordingDescriptor recording; - private final IFlightRecorderCommunicationHelper helper; - - private byte[] buf = new byte[0]; - private int count = 0; - private int pos = 0; - private boolean closed = false; - private boolean endOfStream = false; - private boolean removeOnClose = true; - private final Date startTime; - private final Date endTime; - private Long streamIdentifier = UNKNOWN_STREAM; - - public JfrRecordingInputStreamV1(IFlightRecorderCommunicationHelper helper, IRecordingDescriptor recording, - Date startTime, Date endTime, boolean removeOnClose) { - this.recording = recording; - this.helper = helper; - this.startTime = startTime; - this.endTime = endTime; - this.removeOnClose = removeOnClose; - FlightRecorderServiceV1.LOGGER.log(Level.INFO, "Attempting to open stream from " + recording + " between " //$NON-NLS-1$ //$NON-NLS-2$ - + startTime + " to " + endTime); //$NON-NLS-1$ - - } - - public JfrRecordingInputStreamV1(IFlightRecorderCommunicationHelper helper, IRecordingDescriptor recording, - boolean removeOnClose) { - this(helper, recording, null, null, removeOnClose); - } - - @Override - public synchronized int read() throws IOException { - if (pos >= buf.length) { - if (closed || endOfStream) { - return -1; - } - fill(); - if (endOfStream) { - return -1; - } - } - return buf[pos++] & 0xff; - } - - private void fill() throws IOException { - if (UNKNOWN_STREAM.equals(streamIdentifier)) { - readStreamIdentifier(); - } - buf = readStream(streamIdentifier); - if (buf != null) { - count += buf.length; - pos = 0; - } else { - pos = 0; - count = 0; - buf = new byte[0]; - endOfStream = true; - } - } - - private void readStreamIdentifier() throws IOException { - if (startTime == null) { - streamIdentifier = openStream(recording); - } else { - streamIdentifier = openStream(recording, startTime, endTime); - } - } - - private void ensureOpen() throws IOException { - if (closed) { - throw new IOException("Stream closed"); //$NON-NLS-1$ - } - } - - @Override - public synchronized int available() throws IOException { - ensureOpen(); - return count - pos; - } - - @Override - public void close() throws IOException { - if (closed == true) { - return; - } - closed = true; - if (!UNKNOWN_STREAM.equals(streamIdentifier)) { - closeStream(streamIdentifier); - } - if (removeOnClose) { - try { - helper.closeRecording(recording); - } catch (FlightRecorderException e) { - IOException ioe = new IOException(e.getMessage()); - ioe.initCause(e); - throw ioe; - } - } - } - - private void closeStream(Long streamIdentifier) throws IOException { - invokeOperation(CLOSE_STREAM, streamIdentifier); - } - - private byte[] readStream(Long streamIdentifier) throws IOException { - return (byte[]) invokeOperation(READ_STREAM, streamIdentifier); - } - - private Long openStream(IRecordingDescriptor descriptor) throws IOException { - Long streamId = (Long) invokeOperation(OPEN_STREAM, descriptor.getObjectName()); - if (streamId == null) { - return UNKNOWN_STREAM; - } - return streamId; - } - - private Long openStream(IRecordingDescriptor descriptor, Date startTime, Date endTime) throws IOException { - Long streamId = (Long) invokeOperation(OPEN_STREAM, descriptor.getObjectName(), startTime, endTime); - if (streamId == null) { - return UNKNOWN_STREAM; - } - return streamId; - } - - /** - * If a method invocation fails, we will close the stream immediately. - */ - private Object invokeOperation(String name, Object ... params) throws IOException { - try { - return helper.invokeOperation(name, params); - } catch (Exception ioe) { - FlightRecorderServiceV1.LOGGER.info("Failed to invoke operation " + name + ". Will now close! Message was: " //$NON-NLS-1$ //$NON-NLS-2$ - + ioe.getMessage()); - try { - close(); - } catch (IOException ioe2) { - // Don't care; - } - IOException iot = new IOException(ioe.getLocalizedMessage()); - iot.initCause(ioe); - throw iot; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV2.java deleted file mode 100644 index e4c3fd30..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/JfrRecordingInputStreamV2.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import javax.management.openmbean.OpenDataException; - -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * Class representing an {@link InputStream} from an IRecordingDescriptor between two dates. - */ -// FIXME: If the invoke operations are folded into the IFlightRecorderService implementations then we can avoid having two versions of this stream class -public final class JfrRecordingInputStreamV2 extends InputStream { - private final static String OPEN_STREAM = "openStream"; //$NON-NLS-1$ - private final static String READ_STREAM = "readStream"; //$NON-NLS-1$ - private final static String CLOSE_STREAM = "closeStream"; //$NON-NLS-1$ - // FIXME: This seems to have no advantage over using null. Remove! - private final static Long UNKNOWN_STREAM = Long.valueOf(-1L); - - private final IRecordingDescriptor recording; - private final IFlightRecorderCommunicationHelper helper; - - private byte[] buf = new byte[0]; - private int count = 0; - private int pos = 0; - private boolean closed = false; - private boolean endOfStream = false; - private boolean removeOnClose = true; - private final Date startTime; - private final Date endTime; - private Long streamIdentifier = UNKNOWN_STREAM; - - public JfrRecordingInputStreamV2(IFlightRecorderCommunicationHelper helper, IRecordingDescriptor recording, - Date startTime, Date endTime, boolean removeOnClose) { - this.recording = recording; - this.helper = helper; - this.startTime = startTime; - this.endTime = endTime; - this.removeOnClose = removeOnClose; - FlightRecorderServiceV1.LOGGER.log(Level.INFO, "Attempting to open stream from " + recording + " between " //$NON-NLS-1$ //$NON-NLS-2$ - + startTime + " to " + endTime); //$NON-NLS-1$ - - } - - public JfrRecordingInputStreamV2(IFlightRecorderCommunicationHelper helper, IRecordingDescriptor recording, - boolean removeOnClose) { - this(helper, recording, null, null, removeOnClose); - } - - @Override - public synchronized int read() throws IOException { - if (pos >= buf.length) { - if (closed || endOfStream) { - return -1; - } - fill(); - if (endOfStream) { - return -1; - } - } - return buf[pos++] & 0xff; - } - - private void fill() throws IOException { - if (UNKNOWN_STREAM.equals(streamIdentifier)) { - readStreamIdentifier(); - } - buf = readStream(streamIdentifier); - if (buf != null) { - count += buf.length; - pos = 0; - } else { - pos = 0; - count = 0; - buf = new byte[0]; - endOfStream = true; - } - } - - private void readStreamIdentifier() throws IOException { - if (startTime == null) { - streamIdentifier = openStream(recording); - } else { - streamIdentifier = openStream(recording, startTime, endTime); - } - } - - private void ensureOpen() throws IOException { - if (closed) { - throw new IOException("Stream closed"); //$NON-NLS-1$ - } - } - - @Override - public synchronized int available() throws IOException { - ensureOpen(); - return count - pos; - } - - @Override - public void close() throws IOException { - if (closed == true) { - return; - } - closed = true; - if (!UNKNOWN_STREAM.equals(streamIdentifier)) { - closeStream(streamIdentifier); - } - if (removeOnClose) { - try { - helper.closeRecording(recording); - } catch (FlightRecorderException e) { - IOException ioe = new IOException(e.getMessage()); - ioe.initCause(e); - throw ioe; - } - } - } - - private void closeStream(Long streamIdentifier) throws IOException { - invokeOperation(CLOSE_STREAM, streamIdentifier); - } - - private byte[] readStream(Long streamIdentifier) throws IOException { - return (byte[]) invokeOperation(READ_STREAM, streamIdentifier); - } - - private Long openStream(IRecordingDescriptor descriptor) throws IOException { - return openStream(descriptor, null, null); - } - - private Long openStream(IRecordingDescriptor descriptor, Date startTime, Date endTime) throws IOException { - // FIXME: Replace with suitable IConstrainedMap. - Map options = new HashMap<>(); - if (startTime != null) { - options.put("startTime", Long.toString(startTime.getTime())); //$NON-NLS-1$ - } - if (endTime != null) { - options.put("endTime", Long.toString(endTime.getTime())); //$NON-NLS-1$ - } - Long streamId; - try { - streamId = (Long) invokeOperation(OPEN_STREAM, descriptor.getId(), - RecordingOptionsToolkitV2.createTabularData(options)); - } catch (OpenDataException e) { - throw new IOException(e); - } - if (streamId == null) { - return UNKNOWN_STREAM; - } - return streamId; - } - - /** - * If a method invocation fails, we will close the stream immediately. - */ - private Object invokeOperation(String name, Object ... params) throws IOException { - try { - return helper.invokeOperation(name, params); - } catch (Exception ioe) { - FlightRecorderServiceV1.LOGGER.info("Failed to invoke operation " + name + ". Will now close! Message was: " //$NON-NLS-1$ //$NON-NLS-2$ - + ioe.getMessage()); - try { - close(); - } catch (IOException ioe2) { - // Don't care; - } - IOException iot = new IOException(ioe.getLocalizedMessage()); - iot.initCause(ioe); - throw iot; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/OpenTypeConverter.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/OpenTypeConverter.java deleted file mode 100644 index 8102805b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/OpenTypeConverter.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.FLAG; -import static org.openjdk.jmc.common.unit.UnitLookup.PLAIN_TEXT; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.PERIOD_V1; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POSITIVE_MEMORY; -import static org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints.POSITIVE_TIMESPAN; -import static javax.management.openmbean.SimpleType.LONG; -import static javax.management.openmbean.SimpleType.STRING; - -import java.util.Date; - -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; - -import org.openjdk.jmc.common.unit.ContentType; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.IUnit; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.flightrecorder.configuration.internal.CommonConstraints; - -/** - * Conversion from {@link IConstraint constrained content types} into {@link OpenType} values as - * used by JFR 1.0 (JDK 7/8). - * - * @param

- * The actual "open type" value class (typically primitive wrapper or {@link Date}) - * @param - * The JMC {@link IConstraint} value class - */ -@SuppressWarnings("nls") -public abstract class OpenTypeConverter { - public static final OpenTypeConverter BYTES = new LongQuantity("bytes", UnitLookup.BYTE, - POSITIVE_MEMORY); - public static final OpenTypeConverter NANOSECONDS = new LongQuantity("nanos", - UnitLookup.NANOSECOND, POSITIVE_TIMESPAN); - public static final OpenTypeConverter MILLISECONDS = new LongQuantity("millis", - UnitLookup.MILLISECOND, POSITIVE_TIMESPAN); - public static final OpenTypeConverter MILLIS_PERIODICITY = new LongQuantity("millis_periodicity", - UnitLookup.MILLISECOND, PERIOD_V1) { - @Override - public IQuantity fromOpenType(Long openValue) throws QuantityConversionException { - return (openValue == 0L) ? CommonConstraints.EVERY_CHUNK_MAGIC_INSTANCE : super.fromOpenType(openValue); - }; - }; - public static final OpenTypeConverter DATE = new OpenTypeConverter("date", - Date.class, SimpleType.DATE, CommonConstraints.POINT_IN_TIME) { - @Override - public Date toOpenType(IQuantity value) throws QuantityConversionException { - constraint.validate(value); - return UnitLookup.toDate(value); - } - - @Override - public IQuantity fromOpenType(Date openValue) throws QuantityConversionException { - IQuantity value = UnitLookup.fromDate(openValue); - constraint.validate(value); - return value; - } - }; - public static final OpenTypeConverter BOOLEAN = new Identity<>("boolean", Boolean.class, - SimpleType.BOOLEAN, FLAG); - public static final OpenTypeConverter FILE_NAME = new Identity<>("filename", String.class, STRING, - PLAIN_TEXT); - public static final OpenTypeConverter TEXT = new Identity<>("string", String.class, STRING, - PLAIN_TEXT); - public static final OpenTypeConverter UNKNOWN = new Identity<>("unknown", String.class, STRING, - PLAIN_TEXT); - - public final String key; - public final Class

type; - public final OpenType

openType; - public final IConstraint constraint; - - private static class Identity extends OpenTypeConverter { - private Identity(String key, Class type, OpenType openType, ContentType contentType) { - super(key, type, openType, contentType.getPersister()); - } - - @Override - public S toOpenType(S value) throws QuantityConversionException { - constraint.validate(value); - return value; - } - - @Override - public S fromOpenType(S openValue) throws QuantityConversionException { - constraint.validate(openValue); - return openValue; - } - } - - private static class LongQuantity extends OpenTypeConverter { - private final IUnit unit; - - protected LongQuantity(String key, IUnit unit, IConstraint constraint) { - super(key, Long.class, LONG, constraint); - this.unit = unit; - } - - @Override - public Long toOpenType(IQuantity value) throws QuantityConversionException { - // FIXME: Really special treat null here? Should ideally not reach this point. - if (value == null) { - // Skip validation too, since it is not really a valid value. - return -1L; - } - constraint.validate(value); - return value.longValueIn(unit); - } - - @Override - public IQuantity fromOpenType(Long openValue) throws QuantityConversionException { - // FIXME: Really special treat -1 here? Should ideally not reach this point. - if (openValue.longValue() == -1L) { - // Skip validation too, since it is not really a valid value. - return null; - } - IQuantity value = OpenTypeConverter.inGuessedUnit(unit.quantity(openValue)); - constraint.validate(value); - return value; - } - - } - - // FIXME: Move to a better place. - public static IQuantity inGuessedUnit(IQuantity value) { - IUnit unit = value.getType().getLargestExactUnit(value); - return (unit != null) ? value.in(unit) : value; - } - - protected OpenTypeConverter(String key, Class

type, OpenType

openType, IConstraint constraint) { - this.key = key; - this.type = type; - this.openType = openType; - this.constraint = constraint; - } - - public String getKey() { - return key; - } - - public Class

getType() { - return type; - } - - public OpenType

getOpenType() { - return openType; - } - - public abstract P toOpenType(T value) throws QuantityConversionException; - - public abstract T fromOpenType(P openValue) throws QuantityConversionException; -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorToolkitV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorToolkitV1.java deleted file mode 100644 index 8e2feb82..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorToolkitV1.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.fromDate; - -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * Toolkit for managing recording descriptors. - */ -@SuppressWarnings("nls") -public final class RecordingDescriptorToolkitV1 { - private static final String KEY_NAME = "name"; - private static final String KEY_ID = "id"; - private static final String KEY_STARTED = "started"; - private static final String KEY_STOPPED = "stopped"; - private static final String KEY_RUNNING = "running"; - private static final String KEY_OPTIONS = "options"; - private static final String KEY_DATA_START_TIME = "dataStartTime"; - private static final String KEY_DATA_END_TIME = "dataEndTime"; - private static final String KEY_OBJECT_NAME = "objectName"; - - private RecordingDescriptorToolkitV1() { - throw new AssertionError("Not to be instantiated!"); //$NON-NLS-1$ - } - - /** - * Creates a recording descriptor from composite data. - * - * @param serverId - * @param data - * @return the created recording descriptor - */ - public static IRecordingDescriptor createRecordingDescriptor(String serverId, CompositeData data) { - Map options = createOptions((CompositeData) data.get(KEY_OPTIONS)); - Long id = (Long) data.get(KEY_ID); - String name = (String) data.get(KEY_NAME); - Date dataStartTime = (Date) data.get(KEY_DATA_START_TIME); - Date dataEndTime = (Date) data.get(KEY_DATA_END_TIME); - ObjectName objectName = (ObjectName) data.get(KEY_OBJECT_NAME); - return new RecordingDescriptorV1(serverId, id, name, getBooleanKey(data, KEY_STARTED), - getBooleanKey(data, KEY_STOPPED), getBooleanKey(data, KEY_RUNNING), options, fromDate(dataStartTime), - fromDate(dataEndTime), objectName); - } - - public static CompositeData createRecordingOptions(Map map) { - throw new IllegalArgumentException("To be implemented!"); //$NON-NLS-1$ - } - - /** - * Must not be called with an empty recording! - * - * @param id - * @param recordings - * @return the recording descriptor with given id or null - */ - public static IRecordingDescriptor getRecordingById(long id, IRecordingDescriptor[] recordings) { - for (IRecordingDescriptor recording : recordings) { - if (recording.getId().longValue() == id) { - return recording; - } - } - return null; - } - - private static boolean getBooleanKey(CompositeData data, String key) { - Boolean value = (Boolean) data.get(key); - return value == null ? false : value.booleanValue(); - } - - // FIXME: Why not reuse the code in RecordingOptionsToolkit? The options are the same. - private static Map createOptions(CompositeData compositeData) { - Map options = new HashMap<>(); - for (Object o : compositeData.getCompositeType().keySet()) { - String key = (String) o; - options.put(key, compositeData.get(key)); - } - return options; - } - - public static IRecordingDescriptor getRecordingByDescriptor( - ObjectName objectName, List recordings) { - for (IRecordingDescriptor recording : recordings) { - if (objectName.equals(recording.getObjectName())) { - return recording; - } - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV1.java deleted file mode 100644 index efbacde5..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV1.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.BYTE; -import static org.openjdk.jmc.common.unit.UnitLookup.MILLISECOND; -import static org.openjdk.jmc.common.unit.UnitLookup.fromDate; - -import java.util.Date; -import java.util.Map; - -import javax.management.ObjectName; - -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.common.unit.IUnit; -import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * This class represents a handle to a server side JDK Flight Recorder recording. It is immutable, - * and thus thread safe. - */ -@SuppressWarnings("nls") -public final class RecordingDescriptorV1 implements IRecordingDescriptor { - private final String serverId; - private final ObjectName objectName; - private final Long id; - private final String name; - private final Map options; - private final RecordingState state; - private final IQuantity dataStartTime; - private final IQuantity dataEndTime; - - /** - * Horrid constructor. Not visible to the end user. - * - * @param serverId - * the id of the server where the recording originated from. - * @param id - * the id of the recording. - * @param name - * the name of the recording. - * @param isStarted - * has the recording been started? - * @param isStopped - * has the recording been stopped? - * @param isRunning - * is the recording running? - * @param options - * the recording options. - * @param dataStartTime - * start time of data - * @param dataEndTime - * end time of data - * @param objectName - * the object name used to locate the mbean managing the recording. - */ - RecordingDescriptorV1(String serverId, Long id, String name, boolean isStarted, boolean isStopped, - boolean isRunning, Map options, IQuantity dataStartTime, IQuantity dataEndTime, - ObjectName objectName) { - this.serverId = serverId; - this.id = id; - this.name = name; - state = decideState(isStarted, isStopped, isRunning); - this.options = options; - this.objectName = objectName; - this.dataStartTime = dataStartTime; - this.dataEndTime = dataEndTime; - } - - private RecordingState decideState(boolean isStarted, boolean isStopped, boolean isRunning) { - if (!isStarted) { - return RecordingState.CREATED; - } else if (isRunning) { - return RecordingState.RUNNING; - } else if (isStopped) { - return RecordingState.STOPPED; - } else { - return RecordingState.STOPPING; - } - } - - @Override - public Long getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - @Override - public RecordingState getState() { - return state; - } - - @Override - public Map getOptions() { - return options; - } - - @Override - public ObjectName getObjectName() { - return objectName; - } - - @Override - public boolean equals(Object o) { - if (o instanceof RecordingDescriptorV1) { - RecordingDescriptorV1 that = (RecordingDescriptorV1) o; - return that.id.equals(id) && that.serverId.equals(serverId); - } - return false; - } - - @Override - public int hashCode() { - return id.intValue() ^ serverId.hashCode(); - } - - @Override - public String toString() { - return "RecordingDescriptor@" + serverId + '[' + getName() + '(' + getId() + "), " + getState() + ", " - + getOptions() + ']'; - } - - @Override - public IQuantity getDataStartTime() { - return dataStartTime; - } - - @Override - public IQuantity getDataEndTime() { - return dataEndTime; - } - - @Override - public IQuantity getStartTime() { - Object startTime = getOptions().get(RecordingOptionsBuilder.KEY_START_TIME); - if (startTime instanceof Date) { - return fromDate((Date) startTime); - } - return null; - } - - @Override - public IQuantity getDuration() { - return getLongQuantity(MILLISECOND, RecordingOptionsBuilder.KEY_DURATION); - } - - @Override - public boolean isContinuous() { - IQuantity duration = getDuration(); - return (duration == null) || (duration.doubleValue() == 0.0); - } - - @Override - public boolean getToDisk() { - Object object = getOptions().get(RecordingOptionsBuilder.KEY_TO_DISK); - if (object instanceof Boolean) { - return ((Boolean) object).booleanValue(); - } - return false; - } - - @Override - public IQuantity getMaxAge() { - return getLongQuantity(MILLISECOND, RecordingOptionsBuilder.KEY_MAX_AGE); - } - - @Override - public IQuantity getMaxSize() { - return getLongQuantity(BYTE, RecordingOptionsBuilder.KEY_MAX_SIZE); - } - - private IQuantity getLongQuantity(IUnit unit, String optionKey) { - Object object = getOptions().get(optionKey); - if (object instanceof Long) { - return OpenTypeConverter.inGuessedUnit(unit.quantity((Long) object)); - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV2.java deleted file mode 100644 index 38299593..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingDescriptorV2.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.common.unit.UnitLookup.BYTE; -import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS; -import static org.openjdk.jmc.common.unit.UnitLookup.SECOND; - -import java.util.Map; - -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.common.unit.IQuantity; -import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; - -/** - * This class represents a handle to a server side JDK Flight Recorder recording. It is immutable, - * and thus thread safe. - */ -@SuppressWarnings("nls") -public final class RecordingDescriptorV2 implements IRecordingDescriptor { - private static final String KEY_NAME = "name"; - private static final String KEY_ID = "id"; - private static final String KEY_START_TIME = "startTime"; - private static final String KEY_STOP_TIME = "stopTime"; - private static final String KEY_STATE = "state"; - private static final String KEY_MAX_AGE = "maxAge"; - private static final String KEY_MAX_SIZE = "maxSize"; - // This key does not seem to correspond with the one used to set recording options. - private static final String KEY_TO_DISK = "toDisk"; - private static final String KEY_DESTINATION = "destination"; - private static final String KEY_DURATION = "duration"; - - private final String serverId; - private final long id; - private final String name; - private final RecordingState state; - private final IQuantity startTime; - private final IQuantity stopTime; - private final IQuantity duration; - private final IQuantity maxAge; - private final IQuantity maxSize; - private final boolean toDisk; - private final String destination; - - public RecordingDescriptorV2(String serverId, CompositeData data) { - this.serverId = serverId; - id = (Long) data.get(KEY_ID); - name = (String) data.get(KEY_NAME); - state = decideState((String) data.get(KEY_STATE)); - startTime = EPOCH_MS.quantity((Long) data.get(KEY_START_TIME)); - stopTime = EPOCH_MS.quantity((Long) data.get(KEY_STOP_TIME)); - duration = OpenTypeConverter.inGuessedUnit(SECOND.quantity((Long) data.get(KEY_DURATION))); - maxAge = OpenTypeConverter.inGuessedUnit(SECOND.quantity((Long) data.get(KEY_MAX_AGE))); - maxSize = OpenTypeConverter.inGuessedUnit(BYTE.quantity((Long) data.get(KEY_MAX_SIZE))); - toDisk = (Boolean) data.get(KEY_TO_DISK); - destination = (String) data.get(KEY_DESTINATION); - } - - private static RecordingState decideState(String state) { - if ("NEW".equals(state)) { - return RecordingState.CREATED; - } else if ("RUNNING".equals(state) || "DELAYED".equals(state) || "STARTING".equals(state)) { - return RecordingState.RUNNING; - } else if ("STOPPED".equals(state)) { - return RecordingState.STOPPED; - } else if ("STOPPING".equals(state)) { - return RecordingState.STOPPING; - } else { - // FIXME: CLOSED would fit better but there is no such enum value at the moment - return RecordingState.STOPPED; - } - } - - @Override - public Long getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - @Override - public RecordingState getState() { - return state; - } - - @Override - public Map getOptions() { - return null; - } - - @Override - public ObjectName getObjectName() { - return null; - } - - @Override - public boolean equals(Object o) { - if (o instanceof RecordingDescriptorV2) { - RecordingDescriptorV2 that = (RecordingDescriptorV2) o; - return that.id == id && that.serverId.equals(serverId); - } - return false; - } - - @Override - public int hashCode() { - return (int) id ^ serverId.hashCode(); - } - - @Override - public String toString() { - return "RecordingDescriptor@" + serverId + '[' + getName() + '(' + getId() + "), " + getState() + ", " - + getOptions() + ']'; - } - - @Override - public IQuantity getDataStartTime() { - return startTime; - } - - @Override - public IQuantity getDataEndTime() { - return stopTime; - } - - @Override - public IQuantity getStartTime() { - return startTime; - } - - @Override - public IQuantity getDuration() { - return duration; - } - - @Override - public boolean isContinuous() { - return (duration == null) || (duration.doubleValue() == 0.0); - } - - @Override - public boolean getToDisk() { - return toDisk; - } - - @Override - public IQuantity getMaxAge() { - return maxAge; - } - - @Override - public IQuantity getMaxSize() { - return maxSize; - } - - public String getDestination() { - return destination; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV1.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV1.java deleted file mode 100644 index 535418f4..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV1.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownRecordingOptions.DESCRIPTORS_BY_KEY_V1; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DESTINATION_COMPRESSED; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DESTINATION_FILE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_DURATION; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_MAX_AGE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_MAX_SIZE; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_NAME; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_START_TIME; -import static org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder.KEY_TO_DISK; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; - -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.OpenType; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IMutableConstrainedMap; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.common.unit.QuantityConversionException; -import org.openjdk.jmc.common.version.JavaVersionSupport; -import org.openjdk.jmc.flightrecorder.configuration.ConfigurationToolkit; -import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder; -import org.openjdk.jmc.rjmx.services.jfr.FlightRecorderException; - -/** - * Toolkit for handling marshalling of RecordingOptions for JFR 1.0 (JDK 7/8). - */ -public final class RecordingOptionsToolkitV1 { - private final static Map> CONVERTERS_BY_REC_OPTION_KEY; - - private final static String[] NAMES; - - private final static CompositeType OPTIONS_TYPE; - - static { - Map> converters = new LinkedHashMap<>(); - - // Maintain order with KnownRecordingOptions - // FIXME: Add test to verify that keys are the same? - converters.put(KEY_NAME, OpenTypeConverter.TEXT); - converters.put(KEY_TO_DISK, OpenTypeConverter.BOOLEAN); - converters.put(KEY_DURATION, OpenTypeConverter.MILLISECONDS); - converters.put(KEY_MAX_SIZE, OpenTypeConverter.BYTES); - converters.put(KEY_MAX_AGE, OpenTypeConverter.MILLISECONDS); - converters.put(KEY_DESTINATION_FILE, OpenTypeConverter.FILE_NAME); - converters.put(KEY_START_TIME, OpenTypeConverter.DATE); - converters.put(KEY_DESTINATION_COMPRESSED, OpenTypeConverter.BOOLEAN); - - CONVERTERS_BY_REC_OPTION_KEY = converters; - - NAMES = new String[converters.size()]; - OPTIONS_TYPE = createCompositeType("RecordingOptions", "Recording Options", DESCRIPTORS_BY_KEY_V1, NAMES); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * Create a CompositeType from {@link IOptionDescriptor}s and populate an array with item names - * to be used when creating {@link CompositeData}s. - * - * @param name - * @param description - * @param descriptorMap - * @param names - * an empty array with the length descriptors.{@link Map#size() size()} to be - * populated - * @return - */ - private static CompositeType createCompositeType( - String name, String description, Map> descriptorMap, String[] names) { - int len = descriptorMap.size(); - String[] descriptions = new String[len]; - OpenType[] openTypes = new OpenType[len]; - - int i = 0; - for (Entry> descriptorEntry : descriptorMap.entrySet()) { - String key = descriptorEntry.getKey(); - names[i] = key; - descriptions[i] = descriptorEntry.getValue().getDescription(); - openTypes[i] = CONVERTERS_BY_REC_OPTION_KEY.get(key).getOpenType(); - i++; - } - - try { - return new CompositeType("RecordingOptions", "Recording Options", names, descriptions, openTypes); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (Exception e) { - // Will not ever happen! - e.printStackTrace(); - return null; - } - } - - private RecordingOptionsToolkitV1() { - throw new AssertionError("Not to be instantiatied!"); //$NON-NLS-1$ - } - - public static CompositeData getRecordingOptions(IConstrainedMap options) throws OpenDataException { - Object[] values = new Object[NAMES.length]; - for (int i = 0; i < NAMES.length; i++) { - String key = NAMES[i]; - OpenTypeConverter converter = CONVERTERS_BY_REC_OPTION_KEY.get(key); - Object value = options.get(key); - if (value == null) { - value = DESCRIPTORS_BY_KEY_V1.get(key).getDefault(); - } - if (value != null) { - try { - values[i] = toOpenTypeWithCast(converter, value); - } catch (QuantityConversionException e) { - // FIXME: Add proper logging here - e.printStackTrace(); - } - } - } - return new CompositeDataSupport(OPTIONS_TYPE, NAMES, values); - } - - @SuppressWarnings("unchecked") - static P toOpenTypeWithCast(OpenTypeConverter converter, Object value) - throws QuantityConversionException { - return converter.toOpenType((T) value); - } - - public static Map> getAvailableRecordingOptions() { - return DESCRIPTORS_BY_KEY_V1; - } - - /** - * By recording options builder key... - * - * @param propertyKey - */ - public static IConstraint getRecordingOptionConstraint(String propertyKey) { - IOptionDescriptor desc = DESCRIPTORS_BY_KEY_V1.get(propertyKey); - return (desc != null) ? desc.getConstraint() : null; - } - - public static IConstrainedMap toRecordingOptions(CompositeData recordingOptions) - throws FlightRecorderException { - IMutableConstrainedMap options = ConfigurationToolkit.getRecordingOptions(JavaVersionSupport.JDK_8) - .emptyWithSameConstraints(); - for (String key : recordingOptions.getCompositeType().keySet()) { - OpenTypeConverter converter = CONVERTERS_BY_REC_OPTION_KEY.get(key); - if (converter == null) { - converter = OpenTypeConverter.TEXT; - } - try { - Object openValue = recordingOptions.get(key); - // FIXME: May need to rethink how to handle null values. Store constraint but not value? - // The problem is if null would be allowed but not default, like for recording start time. - if (openValue != null) { - EventOptionsToolkitV1.putWithCast(options, key, converter, openValue); - } - } catch (QuantityConversionException e) { - // FIXME: Add proper logging here - e.printStackTrace(); - } - } - return options; - } - - public static String getName(IConstrainedMap recordingOptions) { - return (String) recordingOptions.get(RecordingOptionsBuilder.KEY_NAME); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV2.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV2.java deleted file mode 100644 index 1c1f4c44..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingOptionsToolkitV2.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import static org.openjdk.jmc.flightrecorder.configuration.internal.KnownRecordingOptions.DESCRIPTORS_BY_KEY_V2; - -import java.util.Map; -import java.util.Map.Entry; - -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; -import javax.management.openmbean.TabularData; -import javax.management.openmbean.TabularDataSupport; -import javax.management.openmbean.TabularType; - -import org.openjdk.jmc.common.unit.IConstrainedMap; -import org.openjdk.jmc.common.unit.IConstraint; -import org.openjdk.jmc.common.unit.IOptionDescriptor; -import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder; - -/** - * Toolkit for handling marshalling of RecordingOptions for JFR 2.0 (JDK 9). - */ -public final class RecordingOptionsToolkitV2 { - final static TabularType OPTIONS_TYPE; - final static CompositeType OPTIONS_ROW_TYPE; - - static { - OPTIONS_ROW_TYPE = createOptionsRowType(); - OPTIONS_TYPE = createOptionsType(OPTIONS_ROW_TYPE); - } - - private static CompositeType createOptionsRowType() { - String typeName = "java.util.Map"; //$NON-NLS-1$ - String[] keyValue = new String[] {"key", "value"}; //$NON-NLS-1$ //$NON-NLS-2$ - OpenType[] openTypes = new OpenType[] {SimpleType.STRING, SimpleType.STRING}; - try { - return new CompositeType(typeName, typeName, keyValue, keyValue, openTypes); - } catch (OpenDataException e) { - // Will never happen - return null; - } - } - - private static TabularType createOptionsType(CompositeType rowType) { - try { - return new TabularType(rowType.getTypeName(), rowType.getTypeName(), rowType, new String[] {"key"}); //$NON-NLS-1$ - } catch (OpenDataException e) { - // Will never happen - return null; - } - } - - private RecordingOptionsToolkitV2() { - throw new AssertionError("Not to be instantiatied!"); //$NON-NLS-1$ - } - - public static TabularData createTabularData(Map map) throws OpenDataException { - TabularDataSupport tdata = new TabularDataSupport(OPTIONS_TYPE); - for (Entry entry : map.entrySet()) { - tdata.put(new CompositeDataSupport(OPTIONS_ROW_TYPE, new String[] {"key", "value"}, //$NON-NLS-1$ //$NON-NLS-2$ - new Object[] {entry.getKey(), entry.getValue()})); - } - return tdata; - } - - public static TabularData toTabularData(IConstrainedMap settings) throws OpenDataException { - TabularDataSupport tdata = new TabularDataSupport(OPTIONS_TYPE); - for (K key : settings.keySet()) { - String value = settings.getPersistableString(key); - if (value != null) { - tdata.put(new CompositeDataSupport(OPTIONS_ROW_TYPE, new String[] {"key", "value"}, //$NON-NLS-1$ //$NON-NLS-2$ - new String[] {key.toString(), value})); - } - } - return tdata; - } - - public static Map> getAvailableRecordingOptions() { - return DESCRIPTORS_BY_KEY_V2; - } - - /** - * By recording options builder key... - * - * @param propertyKey - */ - public static IConstraint getRecordingOptionConstraint(String propertyKey) { - IOptionDescriptor desc = DESCRIPTORS_BY_KEY_V2.get(propertyKey); - return (desc != null) ? desc.getConstraint() : null; - } - - public static String getName(Map recordingOptions) { - return (String) recordingOptions.get(RecordingOptionsBuilder.KEY_NAME); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingTemplateToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingTemplateToolkit.java deleted file mode 100644 index e4a8cb9d..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/RecordingTemplateToolkit.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.services.jfr.internal; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.management.openmbean.CompositeData; - -public final class RecordingTemplateToolkit { - private static final String KEY_CONTENT = "content"; //$NON-NLS-1$ - private static final String KEY_CONTENTS = "contents"; //$NON-NLS-1$ - - public static List getServerTemplatesV1(List compositeData) { - List templates = new ArrayList<>(compositeData.size()); - for (CompositeData data : compositeData) { - String template = (String) data.get(KEY_CONTENT); - templates.add(template); - } - return Collections.unmodifiableList(templates); - } - - public static List getServerTemplatesV2(CompositeData[] compositeData) { - List templates = new ArrayList<>(compositeData.length); - for (CompositeData data : compositeData) { - String template = (String) data.get(KEY_CONTENTS); - templates.add(template); - } - return Collections.unmodifiableList(templates); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanHelperService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanHelperService.java deleted file mode 100644 index 4e809d4b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanHelperService.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.io.IOException; -import java.util.Map; -import java.util.Set; - -import javax.management.InstanceNotFoundException; -import javax.management.IntrospectionException; -import javax.management.JMException; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.subscription.MRI.Type; - -/** - * Little helper service to provide simple access to commonly used functionality when handling - * MBeans. - */ -public interface IMBeanHelperService { - - /** - * Return a set of {@link ObjectName} containing the names of all available MBeans. - * - * @return a set of {@link ObjectName} containing the names of all available MBeans. - * @throws IOException - * if a problem occurred with underlying connection. - */ - Set getMBeanNames() throws IOException; - - /** - * Retrieves the value of an attribute. Note that the {@link Type} of the attribute MUST be - * {@link Type#ATTRIBUTE}. - * - * @param mri - * the self containing description of the MBean Resource to retrieved (ObjectName + - * attribute). - * @return the attribute value. - * @throws IOException - * if a problem occurred with underlying connection. - * @throws JMException - * if a JMX problem occurred. - * @throws MBeanException - * Wraps an exception thrown by the MBean's getter or wraps a JMRuntimeException - * which in turn might wrap a RuntimeException in the MBean's getter. - */ - Object getAttributeValue(MRI mri) throws IOException, JMException, MBeanException; - - /** - * Returns the bean information for all available MBeans. - * - * @return a map with the ObjectNames and their associated MBeanInfos. - * @throws IOException - * if the connection failed or some other IO related problem occurred. - */ - Map getMBeanInfos() throws IOException; - - /** - * Returns the MRI:s with associated metadata for the specified MBean. - * - * @param mbean - * the MBean for which to return the information. - * @return the MRI:s with associated metadata - */ - Map> getMBeanMetadata(ObjectName mbean); - - /** - * Returns the MBeanInfo for the specified MBean. - * - * @param mbean - * the MBean for which to return the information. - * @return the MBeanInfo for the specified MBean - * @throws InstanceNotFoundException - * The MBean specified was not found. - * @throws IntrospectionException - * An exception occurred during introspection. - * @throws ReflectionException - * An exception occurred when trying to invoke the getMBeanInfo of a Dynamic MBean. - * @throws IOException - * A communication problem occurred when talking to the MBean server. - */ - MBeanInfo getMBeanInfo(ObjectName mbean) - throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException; - - /** - * Takes a local time and tries to transform it to what it would have been in server time given - * the last measurements. - * - * @param currentTimeMillis - * the time for which to derive the approximate server time. - * @return the approximate server time. - */ - long getApproximateServerTime(long currentTimeMillis); - - /** - * Adds a listener which will be executed when the MBean configuration in the MBean server - * changes. - * - * @param listener - * the listener add. Should complete quickly. - */ - void addMBeanServerChangeListener(IMBeanServerChangeListener listener); - - /** - * Removes any listener that was added by - * {@link #addMBeanServerChangeListener(IMBeanServerChangeListener)}. If no listener has been - * added nothing happens. - * - * @param listener - * the listener to remove - */ - void removeMBeanServerChangeListener(IMBeanServerChangeListener listener); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanServerChangeListener.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanServerChangeListener.java deleted file mode 100644 index 5ee407c0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMBeanServerChangeListener.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import javax.management.ObjectName; - -/** - * Interface for call-backs due to MBean configuration changes. - */ -public interface IMBeanServerChangeListener { - /** - * Callback called when an MBean is registered in the platform MBean server. - * - * @param mbean - * the MBean that has been registered. - */ - void mbeanRegistered(ObjectName mbean); - - /** - * Callback called when an MBean is unregistered in the platform MBean server. - * - * @param mbean - * the MBean that has been unregistered. - */ - void mbeanUnregistered(ObjectName mbean); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadata.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadata.java deleted file mode 100644 index 0c07386c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadata.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -/** - * This interface provides metadata related to a certain MRI. This is really a convenience wrapper. - * If you simply need to set/get arbitrary values per MRI, use the service directly. - */ -public interface IMRIMetadata extends IMRIMetadataProvider { - - /** - * Returns a text description for this MRI. - * - * @return a text description for this MRI. - */ - public String getDescription(); - - /** - * Returns the fully qualified name representing the type of the value returned in the value - * events. - * - * @return the fully qualified name representing the type of this attribute. This string is - * interned, you may compare by reference to other equal interned strings. - */ - public String getValueType(); - - /** - * @return the name used when displaying the attribute in GUI's. - */ - public String getDisplayName(); - - /** - * Return the unit string (e.g. "%", "bytes" or similar). - * - * @return the unit string for the data of generated by this Attribute. - */ - public String getUnitString(); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProvider.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProvider.java deleted file mode 100644 index f13b5613..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -/** - * The bare essence of providing metadata about a MRI. - */ -public interface IMRIMetadataProvider { - - public static final String KEY_UPDATE_TIME = "UpdateTime"; //$NON-NLS-1$ - public static final String KEY_UNIT_STRING = "UnitString"; //$NON-NLS-1$ - public static final String KEY_DISPLAY_NAME = "DisplayName"; //$NON-NLS-1$ - public static final String KEY_DESCRIPTION = "Description"; //$NON-NLS-1$ - public static final String KEY_VALUE_TYPE = "AttributeType"; //$NON-NLS-1$ - public static final String KEY_COMPOSITE = "composite"; //$NON-NLS-1$ - public static final String KEY_READABLE = "Readable"; //$NON-NLS-1$ - public static final String KEY_WRITABLE = "Writable"; //$NON-NLS-1$ - public static final String KEY_DESCRIPTOR = "Descriptor"; //$NON-NLS-1$ - public static final String KEY_COLOR = "color"; //$NON-NLS-1$ - - /** - * Returns the {@link MRI} with which the metadata is associated. - * - * @return the {@link MRI}. - */ - public MRI getMRI(); - - /** - * Convenience access to general getter. - * - * @param key - * the key for the data to retrieve. - * @return the metadata resulting from the lookup, or {@code null} if no such data exist. - * @see IMRIMetadataService#getMetadata(MRI, String) - */ - public Object getMetadata(String key); - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProviderService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProviderService.java deleted file mode 100644 index 40cfdaa0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataProviderService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -/** - * A service that will provide metadata through the org.openjdk.jmc.rjmx.metadataprovider extension. - */ -public interface IMRIMetadataProviderService { - - /** - * Looks up the specified piece of metadata associated with the specified {@link MRI}. - * - * @param metadataService - * the service to (possible) use for look up existing metadata - * @param mri - * the {@link MRI} for which to retrieve the data. - * @param dataKey - * the key for the data to retrieve. - * @return the metadata resulting from the lookup, or null if no such data exist - */ - Object getMetadata(IMRIMetadataService metadataService, MRI mri, String dataKey); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataService.java deleted file mode 100644 index a4f47137..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIMetadataService.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.ui.common.util.IObservable; - -/** - * Manages {@link IMRIMetadata}s and metadata associated with {@link IMRIMetadata}s. This is one of - * the standard services usually available from an {@link IConnectionHandle}. - */ -public interface IMRIMetadataService extends IObservable { - - /** - * Returns the basic {@link IMRIMetadata} associated with an {@link MRI}. - * - * @param descriptor - * the {@link MRI} for which to retrieve the data. - * @return the basic {@link IMRIMetadata} associated with an {@link MRI}. - */ - IMRIMetadata getMetadata(MRI descriptor); - - /** - * Looks up the specified piece of metadata associated with the specified {@link MRI}. - * - * @param mri - * the {@link MRI} for which to retrieve the data. - * @param dataKey - * the key for the data to retrieve. - * @return the metadata resulting from the lookup, or null if no such data exist. - */ - Object getMetadata(MRI mri, String dataKey); - - /** - * Updates the metadata associated with the {@link MRI}. - * - * @param mri - * the {@link MRI}. - * @param dataKey - * the data key under which to store the metadata. - * @param data - * the actual metadata. - */ - void setMetadata(MRI mri, String dataKey, String data); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIService.java deleted file mode 100644 index 78be3301..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIService.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.util.Set; - -/** - * Service that manages all known MRIs. - */ -public interface IMRIService { - - /** - * Retrieves the whole available set of MRIs. - * - * @return available MRIs - */ - public Set getMRIs(); - - /** - * Whether given MRI is available in repository or not. - * - * @param mri - * the MRI to test - * @return {@code true} if MRI is available, {@code false} otherwise - */ - public boolean isMRIAvailable(MRI mri); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRISubscription.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRISubscription.java deleted file mode 100644 index f62df09e..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRISubscription.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import org.openjdk.jmc.rjmx.IConnectionHandle; - -/** - * Interface for all MRI subscriptions. - */ -public interface IMRISubscription { - /** - * Returns the last value event from the subscription. - * - * @return the last value event from the subscription. - */ - MRIValueEvent getLastMRIValueEvent(); - - /** - * Return the connection handle this subscription is bound to. - * - * @return the associated connection handle. - */ - IConnectionHandle getConnectionHandle(); - - /** - * Returns the metadata associated with this subscription. - * - * @return the metadata associated with this subscription. - */ - IMRIMetadata getMRIMetadata(); - - /** - * Sets the update policy of this subscription. An update policy defines when an attribute is to - * be updated. - *

- * Note that no promises are made as to when this update will be acted upon by the subscription - * service. - * - * @param policy - * the new update police. - */ - void setUpdatePolicy(IUpdatePolicy policy); - - /** - * Returns the update policy. - * - * @return the update policy. - */ - IUpdatePolicy getUpdatePolicy(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformation.java deleted file mode 100644 index 976adc36..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformation.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.util.Properties; - -/** - * Interface for attribute transformations. Will typically generate and propagate a new value when - * one of the value sources it depends on is updated. - */ -public interface IMRITransformation { - - /** - * Used to denote when no new value is available despite that value sources this transformation - * depend on have changed. - */ - public final Object NO_VALUE = new Object(); - - /** - * Setter to initialize the transformation object after it has been created. - * - * @param properties - * the properties to use - */ - void setProperties(Properties properties); - - /** - * Callback invoked when a value source it depends on has been updated. - * - * @param event - * an updated attribute event - * @return a transformed value or {@link IMRITransformation#NO_VALUE} - */ - Object createSubscriptionValue(MRIValueEvent event); - - /** - * Getter for the value sources that this transformation depends on. - * - * @return the dependent value sources - */ - MRI[] getAttributes(); - - /** - * Extends the metadata stored for this transformation. - * - * @param metadataService - * the metadata service to use for lookup and metadata storage - * @param metadata - * the current metadata of this transformation - */ - void extendMetadata(IMRIMetadataService metadataService, IMRIMetadata metadata); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformationFactory.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformationFactory.java deleted file mode 100644 index 438b9bd2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRITransformationFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.util.Properties; - -/** - * Interface for transformation factories. A transformation factory takes a set of properties and - * creates an {@link IMRITransformation}. - */ -public interface IMRITransformationFactory { - - /** - * Invoked when the extension is read and the factory is created. - * - * @param properties - * the properties to use for this factory - * @param transformationProperties - * the properties to add to each transformation instance - */ - void setFactoryProperties(Properties properties, Properties transformationProperties); - - /** - * Creates a transformation for given properties. - * - * @param properties - * the properties to use - * @return a transformation - */ - IMRITransformation createTransformation(Properties properties); - - /** - * Returns the label for a visualization menu item for the factory - * - * @return the visualization menu item - */ - String getVisualizationLabel(); - - /** - * Creates a transformation MRI for given MRI. The resulting MRI can then be used to create the - * actual transformation instance. - * - * @param mri - * the MRI to create a transformation MRI for - * @return the transformed MRI - */ - MRI createTransformationMRI(MRI mri); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIValueListener.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIValueListener.java deleted file mode 100644 index 0007797d..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IMRIValueListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.util.EventListener; - -/** - * Interface for classes that want to subscribe on changes in an MRIs value. - */ -public interface IMRIValueListener extends EventListener { - /** - * This method will be called whenever the subscribed resource value has changed. - * - * @param event - * the event containing change information. - */ - void valueChanged(MRIValueEvent event); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/ISubscriptionService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/ISubscriptionService.java deleted file mode 100644 index c1f14b3c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/ISubscriptionService.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -/** - * The service from which to create and destroy subscriptions on MRIs. A subscription is created for - * a value source when a listener is added to it. The subscription will be disposed when no listener - * remains on a value source. - *

- * A subscription service can be injected into a Console tab: - * - *

-public class SubscriptionExamplePage  {
-
-    {@literal @}Inject
-   private ISubscriptionService subscriptionService;
-
-   {@literal @}Inject
-    protected void createPageContent(IManagedForm managedForm) {
-        managedForm.getToolkit().decorateFormHeading(managedForm.getForm().getForm());
-        final Label valueLabel = managedForm.getToolkit().createLabel(
-            managedForm.getForm().getBody(), "", SWT.CENTER);
-        managedForm.getForm().getBody().setLayout(new FillLayout());
-
-        subscriptionService.addMRIValueListener(
-            new MRI(Type.ATTRIBUTE, "java.lang:type=OperatingSystem","ProcessCpuLoad"),
-            new IMRIValueListener() {
-                {@literal @}Override
-                public void valueChanged(final MRIValueEvent event) {
-                    DisplayToolkit.safeAsyncExec(label, new Runnable() {
-                        {@literal @}Override
-                        public void run() {
-                            Double latestValue = (Double) event.getValue();
-                            label.setText("CPU Load is: " + (latestValue.doubleValue() * 100) + "%");
-                        }
-                    });
-                }
-            });
-    }
-}
- * 
- * - * @see MRI - */ -public interface ISubscriptionService { - /** - * Adds the listener to the subscription on given descriptor (possible creating it). - * - * @param mri - * the MRI stating how and where to listen to value changes. - * @param listener - * the listener to add. - */ - void addMRIValueListener(MRI mri, IMRIValueListener listener); - - /** - * Substitutes two listeners. The new listener will subscribe to all subscriptions that the old - * listener had and the old listener will unsubscribe from them. - * - * @param oldListener - * the old listener to unsubscribe. - * @param newListener - * the new listener to subscribe instead. - */ - void substituteMRIValueListener(IMRIValueListener oldListener, IMRIValueListener newListener); - - /** - * Removes the listener from all its subscriptions, possible disposing of some or all of the - * subscriptions if this was the last listener. - * - * @param listener - * the listener to remove. - */ - void removeMRIValueListener(IMRIValueListener listener); - - /** - * Removes the listener from the subscription of given MRI, possible disposing of the - * subscription if this was the last listener. - * - * @param mri - * the MRI on which to stop listen to value changes. - * @param listener - * the value listener to remove. - */ - void removeMRIValueListener(MRI mri, IMRIValueListener listener); - - /** - * Returns the subscription associated with the {@link MRI}, if such a subscription exists, or - * {@code null} if no such subscription exists. - * - * @param mri - * the MRI describing what data to retrieve. - * @return the subscription, if one already exists, or {@code null} if no subscription for the - * MRI could be found. - */ - IMRISubscription getMRISubscription(MRI mri); - - /** - * Returns the last value event for the given MRI through its subscription. - * - * @param mri - * the MRI for which to get the last value event. - * @return the last value event logged through the subscription with given descriptor. Returns - * {@code null} if either the subscription does not exist or if it holds no value event. - */ - MRIValueEvent getLastMRIValueEvent(MRI mri); - - /** - * Returns whether a subscription on the MRI has been attempted but failed. - * - * @param mri - * the MRI to check. - * @return {@code true} if a subscription on the MRI has been attempted but failed, - * {@code false} if either subscribing on the MRI has not failed or never been - * subscribed to. - */ - boolean isMRIUnavailable(MRI mri); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/IUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/IUpdatePolicy.java deleted file mode 100644 index 2ccde5e3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/IUpdatePolicy.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -/** - * The interface specifying an update police for {@link IMRISubscription}s. - */ -public interface IUpdatePolicy { - - /** - * Return the time to schedule the next update given the last update. - * - * @param lastUpdate - * time of last update, in ms. - * @return the time to schedule the next update, given the time for the last update. This method - * is expected to be a mapping - any given input should always return the same output. - */ - public long getNextUpdate(long lastUpdate); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRI.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/MRI.java deleted file mode 100644 index 8702b1e2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRI.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.io.Serializable; - -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.ConnectionToolkit; - -/** - * The MBean Resource Identifier is a simple data class representing the fully qualified name for a - * JMX based value to be retrieved by the subscription engine. - *

- * Note that that subscription engine handles both attribute based subscriptions as well as - * notification based. Transformation data sources might both based on all kinds value sources, even - * other transformations. - *

- * The value descriptor consists of: - *

    - *
  • A type representing the type of data source.
  • - *
  • An {@link ObjectName} for the MBean from which to retrieve the value.
  • - *
  • A string for the value path, describing how to reach the value.
  • - *
- * The string form for a value descriptor is a String using URI form: - * - *
- * <type>://<ObjectName>/<value path>
- * 
- * - * Note that the FQN for a value descriptor cannot be relied upon for persistence, as ObjectNames - * are allowed to contain slashes. - */ -public final class MRI implements Serializable { - private static final long serialVersionUID = 1L; - private static final String MRI_DELIMITER = "://"; //$NON-NLS-1$ - /** - * The delimiter used to separate the object name from the attribute name in the fully qualified - * form. - */ - private static final char ATTRIBUTE_DELIMITER = '/'; - - /** - * The delimiter used to separate the attribute name from the key name in composite attributes. - */ - public static final char VALUE_COMPOSITE_DELIMITER = '/'; - public static final String VALUE_COMPOSITE_DELIMITER_STRING = "/"; //$NON-NLS-1$ - - /** - * The kind of value source that the attribute descriptor points out. Is either - * {@link Type#ATTRIBUTE} for a standard JMX attribute or {@link Type#NOTIFICATION} if the value - * is derived from a JMX notification. {@link Type#TRANSFORMATION} denotes that the type is a - * transformation of some other type (possible a transformation). - */ - public enum Type { - ATTRIBUTE("attribute"), NOTIFICATION("notification"), TRANSFORMATION("transformation"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private String typeName; - - private Type(String typeName) { - this.typeName = typeName; - } - - /** - * The string representation of the type. - * - * @return the string representation of the type. - */ - public String getTypeName() { - return typeName; - } - - /** - * The type instance given its string representation. - * - * @param typeName - * the string to look up - * @return the type instance or {@code null} if unknown - */ - public static Type fromString(String typeName) { - for (Type type : values()) { - if (typeName.equals(type.getTypeName())) { - return type; - } - } - return null; - } - } - - private final ObjectName m_objectName; - private final Type m_type; - private final String m_dataPath; - private final String m_qualifiedName; - - /** - * Constructor. - * - * @param type - * the type of the MRI. - * @param objectName - * the object name of the MBean. - * @param valuePath - * the path to the data. - * @throws NullPointerException - * if objectName is null. - */ - public MRI(Type type, ObjectName objectName, String valuePath) { - if (objectName == null) { - throw new NullPointerException("objectName may not be null!"); //$NON-NLS-1$ - } - if (valuePath == null) { - throw new NullPointerException("valuePath may not be null!"); //$NON-NLS-1$ - } - if (type == null) { - throw new NullPointerException("type may not be null!"); //$NON-NLS-1$ - } - m_type = type; - m_objectName = objectName; - m_dataPath = valuePath; - m_qualifiedName = generateQualifiedName(type, objectName, valuePath).intern(); - - } - - /** - * Constructor. - * - * @param type - * the type of the MRI. - * @param beanName - * the canonical name of the MBean. - * @param dataPath - * the path to the data. - * @throws NullPointerException - * if beanName is null. - */ - public MRI(Type type, String beanName, String dataPath) { - this(type, ConnectionToolkit.createObjectName(beanName), dataPath); - } - - /** - * Constructor. - * - * @param mri - * the MRI being specialized - * @param child - * the child extension of the MRIs data path - */ - public MRI(MRI mri, String child) { - this(mri.getType(), mri.getObjectName(), mri.getDataPath() + VALUE_COMPOSITE_DELIMITER_STRING + child); - } - - /** - * Returns the fully qualified name (FQN) of the attribute descriptor. - * - * @return the fully qualified name of the attribute descriptor. - */ - public String getQualifiedName() { - return m_qualifiedName; - } - - @Override - public boolean equals(Object obj) { - // Quick equals operator - if (obj != null && obj instanceof MRI) { - return m_qualifiedName.equals(((MRI) obj).getQualifiedName()); - } - return false; - } - - @Override - public int hashCode() { - return m_qualifiedName.hashCode(); - } - - /** - * Returns the object name (MBean) part of the descriptor. - * - * @return the object name (MBean) part of the descriptor. - */ - public ObjectName getObjectName() { - return m_objectName; - } - - /** - * Returns the data path. For attributes this is normally simply the attribute name. - * - * @return the data path. - */ - public String getDataPath() { - return m_dataPath; - } - - /** - * Returns the type of this MRI. - * - * @see Type - * @return the type of this MRI. - */ - public Type getType() { - return m_type; - } - - @Override - public String toString() { - return m_qualifiedName; - } - - /** - * Factory method for creating an MRI from a qualified name. - * - * @param qualName - * the qualified name to create the MRI from. - * @return the created {@link MRI}. - */ - public static MRI createFromQualifiedName(String qualName) { - int index = qualName.indexOf(MRI_DELIMITER); - if (index < 0) { - throw new IllegalArgumentException( - String.format("Malformed FQN. Could not find %s in %s", MRI_DELIMITER, qualName)); //$NON-NLS-1$ - } - Type type = Type.fromString(qualName.substring(0, index)); - if (type == null) { - throw new IllegalArgumentException(String.format("%s is not a recognized type.", qualName.substring(0, //$NON-NLS-1$ - index))); - } - int mbeanStart = index + MRI_DELIMITER.length(); - index = qualName.indexOf(ATTRIBUTE_DELIMITER, mbeanStart); - if (index >= 0) { - String beanName = qualName.substring(mbeanStart, index); - String attributeName = qualName.substring(index + 1); - return new MRI(type, beanName, attributeName); - } else { - throw new IllegalArgumentException(String.format( - "Malformed FQN. Could not find attribute name delimiter '%s' in %s", ATTRIBUTE_DELIMITER, //$NON-NLS-1$ - qualName)); - } - - } - - private static String generateQualifiedName(Type type, ObjectName objectName, String valuePath) { - return type.getTypeName() + MRI_DELIMITER + objectName.getCanonicalName() + ATTRIBUTE_DELIMITER + valuePath; - } - - /** - * Whether given MRI is a child to this MRI. - * - * @param childCandidate - * the candidate MRI to test - * @return {@code true} if given MRI is a child, {@code false} otherwise - */ - public boolean isChild(MRI childCandidate) { - if (!m_objectName.equals(childCandidate.getObjectName()) || childCandidate.getType() != m_type) { - return false; - } - String childMRIDataPath = childCandidate.getDataPath(); - if (childMRIDataPath.startsWith(m_dataPath)) { - String childDataPath = childMRIDataPath.substring(m_dataPath.length()); - return childDataPath.indexOf(VALUE_COMPOSITE_DELIMITER) == 0 - && childDataPath.lastIndexOf(VALUE_COMPOSITE_DELIMITER) == 0; - } - return false; - } - - /** - * Creates an array of all ancestor MRI for this object including itself. - * - * @return all MRI from "topmost" ancestor down to this instance - */ - public MRI[] getParentMRIs() { - String[] dataParts = m_dataPath.split(VALUE_COMPOSITE_DELIMITER_STRING); - MRI[] parentMris = new MRI[dataParts.length - 1]; - StringBuilder dataPath = new StringBuilder(); - for (int i = 0; i < parentMris.length; i++) { - dataPath.append(dataParts[i]); - parentMris[i] = new MRI(m_type, m_objectName, dataPath.toString()); - dataPath.append(VALUE_COMPOSITE_DELIMITER); - } - return parentMris; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIMetadataToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIMetadataToolkit.java deleted file mode 100644 index 95de2a4f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIMetadataToolkit.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.awt.Color; - -import javax.management.Descriptor; -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.common.util.ColorToolkit; -import org.openjdk.jmc.common.util.TypeHandling; -import org.openjdk.jmc.rjmx.IConnectionHandle; - -/** - * Helper class for extracting some commonly used metadata from the {@link IMRIMetadataService}. - */ -public final class MRIMetadataToolkit { - - private MRIMetadataToolkit() { - throw new AssertionError("This is a toolkit! Do not instantiate!"); //$NON-NLS-1$ - } - - /** - * Returns a more user friendly display name for the attribute. If available, the display name - * will be retrieved from the metadata available in the meta data service, otherwise the - * attribute name will be massaged into a more user friendly form. - * - * @param handle - * the connection handle for which to check. - * @param mri - * the descriptor for which to retrieve the display name. - * @return the defined display name for this attribute. Can be overridden by metadata. - */ - public static String getDisplayName(IConnectionHandle handle, MRI mri) { - return getDisplayName(handle.getServiceOrNull(IMRIMetadataService.class), mri); - } - - /** - * Returns a more user friendly display name for the attribute. If available, the display name - * will be retrieved from the metadata available in the meta data service, otherwise the - * attribute name will be massaged into a more user friendly form. - * - * @param service - * the metadata service to use. - * @param mri - * the descriptor for which to retrieve the display name. - * @return the defined display name for this attribute. Can be overridden by metadata. - */ - public static String getDisplayName(IMRIMetadataService service, MRI mri) { - if (service != null) { - String displayName = (String) service.getMetadata(mri, IMRIMetadataProvider.KEY_DISPLAY_NAME); - if (displayName != null && displayName.trim().length() > 0) { - return displayName; - } - } - - StringBuilder builder = new StringBuilder(); - String attributeDisplayName = mri.getDataPath(); - if (attributeDisplayName == null) { - return ""; //$NON-NLS-1$ - } - boolean lastCharLowerCase = false; - for (int n = 0; n < attributeDisplayName.length(); n++) { - char c = attributeDisplayName.charAt(n); - if (lastCharLowerCase && Character.isUpperCase(c)) { - builder.append(' '); - builder.append(Character.toUpperCase(c)); - } else { - builder.append(c); - } - lastCharLowerCase = Character.isLowerCase(c); - } - return builder.toString(); - } - - private static Object getMetadata(IConnectionHandle handle, MRI descriptor, String property) { - IMRIMetadataService infoService = handle.getServiceOrNull(IMRIMetadataService.class); - if (infoService != null) { - return infoService.getMetadata(descriptor, property); - } - return null; - } - - /** - * Returns the description for the specified MRI. - * - * @param handle - * the connection handle for which to check. - * @param mri - * the descriptor for which to retrieve the description. - * @return the description for this attribute. Can be overridden by metadata. - */ - public static String getDescription(IConnectionHandle handle, MRI mri) { - String str = (String) getMetadata(handle, mri, IMRIMetadataProvider.KEY_DESCRIPTION); - if (str != null) { - return str; - } else { - return ""; //$NON-NLS-1$ - } - } - - /** - * Returns the metadata for given MRI. - * - * @param handle - * the connection to use - * @param descriptor - * the MRI - * @return the metadata info - */ - public static IMRIMetadata getMRIMetadata(IConnectionHandle handle, MRI descriptor) { - IMRIMetadataService infoService = handle.getServiceOrNull(IMRIMetadataService.class); - if (infoService != null) { - return infoService.getMetadata(descriptor); - } - return null; - } - - /** - * Answers whether the type of given {@link IMRIMetadata} is of numerical type or not. - * - * @param info - * the {@link IMRIMetadata} to inspect type. - * @return true if type is numerical type, false otherwise - */ - public static boolean isNumerical(IMRIMetadata info) { - return isNumerical(info.getValueType()); - } - - /** - * Answers whether the given type is of a numerical type or not. - * - * @param attributeType - * the type to inspect - * @return true if type is numerical type, false otherwise - */ - public static boolean isNumerical(String attributeType) { - // is not numerical until proven otherwise. Note that it should be - // enough to connect once to get this data properly sorted out. - if (attributeType == null) { - return false; - } - - if (attributeType.equals(int.class.getName())) { - return true; - } - if (attributeType.equals(float.class.getName())) { - return true; - } - if (attributeType.equals(double.class.getName())) { - return true; - } - if (attributeType.equals(long.class.getName())) { - return true; - } - if (attributeType.equals(short.class.getName())) { - return true; - } - if (attributeType.equals(byte.class.getName())) { - return true; - } - try { - return Number.class.isAssignableFrom(Class.forName(attributeType)); - } catch (ClassNotFoundException fallTrough) { - } - return false; - } - - /** - * Convenience method that returns true if the value type of the supplied metadata is certain to - * be of {@link CompositeData} - * - * @param info - * the metadata to check. - * @return true if the supplied info value type is {@link CompositeData}, - * false if not or undecided. - */ - public static boolean isComposite(IMRIMetadataProvider info) { - return getBooleanValue(info, IMRIMetadataProvider.KEY_COMPOSITE); - } - - /** - * Checks whether the string specifies a class name that is a descendant of the CompositeData - * interface. - * - * @param className - * the class to check - * @return true if it a descendant of the CompositeData interface. - */ - public static boolean isCompositeType(String className) { - if (className == null || className.length() == 0) { - return false; - } - try { - if (TypeHandling.isPrimitive(className)) { - return false; - } - return CompositeData.class.isAssignableFrom(Class.forName(className)); - } catch (ClassNotFoundException e) { - return false; - } - } - - /** - * Convenience method that returns true if the value type of the supplied metadata is certain to - * be readable. - * - * @param info - * the metadata to check. - * @return true if the supplied info value type is readable, false otherwise. - */ - public static boolean isReadable(IMRIMetadataProvider info) { - return getBooleanValue(info, IMRIMetadataProvider.KEY_READABLE); - } - - /** - * Convenience method that returns true if the value type of the supplied metadata is certain to - * be writable. - * - * @param info - * the metadata to check. - * @return true if the supplied info value type is writable, false otherwise. - */ - public static boolean isWritable(IMRIMetadataProvider info) { - return getBooleanValue(info, IMRIMetadataProvider.KEY_WRITABLE); - } - - /** - * Returns the possible descriptor for given metadata. - * - * @param info - * the metadata to use - * @return the descriptor object, or {@code null} if not available. - */ - public static Descriptor getDescriptor(IMRIMetadataProvider info) { - return (Descriptor) info.getMetadata(IMRIMetadataProvider.KEY_DESCRIPTOR); - } - - /** - * Returns the metadata color. Either the color stored in the metadata or an assigned - * distinguishable color. - * - * @param info - * the metadata to use - * @return a color to use for given metadata - */ - public static Color getColor(IMRIMetadataProvider info) { - Object colorStr = info.getMetadata(IMRIMetadataProvider.KEY_COLOR); - if (colorStr != null) { - return ColorToolkit.decode(colorStr.toString()); - } - return ColorToolkit.getDistinguishableColor(info.getMRI()); - } - - /** - * Whether a metadata property is {@code true} or not. - * - * @param info - * the metadata to use - * @param key - * the property key to use for look up - * @return {@code true} if the property is present and set to {@code true}, {@code false} - * otherwise - */ - public static boolean getBooleanValue(IMRIMetadataProvider info, String key) { - Boolean b = (Boolean) info.getMetadata(key); - if (b != null) { - return b.booleanValue(); - } - return false; // Default value - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIValueEvent.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIValueEvent.java deleted file mode 100644 index 741465d2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/MRIValueEvent.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription; - -import java.util.Objects; - -/** - * Event mainly used by the subscription engine. Contains information on what attribute was - * retrieved, the value of the attribute and the time when the data was collected. - */ -public class MRIValueEvent { - - private static class UnavailableValue { - @Override - public String toString() { - return "[N/A]"; - } - } - - public final static Object UNAVAILABLE_VALUE = new UnavailableValue(); - - private final long m_timestamp; - private final Object m_value; - private final MRI m_mri; - - /** - * Constructor. - * - * @param mri - * the subscription attribute from which the value originated. (Can be an aggregated - * composite.) - * @param timestamp - * the timestamp when the value was created. - * @param value - * the actual value. - */ - public MRIValueEvent(MRI mri, long timestamp, Object value) { - m_mri = mri; - m_timestamp = timestamp; - m_value = value; - } - - /** - * Returns the subscription value source. - * - * @return the subscription value source. - */ - public final MRI getMRI() { - return m_mri; - } - - /** - * Returns the timestamp. - * - * @return long the timestamp for the event. - */ - public final long getTimestamp() { - return m_timestamp; - } - - /** - * Returns the value. - * - * @return Object - */ - public final Object getValue() { - return m_value; - } - - @Override - public String toString() { - return m_mri.getQualifiedName() + ' ' + getValue() + '@' + m_timestamp; - } - - @Override - public boolean equals(Object theOtherGuy) { - if (theOtherGuy == null || getClass() != theOtherGuy.getClass()) { - return false; - } - MRIValueEvent otherEvent = (MRIValueEvent) theOtherGuy; - if (m_timestamp != otherEvent.m_timestamp || m_mri.equals(otherEvent.m_mri)) { - return false; - } - return Objects.equals(m_value, otherEvent.m_value); - } - - @Override - public int hashCode() { - int hash = 7; - hash = 31 * hash + (int) (m_timestamp ^ (m_timestamp >>> 32)); - hash = 31 * hash + m_mri.hashCode(); - hash = 31 * hash + ((m_value == null) ? 0 : m_value.hashCode()); - return hash; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractAttributeSubscription.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractAttributeSubscription.java deleted file mode 100644 index a507513f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractAttributeSubscription.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.IMRIValueListener; -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Default implementation for AttributeSubscriptions. - */ -public abstract class AbstractAttributeSubscription implements IMRISubscription { - private static final Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.subscription"); //$NON-NLS-1$ - - private final IConnectionHandle m_connectionHandle; - private final Set m_attributeListenerList = Collections - .synchronizedSet(new HashSet(1)); - private final IMRIMetadata m_attributeInfo; - private MRIValueEvent m_lastEvent; - private IUpdatePolicy m_updatePolicy; - private final Predicate m_valueFilter; - - /** - * Constructor for AbstractAttribute. - * - * @param connectionHandle - * the ConnectorModel to bind to. Needs to have the {@link IMBeanHelperService} and - * {@link IMRIMetadataService} service available. - * @param info - * the {@link IMRIMetadata} for the subscription attribute, may not be null! - * @throws IllegalAccessException - */ - public AbstractAttributeSubscription(IConnectionHandle connectionHandle, IMRIMetadata info) { - m_connectionHandle = connectionHandle; - if (info == null || info.getMRI().getObjectName() == null) { - throw new IllegalArgumentException("Subscriptions may not be created from attribute name references."); //$NON-NLS-1$ - } else if (!m_connectionHandle.hasService(IMRIMetadataService.class)) { - throw new IllegalArgumentException( - "Connection handle must have the IMBeanHelperService for subscriptions to work!"); //$NON-NLS-1$ - } else { - m_attributeInfo = info; - } - m_valueFilter = getValueFilter(info); - } - - /** - * Adds the specified listener to the list of objects to be notified whenever a change has - * occurred. - * - * @param listener - * the listener interested in change information. - */ - public void addAttributeValueListener(IMRIValueListener listener) { - if (listener == null) { - throw new NullPointerException("Listener may not be null!"); //$NON-NLS-1$ - } - if (m_attributeListenerList.contains(listener)) { - throw new IllegalArgumentException("This listener has already been added!"); //$NON-NLS-1$ - } - m_attributeListenerList.add(listener); - } - - /** - * Removes the old listener and adds the new. - * - * @param oldListener - * the old listener already subscribing. - * @param newListener - * the new listener that should subscribe instead. - */ - public void substituteAttributeValueListener(IMRIValueListener oldListener, IMRIValueListener newListener) { - if (oldListener == null || newListener == null) { - throw new NullPointerException("Listeners may not be null!"); //$NON-NLS-1$ - } - if (oldListener != newListener) { - synchronized (m_attributeListenerList) { - removeAttributeValueListener(oldListener); - addAttributeValueListener(newListener); - } - } - } - - /** - * Removes the specified listener. Change events will no longer be transmitted to the specified - * listener after this call returns. - * - * @param listener - * the listener to be removed. - */ - public void removeAttributeValueListener(IMRIValueListener listener) { - m_attributeListenerList.remove(listener); - } - - /** - * Return whether the subscription has any value listeners or not. - * - * @return true if subscription has listeners, false otherwise. - */ - public boolean hasAttributeValueListeners() { - return m_attributeListenerList.size() > 0; - } - - /** - * Fires an attribute value change from this attribute. - * - * @param attributeEvent - * the attribute value change to fire. - */ - protected void fireAttributeChange(MRIValueEvent attributeEvent) { - if (attributeEvent == null) { - return; - } - - IMRIValueListener[] tmpListeners; - synchronized (m_attributeListenerList) { - tmpListeners = m_attributeListenerList.toArray(new IMRIValueListener[m_attributeListenerList.size()]); - } - for (IMRIValueListener l : tmpListeners) { - l.valueChanged(attributeEvent); - } - - } - - @Override - public IConnectionHandle getConnectionHandle() { - return m_connectionHandle; - } - - @Override - public MRIValueEvent getLastMRIValueEvent() { - return m_lastEvent; - } - - /** - * This must be called in subclasses to store and fire a newly created event. - * - * @param event - * the newly created event. - */ - protected void storeAndFireEvent(MRIValueEvent event) { - if (m_valueFilter != null && m_valueFilter.test(event.getValue())) { - LOGGER.log(Level.INFO, "Subscription filtered out value: " + event.getValue()); //$NON-NLS-1$ - return; - } - if ((m_lastEvent != null) && (event.getTimestamp() < m_lastEvent.getTimestamp())) { - LOGGER.log(Level.INFO, "Subscription dropped attribute event because timestamp was older than last event."); //$NON-NLS-1$ - return; - } - m_lastEvent = event; - fireAttributeChange(event); - } - - @Override - public IMRIMetadata getMRIMetadata() { - return m_attributeInfo; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof AbstractAttributeSubscription) { - AbstractAttributeSubscription other = (AbstractAttributeSubscription) obj; - return m_connectionHandle.getServerDescriptor().getGUID() - .equals(other.m_connectionHandle.getServerDescriptor().getGUID()) - && getMRIMetadata().equals(other.getMRIMetadata()); - } - return false; - } - - // FIXME: Calculation speed could be improved. - @Override - public int hashCode() { - if (cachedHashCode == null) { - cachedHashCode = (m_connectionHandle.getServerDescriptor().getGUID() - + getMRIMetadata().getMRI().getQualifiedName()).hashCode(); - } - return cachedHashCode.intValue(); - } - - private Integer cachedHashCode; - - @Override - public IUpdatePolicy getUpdatePolicy() { - return m_updatePolicy; - } - - @Override - public void setUpdatePolicy(IUpdatePolicy updatePolicy) { - m_updatePolicy = updatePolicy; - } - - @Override - public String toString() { - return getClass().getName() + '[' + getMRIMetadata() + ']'; - } - - private static Predicate getValueFilter(IMRIMetadata metadata) { - // FIXME: We hard code the filters for now, but this should be handled along with content types - String mri = metadata.getMRI().getQualifiedName(); - if ("attribute://java.lang:type=OperatingSystem/ProcessCpuLoad".equals(mri) //$NON-NLS-1$ - || "attribute://java.lang:type=OperatingSystem/SystemCpuLoad".equals(mri) //$NON-NLS-1$ - || "attribute://java.lang:type=OperatingSystem/SystemLoadAverage".equals(mri)) { //$NON-NLS-1$ - return new Predicate() { - - @Override - public boolean test(Object value) { - return !(value instanceof Number) || ((Number) value).doubleValue() < 0; - } - }; - } - return null; - } -} \ No newline at end of file diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractPropertySyntheticAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractPropertySyntheticAttribute.java deleted file mode 100644 index a800482b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractPropertySyntheticAttribute.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanException; -import javax.management.MBeanInfo; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.IPropertySyntheticAttribute; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * Abstract base class for synthetic property attributes that needs to retrieve values from MBeans - * having attribute descriptors as properties. Also supports a "factor" property that can optional - * be used. The value if present must be a double. - */ -public abstract class AbstractPropertySyntheticAttribute extends AbstractSyntheticAttribute - implements IPropertySyntheticAttribute { - - private Map m_properties; - - @Override - public void setProperties(Map values) { - m_properties = values; - } - - /** - * Checks if the attribute denoted by the property key is present. - * - * @param connection - * the connection to retrieve the value from - * @param key - * which property to use as an attribute descriptor - * @return true if attribute is available, false otherwise - */ - protected boolean hasResolvedAttribute(MBeanServerConnection connection, String key) { - Object value = m_properties.get(key); - if (value == null) { - return false; - } - try { - MRI attribute = MRI.createFromQualifiedName(value.toString()); - String attributeName = AttributeValueToolkit.getAttributeName(attribute.getDataPath()); - MBeanInfo info = connection.getMBeanInfo(attribute.getObjectName()); - for (MBeanAttributeInfo attributeInfo : info.getAttributes()) { - if (attributeInfo.getName().equals(attributeName)) { - return true; - } - } - } catch (Exception e) { - } - return false; - } - - @Override - public void setValue(MBeanServerConnection connection, Object value) { - // by default no value can be set - } - - /** - * Retrieves several attribute values from a connection. - * - * @param connection - * the connection to retrieve the value from - * @param keys - * which properties to use as attribute descriptors - * @return a map of property keys and values - * @throws MBeanException - * wraps an exception thrown by the MBean's getter - * @throws ReflectionException - * wraps an exception thrown while trying to invoke the getter - */ - protected Map getPropertyAttributes(MBeanServerConnection connection, String[] keys) - throws ReflectionException, MBeanException { - Map attributeKeyMap = new HashMap<>(); - List attributes = new ArrayList<>(); - for (String key : keys) { - MRI attribute = lookupAttribute(key); - if (attribute != null) { - attributeKeyMap.put(attribute, key); - attributes.add(attribute); - } - } - Map values; - try { - values = AttributeValueToolkit.getAttributes(connection, attributes); - } catch (InstanceNotFoundException e) { - throw new MBeanException(e); - } catch (IOException e) { - throw new MBeanException(e); - } - Map result = new HashMap<>(); - for (Entry entry : values.entrySet()) { - result.put(attributeKeyMap.get(entry.getKey()), entry.getValue()); - } - return result; - } - - private MRI lookupAttribute(String key) { - Object value = getProperty(key); - if (value == null) { - return null; - } - return MRI.createFromQualifiedName(value.toString()); - } - - /** - * Retrieves a property from the property map. - * - * @param key - * the key to look up - * @return the value of the key or null if not available - */ - protected Object getProperty(String key) { - return m_properties.get(key); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSingleMRITransformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSingleMRITransformation.java deleted file mode 100644 index b5b92a1b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSingleMRITransformation.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Properties; - -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * Base class for transformation depending on a single MRI for input. - */ -public abstract class AbstractSingleMRITransformation implements IMRITransformation { - - private static final String ATTRIBUTE_PROPERTY = "attribute"; //$NON-NLS-1$ - private static final String DISPLAY_NAME_PROPERTY = "displayName"; //$NON-NLS-1$ - private Properties m_transformationProperties; - private MRI m_attribute; - - @Override - public void setProperties(Properties properties) { - m_transformationProperties = properties; - m_attribute = MRI.createFromQualifiedName(m_transformationProperties.getProperty(ATTRIBUTE_PROPERTY)); - } - - @Override - public MRI[] getAttributes() { - return new MRI[] {m_attribute}; - } - - @Override - public void extendMetadata(IMRIMetadataService metadataService, IMRIMetadata metadata) { - MRITransformationToolkit.forwardMetadata(metadataService, metadata.getMRI(), - metadataService.getMetadata(m_attribute), getDisplayNamePattern()); - } - - /** - * Will return the display name pattern for this transformation with a placeholder {0} for the - * attribute's display name. - * - * @return the display name pattern - */ - protected String getDisplayNamePattern() { - return m_transformationProperties.getProperty(DISPLAY_NAME_PROPERTY); - } - - /** - * Does a subtraction of the operands. Will try to use same type in return value as in - * parameters. - * - * @param minuend - * the number to subtract from - * @param subtrahend - * the number to subtract - * @return a number with the subtraction value - */ - protected Number subtract(Number minuend, Number subtrahend) { - if (!minuend.getClass().equals(subtrahend.getClass())) { - throw new IllegalArgumentException("Different type classes!"); //$NON-NLS-1$ - } - if (minuend instanceof Integer) { - return Integer.valueOf(minuend.intValue() - subtrahend.intValue()); - } - if (minuend instanceof Long) { - return Long.valueOf(minuend.longValue() - subtrahend.longValue()); - } - if (minuend instanceof Byte) { - return Byte.valueOf((byte) (minuend.intValue() - subtrahend.intValue())); - } - if (minuend instanceof Short) { - return Short.valueOf((short) (minuend.intValue() - subtrahend.intValue())); - } - if (minuend instanceof Float) { - return Float.valueOf(minuend.floatValue() - subtrahend.floatValue()); - } - // for Double and other types, use double values - return Double.valueOf(minuend.doubleValue() - subtrahend.doubleValue()); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticAttribute.java deleted file mode 100644 index 0cdc6fa4..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import javax.management.MBeanServerConnection; - -import org.openjdk.jmc.rjmx.ISyntheticAttribute; - -/** - * Abstract base class for synthetic attributes. - */ -public abstract class AbstractSyntheticAttribute implements ISyntheticAttribute { - - @Override - public void init(MBeanServerConnection connection) { - // Ignore - } - - @Override - public void stop() { - // Ignore - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticNotification.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticNotification.java deleted file mode 100644 index ed377d7a..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractSyntheticNotification.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.logging.Level; - -import javax.management.MBeanServerConnection; -import javax.management.Notification; -import javax.management.modelmbean.ModelMBeanNotificationBroadcaster; - -import org.openjdk.jmc.rjmx.ISyntheticNotification; -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * This is the base class to extend from for synthetic notifications. - */ -public abstract class AbstractSyntheticNotification implements ISyntheticNotification { - private String m_type; - private String m_message; - private long m_sequenceNumber = 0; - private ModelMBeanNotificationBroadcaster broadcaster; - - @Override - public abstract Object getValue(); - - /** - * This method will by default return the message that is provided by the extension point. - * Override this method to provide your own dynamic message. - * - * @return the message. - */ - protected String getMessage() { - return m_message; - } - - @Override - public void stop() { - } - - /** - * Call this method to trigger a notification. By default this method will call getValue to get - * the value to include in the trigger. - */ - protected final void triggerNotification() { - Object value = getValue(); - Notification notification = new Notification(m_type, this, m_sequenceNumber++, getMessage()); - notification.setUserData(value); - try { - broadcaster.sendNotification(notification); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Unable to trigger notification!", e); //$NON-NLS-1$ - e.printStackTrace(); - } - } - - @Override - public void init(MBeanServerConnection connection, String type, String message) { - m_type = type; - m_message = message; - } - - @Override - public final void init(ModelMBeanNotificationBroadcaster broadcaster) { - this.broadcaster = broadcaster; - } - - @Override - public final ModelMBeanNotificationBroadcaster getBroadcaster() { - return broadcaster; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractUpdatePolicy.java deleted file mode 100644 index f52a93dc..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AbstractUpdatePolicy.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; - -/** - * Abstract superclass for update policies that want the first update to be scheduled other than - * every update after that. - */ -public abstract class AbstractUpdatePolicy implements IUpdatePolicy { - private long firstUpdate = Long.MIN_VALUE; - - @Override - final public long getNextUpdate(long lastUpdate) { - if (firstUpdate == Long.MIN_VALUE) { - firstUpdate = lastUpdate; - } - - if (lastUpdate == firstUpdate) { - return getFirstUpdate(lastUpdate); - } else { - return getFollowingUpdate(lastUpdate); - } - } - - protected abstract long getFirstUpdate(long now); - - protected abstract long getFollowingUpdate(long now); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeExceptionEvent.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeExceptionEvent.java deleted file mode 100644 index 85d7c0ec..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeExceptionEvent.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Instances of this class are delivered when the Subscription fails, typically because an exception - * was thrown during subscription. - */ -public class AttributeExceptionEvent extends MRIValueEvent { - private final Throwable m_exception; - - /** - * Constructor. - * - * @param source - * the subscription that failed . - * @param timestamp - * the time the failure occured. - * @param exception - * the exception that caused the subscription to fail. - */ - public AttributeExceptionEvent(IMRISubscription source, long timestamp, Throwable exception) { - super(source.getMRIMetadata().getMRI(), timestamp, MRIValueEvent.UNAVAILABLE_VALUE); - m_exception = exception; - } - - /** - * @return the exception that was the cause of the failure. - */ - public Throwable getException() { - return m_exception; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeReregisteredEvent.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeReregisteredEvent.java deleted file mode 100644 index eb50b8d9..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeReregisteredEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Instances of this class are delivered when the Subscription is re-registered, typically because - * an attribute became available again. - */ -public class AttributeReregisteredEvent extends MRIValueEvent { - - /** - * @param source - * the subscription that re-registered. - * @param timestamp - * the time the attribute was re-registered. - */ - public AttributeReregisteredEvent(IMRISubscription source, long timestamp) { - super(source.getMRIMetadata().getMRI(), timestamp, null); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeValueToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeValueToolkit.java deleted file mode 100644 index ed4fe446..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AttributeValueToolkit.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.Attribute; -import javax.management.AttributeList; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceNotFoundException; -import javax.management.InvalidAttributeValueException; -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; - -/** - * Toolkit for setting and retrieving values from a {@link MBeanServerConnection} using {@link MRI}. - */ -public final class AttributeValueToolkit { - - private AttributeValueToolkit() throws InstantiationException { - throw new InstantiationException("Should not be instantiated!"); //$NON-NLS-1$ - } - - public static Object getAttribute(MBeanServerConnection connection, MRI attribute) - throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, - IOException { - assert attribute.getType() == Type.ATTRIBUTE; - return getAttribute(connection, attribute.getObjectName(), attribute.getDataPath()); - } - - public static Object getAttribute(MBeanServerConnection connection, ObjectName name, String attribute) - throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException, - IOException { - Object value = connection.getAttribute(name, getAttributeName(attribute)); - return lookupValue(attribute, value); - } - - public static Map getAttributes(MBeanServerConnection connection, Iterable attributes) - throws InstanceNotFoundException, ReflectionException, IOException { - if (attributes == null) { - throw new IllegalArgumentException("Can't fetch anything! attributes == null!"); //$NON-NLS-1$ - } - Map results = new HashMap<>(); - // coalesce all attributes belonging to the same MBean - Map> mbeanMap = new HashMap<>(); - for (MRI attribute : attributes) { - assert attribute.getType() == Type.ATTRIBUTE; - List dataPathList = mbeanMap.get(attribute.getObjectName()); - if (dataPathList == null) { - dataPathList = new ArrayList<>(); - mbeanMap.put(attribute.getObjectName(), dataPathList); - } - dataPathList.add(attribute.getDataPath()); - } - for (Entry> entry : mbeanMap.entrySet()) { - AttributeList values = getAttributes(connection, entry.getKey(), entry.getValue()); - for (Object obj : values) { - Attribute value = (Attribute) obj; - results.put(new MRI(Type.ATTRIBUTE, entry.getKey(), value.getName()), value.getValue()); - } - } - return results; - } - - public static AttributeList getAttributes( - MBeanServerConnection connection, ObjectName name, Iterable dataPaths) - throws InstanceNotFoundException, ReflectionException, IOException { - AttributeList results = new AttributeList(); - Map> attributeMap = new HashMap<>(); - // coalesce all data paths to look up form a single attribute name - for (String dataPath : dataPaths) { - String attributeName = getAttributeName(dataPath); - List attributeList = attributeMap.get(attributeName); - if (attributeList == null) { - attributeList = new ArrayList<>(); - attributeMap.put(attributeName, attributeList); - } - attributeList.add(dataPath); - } - AttributeList values = connection.getAttributes(name, keysAsArray(attributeMap)); - if (values == null) { - /* - * If the MBean implementor for some reason has not implemented the getAttributes method - * correctly (for example having a dynamic MBean with a Eclipse default implementation - * "return null") we should try to handle it as no attributes where read. This in turn - * will most probably force JMC to do a getAttribute invocation for each and every - * attribute. Still better than dying with a NPE. - */ - values = new AttributeList(); - } - for (Object obj : values) { - Attribute value = (Attribute) obj; - for (String dataPath : attributeMap.get(value.getName())) { - try { - Attribute attribute = new Attribute(dataPath, lookupValue(dataPath, value.getValue())); - results.add(attribute); - } catch (AttributeNotFoundException e) { - // skip attributes not found - } - } - } - return results; - } - - private static String[] keysAsArray(Map> attributeMap) { - Set attributesToGet = attributeMap.keySet(); - return attributesToGet.toArray(new String[attributesToGet.size()]); - } - - // FIXME: Do a proper look up - public static Object lookupValue(String dataPath, Object value) throws AttributeNotFoundException { - String[] compositeParts = dataPath.split(MRI.VALUE_COMPOSITE_DELIMITER_STRING); - if (compositeParts.length > 1) { - if (value != null && !(value instanceof CompositeData)) { - throw new AttributeNotFoundException("Unable to lookup up " + dataPath + " in non-composite value!"); //$NON-NLS-1$ //$NON-NLS-2$ - } - CompositeData compositeData = (CompositeData) value; - if (compositeParts.length != 2) { - String msg = "Could not resolve the composite data for " + dataPath + ". Number of components " //$NON-NLS-1$ //$NON-NLS-2$ - + compositeParts.length + " is not supported yet."; //$NON-NLS-1$ - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, msg); - throw new AttributeNotFoundException(msg); - } - if (compositeData == null) { - throw new AttributeNotFoundException("Attribute " + compositeParts[0] + " is null!"); //$NON-NLS-1$ //$NON-NLS-2$ - } - if (!compositeData.containsKey(compositeParts[1])) { - throw new AttributeNotFoundException("Attribute " + dataPath + " not found!"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return compositeData.get(compositeParts[1]); - } else { - return value; - } - } - - // FIXME: Should do a proper match against existing attributes - public static String getAttributeName(String dataPath) { - if (dataPath == null) { - return dataPath; - } - int index = dataPath.indexOf(MRI.VALUE_COMPOSITE_DELIMITER); - if (index >= 0) { - return dataPath.substring(0, index); - } - return dataPath; - } - - public static void setAttribute(MBeanServerConnection connection, MRI attribute, Object value) - throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, - MBeanException, ReflectionException, IOException { - connection.setAttribute(attribute.getObjectName(), new Attribute(attribute.getDataPath(), value)); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AverageTransformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AverageTransformation.java deleted file mode 100644 index e50c6661..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/AverageTransformation.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Properties; - -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Takes an existing attribute as input and creates an averaging transformation. It is possible to - * specify how many samples that should be included in the average. - */ -public class AverageTransformation extends AbstractSingleMRITransformation { - - private int m_maxTerms; - private int m_terms = 0; - private Double m_average = null; - - @Override - public void setProperties(Properties properties) { - super.setProperties(properties); - m_maxTerms = Integer.parseInt(properties.getProperty("terms", "30")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - @Override - public Object createSubscriptionValue(MRIValueEvent event) { - if (event.getValue() instanceof Number) { - double eventValue = ((Number) event.getValue()).doubleValue(); - if (m_average != null) { - if (m_terms < m_maxTerms) { - m_terms += 1; - } - double portion = 1d / m_terms; - m_average = portion * eventValue + (1 - portion) * m_average; - } else { - m_average = eventValue; - m_terms = 1; - } - } - return (m_average == null) ? NO_VALUE : m_average; - } - - @Override - protected String getDisplayNamePattern() { - return String.format(super.getDisplayNamePattern(), m_maxTerms); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ConnectionLostEvent.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ConnectionLostEvent.java deleted file mode 100644 index 52893f40..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ConnectionLostEvent.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Instances of this class are delivered when the subscription thread fails, typically because the - * connection was lost. - */ -public class ConnectionLostEvent extends MRIValueEvent { - - /** - * Constructor. - * - * @param source - * the subscription that failed . - * @param timestamp - * the time the failure occurred. - */ - public ConnectionLostEvent(IMRISubscription source, long timestamp) { - super(source.getMRIMetadata().getMRI(), timestamp, null); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeadlockedThreadCountAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeadlockedThreadCountAttribute.java deleted file mode 100644 index c2f7792c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeadlockedThreadCountAttribute.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.lang.management.ManagementFactory; -import java.util.logging.Level; - -import javax.management.MBeanOperationInfo; -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * Wrapping attribute://java.lang:type=Threading/findDeadlockedThreads invocations as a numeric - * attribute. - */ -public class DeadlockedThreadCountAttribute extends AbstractSyntheticAttribute { - - private static final int METHOD_INVOCATION_ERROR = -1; - private static final int METHOD_NOT_PRESENT = -2; - - // Keep track of if the method is unavailable through reflection so that we can avoid trying to call it - private boolean hasLoggedReflectionError = false; - - @Override - public Object getValue(MBeanServerConnection connection) { - if (hasLoggedReflectionError) { - return METHOD_NOT_PRESENT; - } - return getDeadlockedThreadCount(connection); - } - - private int getDeadlockedThreadCount(MBeanServerConnection connection) { - try { - ObjectName threadMBean = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME); - Object result = connection.invoke(threadMBean, "findDeadlockedThreads", null, null); //$NON-NLS-1$ - if (result != null && result instanceof long[]) { - return ((long[]) result).length; - } - return 0; - } catch (ReflectionException e) { - if (!hasLoggedReflectionError) { - hasLoggedReflectionError = true; - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, - "Unable to find findDeadlockedThreads(). Are you running a JVM version < 1.6?", e); //$NON-NLS-1$ - } - return METHOD_NOT_PRESENT; - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, - "Unable to invoke findDeadlockedThreads(). Are you running a JVM version < 1.6?", e); //$NON-NLS-1$ - return METHOD_INVOCATION_ERROR; - } - } - - @Override - public void setValue(MBeanServerConnection connection, Object value) { - // value can not be set - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - try { - ObjectName threadMBean = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME); - for (MBeanOperationInfo operation : connection.getMBeanInfo(threadMBean).getOperations()) { - if (operation.getName().equals("findDeadlockedThreads") && operation.getSignature().length == 0) { //$NON-NLS-1$ - return true; - } - } - } catch (Exception e) { - } - return false; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscription.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscription.java deleted file mode 100644 index 87945665..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscription.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; - -/** - * The default implementation of an attribute subscription. - */ -public class DefaultAttributeSubscription extends AbstractAttributeSubscription { - public DefaultAttributeSubscription(IConnectionHandle connectionHandle, IMRIMetadata info) { - super(connectionHandle, info); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionService.java deleted file mode 100644 index 399aa0eb..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionService.java +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.internal.IDisposableService; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.IMRIValueListener; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * The default implementation for the attribute subscription service. - */ -public final class DefaultAttributeSubscriptionService - implements ISubscriptionService, IDisposableService, ISubscriptionDebugService { - - // The logger. - private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.subscription"); //$NON-NLS-1$ - - private final IConnectionHandle handle; - - private final Map activeSubscriptions; - // value is either an attribute descriptor or a set of them - private final Map activeListeners; - private final DefaultAttributeSubscriptionThread subscriptionThread; - private final DefaultNotificationSubscriptionManager notificationManager; - - public DefaultAttributeSubscriptionService(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - this.handle = handle; - activeSubscriptions = new HashMap<>(); - activeListeners = new HashMap<>(); - subscriptionThread = new DefaultAttributeSubscriptionThread(handle); - subscriptionThread.start(); - notificationManager = new DefaultNotificationSubscriptionManager(handle); - } - - @Override - public void collectDebugInformation(boolean collect) { - subscriptionThread.collectDebugInformation(collect); - notificationManager.collectDebugInformation(collect); - } - - @Override - public void clearDebugInformation() { - subscriptionThread.clearDebugInformation(); - notificationManager.clearDebugInformation(); - } - - @Override - public Collection getDebugInformation() { - Collection debugInformation = new HashSet<>(); - debugInformation.addAll(subscriptionThread.getDebugInformation()); - debugInformation.addAll(notificationManager.getDebugInformation()); - return debugInformation; - } - - /** - * Adds the given attribute to the given listener's set of attributes. The possible previous - * values are null (no previous attributes), an {@link MRI} (only one attribute) or a - * {@link Set} of attributes. - * - * @param listener - * the listener to add attribute to. - * @param attributeDescriptor - * the attribute to add. - */ - private void addAttributeToListener(IMRIValueListener listener, MRI attributeDescriptor) { - Object listenerAttributes = activeListeners.get(listener); - if (listenerAttributes == null) { - activeListeners.put(listener, attributeDescriptor); - } else if (listenerAttributes instanceof MRI) { - Set attributes = new HashSet<>(5); - attributes.add((MRI) listenerAttributes); - attributes.add(attributeDescriptor); - activeListeners.put(listener, attributes); - } else { - @SuppressWarnings("unchecked") - Set listenerAttributesSet = (Set) listenerAttributes; - listenerAttributesSet.add(attributeDescriptor); - } - } - - /** - * Removes the given attribute from the given listener's set of attributes. The possible - * previous values are null (no previous attributes), an {@link MRI} (only one attribute) or a - * {@link Set} of attributes. Handles the case that given attribute is not part of the previous - * set. - * - * @param listener - * the listener to remove attribute from. - * @param attributeDescriptor - * the attribute to remove. - */ - private void removeAttributeFromListener(IMRIValueListener listener, MRI attributeDescriptor) { - Object listenerAttributes = activeListeners.get(listener); - if (listenerAttributes == null) { - // nothing to do - } else if (listenerAttributes instanceof MRI) { - if (listenerAttributes.equals(attributeDescriptor)) { - activeListeners.remove(listener); - } - } else { - @SuppressWarnings("unchecked") - Set attributes = (Set) listenerAttributes; - attributes.remove(attributeDescriptor); - if (attributes.isEmpty()) { - activeListeners.remove(listener); - } - } - } - - /** - * Returns all present attributes that the given listener is registered on. - * - * @param listener - * the listener to get attributes for. - * @return the current set of attributes. - */ - private MRI[] getListenerAttributes(IMRIValueListener listener) { - Object listenerAttributes = activeListeners.get(listener); - if (listenerAttributes == null) { - return new MRI[0]; - } else if (listenerAttributes instanceof MRI) { - return new MRI[] {(MRI) listenerAttributes}; - } else { - @SuppressWarnings("unchecked") - Set attributes = (Set) listenerAttributes; - return attributes.toArray(new MRI[attributes.size()]); - } - } - - /** - * Answers whether the given listener is registered with the given attribute. - * - * @param listener - * the interesting listener. - * @param attributeDescriptor - * the attribute to search for. - * @return true if the listeners is registered with the attribute, false otherwise. - */ - private boolean listensToAttribute(IMRIValueListener listener, MRI attributeDescriptor) { - Object listenerAttributes = activeListeners.get(listener); - if (listenerAttributes == null) { - return false; - } else if (listenerAttributes instanceof MRI) { - return listenerAttributes.equals(attributeDescriptor); - } else { - @SuppressWarnings("unchecked") - Set listenerAttributesSet = (Set) listenerAttributes; - return listenerAttributesSet.contains(attributeDescriptor); - } - } - - /** - * Adds the given listener to the active subscription with given attribute (possible creating - * it). - * - * @param attributeDescriptor - * the attribute to subscribe on. - * @param listener - * the listener to use. - */ - private void addValueListenerToSubscription(MRI attributeDescriptor, IMRIValueListener listener) { - synchronized (activeSubscriptions) { - AbstractAttributeSubscription activeSubscription = activeSubscriptions.get(attributeDescriptor); - if (activeSubscription == null) { - activeSubscription = createAttributeSubscription(attributeDescriptor); - activeSubscriptions.put(attributeDescriptor, activeSubscription); - } - activeSubscription.addAttributeValueListener(listener); - } - } - - /** - * Substitutes the the listeners on the subscription for given attribute. - * - * @param attributeDescriptor - * the attribute for which it's subscription should be altered. - * @param oldListener - * the listener to remove from the subscription. - * @param newListener - * the listener to add to the subscription. - */ - private void substituteValueListenerForSubscription( - MRI attributeDescriptor, IMRIValueListener oldListener, IMRIValueListener newListener) { - AbstractAttributeSubscription activeSubscription = activeSubscriptions.get(attributeDescriptor); - activeSubscription.substituteAttributeValueListener(oldListener, newListener); - } - - /** - * Remove the given listener from the active subscription with given attribute (possible - * destroying it). - * - * @param attributeDescriptor - * the attribute to stop subscription for. - * @param listener - * the listener to remove. - */ - private void removeValueListenerFromSubscription(MRI attributeDescriptor, IMRIValueListener listener) { - synchronized (activeSubscriptions) { - AbstractAttributeSubscription activeSubscription = activeSubscriptions.get(attributeDescriptor); - activeSubscription.removeAttributeValueListener(listener); - if (!activeSubscription.hasAttributeValueListeners()) { - destroyAttibuteSubscription(activeSubscription); - activeSubscriptions.remove(attributeDescriptor); - } - } - } - - @Override - public void addMRIValueListener(MRI attributeDescriptor, IMRIValueListener listener) { - synchronized (activeListeners) { - if (!listensToAttribute(listener, attributeDescriptor)) { - addValueListenerToSubscription(attributeDescriptor, listener); - addAttributeToListener(listener, attributeDescriptor); - } - } - } - - @Override - public void substituteMRIValueListener(IMRIValueListener oldListener, IMRIValueListener newListener) { - synchronized (activeListeners) { - for (MRI attribute : getListenerAttributes(oldListener)) { - substituteValueListenerForSubscription(attribute, oldListener, newListener); - addAttributeToListener(newListener, attribute); - } - activeListeners.remove(oldListener); - } - } - - @Override - public void removeMRIValueListener(IMRIValueListener listener) { - synchronized (activeListeners) { - for (MRI attribute : getListenerAttributes(listener)) { - removeValueListenerFromSubscription(attribute, listener); - } - activeListeners.remove(listener); - } - } - - @Override - public void removeMRIValueListener(MRI attributeDescriptor, IMRIValueListener listener) { - synchronized (activeListeners) { - if (listensToAttribute(listener, attributeDescriptor)) { - removeValueListenerFromSubscription(attributeDescriptor, listener); - removeAttributeFromListener(listener, attributeDescriptor); - } - } - } - - private void destroyAttibuteSubscription(AbstractAttributeSubscription subscription) { - switch (subscription.getMRIMetadata().getMRI().getType()) { - case ATTRIBUTE: - subscriptionThread.unregisterAttributeSubscription(subscription); - break; - case NOTIFICATION: - notificationManager.unregisterNotificationAttributeSubscription(subscription); - break; - case TRANSFORMATION: - if (subscription instanceof TransformationSubscription) { - ((TransformationSubscription) subscription).unregisterSubscription(); - } - break; - } - if (subscription instanceof IMRIValueListener) { - removeMRIValueListener((IMRIValueListener) subscription); - } - - } - - private AbstractAttributeSubscription createAttributeSubscription(MRI attributeDescriptor) { - if (attributeDescriptor == null) { - throw new IllegalArgumentException("Can not subscribe to null!"); //$NON-NLS-1$ - } - IMRIMetadata attributeInfo = handle.getServiceOrDummy(IMRIMetadataService.class) - .getMetadata(attributeDescriptor); - if (attributeInfo == null) { - throw new IllegalArgumentException("Tried to get an AttributeSubscription for null!"); //$NON-NLS-1$ - } - - LOGGER.finest("Getting subscription for " + attributeDescriptor); //$NON-NLS-1$ - - return createAttributeSubscriptionInternal(attributeInfo); - } - - private AbstractAttributeSubscription createAttributeSubscriptionInternal(IMRIMetadata info) { - if (info.getMRI().getObjectName() == null) { - throw new IllegalArgumentException( - "The attribute name associated with the attribute info must be resolved before being used to create subscriptions."); //$NON-NLS-1$ - } - if (info.getMRI().getType() == Type.TRANSFORMATION) { - IMRITransformation transformation = MRITransformationToolkit.createTransformation(info.getMRI()); - return new TransformationSubscription(handle, info, transformation); - } else { - AbstractAttributeSubscription subscription = new DefaultAttributeSubscription(handle, info); - registerWithSubscriptionManagers(handle, subscription); - return subscription; - } - } - - /** - * Checks if we're connected. If we are, we will check if there is a subscription thread. If - * there is one, the subscription will be registered with it, else a subscription thread will be - * created. If it is a notification based subscription, it will be registered with the - * notification manager instead of the subscription thread. - * - * @param connectionHandle - * @param subscription - */ - private void registerWithSubscriptionManagers( - IConnectionHandle connectionHandle, AbstractAttributeSubscription subscription) { - setUpPolicy(connectionHandle, subscription); - if (!connectionHandle.isConnected()) { - return; - } - if (subscription.getMRIMetadata().getMRI().getType() == Type.NOTIFICATION) { - notificationManager.registerNotificationAttributeSubscription(subscription); - } else { - subscriptionThread.registerAttributeSubscription(subscription); - } - } - - private void setUpPolicy(IConnectionHandle connectionHandle, AbstractAttributeSubscription subscription) { - subscription.setUpdatePolicy( - UpdatePolicyToolkit.getUpdatePolicy(connectionHandle, subscription.getMRIMetadata().getMRI())); - } - - /** - * Will shut down all subscription threads and clear all subscriptions for the the specified - * connector model, and stop listening on changes in the connector model. - *

- * No more events will ever be sent from the subscriptions previously created and associated - * with this service. - */ - @Override - public synchronized void dispose() { - subscriptionThread.shutdown(); - notificationManager.shutdown(); - activeSubscriptions.clear(); - activeListeners.clear(); - } - - @Override - public IMRISubscription getMRISubscription(MRI attributeDescriptor) { - // FIXME: Can be optimized if necessary. - synchronized (activeSubscriptions) { - return activeSubscriptions.get(attributeDescriptor); - } - } - - @Override - public MRIValueEvent getLastMRIValueEvent(MRI attributeDescriptor) { - IMRISubscription subscription = getMRISubscription(attributeDescriptor); - if (subscription != null) { - return subscription.getLastMRIValueEvent(); - } else { - return null; - } - } - - @Override - public boolean isMRIUnavailable(MRI attributeDescriptor) { - return subscriptionThread.isAttributeUnavailable(attributeDescriptor); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionThread.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionThread.java deleted file mode 100644 index 78917f2f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultAttributeSubscriptionThread.java +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.net.ConnectException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Logger; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.services.IAttributeStorageService; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; -import org.openjdk.jmc.rjmx.subscription.internal.IMRISubscriptionDebugInformation.SubscriptionState; - -/** - * This is the core subscription engine. It is responsible for periodically, depending on the policy - * of the AttributeSubscriptions, schedule calls for retrieving the current value of the - * corresponding attribute. - *

- * Note that some attributes are not handled by this subscription thread, for instance notification - * based ones. - */ -public class DefaultAttributeSubscriptionThread extends Thread { - // The logger. - private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.subscription"); //$NON-NLS-1$ - - private final IConnectionHandle connectionHandle; - private IAttributeStorageService attributeStorageService; - private final IMBeanHelperService helperService; - private final MBeanServerConnection server; - private final Map attributeSubscriptions = new HashMap<>(); - - private final Map subscriptionStats = new HashMap<>(); - private volatile boolean isRunning = true; - private long lastTimestamp; - private final static long MAX_SLEEP_TIME = 2000; - private final static long MIN_SLEEP_TIME = 100; - private final Set recentlyAddedSubscriptions = new HashSet<>(); - private final Set recentlyRemovedSubscriptions = new HashSet<>(); - private final UnavailableSubscriptionsRepository unavailableSubscriptionsRepository; - - private boolean sendNulls; - - private volatile boolean collectDebugInfo; - private Map subscriptionDebugInfo; - - public static class SubscriptionStats { - public long lastUpdate = Long.MIN_VALUE; - } - - public DefaultAttributeSubscriptionThread(IConnectionHandle connectionHandle) - throws ConnectionException, ServiceNotAvailableException { - super("RJMX Subscription thread on " + connectionHandle.getServerDescriptor().getDisplayName()); //$NON-NLS-1$ - this.connectionHandle = connectionHandle; - helperService = connectionHandle.getServiceOrThrow(IMBeanHelperService.class); - server = connectionHandle.getServiceOrThrow(MBeanServerConnection.class); - unavailableSubscriptionsRepository = new UnavailableSubscriptionsRepository(connectionHandle); - clearDebugInformation(); - } - - /** - * This is where all the action is. Starting this thread will start the subscription of the - * registered subscriptions. - */ - @Override - public void run() { - while (isRunning) { - unregisterSubscriptionsQueuedForRemove(); - reregisterPreviouslyBadSubscriptions(); - registerSubscriptionsQueuedForAdd(); - long sleepTime = retrieveAndDispatchValues(); - try { - sleep(sleepTime); - } catch (InterruptedException e) { - // We were interrupted - close down shop. - isRunning = false; - } - } - synchronized (recentlyRemovedSubscriptions) { - recentlyRemovedSubscriptions.addAll(attributeSubscriptions.values()); - recentlyRemovedSubscriptions.addAll(unavailableSubscriptionsRepository.getAllSubscriptions()); - unavailableSubscriptionsRepository.dispose(); - } - unregisterSubscriptionsQueuedForRemove(); - } - - private long retrieveAndDispatchValues() { - if (attributeSubscriptions.isEmpty()) { - return MIN_SLEEP_TIME; - } - long now = System.currentTimeMillis(); - long nextUpdate = Long.MAX_VALUE; - List normalAttributes = new ArrayList<>(); - for (AbstractAttributeSubscription subscription : attributeSubscriptions.values()) { - SubscriptionStats stats = subscriptionStats.get(subscription); - long targetTime = subscription.getUpdatePolicy().getNextUpdate(stats.lastUpdate); - if (targetTime <= now) { - normalAttributes.add(subscription.getMRIMetadata().getMRI()); - stats.lastUpdate = now; - targetTime = subscription.getUpdatePolicy().getNextUpdate(now); - } - nextUpdate = Math.min(nextUpdate, targetTime); - } - retrieveAndDispatchNormalAttributes(normalAttributes); - return Math.max(MIN_SLEEP_TIME, Math.min(nextUpdate - now, MAX_SLEEP_TIME)); - } - - private void retrieveAndDispatchNormalAttributes(List normalAttributes) { - // Attempt to retrieve all attributes. - // Will automatically remove all failing attribute subscriptions. - try { - List attributeValues = sampleAttributes(normalAttributes); - dispatchEvents(attributeValues); - if (attributeValues.size() != normalAttributes.size()) { - removeBadAttributes(normalAttributes, attributeValues); - } - } catch (InstanceNotFoundException e) { - searchAndRemoveBadAttributes(normalAttributes); - } catch (ReflectionException e) { - searchAndRemoveBadAttributes(normalAttributes); - } catch (InvoluntaryDisconnectException e) { - LOGGER.warning("Subscription thread is terminating due to loss of connection!"); //$NON-NLS-1$ - dispatchConnectionLostEvents(); - shutdown(); - } catch (ConnectException e) { - LOGGER.warning("Subscription thread is terminating due to loss of connection!"); //$NON-NLS-1$ - dispatchConnectionLostEvents(); - shutdown(); - } catch (IOException e) { - searchAndRemoveBadAttributes(normalAttributes); - } catch (RuntimeException e) { - if (isRunning) { - throw e; - } else { - LOGGER.fine("Failed to get attributes, probably since the subscription thread is terminating"); //$NON-NLS-1$ - } - } - } - - private List sampleAttributes(Iterable attributes) - throws IOException, InstanceNotFoundException, ReflectionException { - long before = System.currentTimeMillis(); - Map values = AttributeValueToolkit.getAttributes(server, attributes); - // FIXME: JMC-4270 - Server time approximation is not reliable -// long timestamp = helperService.getApproximateServerTime((System.currentTimeMillis() + before) / 2); - long timestamp = (System.currentTimeMillis() + before) / 2; - - List results = new ArrayList<>(); - for (Entry entry : values.entrySet()) { - results.add(new MRIValueEvent(entry.getKey(), timestamp, entry.getValue())); - } - return results; - } - - private void dispatchConnectionLostEvents() { - for (AbstractAttributeSubscription subscription : attributeSubscriptions.values()) { - // Desperate times call for desperate measures. We time stamp these with the client system time. - ConnectionLostEvent event = new ConnectionLostEvent(subscription, System.currentTimeMillis()); - subscription.storeAndFireEvent(event); - } - } - - /** - * @return the connection handle associated with this subscription thread. - */ - public IConnectionHandle getConnectionHandle() { - return connectionHandle; - } - - /** - * @param subscription - * the subscription to register. - */ - public void registerAttributeSubscription(IMRISubscription subscription) { - if (!(subscription instanceof AbstractAttributeSubscription)) { - throw new IllegalArgumentException( - "This version of the subscription service can only handle AbstractAttributeSubscriptions."); //$NON-NLS-1$ - } - synchronized (recentlyAddedSubscriptions) { - recentlyAddedSubscriptions.add((AbstractAttributeSubscription) subscription); - } - } - - /** - * This method is only to be called from the subscription thread! - */ - private void registerSubscriptionsQueuedForAdd() { - if (Thread.currentThread() != this) { - LOGGER.warning("registerQueuedSubscriptions abused in DefaultAttributeSubscriptionThread!"); //$NON-NLS-1$ - } - - List recentlyAdded = new ArrayList<>(); - synchronized (recentlyAddedSubscriptions) { - recentlyAdded.addAll(recentlyAddedSubscriptions); - recentlyAddedSubscriptions.clear(); - } - - for (AbstractAttributeSubscription subscription : recentlyAdded) { - registerSubscription(subscription); - } - } - - private void registerSubscription(AbstractAttributeSubscription subscription) { - if (subscriptionStats.get(subscription) == null) { - sendNull(subscription); - attributeSubscriptions.put(subscription.getMRIMetadata().getMRI(), subscription); - recordConnected(subscription.getMRIMetadata().getMRI()); - subscriptionStats.put(subscription, new SubscriptionStats()); - } - } - - /** - * This method is only to be called from the subscription thread! - */ - private void unregisterSubscriptionsQueuedForRemove() { - if (Thread.currentThread() != this) { - LOGGER.warning("unregisterQueuedSubscriptions abused in DefaultAttributeSubscriptionThread!"); //$NON-NLS-1$ - } - - List recentlyRemoved = new ArrayList<>(); - synchronized (recentlyRemovedSubscriptions) { - if (recentlyRemovedSubscriptions.isEmpty()) { - return; - } - recentlyRemoved.addAll(recentlyRemovedSubscriptions); - recentlyRemovedSubscriptions.clear(); - } - for (AbstractAttributeSubscription subscription : recentlyRemoved) { - unregisterSubscription(subscription); - recordDisconnected(subscription.getMRIMetadata().getMRI()); - unavailableSubscriptionsRepository.remove(subscription); - } - } - - private void unregisterSubscription(AbstractAttributeSubscription subscription) { - if (subscriptionStats.get(subscription) != null) { - attributeSubscriptions.remove(subscription.getMRIMetadata().getMRI()); - subscriptionStats.remove(subscription); - sendNull(subscription); - } - } - - private void sendNull(AbstractAttributeSubscription subscription) { - if (isSendNulls()) { - if (getLastTimestamp() == 0) { - // FIXME: JMC-4270 - Server time approximation is not reliable -// setLastTimestamp(helperService.getApproximateServerTime(System.currentTimeMillis())); - setLastTimestamp(System.currentTimeMillis()); - } - subscription.storeAndFireEvent( - new MRIValueEvent(subscription.getMRIMetadata().getMRI(), getLastTimestamp(), null)); - } - } - - /** - * Check if we can now add back subscriptions gone bad. - */ - private void reregisterPreviouslyBadSubscriptions() { - for (AbstractAttributeSubscription subscription : unavailableSubscriptionsRepository - .getBackoffedSubscriptions()) { - if (hasSubscriptionBecomeAvailable(subscription)) { - recordSucceededReconnection(subscription.getMRIMetadata().getMRI()); - registerSubscription(subscription); - unavailableSubscriptionsRepository.remove(subscription); - subscription.fireAttributeChange(new AttributeReregisteredEvent(subscription, getLastTimestamp())); - } - } - } - - private boolean hasSubscriptionBecomeAvailable(AbstractAttributeSubscription subscription) { - return getBadAttributeError(subscription.getMRIMetadata().getMRI()) == null; - } - - /** - * @param subscription - * the subscription to unregister. - */ - public void unregisterAttributeSubscription(IMRISubscription subscription) { - if (!(subscription instanceof AbstractAttributeSubscription)) { - throw new IllegalArgumentException( - "This version of the subscription service can only handle AbstractAttributeSubscriptions."); //$NON-NLS-1$ - } - synchronized (recentlyRemovedSubscriptions) { - recentlyRemovedSubscriptions.add((AbstractAttributeSubscription) subscription); - } - } - - /** - * - */ - public void shutdown() { - isRunning = false; - interrupt(); - } - - /** - * Tests each individual attribute in the list and removes any subscriptions that corresponds to - * attributes that it fails to access. - * - * @param attributesToFetch - * A list of MRI objects to test. - */ - private void searchAndRemoveBadAttributes(List attributesToFetch) { - for (MRI mri : attributesToFetch) { - if (!getConnectionHandle().isConnected()) { - return; - } - Exception e = getBadAttributeError(mri); - if (e != null) { - recordConnectionLost(mri); - removeBadAttribute(mri, e); - } else { - recordEventPolled(mri); - } - } - } - - /** - * Searches through the wanted and returned attributes to find which attributes where - * unavailable. - * - * @param attributesToFetch - * the attributes that where requested - * @param returnedAttributeValues - * the attribute values that where returned - */ - private void removeBadAttributes(List attributesToFetch, List returnedAttributeValues) { - int missing = attributesToFetch.size() - returnedAttributeValues.size(); - for (MRI attributeToFetch : attributesToFetch) { - boolean found = false; - for (MRIValueEvent returnedAttributeValue : returnedAttributeValues) { - if (attributeToFetch.equals(returnedAttributeValue.getMRI())) { - found = true; - break; - } - } - if (!found) { - recordConnectionLost(attributeToFetch); - removeBadAttribute(attributeToFetch, null); - missing -= 1; - if (missing <= 0) { - return; - } - } - } - } - - private void logError(Exception e, MRI mri) { - LOGGER.info("The attribute " + mri //$NON-NLS-1$ - + " could not be found in the specified JVM, and has been removed from the subscription engine!"); //$NON-NLS-1$ - } - - private void removeBadAttribute(MRI mri, Exception e) { - AbstractAttributeSubscription subscription = getSubscription(mri); - unregisterSubscription(subscription); - unavailableSubscriptionsRepository.add(subscription); - subscription.fireAttributeChange(new AttributeExceptionEvent(subscription, getLastTimestamp(), e)); - logError(e, mri); - } - - /** - * Note that we can not use the subscription service for this as we may deadlock! - * - * @param mri - * @return - */ - private AbstractAttributeSubscription getSubscription(MRI mri) { - return attributeSubscriptions.get(mri); - } - - /** - * Tries retrieving an attribute and returns any exceptions caused by the operation, or null if - * the retrieval went ok. - * - * @param mri - * The attribute to test. - * @return true if the attribute is bad, false if it is seemingly ok. - */ - private Exception getBadAttributeError(MRI mri) { - try { - recordTriedReconnection(mri); - helperService.getAttributeValue(mri); - return null; - } catch (Exception e) { - return e; - } - } - - private void dispatchEvents(List timestampedDataList) { - for (MRIValueEvent event : timestampedDataList) { - AbstractAttributeSubscription subscription = getSubscription(event.getMRI()); - setLastTimestamp(Math.max(event.getTimestamp(), getLastTimestamp())); - recordEventRecieved(event); - subscription.storeAndFireEvent(event); - } - } - - public boolean isAttributeUnavailable(MRI descriptor) { - return unavailableSubscriptionsRepository.contains(descriptor); - } - - public synchronized long getLastTimestamp() { - return lastTimestamp; - } - - public synchronized void setLastTimestamp(long timestamp) { - lastTimestamp = timestamp; - } - - public void setSendNulls(boolean sendNulls) { - this.sendNulls = sendNulls; - } - - public boolean isSendNulls() { - return sendNulls; - } - - public void collectDebugInformation(boolean collect) { - collectDebugInfo = collect; - } - - public void clearDebugInformation() { - subscriptionDebugInfo = new HashMap<>(); - } - - public Collection getDebugInformation() { - return subscriptionDebugInfo.values(); - } - - private void recordConnected(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.SUBSCRIBED); - info.m_connectionCount += 1; - } - } - - private void recordDisconnected(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.UNSUBSCRIBED); - info.m_disconnectionCount += 1; - } - } - - private void recordEventRecieved(MRIValueEvent event) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(event.getMRI(), - SubscriptionState.SUBSCRIBED); - info.m_eventCount += 1; - info.m_lastEvent = event; - info.m_retainedEventCount = getRetainedLength(event.getMRI()); - } - } - - private int getRetainedLength(MRI mri) { - if (attributeStorageService == null) { - attributeStorageService = getConnectionHandle().getServiceOrNull(IAttributeStorageService.class); - } - if (attributeStorageService != null) { - return attributeStorageService.getRetainedLength(mri); - } - return 0; - } - - private void recordEventPolled(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.SUBSCRIBED); - info.m_eventCount += 1; - info.m_retainedEventCount = getRetainedLength(mri); - } - } - - private void recordConnectionLost(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.LOST); - info.m_connectionLostCount += 1; - } - } - - private void recordTriedReconnection(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.LOST); - info.m_triedReconnectionCount += 1; - } - } - - private void recordSucceededReconnection(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.SUBSCRIBED); - info.m_succeededReconnectionCount += 1; - } - } - - private DefaultSubscriptionDebugInformation getDebugInformation(MRI attribute, SubscriptionState state) { - synchronized (subscriptionDebugInfo) { - DefaultSubscriptionDebugInformation info = subscriptionDebugInfo.get(attribute); - if (info == null) { - info = new DefaultSubscriptionDebugInformation(attribute, state); - subscriptionDebugInfo.put(attribute, info); - } else { - info.m_state = state; - } - return info; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultMRIMetadataService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultMRIMetadataService.java deleted file mode 100644 index bee20273..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultMRIMetadataService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Map; -import java.util.Observable; -import java.util.Observer; - -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.internal.IDisposableService; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMBeanServerChangeListener; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * This is the default implementation of the metadata service. - */ -public final class DefaultMRIMetadataService extends Observable implements IMRIMetadataService, IDisposableService { - - private final Observer metadataObserver; - private final IMBeanHelperService mbeanService; - private final IMBeanServerChangeListener mbeanListener = new IMBeanServerChangeListener() { - - @Override - public void mbeanUnregistered(ObjectName mbean) { - metadataObserver.update(null, mbean); - } - - @Override - public void mbeanRegistered(ObjectName mbean) { - metadataObserver.update(null, mbean); - } - }; - - /** - * Constructor. - * - * @throws ServiceException - */ - public DefaultMRIMetadataService(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - metadataObserver = createMetadataObserver(); - getGlobalService().addObserver(metadataObserver); - mbeanService = handle.getServiceOrThrow(IMBeanHelperService.class); - mbeanService.addMBeanServerChangeListener(mbeanListener); - } - - @Override - public IMRIMetadata getMetadata(MRI mri) { - return new MRIMetadataWrapper(mri, this); - } - - @Override - public Object getMetadata(MRI mri, String dataKey) { - Object md = getGlobalService().getMetadata(mri, dataKey); - if (md != null) { - return md; - } - Map mriMetadata = mbeanService.getMBeanMetadata(mri.getObjectName()).get(mri); - return mriMetadata != null ? mriMetadata.get(dataKey) : null; - } - - @Override - public void setMetadata(MRI mri, String dataKey, String data) { - getGlobalService().setMetadata(mri, dataKey, data); - } - - @Override - public void dispose() { - mbeanService.removeMBeanServerChangeListener(mbeanListener); - getGlobalService().deleteObserver(metadataObserver); - } - - private static IMRIMetadataService getGlobalService() { - return RJMXPlugin.getDefault().getService(IMRIMetadataService.class); - } - - private Observer createMetadataObserver() { - return new Observer() { - @Override - public void update(Observable o, Object arg) { - setChanged(); - notifyObservers(arg); - } - }; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultNotificationSubscriptionManager.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultNotificationSubscriptionManager.java deleted file mode 100644 index 9d1b85e5..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultNotificationSubscriptionManager.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.management.AttributeNotFoundException; -import javax.management.JMException; -import javax.management.MBeanServerConnection; -import javax.management.MalformedObjectNameException; -import javax.management.Notification; -import javax.management.NotificationFilterSupport; -import javax.management.NotificationListener; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; -import org.openjdk.jmc.rjmx.subscription.internal.IMRISubscriptionDebugInformation.SubscriptionState; - -/** - * Handles the notification based subscriptions. Since we're relying on the MBeanServerConnection to - * deliver the events to us, this is not running in a separate thread. Hence the name "Manager". - */ -// FIXME: The Notification manager will currently not send out any null events on creation/destruction. -public final class DefaultNotificationSubscriptionManager { - // The logger. - private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.subscription"); //$NON-NLS-1$ - - // NOTE: Commented out because only used by commented out code in handleNotification -// private final IMBeanHelperService service; - private final MBeanServerConnection mbeanServer; - - private volatile boolean collectDebugInfo; - private Map subscriptionDebugInfo; - - /** - * HashSet used to keep track of what NotificationHandlers have been registered, to avoid too - * many registrations or too many deletions. - */ - private final Map registeredHandlers = Collections - .synchronizedMap(new HashMap()); - - /** - * An instance of this class is used to intercept a certain notification attribute. - */ - private class NotificationHandler implements NotificationListener { - private final AbstractAttributeSubscription m_subscription; - private final NotificationFilterSupport m_filter; - - /** - * Constructor. - * - * @param subscription - * the subscription that this notification handler corresponds to. - */ - public NotificationHandler(AbstractAttributeSubscription subscription) { - m_subscription = subscription; - String type = AttributeValueToolkit.getAttributeName(subscription.getMRIMetadata().getMRI().getDataPath()); - m_filter = new NotificationFilterSupport(); - m_filter.enableType(type); - } - - /** - * @throws MalformedObjectNameException - * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, - * java.lang.Object) - */ - @Override - public void handleNotification(Notification notification, Object callbackObj) { - if (registeredHandlers.isEmpty()) { - return; - } - try { - MRI mri = m_subscription.getMRIMetadata().getMRI(); - String dataPath = mri.getDataPath(); - Object value = AttributeValueToolkit.lookupValue(dataPath, notification.getUserData()); - // FIXME: JMC-4270 - Server time approximation is not reliable -// MRIValueEvent event = new MRIValueEvent(mri, -// service.getApproximateServerTime(System.currentTimeMillis()), value); - MRIValueEvent event = new MRIValueEvent(mri, System.currentTimeMillis(), value); - recordEventRecieved(event); - m_subscription.storeAndFireEvent(event); - } catch (AttributeNotFoundException e) { - LOGGER.log(Level.WARNING, "Notification object doesn't match declared structure.", e); //$NON-NLS-1$ - } - } - - /** - * Registers this notification handler with the MBeanServerConnection, effectively starting - * the subscription. - */ - public void registerWithMBeanServer() { - // Ensure that the handler has not been successfully registered yet - try { - IMRIMetadata info = m_subscription.getMRIMetadata(); - LOGGER.log(Level.FINE, "Adding listener " + info); //$NON-NLS-1$ - mbeanServer.addNotificationListener(info.getMRI().getObjectName(), this, m_filter, null); - recordConnected(info.getMRI()); - } catch (IOException e) { - // Silently fail. We we're probably just disconnected. - LOGGER.log(Level.INFO, "Exception occured when registering notification handler.", e); //$NON-NLS-1$ - } catch (JMException e) { - // Debug.exception(e); - LOGGER.log(Level.WARNING, "Exception occured when registering notification handler.", e); //$NON-NLS-1$ - } - } - - /** - * @param info - */ - private void unregisterWithMBeanServer() { - // Ensure that this handler is really successfully registered, - // before trying to unregister it - IMRIMetadata info = m_subscription.getMRIMetadata(); - try { - mbeanServer.removeNotificationListener(info.getMRI().getObjectName(), this, m_filter, null); - } catch (JMException e) { - // Ignore. Was most likely removed with other filter. - LOGGER.log(Level.FINEST, - "Got exception whilst removing notification listener. It was most likely already removed by some other handler.", //$NON-NLS-1$ - e); - } catch (IOException e) { - // Silently fail. Connection is down. - LOGGER.log(Level.FINER, - "Got exception whilst shutting down notification listeners. We were probably disconnected too early!", //$NON-NLS-1$ - e); - } - recordDisconnected(info.getMRI()); - } - } - - public DefaultNotificationSubscriptionManager(IConnectionHandle handle) - throws ConnectionException, ServiceNotAvailableException { - mbeanServer = handle.getServiceOrThrow(MBeanServerConnection.class); - // NOTE: Commented out because only used by commented out code in handleNotification -// service = handle.getServiceOrThrow(IMBeanHelperService.class); - clearDebugInformation(); - } - - public void shutdown() { - // Unregister all the handlers... - NotificationHandler[] handlers; - synchronized (registeredHandlers) { - Collection handlersCol = registeredHandlers.values(); - handlers = handlersCol.toArray(new NotificationHandler[handlersCol.size()]); - registeredHandlers.clear(); - } - for (NotificationHandler handler : handlers) { - handler.unregisterWithMBeanServer(); - } - - } - - public void registerNotificationAttributeSubscription(AbstractAttributeSubscription attributeSubscription) { - if (attributeSubscription.getMRIMetadata().getMRI().getType() != Type.NOTIFICATION) { - throw new IllegalArgumentException( - "This subscription manager only handles notification based attributes that extends AbstractAttributeSubscription."); //$NON-NLS-1$ - } - NotificationHandler handler = new NotificationHandler(attributeSubscription); - handler.registerWithMBeanServer(); - NotificationHandler oldHandler = registeredHandlers.put(attributeSubscription, handler); - if (oldHandler != null) { - oldHandler.unregisterWithMBeanServer(); - } - } - - public void unregisterNotificationAttributeSubscription(IMRISubscription attributeSubscription) { - NotificationHandler handler = registeredHandlers.remove(attributeSubscription); - if (handler != null) { - handler.unregisterWithMBeanServer(); - } - } - - public void collectDebugInformation(boolean collect) { - collectDebugInfo = collect; - } - - public void clearDebugInformation() { - subscriptionDebugInfo = new HashMap<>(); - } - - public Collection getDebugInformation() { - return subscriptionDebugInfo.values(); - } - - private void recordConnected(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.SUBSCRIBED); - info.m_connectionCount += 1; - } - } - - private void recordDisconnected(MRI mri) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(mri, SubscriptionState.UNSUBSCRIBED); - info.m_disconnectionCount += 1; - } - } - - private void recordEventRecieved(MRIValueEvent event) { - if (collectDebugInfo) { - DefaultSubscriptionDebugInformation info = getDebugInformation(event.getMRI(), - SubscriptionState.SUBSCRIBED); - info.m_eventCount += 1; - info.m_lastEvent = event; - } - } - - private DefaultSubscriptionDebugInformation getDebugInformation(MRI attribute, SubscriptionState state) { - synchronized (subscriptionDebugInfo) { - DefaultSubscriptionDebugInformation info = subscriptionDebugInfo.get(attribute); - if (info == null) { - info = new DefaultSubscriptionDebugInformation(attribute, state); - subscriptionDebugInfo.put(attribute, info); - } else { - info.m_state = state; - } - return info; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultSubscriptionDebugInformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultSubscriptionDebugInformation.java deleted file mode 100644 index 482b47d3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultSubscriptionDebugInformation.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -public class DefaultSubscriptionDebugInformation implements IMRISubscriptionDebugInformation { - - public MRI m_mri; - public SubscriptionState m_state; - public int m_connectionCount; - public int m_disconnectionCount; - public int m_eventCount; - public int m_retainedEventCount; - public MRIValueEvent m_lastEvent; - public int m_connectionLostCount; - public int m_triedReconnectionCount; - public int m_succeededReconnectionCount; - - public DefaultSubscriptionDebugInformation(MRI mri, SubscriptionState state) { - m_mri = mri; - m_state = state; - } - - @Override - public MRI getMRI() { - return m_mri; - } - - @Override - public SubscriptionState getState() { - return m_state; - } - - @Override - public int getConnectionCount() { - return m_connectionCount; - } - - @Override - public int getDisconnectionCount() { - return m_disconnectionCount; - } - - @Override - public int getEventCount() { - return m_eventCount; - } - - @Override - public int getRetainedEventCount() { - return m_retainedEventCount; - } - - @Override - public MRIValueEvent getLastEvent() { - return m_lastEvent; - } - - @Override - public int getConnectionLostCount() { - return m_connectionLostCount; - } - - @Override - public int getTriedReconnectionsCount() { - return m_triedReconnectionCount; - } - - @Override - public int getSucceededReconnectionsCount() { - return m_succeededReconnectionCount; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultUpdatePolicy.java deleted file mode 100644 index f71b841a..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DefaultUpdatePolicy.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; - -/** - * Policy that updates the {@link IMRISubscription} with the default update interval. - */ -final public class DefaultUpdatePolicy extends AbstractUpdatePolicy implements IIntervalUpdatePolicy { - - private DefaultUpdatePolicy() { - // don't instantiate - } - - @Override - public long getFollowingUpdate(long lastUpdate) { - int updateInterval = getIntervalTime(); - // Place the following update on a multiple of the update interval to synchronize retrieval - return lastUpdate - lastUpdate % updateInterval + updateInterval; - } - - @Override - protected long getFirstUpdate(long now) { - return now; - } - - public static IUpdatePolicy newPolicy() { - return new DefaultUpdatePolicy(); - } - - @Override - public int getIntervalTime() { - return UpdatePolicyToolkit.getDefaultUpdateInterval(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeltaTransformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeltaTransformation.java deleted file mode 100644 index 621e93f5..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DeltaTransformation.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * A delta transformation. Will keep track of a relative offset and return numerical values relative - * this offset. - */ -public class DeltaTransformation extends AbstractSingleMRITransformation { - - private Number m_offset; - - @Override - public Object createSubscriptionValue(MRIValueEvent event) { - Object value = event.getValue(); - if (value instanceof Number) { - if (m_offset == null) { - m_offset = (Number) value; - } - return subtract((Number) value, m_offset); - } - return NO_VALUE; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceAttribute.java deleted file mode 100644 index a39070eb..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceAttribute.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Map; - -import javax.management.AttributeNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -/** - * A synthetic attribute calculated as a difference between the specified minuend and subtrahend. - */ -public class DifferenceAttribute extends AbstractPropertySyntheticAttribute { - - private static String MINUEND = "minuend"; //$NON-NLS-1$ - private static String SUBTRAHEND = "subtrahend"; //$NON-NLS-1$ - - @Override - public Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException { - Map values = getPropertyAttributes(connection, new String[] {MINUEND, SUBTRAHEND}); - return getMinuend(values) - getSubtrahend(values); - } - - private double getMinuend(Map values) throws MBeanException { - return getDouble(values, MINUEND); - } - - private double getSubtrahend(Map values) throws MBeanException { - return getDouble(values, SUBTRAHEND); - } - - private double getDouble(Map values, String key) throws MBeanException { - if (!values.containsKey(key)) { - try { - throw new AttributeNotFoundException("Attribute " + key + " not found!"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (AttributeNotFoundException e) { - throw new MBeanException(e); - } - } - return ((Number) values.get(key)).doubleValue(); - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return hasResolvedAttribute(connection, MINUEND) && hasResolvedAttribute(connection, SUBTRAHEND); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceTransformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceTransformation.java deleted file mode 100644 index 6f6a8f8d..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DifferenceTransformation.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Properties; - -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * A difference transformation. Will keep track of the last value and on each update return the - * difference between the current and last value. - */ -public class DifferenceTransformation extends AbstractSingleMRITransformation { - - private MRIValueEvent m_lastAttributeEvent; - private long m_rateMS; - - @Override - public void setProperties(Properties properties) { - super.setProperties(properties); - m_rateMS = Long.parseLong(properties.getProperty("rate", "0")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - @Override - public Object createSubscriptionValue(MRIValueEvent event) { - Object lastValue = null; - if (m_lastAttributeEvent != null) { - lastValue = m_lastAttributeEvent.getValue(); - } - Object value = event.getValue(); - Number eventValue = null; - if (value instanceof Number && lastValue instanceof Number) { - eventValue = subtract((Number) value, (Number) lastValue); - if (m_rateMS > 0) { - eventValue = eventValue.doubleValue() * m_rateMS - / (event.getTimestamp() - m_lastAttributeEvent.getTimestamp()); - } - } - m_lastAttributeEvent = event; - return (eventValue == null) ? NO_VALUE : eventValue; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DivisionAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DivisionAttribute.java deleted file mode 100644 index 3162abbf..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/DivisionAttribute.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Map; - -import javax.management.AttributeNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -/** - * A synthetic attribute calculated as a division between the specified dividend and divisor. - */ -public class DivisionAttribute extends AbstractPropertySyntheticAttribute { - - private static final String DIVIDEND = "dividend"; //$NON-NLS-1$ - private static final String DIVISOR = "divisor"; //$NON-NLS-1$ - private static final String FACTOR = "factor"; //$NON-NLS-1$ - - @Override - public Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException { - Map values = getPropertyAttributes(connection, new String[] {DIVIDEND, DIVISOR}); - return getDividend(values) / getDivisor(values) * getFactor(); - } - - private double getDividend(Map values) throws MBeanException { - return getDouble(values, DIVIDEND); - } - - private double getDivisor(Map values) throws MBeanException { - return getDouble(values, DIVISOR); - } - - private double getDouble(Map values, String key) throws MBeanException { - if (!values.containsKey(key)) { - try { - throw new AttributeNotFoundException("Attribute " + key + " not found!"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (AttributeNotFoundException e) { - throw new MBeanException(e); - } - } - return ((Number) values.get(key)).doubleValue(); - } - - private double getFactor() { - if (!hasFactor()) { - return 1; - } - return ((Number) getProperty(FACTOR)).doubleValue(); - } - - private boolean hasFactor() { - Object value = getProperty(FACTOR); - return value != null && value instanceof Number; - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return hasResolvedAttribute(connection, DIVIDEND) && hasResolvedAttribute(connection, DIVISOR); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtendedMRIMetadataToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtendedMRIMetadataToolkit.java deleted file mode 100644 index 339a504f..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtendedMRIMetadataToolkit.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.common.unit.IUnit; -import org.openjdk.jmc.common.unit.UnitLookup; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * Helper class for extracting some commonly used metadata from the {@link IMRIMetadataService} that - * we currently want to expose to third party. - */ -public final class ExtendedMRIMetadataToolkit { - - private ExtendedMRIMetadataToolkit() { - throw new AssertionError("This is a toolkit! Do not instantiate!"); //$NON-NLS-1$ - } - - private static Object getMetadata(IConnectionHandle handle, MRI descriptor, String property) { - IMRIMetadataService infoService = handle.getServiceOrNull(IMRIMetadataService.class); - if (infoService != null) { - return infoService.getMetadata(descriptor, property); - } - return null; - } - - public static IUnit getUnit(IConnectionHandle handle, MRI mri) { - return UnitLookup.getUnitOrNull((String) getMetadata(handle, mri, IMRIMetadataProvider.KEY_UNIT_STRING)); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtensionMetadataProviderService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtensionMetadataProviderService.java deleted file mode 100644 index 18963148..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ExtensionMetadataProviderService.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProviderService; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * The holder of the metadata providers. Should typically not return metadata until all plug-ins are - * loaded... - */ -public class ExtensionMetadataProviderService implements IMRIMetadataProviderService { - - private boolean m_hasInitializedExtensions = false; - private final List m_providers = new ArrayList<>(); - - private synchronized void checkExtenstionsInitialized() { - if (!m_hasInitializedExtensions) { - initializeFromExtensions(); - m_hasInitializedExtensions = true; - } - } - - private void initializeFromExtensions() { - // None registered - } - - @Override - public Object getMetadata(IMRIMetadataService metadataService, MRI mri, String dataKey) { - checkExtenstionsInitialized(); - for (IMRIMetadataProviderService providerService : m_providers) { - Object value = providerService.getMetadata(metadataService, mri, dataKey); - if (value != null) { - return value; - } - } - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadata.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadata.java deleted file mode 100644 index b585579b..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadata.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.openjdk.jmc.common.util.XmlToolkit; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; -import org.openjdk.jmc.rjmx.subscription.MRIMetadataToolkit; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * This class is used to read the default metadata from the mrimetadata.xml file. - */ -class FileMRIMetadata { - private static final String ELEMENT_METADATA_COLLECTION = "metadatacollection"; //$NON-NLS-1$ - private static final String ELEMENT_METADATA = "metadata"; //$NON-NLS-1$ - private static final String ELEMENT_MRI_DATA_PATH = "mri.dataPath"; //$NON-NLS-1$ - private static final String ELEMENT_MRI_OBJECT_NAME = "mri.objectName"; //$NON-NLS-1$ - private static final String ELEMENT_MRI_TYPE = "mri.type"; //$NON-NLS-1$ - private static final String ELEMENT_MRI_QUALIFIED_NAME = "mri.qualifiedName"; //$NON-NLS-1$ - private static final String ELEMENT_DISPLAY_NAME = "displayname"; //$NON-NLS-1$ - private static final String ELEMENT_DESCRIPTION = "description"; //$NON-NLS-1$ - private static final String ELEMENT_UPDATE_TIME = "updatetime"; //$NON-NLS-1$ - private static final String ELEMENT_UNIT_STRING = "unitstring"; //$NON-NLS-1$ - private static final String ELEMENT_COMPOSITE = "composite"; //$NON-NLS-1$ - private static final String ELEMENT_TYPE = "type"; //$NON-NLS-1$ - private static final String ELEMENT_ARGUMENTS = "arguments"; //$NON-NLS-1$ - private static final String DEFAULT_DISPLAY_NAME = "No name"; //$NON-NLS-1$ - private static final String DEFAULT_DESCRIPTION = "This attribute has no extended description"; //$NON-NLS-1$ - - // The logger. - private static final Logger LOGGER = Logger.getLogger("org.openjdk.jmc.rjmx.subscription"); //$NON-NLS-1$ - - private final Map> metadataMap = new HashMap<>(); - - static Map> readDefaultsFromFile() { - FileMRIMetadata metadataLoader = new FileMRIMetadata(); - try (InputStream is = FileMRIMetadata.class.getResourceAsStream("mrimetadata.xml")) { //$NON-NLS-1$ - Document doc = XmlToolkit.loadDocumentFromStream(is); - List elems = XmlToolkit.getChildElementsByTag(doc.getDocumentElement(), - ELEMENT_METADATA_COLLECTION); - if (elems.size() != 1 || elems.get(0) == null) { - throw new Exception("Could not find the attributes element!"); //$NON-NLS-1$ - } - for (Element e : XmlToolkit.getChildElementsByTag(elems.get(0), FileMRIMetadata.ELEMENT_METADATA)) { - try { - metadataLoader.loadMetadataElement(e); - } catch (Exception e1) { - LOGGER.log(Level.WARNING, "Malformed descriptor in mrimetadata.xml, skipping metadata", e1); //$NON-NLS-1$ - } - } - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Tried reading mrimetadata.xml, but an exception occurred: " + e.getMessage() //$NON-NLS-1$ - + "Extended information about attributes may not be available, " //$NON-NLS-1$ - + "and the console will not operate optimally.", e); //$NON-NLS-1$ - } - return metadataLoader.metadataMap; - } - - private void loadMetadataElement(Element e) { - String mriType = XmlToolkit.getSetting(e, ELEMENT_MRI_TYPE, Type.ATTRIBUTE.getTypeName()); - String mriDataPath = XmlToolkit.getSetting(e, ELEMENT_MRI_DATA_PATH, null); - String mriObjectName = XmlToolkit.getSetting(e, ELEMENT_MRI_OBJECT_NAME, null); - String mriQualifiedName = XmlToolkit.getSetting(e, ELEMENT_MRI_QUALIFIED_NAME, null); - - if ((mriDataPath == null || mriObjectName == null) && mriQualifiedName == null) { - LOGGER.warning("Could not read metadata information properly. [dataPath=" + mriDataPath + ",objectName=" //$NON-NLS-1$ //$NON-NLS-2$ - + mriObjectName + "|qualifiedName=null] will not be properly configured."); //$NON-NLS-1$ - return; - } - MRI mri = mriQualifiedName != null ? MRI.createFromQualifiedName(mriQualifiedName) - : new MRI(Type.fromString(mriType), mriObjectName, mriDataPath); - putMetadataForElement(mri, e); - String updateTime = XmlToolkit.getSetting(e, ELEMENT_UPDATE_TIME, null); - putValue(mri, IMRIMetadataProvider.KEY_UPDATE_TIME, updateTime); - - boolean hasCompositeTag = XmlToolkit.getChildElementOrNull(e, ELEMENT_COMPOSITE) != null; - if (hasCompositeTag) { - String rootName = mri.getDataPath() + MRI.VALUE_COMPOSITE_DELIMITER_STRING; - for (Element childElement : XmlToolkit.getChildElementsByTag(e, FileMRIMetadata.ELEMENT_METADATA)) { - String childDataPath = XmlToolkit.getSetting(childElement, FileMRIMetadata.ELEMENT_MRI_DATA_PATH, ""); //$NON-NLS-1$ - MRI childMri = new MRI(mri.getType(), mri.getObjectName(), rootName + childDataPath); - putMetadataForElement(childMri, childElement); - putValue(childMri, IMRIMetadataProvider.KEY_UPDATE_TIME, updateTime); - } - } - } - - private void putMetadataForElement(MRI mri, Element e) { - putValue(mri, IMRIMetadataProvider.KEY_DISPLAY_NAME, - XmlToolkit.getSetting(e, ELEMENT_DISPLAY_NAME, DEFAULT_DISPLAY_NAME)); - putValue(mri, IMRIMetadataProvider.KEY_DESCRIPTION, - XmlToolkit.getSetting(e, ELEMENT_DESCRIPTION, DEFAULT_DESCRIPTION)); - String unitString = XmlToolkit.getSetting(e, ELEMENT_UNIT_STRING, null); - putValue(mri, IMRIMetadataProvider.KEY_UNIT_STRING, unitString); - String valueType = XmlToolkit.getSetting(e, ELEMENT_TYPE, null); - putValue(mri, IMRIMetadataProvider.KEY_VALUE_TYPE, valueType); - if (MRIMetadataToolkit.isNumerical(valueType) && unitString == null) { - LOGGER.warning("Unit is missing for " + mri); //$NON-NLS-1$ - } - List propsList = XmlToolkit.getChildElementsByTag(e, ELEMENT_ARGUMENTS); - if (propsList.size() != 0) { - if (propsList.size() != 1) { - LOGGER.warning("Warning: Found several arguments listings for attribute " + mri.toString() //$NON-NLS-1$ - + ". Will use only first."); //$NON-NLS-1$ - } - NodeList arguments = propsList.get(0).getChildNodes(); - for (int i = 0, length = arguments.getLength(); i < length; i++) { - if (arguments.item(i) instanceof Element) { - Element argument = (Element) arguments.item(i); - putValue(mri, argument.getNodeName(), XmlToolkit.getStringValue(argument)); - } - } - } - } - - private void putValue(MRI mri, String key, Object value) { - metadataMap.computeIfAbsent(mri, k -> new HashMap<>()).put(key, value); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadataDB.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadataDB.java deleted file mode 100644 index fc5f320c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/FileMRIMetadataDB.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Observable; - -import org.openjdk.jmc.common.IState; -import org.openjdk.jmc.common.IStateful; -import org.openjdk.jmc.common.IWritableState; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProviderService; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * This class handles metadata for MRIs. Metadata currently comes from either the user, such as when - * the user specifies the update times for attribute subscriptions, or from the mrimetadata.xml file - * that stores default values. These two sources of metadata means that metadata lookups are usually - * performed in two steps, first this manager looks at the user-specified metadata, otherwise it - * returns the default values. - */ -public final class FileMRIMetadataDB extends Observable implements IStateful, IMRIMetadataService { - - private static final String ELEMENT_MAP_ENTRY = "mapEntry"; //$NON-NLS-1$ - private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ - private static final String ATTRIBUTE_KEY = "key"; //$NON-NLS-1$ - - // Maps attribute names to AttributeInfo objects that represent metadata - private final Map> metadataMap; - private final Map> changedMetadataStore; - private final IMRIMetadataProviderService subService; - - private FileMRIMetadataDB(Map> changedMetadataStore, - IMRIMetadataProviderService subService) { - this.changedMetadataStore = changedMetadataStore; - metadataMap = FileMRIMetadata.readDefaultsFromFile(); - this.subService = subService; - } - - /** - * Changes the value of a metadata item with a certain key. - * - * @param mri - * @param key - * @param value - */ - @Override - public void setMetadata(MRI mri, String key, String value) { - synchronized (changedMetadataStore) { - changedMetadataStore.computeIfAbsent(mri, k -> new HashMap<>()).put(key, value); - } - setChanged(); - notifyObservers(mri); - } - - /** - * Will attempt to look up the metadata value for the certain key. - * - * @param mri - * @param dataKey - * @return the metadata. - */ - @Override - public Object getMetadata(MRI mri, String dataKey) { - synchronized (changedMetadataStore) { - Map mriMetadataMap = changedMetadataStore.get(mri); - if (mriMetadataMap != null && mriMetadataMap.containsKey(dataKey)) { - return mriMetadataMap.get(dataKey); - } - } - Map metadataForMri; - synchronized (metadataMap) { - metadataForMri = metadataMap.computeIfAbsent(mri, k -> new HashMap<>(2)); - Object metadata = metadataForMri.get(dataKey); - if (metadata != null) { - return metadata; - } - } - Object metadata = subService.getMetadata(this, mri, dataKey); - synchronized (metadataMap) { - // FIXME: JMC-4672 - We cache the value to avoid multiple queries to the server. This may or may not be desirable. - metadataForMri.put(dataKey, metadata); - } - return metadata; - } - - @Override - public IMRIMetadata getMetadata(MRI mri) { - return new MRIMetadataWrapper(mri, this); - } - - @Override - public void saveTo(IWritableState state) { - synchronized (changedMetadataStore) { - for (Entry> mriEntry : changedMetadataStore.entrySet()) { - IWritableState mriChild = state.createChild(ELEMENT_MAP_ENTRY); - mriChild.putString(ATTRIBUTE_KEY, mriEntry.getKey().getQualifiedName()); - for (Entry dataEntry : mriEntry.getValue().entrySet()) { - IWritableState dataChild = mriChild.createChild(ELEMENT_MAP_ENTRY); - dataChild.putString(ATTRIBUTE_KEY, dataEntry.getKey()); - dataChild.putString(ATTRIBUTE_VALUE, dataEntry.getValue()); - } - } - } - } - - public static FileMRIMetadataDB buildFromState(IState state, IMRIMetadataProviderService subService) - throws RuntimeException { - HashMap> metadata = new HashMap<>(); - for (IState mriElement : state.getChildren()) { - MRI mri = MRI.createFromQualifiedName(mriElement.getAttribute(ATTRIBUTE_KEY)); - Map data = new HashMap<>(); - for (IState dataElement : mriElement.getChildren()) { - data.put(dataElement.getAttribute(ATTRIBUTE_KEY), dataElement.getAttribute(ATTRIBUTE_VALUE)); - } - metadata.put(mri, data); - } - return new FileMRIMetadataDB(metadata, subService); - } - - public static FileMRIMetadataDB buildDefault(IMRIMetadataProviderService subService) { - return new FileMRIMetadataDB(new HashMap>(), subService); - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotGcNotification.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotGcNotification.java deleted file mode 100644 index 75a4c085..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotGcNotification.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Set; -import java.util.logging.Level; - -import javax.management.MBeanServerConnection; -import javax.management.Notification; -import javax.management.NotificationListener; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenDataException; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.SimpleType; - -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * A unifying GC notification attribute for HotSpot. - */ -public class HotSpotGcNotification extends AbstractSyntheticNotification { - - private static final String[] FIELD_NAMES = new String[] {"HeapLiveSet", "HeapLiveSetSize", "Duration"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - private static final CompositeType TYPE; - static { - try { - TYPE = new CompositeType("org.openjdk.jmc.rjmx.subscription.internal.hotspotgcdata", "GC Data", FIELD_NAMES, //$NON-NLS-1$ //$NON-NLS-2$ - FIELD_NAMES, new OpenType[] {SimpleType.DOUBLE, SimpleType.LONG, SimpleType.LONG}); - } catch (OpenDataException e) { - throw new RuntimeException(e); - } - } - - private static final String COM_SUN_MANAGEMENT_GC_NOTIFICATION = "com.sun.management.gc.notification"; //$NON-NLS-1$ - private MBeanServerConnection m_connection; - private Set m_garbageCollectorMxBeans; - private CompositeData m_lastValue; - private String m_lastMessage; - private final NotificationListener m_listener; - - public HotSpotGcNotification() { - m_listener = createListener(); - } - - @Override - public void init(MBeanServerConnection connection, String type, String message) { - super.init(connection, type, message); - m_connection = connection; - // TODO: Save metadata -// IAttributeInfoService service = connectionHandle.getService(IAttributeInfoService.class); -// service.setMetadata(getAttributeInfo().getAttributeDescriptor(), -// AttributeMetadataManager.KEY_DESCRIPTION, -// "Sends an event every time a garbage collection has taken place. Identity number is the sequence number of the collection since the JMC connection was established." -// ); - m_garbageCollectorMxBeans = SyntheticAttributeToolkit.lookupMxBeans(m_connection, "java.lang", //$NON-NLS-1$ - "GarbageCollector"); //$NON-NLS-1$ - SyntheticAttributeToolkit.subscribeToNotifications(m_connection, m_listener, m_garbageCollectorMxBeans, - COM_SUN_MANAGEMENT_GC_NOTIFICATION); - } - - private NotificationListener createListener() { - return new NotificationListener() { - - @Override - public void handleNotification(Notification notification, Object handback) { - synchronized (HotSpotGcNotification.this) { - try { - CompositeData userData = (CompositeData) notification.getUserData(); - CompositeData gcInfo = (CompositeData) userData.get("gcInfo"); //$NON-NLS-1$ - Object[] values = new Object[FIELD_NAMES.length]; - long usedHeap = HotSpotLiveSetAttribute.lookupUsedHeap(gcInfo); - values[0] = HotSpotLiveSetAttribute.calculateLiveSet(usedHeap, m_connection); - values[1] = usedHeap; - values[2] = gcInfo.get("duration"); //$NON-NLS-1$ - m_lastValue = new CompositeDataSupport(TYPE, FIELD_NAMES, values); - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Failed to update HotSpotGcNotification value", e); //$NON-NLS-1$ - } - - m_lastMessage = notification.getMessage(); - } - triggerNotification(); - } - }; - } - - @Override - protected String getMessage() { - return m_lastMessage; - } - - @Override - public Object getValue() { - return m_lastValue; - } - - @Override - public void stop() { - SyntheticAttributeToolkit.unsubscribeFromNotifications(m_connection, m_listener, m_garbageCollectorMxBeans); - } - - @Override - public CompositeType getValueType() { - return TYPE; - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return !SyntheticAttributeToolkit.lookupMxBeans(connection, "java.lang", "GarbageCollector").isEmpty(); //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLastGcAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLastGcAttribute.java deleted file mode 100644 index 6618d0c0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLastGcAttribute.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Set; - -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.Notification; -import javax.management.NotificationListener; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.openmbean.CompositeData; - -/** - * An aggregator for the LastGcInfo attribute found in GarbageCollector MBeans. On initialization it - * will query all LastGcInfo attributes and save the latest one in a local cache. After this it will - * set up a subscription for GC notifications from each MBean. Each received notification will - * update the locally cached value. - */ -public class HotSpotLastGcAttribute extends AbstractSyntheticAttribute { - - private static final String COM_SUN_MANAGEMENT_GC_NOTIFICATION = "com.sun.management.gc.notification"; //$NON-NLS-1$ - - private MBeanServerConnection m_connection = null; - private Set m_garbageCollectorMxBeans; - private final NotificationListener m_listener; - private CompositeData m_lastGcInfo = null; - - public HotSpotLastGcAttribute() { - m_listener = createListener(); - } - - @Override - public Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException { - return m_lastGcInfo; - } - - @Override - public void setValue(MBeanServerConnection connection, Object value) throws MBeanException, ReflectionException { - // Ignore - } - - @Override - public void init(MBeanServerConnection connection) { - super.init(connection); - m_connection = connection; - m_garbageCollectorMxBeans = SyntheticAttributeToolkit.lookupMxBeans(m_connection, "java.lang", //$NON-NLS-1$ - "GarbageCollector"); //$NON-NLS-1$ - m_lastGcInfo = findLatestGcInfo(m_garbageCollectorMxBeans); - SyntheticAttributeToolkit.subscribeToNotifications(m_connection, m_listener, m_garbageCollectorMxBeans, - COM_SUN_MANAGEMENT_GC_NOTIFICATION); - } - - @Override - public void stop() { - SyntheticAttributeToolkit.unsubscribeFromNotifications(m_connection, m_listener, m_garbageCollectorMxBeans); - } - - private NotificationListener createListener() { - return new NotificationListener() { - @Override - public void handleNotification(Notification notification, Object handback) { - synchronized (HotSpotLastGcAttribute.this) { - m_lastGcInfo = (CompositeData) ((CompositeData) notification.getUserData()).get("gcInfo"); //$NON-NLS-1$ - } - } - }; - } - - private CompositeData findLatestGcInfo(Set garbageCollectorMxBeans) { - // Find the GC type with the latest end timestamp of its last GC - long lastTimestamp = 0; - CompositeData lastLastGc = null; - for (ObjectName objectName : garbageCollectorMxBeans) { - try { - CompositeData lastGcInfo = (CompositeData) AttributeValueToolkit.getAttribute(m_connection, objectName, - "LastGcInfo"); //$NON-NLS-1$ - if (lastGcInfo != null) { - long endTime = (Long) lastGcInfo.get("endTime"); //$NON-NLS-1$ - if (endTime > lastTimestamp) { - lastTimestamp = endTime; - lastLastGc = lastGcInfo; - } - } - } catch (Exception e) { - // Ignore - } - } - return lastLastGc; - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return !SyntheticAttributeToolkit.lookupMxBeans(connection, "java.lang", "GarbageCollector").isEmpty(); //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLiveSetAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLiveSetAttribute.java deleted file mode 100644 index 069e1f63..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/HotSpotLiveSetAttribute.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Set; - -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.Notification; -import javax.management.NotificationListener; -import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.TabularData; - -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; - -/** - * Calculates and saves the heap live set usage after each major GC. On initialization it selects - * the GC MBean that is most probably the major GC performer and calculates an initial value based - * on the last GC. - */ -public class HotSpotLiveSetAttribute extends AbstractSyntheticAttribute { - - private static final String COM_SUN_MANAGEMENT_GC_NOTIFICATION = "com.sun.management.gc.notification"; //$NON-NLS-1$ - private MBeanServerConnection m_connection = null; - private Set m_garbageCollectorMxBeans; - private final NotificationListener m_listener; - private Double m_liveSet = null; - - public HotSpotLiveSetAttribute() { - m_listener = createListener(); - } - - @Override - public Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException { - return m_liveSet; - } - - @Override - public void setValue(MBeanServerConnection connection, Object value) throws MBeanException, ReflectionException { - // Ignore - } - - @Override - public void init(MBeanServerConnection connection) { - super.init(connection); - m_connection = connection; - m_garbageCollectorMxBeans = SyntheticAttributeToolkit.lookupMxBeans(m_connection, "java.lang", //$NON-NLS-1$ - "GarbageCollector"); //$NON-NLS-1$ - setInitialValue(m_garbageCollectorMxBeans); - SyntheticAttributeToolkit.subscribeToNotifications(m_connection, m_listener, m_garbageCollectorMxBeans, - COM_SUN_MANAGEMENT_GC_NOTIFICATION); - } - - @Override - public void stop() { - SyntheticAttributeToolkit.unsubscribeFromNotifications(m_connection, m_listener, m_garbageCollectorMxBeans); - } - - private NotificationListener createListener() { - return new NotificationListener() { - @Override - public void handleNotification(Notification notification, Object handback) { - CompositeData userData = (CompositeData) notification.getUserData(); - if (isOldCollection(userData)) { - CompositeData gcInfo = (CompositeData) userData.get("gcInfo"); //$NON-NLS-1$ - m_liveSet = calculateLiveSet(gcInfo, m_connection); - } - } - - }; - } - - private void setInitialValue(Set garbageCollectorMxBeans) { - ObjectName majorGcObjectName = findMajorGcMbean(garbageCollectorMxBeans); - if (majorGcObjectName != null) { - try { - CompositeData gcInfo = (CompositeData) AttributeValueToolkit.getAttribute(m_connection, - majorGcObjectName, "LastGcInfo"); //$NON-NLS-1$ - if (gcInfo != null) { - m_liveSet = calculateLiveSet(gcInfo, m_connection); - } - } catch (Exception e) { - // Ignore - } - } - } - - private ObjectName findMajorGcMbean(Set garbageCollectorMxBeans) { - // Find the GC type with the highest number of memory pools and assume that this is the one used for major GCs - // TODO: Is there a better way of finding the GC used for major collections? - int maxGcPools = 0; - ObjectName majorGcObjectName = null; - for (ObjectName objectName : garbageCollectorMxBeans) { - try { - Object poolNames = AttributeValueToolkit.getAttribute(m_connection, objectName, "MemoryPoolNames"); //$NON-NLS-1$ - if (poolNames instanceof String[]) { - int gcPools = ((String[]) poolNames).length; - if (gcPools > maxGcPools) { - majorGcObjectName = objectName; - maxGcPools = gcPools; - } - } - } catch (Exception e) { - // Ignore - } - } - return majorGcObjectName; - } - - static Double calculateLiveSet(CompositeData gcInfo, MBeanServerConnection connection) { - return calculateLiveSet(lookupUsedHeap(gcInfo), connection); - } - - static Double calculateLiveSet(long usedHeap, MBeanServerConnection connection) { - long committedHeap = getCommittedHeap(connection); - if (committedHeap > 0) { - return (double) usedHeap / (double) committedHeap; - } else { - return null; - } - } - - private static boolean isOldCollection(CompositeData data) { - return ((String) data.get("gcAction")).indexOf("major") >= 0; //$NON-NLS-1$ //$NON-NLS-2$ - } - - static long lookupUsedHeap(CompositeData gcInfo) { - long usedHeap = 0; - TabularData memoryUsageAfterGc = (TabularData) gcInfo.get("memoryUsageAfterGc"); //$NON-NLS-1$ - for (Object memoryPool : memoryUsageAfterGc.values()) { - usedHeap += getMemoryPoolUsed((CompositeData) memoryPool); - } - return usedHeap; - } - - private static long getMemoryPoolUsed(CompositeData memoryPool) { - if (includeMemoryPool(memoryPool.get("key").toString())) { //$NON-NLS-1$ - Long memoryPoolUsed = (Long) ((CompositeData) memoryPool.get("value")).get("used"); //$NON-NLS-1$ //$NON-NLS-2$ - return memoryPoolUsed.longValue(); - } - return 0; - } - - private static boolean includeMemoryPool(String memoryPoolName) { - if (memoryPoolName.equals("Code Cache")) { //$NON-NLS-1$ - return false; - } else if (memoryPoolName.contains("Perm Gen")) { //$NON-NLS-1$ - return false; - } else if (memoryPoolName.contains("Metaspace")) { //$NON-NLS-1$ - return false; - } - return true; - } - - private static long getCommittedHeap(MBeanServerConnection connection) { - try { - return ((Number) AttributeValueToolkit.getAttribute(connection, - new MRI(Type.ATTRIBUTE, "java.lang:type=Memory", "HeapMemoryUsage/committed"))).longValue(); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (Exception e) { - return -1; - } - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return !SyntheticAttributeToolkit.lookupMxBeans(connection, "java.lang", "GarbageCollector").isEmpty(); //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IIntervalUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IIntervalUpdatePolicy.java deleted file mode 100644 index 8afecbe3..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IIntervalUpdatePolicy.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; - -/** - * Update policies that have equal time step between each update. - */ -public interface IIntervalUpdatePolicy extends IUpdatePolicy { - - /** - * Returns the time in milliseconds between two consecutive updates. - * - * @return the time in milliseconds between two consecutive updates - */ - public int getIntervalTime(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IMRISubscriptionDebugInformation.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IMRISubscriptionDebugInformation.java deleted file mode 100644 index 66462cbf..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/IMRISubscriptionDebugInformation.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -public interface IMRISubscriptionDebugInformation { - public static enum SubscriptionState { - SUBSCRIBED, UNSUBSCRIBED, LOST - } - - public MRI getMRI(); - - public SubscriptionState getState(); - - public int getConnectionCount(); - - public int getDisconnectionCount(); - - public int getEventCount(); - - public int getRetainedEventCount(); - - public MRIValueEvent getLastEvent(); - - public int getConnectionLostCount(); - - public int getTriedReconnectionsCount(); - - public int getSucceededReconnectionsCount(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ISubscriptionDebugService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ISubscriptionDebugService.java deleted file mode 100644 index 52eb514c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/ISubscriptionDebugService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collection; - -/** - * The subscription debug service interface. - */ -public interface ISubscriptionDebugService { - - public void collectDebugInformation(boolean collect); - - public void clearDebugInformation(); - - public Collection getDebugInformation(); -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/InvoluntaryDisconnectException.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/InvoluntaryDisconnectException.java deleted file mode 100644 index 7205f151..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/InvoluntaryDisconnectException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; - -public class InvoluntaryDisconnectException extends IOException { - private static final long serialVersionUID = -3849414596693117635L; - - public InvoluntaryDisconnectException(String message) { - super(message); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/LongDifferenceAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/LongDifferenceAttribute.java deleted file mode 100644 index efa21034..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/LongDifferenceAttribute.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Map; - -import javax.management.AttributeNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanServerConnection; -import javax.management.ReflectionException; - -/** - * A synthetic attribute calculated as a difference between the specified minuend and subtrahend. - */ -public class LongDifferenceAttribute extends AbstractPropertySyntheticAttribute { - - private static String MINUEND = "minuend"; //$NON-NLS-1$ - private static String SUBTRAHEND = "subtrahend"; //$NON-NLS-1$ - - @Override - public Object getValue(MBeanServerConnection connection) throws MBeanException, ReflectionException { - Map values = getPropertyAttributes(connection, new String[] {MINUEND, SUBTRAHEND}); - return getMinuend(values) - getSubtrahend(values); - } - - private long getMinuend(Map values) throws MBeanException { - return getLong(values, MINUEND); - } - - private long getSubtrahend(Map values) throws MBeanException { - return getLong(values, SUBTRAHEND); - } - - private long getLong(Map values, String key) throws MBeanException { - if (!values.containsKey(key)) { - try { - throw new AttributeNotFoundException("Attribute " + key + " not found!"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (AttributeNotFoundException e) { - throw new MBeanException(e); - } - } - return ((Number) values.get(key)).longValue(); - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - return hasResolvedAttribute(connection, MINUEND) && hasResolvedAttribute(connection, SUBTRAHEND); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MBeanMRIMetadataDB.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MBeanMRIMetadataDB.java deleted file mode 100644 index bfdd28ad..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MBeanMRIMetadataDB.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.logging.Level; - -import javax.management.Descriptor; -import javax.management.InstanceNotFoundException; -import javax.management.JMX; -import javax.management.MBeanAttributeInfo; -import javax.management.MBeanInfo; -import javax.management.MBeanNotificationInfo; -import javax.management.ObjectName; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenType; - -import org.openjdk.jmc.common.util.TypeHandling; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMBeanServerChangeListener; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.IMRIService; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; - -/** - * Responsible for querying the existing MBean server for metadata. Will cache metadata for - * everything that is not directly available through the MBean information of the MBean server. - */ -public final class MBeanMRIMetadataDB implements IMRIService, IMBeanServerChangeListener { - // FIXME: extend possibility to record MBean metadata about notifications - private final IMBeanHelperService mbeanService; - private final Map>> cachedMRIMetadata = new HashMap<>(); - private final Set introspectedMBeans = new HashSet<>(); - - public MBeanMRIMetadataDB(IMBeanHelperService mbeanService) { - this.mbeanService = mbeanService; - } - - @Override - public Set getMRIs() { - Set allMRIOnServer = new HashSet<>(); - try { - for (ObjectName mbean : mbeanService.getMBeanNames()) { - allMRIOnServer.addAll(getMBeanData(mbean).keySet()); - } - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Unable to retrieve MBean names from server!", e); //$NON-NLS-1$ - } - return allMRIOnServer; - } - - @Override - public boolean isMRIAvailable(MRI mri) { - if (mri.getType() == Type.TRANSFORMATION) { - return isTransformationAvailable(mri); - } - return getMBeanData(mri.getObjectName()).keySet().contains(mri); - } - - private boolean isTransformationAvailable(MRI mri) { - IMRITransformation transformation = MRITransformationToolkit.createTransformation(mri); - for (MRI attribute : transformation.getAttributes()) { - if (!isMRIAvailable(attribute)) { - return false; - } - } - return true; - } - - @Override - public void mbeanUnregistered(ObjectName mbean) { - synchronized (cachedMRIMetadata) { - introspectedMBeans.remove(mbean); - cachedMRIMetadata.remove(mbean); - } - } - - @Override - public void mbeanRegistered(ObjectName mbean) { - } - - public Map> getMBeanData(ObjectName mbean) { - if (hasIntrospectedMBean(mbean)) { - synchronized (cachedMRIMetadata) { - return getNonNullMap(cachedMRIMetadata, mbean); - } - } - return introspectMBean(mbean); - } - - private boolean hasIntrospectedMBean(ObjectName mbean) { - return introspectedMBeans.contains(mbean); - } - - private Map getNonNullMap(Map> map, K key) { - Map keyMap = map.get(key); - if (keyMap == null) { - return Collections.emptyMap(); - } - return keyMap; - } - - private Map> lookupMBeanMRIData(ObjectName mbean) { - MBeanInfo info = lookupMBeanInfo(mbean); - if (info != null) { - Map> mbeanMetadata = new HashMap<>(); - for (MBeanAttributeInfo attribute : info.getAttributes()) { - if (attribute.getName() == null) { - RJMXPlugin.getDefault().getLogger() - .warning("Omitting attribute with name==null in MBean + " + mbean.toString()); //$NON-NLS-1$ - } else { - if (attribute.getType() == null) { - RJMXPlugin.getDefault().getLogger().warning( - "Found MBean attribute with invalid type for " + mbean + "/" + attribute.getName()); //$NON-NLS-1$ //$NON-NLS-2$ - } - mbeanMetadata.put(new MRI(Type.ATTRIBUTE, mbean, attribute.getName()), createMetadata(attribute)); - } - } - for (MBeanNotificationInfo notification : info.getNotifications()) { - for (String type : notification.getNotifTypes()) { - mbeanMetadata.put(new MRI(Type.NOTIFICATION, mbean, type), createMetadata(notification, type)); - } - } - return mbeanMetadata; - } - return null; - } - - private MBeanInfo lookupMBeanInfo(ObjectName mbean) { - try { - return mbeanService.getMBeanInfo(mbean); - } catch (InstanceNotFoundException e) { - RJMXPlugin.getDefault().getLogger().log(Level.INFO, "MBean " + mbean + " does not exist on the server"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Unable to retrieve MBean information from server!", //$NON-NLS-1$ - e); - } - return null; - } - - private Map createMetadata(MBeanAttributeInfo attribute) { - String typeName = attribute.getType(); - Object originalType = attribute.getDescriptor().getFieldValue("originalType"); //$NON-NLS-1$ - if (originalType instanceof String) { - typeName = (String) originalType; - } - Map metadata = new HashMap<>(); - metadata.put(IMRIMetadataProvider.KEY_DISPLAY_NAME, attribute.getName()); - metadata.put(IMRIMetadataProvider.KEY_DESCRIPTION, attribute.getDescription()); - metadata.put(IMRIMetadataProvider.KEY_VALUE_TYPE, typeName); - metadata.put(IMRIMetadataProvider.KEY_COMPOSITE, isCompositeType(attribute.getType())); - metadata.put(IMRIMetadataProvider.KEY_READABLE, attribute.isReadable()); - metadata.put(IMRIMetadataProvider.KEY_WRITABLE, attribute.isWritable()); - metadata.put(IMRIMetadataProvider.KEY_DESCRIPTOR, attribute.getDescriptor()); - return metadata; - } - - private Map createMetadata(MBeanNotificationInfo notification, String type) { - Map metadata = new HashMap<>(); - metadata.put(IMRIMetadataProvider.KEY_DISPLAY_NAME, type); - metadata.put(IMRIMetadataProvider.KEY_DESCRIPTION, notification.getDescription()); - metadata.put(IMRIMetadataProvider.KEY_VALUE_TYPE, notification.getName()); - metadata.put(IMRIMetadataProvider.KEY_DESCRIPTOR, notification.getDescriptor()); - return metadata; - } - - private boolean isCompositeType(String className) { - if (className == null) { - return false; - } - try { - return CompositeData.class.isAssignableFrom(TypeHandling.getClassWithName(className)); - } catch (ClassNotFoundException e) { - return false; - } - } - - private Map> introspectMBean(ObjectName mbean) { - Map> cachedMBeanInfo; - synchronized (cachedMRIMetadata) { - Map> mbeanMetadata = cachedMRIMetadata.get(mbean); - if (mbeanMetadata == null) { - mbeanMetadata = lookupMBeanMRIData(mbean); - if (mbeanMetadata == null) { - return Collections.emptyMap(); - } - } - cachedMBeanInfo = new HashMap<>(mbeanMetadata); - boolean hasIntrospected = true; - for (Entry> entry : mbeanMetadata.entrySet()) { - CompositeType type = getCompositeType(entry.getValue()); - if (type == null && isComposite(entry.getValue())) { - // FIXME: We ought to retrieve all composites at once but we will not need this for well behaved MBeans - CompositeData compositeData = getCompositeData(entry.getKey()); - if (compositeData != null) { - type = compositeData.getCompositeType(); - } else { - hasIntrospected = false; - } - } - if (type != null) { - Object readable = entry.getValue().get(IMRIMetadataProvider.KEY_READABLE); - Object writable = entry.getValue().get(IMRIMetadataProvider.KEY_WRITABLE); - entry.getValue().put(IMRIMetadataProvider.KEY_COMPOSITE, true); - cachedMBeanInfo.putAll(introspectChildren(entry.getKey(), type, readable, writable)); - } - } - cachedMRIMetadata.put(mbean, cachedMBeanInfo); - if (hasIntrospected) { - introspectedMBeans.add(mbean); - } - } - return new HashMap<>(cachedMBeanInfo); - } - - private boolean isComposite(Map metadata) { - Object object = metadata.get(IMRIMetadataProvider.KEY_COMPOSITE); - if (object != null && object instanceof Boolean) { - return ((Boolean) object).booleanValue(); - } - return false; - } - - private CompositeType getCompositeType(Map metadata) { - Object descriptor = metadata.get(IMRIMetadataProvider.KEY_DESCRIPTOR); - if (descriptor instanceof Descriptor) { - Object type = ((Descriptor) descriptor).getFieldValue(JMX.OPEN_TYPE_FIELD); - if (type instanceof CompositeType) { - return (CompositeType) type; - } - } - return null; - } - - private CompositeData getCompositeData(MRI mri) { - try { - Object attributeValue = mbeanService.getAttributeValue(mri); - if (attributeValue instanceof CompositeData) { - return (CompositeData) attributeValue; - } - return null; - } catch (Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Could not retrieve attribute: " + mri, e); //$NON-NLS-1$ - return null; - } - } - - private Map> introspectChildren( - MRI parentMRI, CompositeType parentType, Object readable, Object writable) { - Map> children = new HashMap<>(); - for (Object key : parentType.keySet()) { - String childAttribute = String.valueOf(key); - MRI childMRI = new MRI(parentMRI, childAttribute); - Map childMetadata = new HashMap<>(); - children.put(childMRI, childMetadata); - childMetadata.put(IMRIMetadataProvider.KEY_DISPLAY_NAME, childAttribute); - childMetadata.put(IMRIMetadataProvider.KEY_DESCRIPTION, parentType.getDescription(childAttribute)); - childMetadata.put(IMRIMetadataProvider.KEY_VALUE_TYPE, parentType.getType(childAttribute).getClassName()); - childMetadata.put(IMRIMetadataProvider.KEY_READABLE, readable); - childMetadata.put(IMRIMetadataProvider.KEY_WRITABLE, writable); - OpenType childType = parentType.getType(childAttribute); - if (childType instanceof CompositeType) { - childMetadata.put(IMRIMetadataProvider.KEY_COMPOSITE, true); - children.putAll(introspectChildren(childMRI, (CompositeType) childType, readable, writable)); - } - } - return children; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRIMetadataWrapper.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRIMetadataWrapper.java deleted file mode 100644 index ec4e5338..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRIMetadataWrapper.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -public class MRIMetadataWrapper implements IMRIMetadata { - - private final MRI mri; - private final IMRIMetadataService service; - - public MRIMetadataWrapper(MRI mri, IMRIMetadataService service) { - this.mri = mri; - this.service = service; - } - - @Override - public MRI getMRI() { - return mri; - } - - @Override - public Object getMetadata(String key) { - return service.getMetadata(getMRI(), key); - } - - @Override - public String getDescription() { - return (String) getMetadata(IMRIMetadataProvider.KEY_DESCRIPTION); - } - - @Override - public String getValueType() { - return (String) getMetadata(IMRIMetadataProvider.KEY_VALUE_TYPE); - } - - @Override - public String getDisplayName() { - return (String) getMetadata(IMRIMetadataProvider.KEY_DISPLAY_NAME); - } - - @Override - public String getUnitString() { - return (String) getMetadata(IMRIMetadataProvider.KEY_UNIT_STRING); - } - - @Override - public boolean equals(Object that) { - if (that instanceof MRIMetadataWrapper) { - return getMRI().equals(((MRIMetadataWrapper) that).getMRI()); - } - return false; - } - - @Override - public int hashCode() { - return getMRI().hashCode(); - } - - @Override - public String toString() { - return getClass().getName() + '[' + getMRI() + ']'; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRITransformationToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRITransformationToolkit.java deleted file mode 100644 index 477b0057..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MRITransformationToolkit.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.IMRITransformationFactory; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * An MRI transformation toolkit responsible for creating transformations from MRI, finding - * attributes they depend on, etc. Will read available transformation factories from the extension - * "org.openjdk.jmc.rjmx.attributeTransformation". - */ -public class MRITransformationToolkit { - - static final String TRANSFORMATION_EXTENSION_NAME = "org.openjdk.jmc.rjmx.attributeTransformation"; //$NON-NLS-1$ - static final String TRANSFORMATION_ELEMENT = "attributeTransformation"; //$NON-NLS-1$ - public static final String TRANSFORMATION_NAME_ATTRIBUTE = "transformationName"; //$NON-NLS-1$ - static final String TRANSFORMATION_PROPERTY_ELEMENT = "property"; //$NON-NLS-1$ - static final String TRANSFORMATION_PROPERTY_NAME = "name"; //$NON-NLS-1$ - static final String TRANSFORMATION_PROPERTY_VALUE = "value"; //$NON-NLS-1$ - static final String TRANSFORMATION_PROPERTIES_ELEMENT = "transformationProperties"; //$NON-NLS-1$ - - private static final Map TRANSFORMATION_FACTORIES = new HashMap<>(); - - private MRITransformationToolkit() { - throw new AssertionError("Not to be instantiated!"); //$NON-NLS-1$ - } - - static { - initializeFromExtensions(); - } - - private static void initializeFromExtensions() { - IMRITransformationFactory transformationFactory = new SingleMRITransformationFactory(); - String transformationName = "difference"; - Properties props = new Properties(); - props.put("visualizeLabel", "Visualize difference..."); - props.put("transformationClass", "org.openjdk.jmc.rjmx.subscription.internal.DifferenceTransformation"); - Properties transProps = new Properties(); - transProps.put("displayName", "%s (difference)"); - props.put(TRANSFORMATION_NAME_ATTRIBUTE, transformationName); - transformationFactory.setFactoryProperties(props, transProps); - TRANSFORMATION_FACTORIES.put(transformationName, transformationFactory); - - transformationFactory = new SingleMRITransformationFactory(); - transformationName = "rate"; - props = new Properties(); - props.put("visualizeLabel", "Visualize rate per second..."); - props.put("transformationClass", "org.openjdk.jmc.rjmx.subscription.internal.DifferenceTransformation"); - transProps = new Properties(); - transProps.put("displayName", "%s (rate per second)"); - transProps.put("rate", "1000"); - props.put(TRANSFORMATION_NAME_ATTRIBUTE, transformationName); - transformationFactory.setFactoryProperties(props, transProps); - TRANSFORMATION_FACTORIES.put(transformationName, transformationFactory); - - transformationFactory = new SingleMRITransformationFactory(); - transformationName = "average"; - props = new Properties(); - props.put("visualizeLabel", "Visualize average..."); - props.put("transformationClass", "org.openjdk.jmc.rjmx.subscription.internal.AverageTransformation"); - transProps = new Properties(); - transProps.put("terms", "30"); - transProps.put("displayName", "%%s (average over %s samples)"); - props.put(TRANSFORMATION_NAME_ATTRIBUTE, transformationName); - transformationFactory.setFactoryProperties(props, transProps); - TRANSFORMATION_FACTORIES.put(transformationName, transformationFactory); - - transformationFactory = new SingleMRITransformationFactory(); - transformationName = "delta"; - props = new Properties(); - props.put("visualizeLabel", "Visualize delta..."); - props.put("transformationClass", "org.openjdk.jmc.rjmx.subscription.internal.DeltaTransformation"); - transProps = new Properties(); - transProps.put("displayName", "%s (delta)"); - props.put(TRANSFORMATION_NAME_ATTRIBUTE, transformationName); - transformationFactory.setFactoryProperties(props, transProps); - TRANSFORMATION_FACTORIES.put(transformationName, transformationFactory); - } - - /** - * Creates a new transformation with given transformation MRI for given connection. - * - * @param mri - * the transformation MRI - * @return the corresponding transformation object - */ - public static IMRITransformation createTransformation(MRI mri) { - String transformationName = getTransformationName(mri); - if (TRANSFORMATION_FACTORIES.containsKey(transformationName)) { - Properties properties = createProperties(mri); - return TRANSFORMATION_FACTORIES.get(transformationName).createTransformation(properties); - } - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, - "Could not instantiate unknown transformation type " + transformationName + "!"); //$NON-NLS-1$ //$NON-NLS-2$ - return null; - } - - /** - * Returns the different available transformation factories. - * - * @return the set of transformation factories - */ - public static Iterable getFactories() { - return Collections.unmodifiableCollection(TRANSFORMATION_FACTORIES.values()); - } - - private static String getTransformationName(MRI mri) { - String path = mri.getDataPath(); - int partitionIndex = path.indexOf('?'); - if (partitionIndex >= 0) { - return path.substring(0, partitionIndex); - } - return path; - } - - private static Properties createProperties(MRI mri) { - Properties properties = new Properties(); - String path = mri.getDataPath(); - int partitionIndex = path.indexOf('?'); - if (partitionIndex >= 0) { - path = path.substring(partitionIndex + 1); - for (String property : path.split("&")) { //$NON-NLS-1$ - int equalIndex = property.indexOf('='); - properties.put(property.substring(0, equalIndex), property.substring(equalIndex + 1)); - } - } - return properties; - } - - public static void forwardMetadata( - IMRIMetadataService metadataService, MRI mri, IMRIMetadata attributeMetadata, String textPattern) { - metadataService.setMetadata(mri, IMRIMetadataProvider.KEY_DISPLAY_NAME, - String.format(textPattern, attributeMetadata.getMetadata(IMRIMetadataProvider.KEY_DISPLAY_NAME))); - metadataService.setMetadata(mri, IMRIMetadataProvider.KEY_DESCRIPTION, - String.format(textPattern, attributeMetadata.getMetadata(IMRIMetadataProvider.KEY_DESCRIPTION))); - metadataService.setMetadata(mri, IMRIMetadataProvider.KEY_UPDATE_TIME, - (String) attributeMetadata.getMetadata(IMRIMetadataProvider.KEY_UPDATE_TIME)); - metadataService.setMetadata(mri, IMRIMetadataProvider.KEY_UNIT_STRING, - (String) attributeMetadata.getMetadata(IMRIMetadataProvider.KEY_UNIT_STRING)); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MonitoredDeadlockedThreadCountAttribute.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MonitoredDeadlockedThreadCountAttribute.java deleted file mode 100644 index 6894ad2d..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/MonitoredDeadlockedThreadCountAttribute.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadMXBean; -import java.util.logging.Level; - -import javax.management.MBeanServerConnection; -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.RJMXPlugin; - -/** - * Wrapping attribute://java.lang:type=Threading/findMonitoredDeadlockedThreads invocations as a - * numeric attribute. - */ -public class MonitoredDeadlockedThreadCountAttribute extends AbstractSyntheticAttribute { - - private ThreadMXBean m_threadMBean; - - @Override - public Object getValue(MBeanServerConnection connection) { - ThreadMXBean threadMBean = getThreadMBean(connection); - if (threadMBean == null) { - return null; - } - long[] monitorDeadlockedThreads = threadMBean.findMonitorDeadlockedThreads(); - return (monitorDeadlockedThreads == null) ? 0 : monitorDeadlockedThreads.length; - } - - private ThreadMXBean getThreadMBean(MBeanServerConnection connection) { - if (m_threadMBean == null) { - try { - m_threadMBean = ManagementFactory.newPlatformMXBeanProxy(connection, - ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class); - } catch (IOException e) { - RJMXPlugin.getDefault().getLogger().log(Level.SEVERE, "Unable to look up threading MX bean!", e); //$NON-NLS-1$ - } - } - return m_threadMBean; - } - - @Override - public void setValue(MBeanServerConnection connection, Object value) { - // value can not be set - } - - @Override - public boolean hasResolvedDependencies(MBeanServerConnection connection) { - try { - return connection.getMBeanInfo(new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME)) != null; - } catch (Exception e) { - } - return false; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/OneShotUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/OneShotUpdatePolicy.java deleted file mode 100644 index 077b84c2..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/OneShotUpdatePolicy.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -/** - * This update policy will schedule the first update ASAP, and the next one at the end of time - * (Long.MAX_VALUE). - *

- * This class is unfortunately not stateless, as the first update time will need to be recorded for - * the initial update, hence the factory method will return new instances each time it is called. - */ -public final class OneShotUpdatePolicy extends AbstractUpdatePolicy { - private OneShotUpdatePolicy() { - } - - @Override - protected long getFirstUpdate(long now) { - return now; - } - - @Override - protected long getFollowingUpdate(long now) { - return Long.MAX_VALUE; - } - - public static OneShotUpdatePolicy newPolicy() { - return new OneShotUpdatePolicy(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SimpleUpdatePolicy.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SimpleUpdatePolicy.java deleted file mode 100644 index a92a2fd8..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SimpleUpdatePolicy.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; - -/** - * Update policy that updates the {@link IMRISubscription} every {@link #getIntervalTime()} - * millisecond. - */ -public final class SimpleUpdatePolicy extends AbstractUpdatePolicy implements IIntervalUpdatePolicy { - private final static SimpleUpdatePolicy DEFAULT_POLICY = new SimpleUpdatePolicy( - UpdatePolicyToolkit.getDefaultUpdateInterval()); - private final int updateTime; - - /** - * Creates an update policy with the specified update time. - * - * @param updateTime - * the updateTime to use. - */ - private SimpleUpdatePolicy(int updateTime) { - this.updateTime = updateTime; - } - - @Override - protected long getFollowingUpdate(long lastUpdate) { - int updateInterval = getIntervalTime(); - // Place the following update on a multiple of the update interval to synchronize retrieval - return lastUpdate - lastUpdate % updateInterval + updateInterval; - } - - @Override - public int getIntervalTime() { - return updateTime; - } - - @Override - protected long getFirstUpdate(long now) { - return now; - } - - /** - * Factory method for {@link SimpleUpdatePolicy}. - * - * @param updateTime - * the update interval for this policy. - * @return the configured {@link SimpleUpdatePolicy}. - */ - public static IUpdatePolicy newPolicy(int updateTime) { - if (DEFAULT_POLICY.updateTime == updateTime) { - return DEFAULT_POLICY; - } else if (updateTime == -1) { - return DEFAULT_POLICY; - } - return new SimpleUpdatePolicy(updateTime); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SingleMRITransformationFactory.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SingleMRITransformationFactory.java deleted file mode 100644 index b1806506..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SingleMRITransformationFactory.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Properties; -import java.util.logging.Level; - -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.IMRITransformationFactory; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * A transformation factory used be several of our own transformations. - */ -public class SingleMRITransformationFactory implements IMRITransformationFactory { - - private static final String TRANSFORMATION_CLASS_NAME_PROPERTY = "transformationClass"; //$NON-NLS-1$ - private Properties m_properties; - private Properties m_transformationProperties; - - @Override - public void setFactoryProperties(Properties properties, Properties transformationProperties) { - m_properties = properties; - m_transformationProperties = transformationProperties; - } - - @Override - public IMRITransformation createTransformation(Properties properties) { - String className = m_properties.getProperty(TRANSFORMATION_CLASS_NAME_PROPERTY); - if (className == null) { - return null; - } - try { - @SuppressWarnings("unchecked") - Class clz = (Class) Class.forName(className); - IMRITransformation transformation = clz.newInstance(); - properties.putAll(m_transformationProperties); - transformation.setProperties(properties); - return transformation; - } catch (ClassNotFoundException e) { - logException(e); - } catch (InstantiationException e) { - logException(e); - } catch (IllegalAccessException e) { - logException(e); - } - return null; - } - - private void logException(Exception e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Unable to create transformation!", e); //$NON-NLS-1$ - } - - @Override - public String getVisualizationLabel() { - return m_properties.getProperty("visualizeLabel"); //$NON-NLS-1$ - } - - @Override - public MRI createTransformationMRI(MRI mri) { - String transformationName = m_properties.getProperty(MRITransformationToolkit.TRANSFORMATION_NAME_ATTRIBUTE); - // FIXME: Would be nice to not have to specify an ObjectName but until then let us use something meaningful. - return new MRI(MRI.Type.TRANSFORMATION, "transformation:type=" + transformationName, //$NON-NLS-1$ - transformationName + "?attribute=" + mri); //$NON-NLS-1$ - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SyntheticAttributeToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SyntheticAttributeToolkit.java deleted file mode 100644 index 621da47e..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/SyntheticAttributeToolkit.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.management.MBeanNotificationInfo; -import javax.management.MBeanServerConnection; -import javax.management.NotificationFilter; -import javax.management.NotificationFilterSupport; -import javax.management.NotificationListener; -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRI.Type; - -/** - * Utility class for common operations performed by synthetic attributes and notifications. - */ -public class SyntheticAttributeToolkit { - - public static Set lookupMxBeans(MBeanServerConnection connection, String domain, String type) { - Set mxBeans = new HashSet<>(); - try { - for (ObjectName objectName : connection.queryNames(null, null)) { - if (objectName.getDomain().equals(domain)) { - if (type.equals(objectName.getKeyProperty("type"))) { //$NON-NLS-1$ - mxBeans.add(objectName); - } - } - } - } catch (IOException e) { - // Ignore - } - return mxBeans; - } - - public static MRI[] createNotificationDescriptors( - MBeanServerConnection connection, Set mxBeans, String type) { - List notificationDescriptors = new ArrayList<>(); - NEXT_BEAN: for (ObjectName mxBean : mxBeans) { - try { - for (MBeanNotificationInfo notification : connection.getMBeanInfo(mxBean).getNotifications()) { - for (String notifType : notification.getNotifTypes()) { - if (notifType.equals(type)) { - notificationDescriptors.add(new MRI(Type.NOTIFICATION, mxBean, type)); - continue NEXT_BEAN; - } - } - } - } catch (Exception e) { - // Ignore - } - } - return notificationDescriptors.toArray(new MRI[notificationDescriptors.size()]); - } - - public static void subscribeToNotifications( - MBeanServerConnection connection, NotificationListener listener, Iterable beans, - String type) { - for (ObjectName bean : beans) { - try { - connection.addNotificationListener(bean, listener, createNotificationFilter(type), null); - } catch (Exception e) { - // Ignore - } - } - } - - private static NotificationFilter createNotificationFilter(String type) { - NotificationFilterSupport filter = new NotificationFilterSupport(); - filter.enableType(type); - return filter; - } - - public static void unsubscribeFromNotifications( - MBeanServerConnection connection, NotificationListener listener, Iterable beans) { - for (ObjectName bean : beans) { - try { - connection.removeNotificationListener(bean, listener); - } catch (Exception e) { - // Ignore - } - } - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/TransformationSubscription.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/TransformationSubscription.java deleted file mode 100644 index 05583fec..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/TransformationSubscription.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadata; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRITransformation; -import org.openjdk.jmc.rjmx.subscription.IMRIValueListener; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * Will encapsulate an attribute transformation and set up subscriptions of all attributes that the - * transformation reports as used. Will propagate updated values for the transformation. - */ -public class TransformationSubscription extends AbstractAttributeSubscription { - - private final IMRITransformation m_transformation; - private final IMRIValueListener m_mriListener; - private final ISubscriptionService m_subscriptionService; - - public TransformationSubscription(IConnectionHandle connectionHandle, IMRIMetadata info, - IMRITransformation transformation) { - super(connectionHandle, info); - - m_transformation = transformation; - m_mriListener = createListener(); - m_subscriptionService = getConnectionHandle().getServiceOrDummy(ISubscriptionService.class); - for (MRI mri : transformation.getAttributes()) { - m_subscriptionService.addMRIValueListener(mri, m_mriListener); - } - transformation.extendMetadata(connectionHandle.getServiceOrDummy(IMRIMetadataService.class), info); - } - - private IMRIValueListener createListener() { - return new IMRIValueListener() { - @Override - public void valueChanged(MRIValueEvent event) { - Object eventValue = m_transformation.createSubscriptionValue(event); - if (eventValue != IMRITransformation.NO_VALUE) { - MRIValueEvent newEvent = new MRIValueEvent(getMRIMetadata().getMRI(), event.getTimestamp(), - eventValue); - fireAttributeChange(newEvent); - } - } - }; - } - - /** - * Unsubscribes to the transformation attributes. - */ - public void unregisterSubscription() { - m_subscriptionService.removeMRIValueListener(m_mriListener); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableChildSubscriptions.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableChildSubscriptions.java deleted file mode 100644 index c53eb467..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableChildSubscriptions.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import javax.management.openmbean.CompositeData; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.subscription.IMRIValueListener; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; - -/** - * When one or more subscriptions try to retrieve an non-existing composite child value we first - * subscribe on the actual attribute and wait for a concrete value. - */ -class UnavailableChildSubscriptions { - private final ISubscriptionService m_subscriptionService; - private final MRI m_parentMRI; - private final IMRIValueListener m_parentValueListener; - private final UnavailableSubscriptionsRepository m_repository; - private final Set m_unavailableChildSubscriptions = new HashSet<>(); - - public UnavailableChildSubscriptions(IConnectionHandle connectionHandle, MRI parentMRI, - UnavailableSubscriptionsRepository repository) { - m_subscriptionService = connectionHandle.getServiceOrNull(ISubscriptionService.class); - m_parentMRI = parentMRI; - m_repository = repository; - m_parentValueListener = createValueListener(); - if (m_subscriptionService != null) { - m_subscriptionService.addMRIValueListener(m_parentMRI, m_parentValueListener); - } - } - - public MRI getParentMRI() { - return m_parentMRI; - } - - public void dispose() { - if (m_subscriptionService != null) { - m_subscriptionService.removeMRIValueListener(m_parentValueListener); - } - } - - public boolean addChildSubscription(AbstractAttributeSubscription subscription) { - if (!subscription.getMRIMetadata().getMRI().toString().startsWith(m_parentMRI.toString())) { - throw new IllegalArgumentException( - "Child " + subscription.getMRIMetadata().getMRI() + " is not child of " + m_parentMRI); //$NON-NLS-1$ //$NON-NLS-2$ - } - boolean result = m_unavailableChildSubscriptions.add(subscription); - adjustUpdatePolicy(subscription); - return result; - } - - private void adjustUpdatePolicy(AbstractAttributeSubscription subscription) { - IUpdatePolicy updatePolicy = UpdatePolicyToolkit.getUpdatePolicy(subscription.getMRIMetadata()); - if (updatePolicy instanceof IIntervalUpdatePolicy && m_subscriptionService != null) { - int updateInterval = ((IIntervalUpdatePolicy) updatePolicy).getIntervalTime(); - IUpdatePolicy parentPolicy = m_subscriptionService.getMRISubscription(m_parentMRI).getUpdatePolicy(); - if (parentPolicy instanceof IIntervalUpdatePolicy - && updateInterval < ((IIntervalUpdatePolicy) parentPolicy).getIntervalTime()) { - m_subscriptionService.getMRISubscription(m_parentMRI) - .setUpdatePolicy(SimpleUpdatePolicy.newPolicy(updateInterval)); - } - } - } - - public Collection getChildSubscriptions() { - return m_unavailableChildSubscriptions; - } - - private IMRIValueListener createValueListener() { - return new IMRIValueListener() { - @Override - public void valueChanged(MRIValueEvent event) { - if (event.getValue() instanceof CompositeData) { - // FIXME: change to a better test of containment? - dispose(); - m_repository.movePossibleChildSubscriptions(UnavailableChildSubscriptions.this); - } - } - - }; - } - - public static boolean isCompositeChildSubscription(AbstractAttributeSubscription subscription) { - MRI[] parents = subscription.getMRIMetadata().getMRI().getParentMRIs(); - return parents.length > 0; - } - - public static MRI getParentMRI(AbstractAttributeSubscription subscription) { - return subscription.getMRIMetadata().getMRI().getParentMRIs()[0]; - } - -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableSubscriptionsRepository.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableSubscriptionsRepository.java deleted file mode 100644 index 47782083..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UnavailableSubscriptionsRepository.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.management.ObjectName; - -import org.openjdk.jmc.rjmx.ConnectionException; -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.ServiceNotAvailableException; -import org.openjdk.jmc.rjmx.subscription.IMBeanHelperService; -import org.openjdk.jmc.rjmx.subscription.IMBeanServerChangeListener; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * Class responsible for keeping track of subscriptions that for one reason or another have become - * unavailable. This might be because the MBean they belong to has been unregistered or that an - * attribute is simply not available yet. A typical example of that are composite children of the - * GarbageCollectorMXBean.getLastGcInfo() attribute. - */ -public class UnavailableSubscriptionsRepository { - - private static class BackoffTimeInformation { - private long backoffTime; - private long lastTestTime; - - public BackoffTimeInformation() { - this(1000, System.currentTimeMillis()); - } - - public BackoffTimeInformation(long backoff, long lastTest) { - backoffTime = backoff; - lastTestTime = lastTest; - } - } - - private final IConnectionHandle m_connectionHandle; - private final IMBeanHelperService m_helperService; - private final IMBeanServerChangeListener m_mbeanServerChangeListener; - private final Set m_unregisteredMBeans = new HashSet<>(); - - private final Map> m_unregisteredSubscriptions = new HashMap<>(); - private final Map m_unavailableChildSubscriptions = new HashMap<>(); - private final Map m_possibleSubscriptions = new HashMap<>(); - - public UnavailableSubscriptionsRepository(IConnectionHandle connectionHandle) - throws ConnectionException, ServiceNotAvailableException { - m_connectionHandle = connectionHandle; - m_helperService = connectionHandle.getServiceOrThrow(IMBeanHelperService.class); - m_mbeanServerChangeListener = createMBeanServerChangeListener(); - getMBeanHelperService().addMBeanServerChangeListener(m_mbeanServerChangeListener); - } - - public void dispose() { - getMBeanHelperService().removeMBeanServerChangeListener(m_mbeanServerChangeListener); - m_unregisteredMBeans.clear(); - } - - private IMBeanHelperService getMBeanHelperService() { - return m_helperService; - } - - private IMBeanServerChangeListener createMBeanServerChangeListener() { - return new IMBeanServerChangeListener() { - @Override - public void mbeanUnregistered(ObjectName mbean) { - if (unregisterMBean(mbean)) { - moveUnregisteredMBeanSubscriptions(mbean); - } - } - - private boolean unregisterMBean(ObjectName mbean) { - synchronized (m_unregisteredMBeans) { - return m_unregisteredMBeans.add(mbean); - } - } - - @Override - public void mbeanRegistered(ObjectName mbean) { - if (registerMBean(mbean)) { - moveRegisteredMBeanSubscriptions(mbean); - } - } - - private boolean registerMBean(ObjectName mbean) { - synchronized (m_unregisteredMBeans) { - return m_unregisteredMBeans.remove(mbean); - } - } - }; - } - - synchronized void movePossibleChildSubscriptions(UnavailableChildSubscriptions possibleChildSubscriptions) { - m_unavailableChildSubscriptions.remove(possibleChildSubscriptions.getParentMRI()); - for (AbstractAttributeSubscription subscription : possibleChildSubscriptions.getChildSubscriptions()) { - m_possibleSubscriptions.put(subscription, new BackoffTimeInformation()); - } - - } - - private synchronized void moveRegisteredMBeanSubscriptions(ObjectName mbean) { - Set subscriptions = m_unregisteredSubscriptions.remove(mbean); - if (subscriptions != null) { - for (AbstractAttributeSubscription subscription : subscriptions) { - m_possibleSubscriptions.put(subscription, new BackoffTimeInformation()); - } - } - } - - private synchronized void moveUnregisteredMBeanSubscriptions(ObjectName mbean) { - for (AbstractAttributeSubscription subscription : getPossibleSubscriptions()) { - if (subscription.getMRIMetadata().getMRI().getObjectName().equals(mbean)) { - m_possibleSubscriptions.remove(subscription); - getUnregisteredSubscriptions(mbean).add(subscription); - } - } - } - - private Set getUnregisteredSubscriptions(ObjectName mbean) { - Set subscriptions = m_unregisteredSubscriptions.get(mbean); - if (subscriptions == null) { - subscriptions = new HashSet<>(); - m_unregisteredSubscriptions.put(mbean, subscriptions); - } - return subscriptions; - } - - private Collection getPossibleSubscriptions() { - return new ArrayList<>(m_possibleSubscriptions.keySet()); - } - - public synchronized Collection getBackoffedSubscriptions() { - Collection subscriptions = new ArrayList<>(); - long currentTime = System.currentTimeMillis(); - for (Entry entry : m_possibleSubscriptions.entrySet()) { - BackoffTimeInformation info = entry.getValue(); - if (info.lastTestTime + info.backoffTime < currentTime) { - info.lastTestTime = currentTime; - info.backoffTime *= 2; - subscriptions.add(entry.getKey()); - } - } - return subscriptions; - } - - private synchronized Collection getUnregisteredSubscriptions() { - Collection subscriptions = new ArrayList<>(); - for (Set mbeanSubscriptions : m_unregisteredSubscriptions.values()) { - subscriptions.addAll(mbeanSubscriptions); - } - return subscriptions; - } - - public synchronized Collection getAllSubscriptions() { - Collection subscriptions = getUnregisteredSubscriptions(); - subscriptions.addAll(getUnavailableChildSubscriptions()); - subscriptions.addAll(getPossibleSubscriptions()); - return subscriptions; - } - - private synchronized Collection getUnavailableChildSubscriptions() { - Collection subscriptions = new ArrayList<>(); - for (UnavailableChildSubscriptions unavailableChildSubscriptions : m_unavailableChildSubscriptions.values()) { - subscriptions.addAll(unavailableChildSubscriptions.getChildSubscriptions()); - } - return subscriptions; - } - - public synchronized boolean add(AbstractAttributeSubscription subscription) { - ObjectName mbean = subscription.getMRIMetadata().getMRI().getObjectName(); - if (isMBeanUnregistered(mbean)) { - return getUnregisteredSubscriptions(mbean).add(subscription); - } else if (UnavailableChildSubscriptions.isCompositeChildSubscription(subscription)) { - return getUnavailableSubscriptions(subscription).addChildSubscription(subscription); - } else { - return m_possibleSubscriptions.put(subscription, new BackoffTimeInformation()) == null; - } - } - - private boolean isMBeanUnregistered(ObjectName mbean) { - synchronized (m_unregisteredMBeans) { - return m_unregisteredMBeans.contains(mbean); - } - } - - private UnavailableChildSubscriptions getUnavailableSubscriptions(AbstractAttributeSubscription subscription) { - MRI parentMRI = UnavailableChildSubscriptions.getParentMRI(subscription); - UnavailableChildSubscriptions unavailableChildSubscriptions = m_unavailableChildSubscriptions.get(parentMRI); - if (unavailableChildSubscriptions == null) { - unavailableChildSubscriptions = new UnavailableChildSubscriptions(m_connectionHandle, parentMRI, this); - m_unavailableChildSubscriptions.put(parentMRI, unavailableChildSubscriptions); - } - return unavailableChildSubscriptions; - } - - public synchronized boolean remove(AbstractAttributeSubscription subscription) { - return m_possibleSubscriptions.remove(subscription) != null || hasUnavilableChildSubscription(subscription) - || getUnregisteredSubscriptions(subscription.getMRIMetadata().getMRI().getObjectName()) - .remove(subscription); - } - - private boolean hasUnavilableChildSubscription(AbstractAttributeSubscription subscription) { - if (UnavailableChildSubscriptions.isCompositeChildSubscription(subscription)) { - MRI parentMRI = UnavailableChildSubscriptions.getParentMRI(subscription); - UnavailableChildSubscriptions unavailableChildSubscriptions = m_unavailableChildSubscriptions - .get(parentMRI); - if (unavailableChildSubscriptions != null) { - return removeSubscription(unavailableChildSubscriptions, subscription, parentMRI); - } - } - return false; - } - - private boolean removeSubscription( - UnavailableChildSubscriptions unavailableChildSubscriptions, AbstractAttributeSubscription subscription, - MRI parentMRI) { - boolean result = unavailableChildSubscriptions.getChildSubscriptions().remove(subscription); - if (unavailableChildSubscriptions.getChildSubscriptions().size() == 0) { - unavailableChildSubscriptions.dispose(); - m_unavailableChildSubscriptions.remove(parentMRI); - } - return result; - } - - public synchronized boolean contains(MRI mri) { - for (AbstractAttributeSubscription subscription : getAllSubscriptions()) { - if (mri.equals(subscription.getMRIMetadata().getMRI())) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UpdatePolicyToolkit.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UpdatePolicyToolkit.java deleted file mode 100644 index 12f7b552..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/internal/UpdatePolicyToolkit.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.internal; - -import java.util.logging.Level; - -import org.openjdk.jmc.rjmx.IConnectionHandle; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.preferences.PreferencesKeys; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataProvider; -import org.openjdk.jmc.rjmx.subscription.IMRIMetadataService; -import org.openjdk.jmc.rjmx.subscription.IMRISubscription; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.IUpdatePolicy; -import org.openjdk.jmc.rjmx.subscription.MRI; - -public final class UpdatePolicyToolkit { - - private static final String DEFAULT_UPDATE_INTERVAL = "defaultUpdateInterval"; //$NON-NLS-1$ - - private UpdatePolicyToolkit() throws InstantiationException { - throw new InstantiationException("Should not be instantiated!"); //$NON-NLS-1$ - } - - public static int getDefaultUpdateInterval() { - return PreferencesKeys.DEFAULT_UPDATE_INTERVAL; - } - - /** - * Sets the {@link IUpdatePolicy} for an {@link MRI} . - * - * @param handle - * the connection handle for which to set to policy. - * @param attributeDescriptor - * the descriptor for which to set the policy. - * @param policy - * the policy to set. - * @throws UnsupportedOperationException - * if the policy is unknown to the system. - */ - public static void setUpdatePolicy(IConnectionHandle handle, MRI attributeDescriptor, IUpdatePolicy policy) { - IMRIMetadataService metadataService = getMetadataService(handle); - if (metadataService == null) { - return; - } - if (policy instanceof OneShotUpdatePolicy) { - metadataService.setMetadata(attributeDescriptor, IMRIMetadataProvider.KEY_UPDATE_TIME, Integer.toString(0)); - } else if (policy instanceof SimpleUpdatePolicy) { - SimpleUpdatePolicy s = (SimpleUpdatePolicy) policy; - metadataService.setMetadata(attributeDescriptor, IMRIMetadataProvider.KEY_UPDATE_TIME, - Integer.toString(s.getIntervalTime())); - } else if (policy instanceof DefaultUpdatePolicy) { - metadataService.setMetadata(attributeDescriptor, IMRIMetadataProvider.KEY_UPDATE_TIME, - DEFAULT_UPDATE_INTERVAL); - } else { - throw new UnsupportedOperationException(policy.getClass() + "is not supported!"); //$NON-NLS-1$ - } - updateExistingSubscription(handle, attributeDescriptor); - } - - private static void updateExistingSubscription(IConnectionHandle handle, MRI attributeDescriptor) { - ISubscriptionService service = handle.getServiceOrNull(ISubscriptionService.class); - if (service == null) { - return; - } - IMRISubscription attributeSubscription = service.getMRISubscription(attributeDescriptor); - if (attributeSubscription != null) { - attributeSubscription.setUpdatePolicy(getUpdatePolicy(handle, attributeDescriptor)); - } - } - - /** - * Returns the update policy for an {@link MRI}. If no policy is set the default policy will be - * returned. - * - * @param handle - * the handle for which to get the policy. - * @param attributeDescriptor - * the descriptor for which to set the policy. - * @return an {@link IUpdatePolicy}. - */ - public static IUpdatePolicy getUpdatePolicy(IConnectionHandle handle, MRI attributeDescriptor) { - IMRIMetadataService metadataService = getMetadataService(handle); - if (metadataService != null) { - return getUpdatePolicy(metadataService.getMetadata(attributeDescriptor)); - } - return DefaultUpdatePolicy.newPolicy(); - } - - public static IUpdatePolicy getUpdatePolicy(IMRIMetadataProvider info) { - String update = (String) info.getMetadata(IMRIMetadataProvider.KEY_UPDATE_TIME); - if (update != null && !update.equals(DEFAULT_UPDATE_INTERVAL)) { - try { - int interval = Integer.parseInt(update); - return interval == 0 ? OneShotUpdatePolicy.newPolicy() : SimpleUpdatePolicy.newPolicy(interval); - } catch (NumberFormatException e) { - RJMXPlugin.getDefault().getLogger().log(Level.WARNING, - "Warning: The update_interval specified for attribute " + info.getMRI() //$NON-NLS-1$ - + " is malformed. The default update time (" //$NON-NLS-1$ - + Integer.toString(UpdatePolicyToolkit.getDefaultUpdateInterval()) - + ") will be used instead.", //$NON-NLS-1$ - e); - } - } - return DefaultUpdatePolicy.newPolicy(); - } - - private static IMRIMetadataService getMetadataService(IConnectionHandle handle) { - return handle.getServiceOrNull(IMRIMetadataService.class); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/BufferingAttributeStorage.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/BufferingAttributeStorage.java deleted file mode 100644 index 2392ede0..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/BufferingAttributeStorage.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.storage.internal; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Observable; -import java.util.Observer; - -import org.openjdk.jmc.common.collection.BoundedList; -import org.openjdk.jmc.rjmx.RJMXPlugin; -import org.openjdk.jmc.rjmx.preferences.PreferencesKeys; -import org.openjdk.jmc.rjmx.services.IAttributeStorage; -import org.openjdk.jmc.rjmx.services.MRIDataSeries; -import org.openjdk.jmc.rjmx.subscription.IMRIValueListener; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.MRI; -import org.openjdk.jmc.rjmx.subscription.MRIValueEvent; -import org.openjdk.jmc.ui.common.xydata.DefaultTimestampedData; -import org.openjdk.jmc.ui.common.xydata.ITimestampedData; - -/** - * Simple attribute storage that contains attribute events. - *

- * NOTE: You must synchronize on the storage if you use the dataseries iterator! - */ -public class BufferingAttributeStorage extends Observable implements IAttributeStorage { - - private static int preferenceLookupCounter = 0; - private static int currentRetainedEventValues; - - private static int lookupRetainedEventValues() { - if (preferenceLookupCounter++ % 1000 == 0) { - currentRetainedEventValues = PreferencesKeys.DEFAULT_RETAINED_EVENT_VALUES; - } - return currentRetainedEventValues; - } - - private final BoundedList cache = new BoundedList<>(lookupRetainedEventValues()); - private final MRI mri; - private final ISubscriptionService subscriptionService; - private final IMRIValueListener valueListener = new IMRIValueListener() { - @Override - public void valueChanged(MRIValueEvent event) { - Object value = event.getValue(); - if (value instanceof Number) { - if (lookupRetainedEventValues() != cache.getMaxSize()) { - cache.setMaxSize(Math.max(lookupRetainedEventValues(), Math.max(cache.getSize() - 1000, 1))); - } - DefaultTimestampedData data = new DefaultTimestampedData(event.getTimestamp() * 1000 * 1000L, - ((Number) value).doubleValue()); - cache.add(data); - setChanged(); - notifyObservers(data); - } - } - }; - private final List dataSeries = new ArrayList<>(1); - - public BufferingAttributeStorage(MRI attribute, ISubscriptionService subscriptionService) { - mri = attribute; - this.subscriptionService = subscriptionService; - dataSeries.add(new MRIDataSeries() { - - @Override - public Iterator createIterator(long min, long max) { - return cache.iterator(); - } - - @Override - public MRI getAttribute() { - return mri; - } - }); - - } - - @Override - public long getDataStart() { - ITimestampedData first = cache.getFirst(); - return first != null ? first.getX() : Long.MAX_VALUE; - } - - @Override - public long getDataEnd() { - ITimestampedData last = cache.getLast(); - return last != null ? last.getX() : Long.MIN_VALUE; - } - - @Override - public synchronized void addObserver(Observer o) { - if (countObservers() == 0) { - subscriptionService.addMRIValueListener(mri, valueListener); - } - super.addObserver(o); - } - - @Override - public synchronized void deleteObserver(Observer o) { - super.deleteObserver(o); - if (countObservers() == 0) { - subscriptionService.removeMRIValueListener(mri, valueListener); - } - } - - void dispose() { - subscriptionService.removeMRIValueListener(mri, valueListener); - } - - @Override - public List getDataSeries() { - return dataSeries; - } - - public int getRetainedLength() { - return cache.getSize(); - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/DefaultAttributeStorageService.java b/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/DefaultAttributeStorageService.java deleted file mode 100644 index 8be7d51c..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/subscription/storage/internal/DefaultAttributeStorageService.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.subscription.storage.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.openjdk.jmc.rjmx.internal.IDisposableService; -import org.openjdk.jmc.rjmx.services.IAttributeStorage; -import org.openjdk.jmc.rjmx.services.IAttributeStorageService; -import org.openjdk.jmc.rjmx.subscription.ISubscriptionService; -import org.openjdk.jmc.rjmx.subscription.MRI; - -/** - * Default implementation of {@link IAttributeStorageService}. Keeps a pretty rigid synchronization - * on the methods. - */ -public class DefaultAttributeStorageService implements IAttributeStorageService, IDisposableService { - - private final ISubscriptionService attributeSubscriptionService; - private Map activeStorages = new HashMap<>(); - - /** - * Creates a new {@link IAttributeStorageService}. - * - * @param subscriptionService - */ - public DefaultAttributeStorageService(ISubscriptionService subscriptionService) { - attributeSubscriptionService = subscriptionService; - } - - @Override - public synchronized IAttributeStorage getAttributeStorage(MRI mri) { - if (activeStorages == null) { - throw new IllegalStateException("Attribute storage service is disposed!"); //$NON-NLS-1$ - } - BufferingAttributeStorage storage = activeStorages.get(mri); - if (storage == null) { - storage = new BufferingAttributeStorage(mri, attributeSubscriptionService); - activeStorages.put(mri, storage); - } - return storage; - } - - @Override - public int getRetainedLength(MRI mri) { - if (activeStorages == null) { - throw new IllegalStateException("Attribute storage service is disposed!"); //$NON-NLS-1$ - } - BufferingAttributeStorage storage = activeStorages.get(mri); - if (storage != null) { - return storage.getRetainedLength(); - } - return 0; - } - - @Override - public synchronized void dispose() { - for (BufferingAttributeStorage s : activeStorages.values()) { - s.dispose(); - } - activeStorages = null; - } -} diff --git a/src/main/java/org/openjdk/jmc/rjmx/util/internal/SimpleAttributeInfo.java b/src/main/java/org/openjdk/jmc/rjmx/util/internal/SimpleAttributeInfo.java deleted file mode 100644 index 7f035e7e..00000000 --- a/src/main/java/org/openjdk/jmc/rjmx/util/internal/SimpleAttributeInfo.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.rjmx.util.internal; - -import org.openjdk.jmc.rjmx.services.IAttributeInfo; - -public class SimpleAttributeInfo implements IAttributeInfo { - - private final String name; - private final String type; - private final String description; - - public SimpleAttributeInfo(String name, String type) { - this(name, type, null); - } - - public SimpleAttributeInfo(String name, String type, String description) { - this.name = name; - this.type = type; - this.description = description; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public String getType() { - return type; - } - - // FIXME: add description to equals and hashcode? - @Override - public boolean equals(Object obj) { - if (!(obj instanceof SimpleAttributeInfo)) { - return super.equals(obj); - } - SimpleAttributeInfo that = (SimpleAttributeInfo) obj; - if (getName() == null) { - if (getType() == null) { - return that.getName() == null && that.getType() == null; - } - return getType().equals(that.getType()); - } - if (getType() == null) { - return that.getType() == null && getName().equals(that.getName()); - } - return getName().equals(that.getName()) && getType().equals(that.getType()); - } - - @Override - public int hashCode() { - if (getName() == null && getType() == null) { - return 4711; - } - if (getType() == null) { - return getName().hashCode(); - } - if (getName() == null) { - return getType().hashCode(); - } - return getName().hashCode() ^ getType().hashCode(); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/CorePlugin.java b/src/main/java/org/openjdk/jmc/ui/common/CorePlugin.java deleted file mode 100644 index a50ae968..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/CorePlugin.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common; - -import java.util.logging.Logger; - -/** - * The Core Plug-in class for Mission Control - */ -public class CorePlugin { - - public static final String PLUGIN_ID = "org.openjdk.jmc.ui.common"; //$NON-NLS-1$ - - private static final CorePlugin plugin = new CorePlugin(); - private static final Logger m_logger = Logger.getLogger(PLUGIN_ID); - - private CorePlugin() { - } - - public static CorePlugin getDefault() { - return plugin; - } - - public Logger getLogger() { - return m_logger; - } - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/action/Executable.java b/src/main/java/org/openjdk/jmc/ui/common/action/Executable.java deleted file mode 100644 index 3542da4b..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/action/Executable.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.action; - -/** - * An interface for objects that can be executed. This is very similar to the {@link Runnable} - * interface but the execute method in this interface may throw exceptions. - */ -public interface Executable { - - /** - * Run this executable. Like {@link Runnable#run()} but may throw an exception. - */ - public void execute() throws Exception; -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/action/IActionProvider.java b/src/main/java/org/openjdk/jmc/ui/common/action/IActionProvider.java deleted file mode 100644 index 6d8ba1d9..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/action/IActionProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.action; - -import java.util.Collection; - -import org.openjdk.jmc.ui.common.tree.IParent; - -/** - * A tree of {@link IUserAction}. - */ -public interface IActionProvider extends IParent { - - /** - * @return The default action for this provider. This action should be a member of the - * {@link #getActions()} collection. - */ - IUserAction getDefaultAction(); - - /** - * @return a collection of actions for this provider - */ - Collection getActions(); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/action/IUserAction.java b/src/main/java/org/openjdk/jmc/ui/common/action/IUserAction.java deleted file mode 100644 index 41743264..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/action/IUserAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.action; - -import org.openjdk.jmc.common.IDescribable; - -/** - * An action that may be displayed in a user interface and also may be executed. - */ -public interface IUserAction extends IDescribable, Executable { - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/jvm/Connectable.java b/src/main/java/org/openjdk/jmc/ui/common/jvm/Connectable.java deleted file mode 100644 index 79b2ecef..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/jvm/Connectable.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.jvm; - -/** - * Enum describing different JVM connectability possibilities. - */ -public enum Connectable { - /** - * The JVM can be connected to using attach. - */ - ATTACHABLE, - /** - * The JVM can be connected to using the management agent. - */ - MGMNT_AGENT_STARTED, - /** - * The JVM can't be connected to. - */ - NO, - UNKNOWN; - - public boolean isUnconnectable() { - return this == NO; - } - - public boolean isAttachable() { - return this == ATTACHABLE; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMArch.java b/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMArch.java deleted file mode 100644 index 63cb1172..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMArch.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.jvm; - -import java.util.Properties; - -/** - * Enum for the different JVM architectures. - */ -public enum JVMArch { - BIT32, BIT64, UNKNOWN, OTHER; - - public static JVMArch getCurrentJVMArch() { - return getJVMArch(System.getProperties()); - } - - public static JVMArch getJVMArch(Properties props) { - String jreArch = System.getProperty("sun.arch.data.model"); //$NON-NLS-1$ - if (jreArch.contains("64")) { //$NON-NLS-1$ - return JVMArch.BIT64; - } else if (jreArch.contains("32")) { //$NON-NLS-1$ - return JVMArch.BIT32; - } else { - return OTHER; - } - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMCommandLineToolkit.java b/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMCommandLineToolkit.java deleted file mode 100644 index 10b2a61c..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMCommandLineToolkit.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.jvm; - -import java.util.StringTokenizer; - -public class JVMCommandLineToolkit { - - /** - * @param commandLine - * @return the class/jar that is being run. - */ - public static String getMainClassOrJar(String commandLine) { - if (commandLine == null || commandLine.length() == 0) { - return commandLine; - } - // Does not handle the case where directory name contains ' -'. - String[] s = commandLine.split(" -"); //$NON-NLS-1$ - return s[0]; - } - - /** - * Removes jvm flags from full commandline Does not handle space in paths. - * - * @param cmdLine - * Full commandline of jvm - * @return Commandline with only main class or jar file, and args to the java application. - */ - public static String getJavaCommandLine(String cmdLine) { - if (cmdLine == null || cmdLine.length() == 0) { - return cmdLine; - } - StringTokenizer tokenizer = new StringTokenizer(cmdLine, " "); //$NON-NLS-1$ - StringBuilder sb = new StringBuilder(); - boolean foundJava = false; - String token = ""; //$NON-NLS-1$ - String previousToken; - while (tokenizer.hasMoreElements()) { - previousToken = token; - token = tokenizer.nextToken(); - if (!foundJava) { - // Find the first token that does not start with -, or is the first after -cp or -classpath, that should - // be the classname or jarfile - if (!token.startsWith("-") && !previousToken.equals("-cp") && !previousToken.equals("-classpath")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - foundJava = true; - sb.append(token).append(" "); //$NON-NLS-1$ - } - } else { - sb.append(token).append(" "); //$NON-NLS-1$ - } - } - return sb.toString().trim(); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java b/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java deleted file mode 100644 index 4a1cff1d..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.jvm; - -/** - * Metadata for a running JVM - */ -public class JVMDescriptor { - private final String javaVersion; - private final JVMType jvmType; - private final String jvmName; - private final String jvmVendor; - private final JVMArch jvmArch; - private final String javaCommand; - private final String jvmArguments; - private final Integer pid; - private final Boolean debug; - private final Connectable connectable; - - public JVMDescriptor(String javaVersion, JVMType jvmType, JVMArch jvmArch, String javaCommand, String jvmArguments, - String jvmName, String jvmVendor, Integer pid, boolean debug, Connectable attachable) { - super(); - this.javaVersion = javaVersion; - this.jvmType = jvmType; - this.jvmArch = jvmArch; - this.javaCommand = javaCommand; - this.jvmArguments = jvmArguments; - this.jvmName = jvmName; - this.jvmVendor = jvmVendor; - this.pid = pid; - this.debug = debug; - connectable = attachable; - } - - public String getJavaVersion() { - return javaVersion; - } - - public JVMType getJvmType() { - return jvmType; - } - - public JVMArch getJvmArch() { - return jvmArch; - } - - public String getJavaCommand() { - return javaCommand; - } - - public String getJVMArguments() { - return jvmArguments; - } - - public String getJvmName() { - return jvmName; - } - - public String getJvmVendor() { - return jvmVendor; - } - - public Integer getPid() { - return pid; - } - - public Boolean isDebug() { - return debug; - } - - public Boolean isUnconnectable() { - return connectable.isUnconnectable(); - } - - public Boolean isAttachable() { - return connectable.isAttachable(); - } - - @Override - public String toString() { - return "[JVMDescriptor] Java command: " + getJavaCommand() + " PID: " + getPid(); //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMType.java b/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMType.java deleted file mode 100644 index e1dd0ede..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMType.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.jvm; - -import org.openjdk.jmc.common.version.JavaVMVersionToolkit; - -/** - * Enum for the different JVMs. - */ -public enum JVMType { - /** - * The JVM is JRockit. - */ - JROCKIT, - /** - * The JVM is Hotspot. - */ - HOTSPOT, - /** - * The JVM is unknown. - */ - UNKNOWN, - /** - * The JVM is some other JVM. - */ - OTHER; - - /** - * Derive the {@link JVMType} from a jvm name, e.g. the system property java.vm.name. - * - * @param jvmName - * the jvm name to get the JVMType for. - * @return the {@link JVMType} for the jvm name. - */ - public static JVMType getJVMType(String jvmName) { - if (JavaVMVersionToolkit.isJRockitJVMName(jvmName)) { - return JVMType.JROCKIT; - } else if (JavaVMVersionToolkit.isHotspotJVMName(jvmName)) { - return JVMType.HOTSPOT; - } - return JVMType.OTHER; - } - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Constants.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Constants.java deleted file mode 100644 index 7779d519..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Constants.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.util.HashMap; - -import org.openjdk.jmc.ui.common.labelingrules.NameConverter.ValueArrayInfo; - -/** - * Constant mapping database. - */ -final class Constants { - // A mapping from constants to their expanded form. - private final static HashMap constants = new HashMap<>(); - private final static Constants instance = new Constants(); - - static Constants getInstance() { - return instance; - } - - public Constants() { - initDefaultConstants(); - } - - private void initDefaultConstants() { - // setConstant("ThisPID", MessageFormat.format("{0,number,#}", new Object[] {Integer.valueOf(MBeanToolkit.getThisPID())})); //$NON-NLS-1$ //$NON-NLS-2$ - for (ValueArrayInfo info : ValueArrayInfo.values()) { - setConstant(info.getValueName(), info.getMatchExpression()); - } - setConstant("StrConstDebug", "Debug"); //$NON-NLS-1$ - setConstant("StrConstJVMJRockit", "JRockit"); //$NON-NLS-1$ - setConstant("StrConstJVMUnknown", "Unknown"); //$NON-NLS-1$ - } - - /** - * Adds a constant to this name converter. - * - * @param key - * the name of the constant. - * @param value - * the value to assign the constant. - */ - public void setConstant(String key, Object value) { - if (value == null) { - throw new IllegalArgumentException("You may not add a variable which has a value that is null!"); //$NON-NLS-1$ - } - constants.put(key, value); - } - - public Object getConstant(String key) { - return constants.get(key); - } - - public boolean containsConstant(String key) { - return constants.containsKey(key); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Formatter.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Formatter.java deleted file mode 100644 index e7a76fe9..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Formatter.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.text.MessageFormat; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Helper class for doing the formatting. - */ -final class Formatter { - private static final char REGEXP_DELIMITER = ':'; - private final String formatPart; - - public Formatter(String formatPart) { - this.formatPart = formatPart; - } - - /** - * @param vals - * the array of values to format. - * @return a formatted string representing the values according to the formatting string - * supplied on creation. - */ - public String format(Object[] vals) { - return MessageFormat.format(Formatter.replaceVariables(formatPart, vals), vals).trim(); - } - - static String replaceVariables(String formatString, Object[] input) { - StringBuffer buffer = new StringBuffer(); - StringTokenizer stringTokenizer = new StringTokenizer(formatString, "{}", true); //$NON-NLS-1$ - while (stringTokenizer.hasMoreTokens()) { - String token = stringTokenizer.nextToken(); - if (token.equals("{")) { //$NON-NLS-1$ - if (!stringTokenizer.hasMoreTokens()) { - throw new IllegalArgumentException("Found unmatched { in rule!"); //$NON-NLS-1$ - } - String content = stringTokenizer.nextToken(); - String regexp = getRegexpPart(content); - - if (regexp != null) { - content = getVariablePart(content); - } - - if (Variables.getInstance().containsVariable(content)) { - token = Variables.getInstance().getVariable(content).evaluate(input); - if (regexp != null) { - token = apply(regexp, token); - } - stringTokenizer.nextToken(); - } else { - token = "{" + content; //$NON-NLS-1$ - } - } - buffer.append(token); - } - return buffer.toString(); - } - - /** - * Applies the regular expression on the content and returns the first capture group for each - * match appended together. The idea is to only have one. We could start supporting more if we - * need to. - * - * @param regexp - * the regular expression (should currently contain at least one capture group, and - * only the first will be used). - * @param content - * the content to which apply the regular expression. - * @return the matching capture group for every match found, appended together. - */ - private static String apply(String regexp, String content) { - StringBuilder builder = new StringBuilder(); - Pattern pattern = Pattern.compile(regexp); - Matcher matcher = pattern.matcher(content); - - while (matcher.find()) { - builder.append(matcher.group(1)); - } - return builder.toString(); - } - - private static String getVariablePart(String content) { - int index = content.indexOf(REGEXP_DELIMITER); - return content.substring(0, index); - } - - private static String getRegexpPart(String content) { - int index = content.indexOf(REGEXP_DELIMITER); - if (index < 0) { - return null; - } - return content.substring(index + 1); - } - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/IVariableEvaluator.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/IVariableEvaluator.java deleted file mode 100644 index 050007e7..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/IVariableEvaluator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -interface IVariableEvaluator { - /** - * @param input - * the values to evaluate. - * @return the result from the evaluation. - */ - String evaluate(Object[] input); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Matcher.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Matcher.java deleted file mode 100644 index 3f62a9f9..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Matcher.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.text.MessageFormat; -import java.util.Locale; - -/** - * Helper class for doing the matching. - */ -final class Matcher { - private final String matchPart; - private MessageFormat matchMessageFormat; - - /** - * Constructor - */ - public Matcher(String matchPart) { - this.matchPart = matchPart.replace('=', '\0'); - initialize(this.matchPart); - } - - private void initialize(String matchPart) { - matchMessageFormat = new MessageFormat(matchPart, new Locale("sv", "SE")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * @param vals - * the array of values to check. - * @return true if the set of values matches the matching part of the rule. - */ - public boolean matches(Object[] vals) { - // Resolving all variables... - String resolved = matchMessageFormat.format(vals).replace('\n', ' '); - String[] parts = resolved.split("\0"); //$NON-NLS-1$ - String left = parts[0].trim(); - String right = parts[1].trim(); - return left.equals(right) || left.matches(right); - } - - @Override - public String toString() { - return "Matcher [" + matchPart + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NameConverter.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NameConverter.java deleted file mode 100644 index 68ee52d7..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NameConverter.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.logging.Level; - -import org.openjdk.jmc.ui.common.CorePlugin; -import org.openjdk.jmc.ui.common.jvm.JVMCommandLineToolkit; -import org.openjdk.jmc.ui.common.jvm.JVMDescriptor; -import org.openjdk.jmc.ui.common.resource.Resource; -import org.openjdk.jmc.ui.common.util.Environment; - -/** - * Converts names according to rules specified with the {@value #LABELING_RULES_EXTENSION_POINT} - * extension point. - */ -public final class NameConverter { - private static final String LABELING_RULES_EXTENSION_POINT = "org.openjdk.jmc.ui.common.labelingRules"; //$NON-NLS-1$ - private static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$ - private static final Comparator COMPARATOR = new Comparator() { - @Override - public int compare(NamingRule o1, NamingRule o2) { - return o2.getPriority() - o1.getPriority(); - } - }; - - private static final NameConverter INSTANCE = new NameConverter(); - - static enum ValueArrayInfo { - JAVAVERSION(0, "JDK", "{0}"), //$NON-NLS-1$ //$NON-NLS-2$ - JVMTYPE(1, "JVMType", "{1}"), //$NON-NLS-1$ //$NON-NLS-2$ - JVMARCH(2, "JVMArch", "{2}"), //$NON-NLS-1$ //$NON-NLS-2$ - NAME(3, "Name", "{3}"), //$NON-NLS-1$ //$NON-NLS-2$ - JAVACOMMAND(4, "JavaCmd", "{4}"), //$NON-NLS-1$ //$NON-NLS-2$ - PID(5, "PID", "{5}"), //$NON-NLS-1$ //$NON-NLS-2$ - DEBUG(6, "IsDebug", "{6}"), //$NON-NLS-1$ //$NON-NLS-2$ - JVMARGS(7, "JVMArgs", "{7}"); //$NON-NLS-1$ //$NON-NLS-2$ - - private int index; - private String valueName; - private String matchExpression; - - ValueArrayInfo(int index, String valueName, String matchExpression) { - this.index = index; - this.valueName = valueName; - this.matchExpression = matchExpression; - } - - public int getIndex() { - return index; - } - - public String getValueName() { - return valueName; - } - - public String getMatchExpression() { - return matchExpression; - } - } - - private final List rules = new ArrayList<>(); - - /** - * @return a singleton instance - */ - public static NameConverter getInstance() { - return INSTANCE; - } - - /** - * Create a new name converter instance. This should only be used if you want a new, clean - * instance. Normally the {@link NameConverter#getInstance()} method should be used instead to - * get a singleton instance. - */ - public NameConverter() { - initializeRulesFromExtensions(); - } - - /** - * @param descriptor - * @return the properly formatted values. If no matching formatter could be found, the default - * format String as defined in NameConverter_LOCAL_NAME_TEMPLATE will be used. - */ - public String format(JVMDescriptor descriptor) { - // FIXME: Somehow rewrite this to avoid things like [Unknown][Unknown] and empty () when the pid is unknown. - // JDP being the typical use case. - Object[] values = prepareValues(descriptor); - NamingRule rule = getMatchingRule(values); - if (rule != null) { - return rule.format(values); - } - // Should always be a catch all rule, but if someone messes up, we will use the LOCAL_NAME_TEMPLATE. - return MessageFormat.format(" ({0}) {1}{2} ({3})", descriptor); - } - - public Resource getImageResource(JVMDescriptor descriptor) { - NamingRule rule = getMatchingRule(prepareValues(descriptor)); - return rule == null ? null : rule.getImageResource(); - } - - /** - * Adds a rule to the name converter. - *

- * Adding rules should normally not be done using this method, but rather through the - * {@value #LABELING_RULES_EXTENSION_POINT} extension point. - * - * @param rule - * the rule to add. - */ - public void addNamingRule(NamingRule rule) { - rules.add(rule); - rules.sort(COMPARATOR); - } - - /** - * @return an immutable list of the available rules. - */ - public List getRules() { - return Collections.unmodifiableList(rules); - } - - private NamingRule getMatchingRule(Object[] values) { - for (NamingRule rule : rules) { - try { - if (rule.matches(values)) { - return rule; - } - } catch (RuntimeException e) { - // Silently ignore broken rules for now. - } - } - return null; - } - - private void initializeRulesFromExtensions() { - // None registered - } - - private Object[] prepareValues(JVMDescriptor descriptor) { - return new Object[] {descriptor.getJavaVersion(), descriptor.getJvmType(), descriptor.getJvmArch(), - getValidName(descriptor), descriptor.getJavaCommand(), - descriptor.getPid() != null ? String.valueOf(descriptor.getPid()) : "", descriptor.isDebug(), //$NON-NLS-1$ - descriptor.getJVMArguments()}; - } - - private String getValidName(JVMDescriptor descriptor) { - Integer pid = descriptor.getPid(); - if (pid != null && pid.intValue() == Environment.getThisPID() && descriptor.isAttachable()) { - return "io.cryostat" + ".this"; //$NON-NLS-1$ - } - String name = JVMCommandLineToolkit.getMainClassOrJar(descriptor.getJavaCommand()); - if (name != null && name.length() > 0) { - return name; - } - return "Local"; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NamingRule.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NamingRule.java deleted file mode 100644 index 80a3699f..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/NamingRule.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.util.StringTokenizer; - -import org.openjdk.jmc.ui.common.resource.Resource; - -/** - */ -public final class NamingRule { - private final String normalizedExpression; - private final Matcher matcher; - private final Formatter formatter; - private final int priority; - private final String name; - private final Resource icon; - - public NamingRule(String name, String matchingPart, String formattingPart, int priority, Resource icon) { - this(name, createNormalizedExpression(matchingPart, formattingPart), priority, icon); - } - - public NamingRule(String name, String normalizedExpression, int priority, Resource icon) { - this.normalizedExpression = normalizedExpression; - if (normalizedExpression.equals("")) { //$NON-NLS-1$ - throw new IllegalArgumentException("Invalid rule - you may not add empty rules!"); //$NON-NLS-1$ - } - String expandedExpression = replaceConstants(normalizedExpression); - String[] expressions = expandedExpression.split("=>"); //$NON-NLS-1$ - if (expressions.length != 2) { - throw new IllegalArgumentException("Invalid rule - need both match part and transform part."); //$NON-NLS-1$ - } - matcher = new Matcher(expressions[0]); - formatter = new Formatter(expressions[1]); - this.priority = priority; - this.icon = icon; - this.name = name; - } - - private static String createNormalizedExpression(String matchPart, String formattingPart) { - return matchPart + "=>" + formattingPart; //$NON-NLS-1$ - } - - /** - * @return the full naming rule in a single string expression on the format: - * matchPart=>formatPart. - */ - public String getNormalizedExpression() { - return normalizedExpression; - } - - public boolean matches(Object[] values) { - return matcher.matches(values); - } - - public String format(Object[] values) { - return formatter.format(values); - } - - @Override - public String toString() { - return "MatchingRule [name: " + name + ", expression: " + normalizedExpression + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - @Override - public int hashCode() { - return normalizedExpression.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof NamingRule)) { - return false; - } - return normalizedExpression.equals(((NamingRule) obj).normalizedExpression); - } - - public int getPriority() { - return priority; - } - - public String getName() { - return name; - } - - private static String replaceConstants(String rule) { - StringBuffer buffer = new StringBuffer(); - StringTokenizer stringTokenizer = new StringTokenizer(rule, "{}", true); //$NON-NLS-1$ - while (stringTokenizer.hasMoreTokens()) { - String token = stringTokenizer.nextToken(); - if (token.equals("{")) { //$NON-NLS-1$ - if (!stringTokenizer.hasMoreTokens()) { - throw new IllegalArgumentException("Found unmatched { in rule!"); //$NON-NLS-1$ - } - String content = stringTokenizer.nextToken(); - if (Constants.getInstance().containsConstant(content)) { - token = Constants.getInstance().getConstant(content).toString(); - stringTokenizer.nextToken(); - } else { - token += content; - } - } - buffer.append(token); - } - return buffer.toString(); - } - - public Resource getImageResource() { - return icon; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Variables.java b/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Variables.java deleted file mode 100644 index 75133de0..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/labelingrules/Variables.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.labelingrules; - -import java.util.HashMap; - -import org.openjdk.jmc.ui.common.jvm.JVMArch; -import org.openjdk.jmc.ui.common.jvm.JVMType; -import org.openjdk.jmc.ui.common.labelingrules.NameConverter.ValueArrayInfo; - -/** - * Variable mapping database. - */ -class Variables { - // A mapping from variables to IVariableEvaluator. - private final static HashMap variables = new HashMap<>(); - private final static Variables instance = new Variables(); - - public Variables() { - initDefaultVariables(); - } - - // Variables are late bound matching variables that (for performance reasons) will be applied to the resulting - // string just before returning it. - private void initDefaultVariables() { - // FIXME: Could possibly be a good idea to combine JVMType and JVMArch into one enum, at least to avoid "[Unknown][Unknown]" - // This occurs for JDP connections. - variables.put("StrJVMType", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - JVMType type = (JVMType) input[ValueArrayInfo.JVMTYPE.getIndex()]; - String typeStr = getLocalizedTypeStr(type); - if (typeStr == null) { - return ""; //$NON-NLS-1$ - } - return "[" + typeStr + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - private String getLocalizedTypeStr(JVMType type) { - if (type == JVMType.JROCKIT) { - return "JRockit"; - } - if (type == JVMType.HOTSPOT) { - return "HotSpot"; - } - if (type == JVMType.OTHER) { - return "Other"; - } - return "Unknown"; - } - }); - variables.put("UnsupportedStrJVMType", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - JVMType type = (JVMType) input[ValueArrayInfo.JVMTYPE.getIndex()]; - String typeStr = getLocalizedTypeStr(type); - if (typeStr == null) { - return ""; //$NON-NLS-1$ - } - return "[" + typeStr + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - private String getLocalizedTypeStr(JVMType type) { - if (type == JVMType.JROCKIT) { - return "JRockit"; - } - if (type == JVMType.HOTSPOT) { - return null; - } - if (type == JVMType.OTHER) { - return null; - } - return "Unknown"; - } - }); - variables.put("StrJVMArch", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - JVMArch arch = (JVMArch) input[ValueArrayInfo.JVMARCH.getIndex()]; - String archStr = getLocalizedArchStr(arch); - if (archStr == null) { - return ""; //$NON-NLS-1$ - } - return "[" + archStr + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - private String getLocalizedArchStr(JVMArch arch) { - if (arch == JVMArch.BIT32) { - return "32-bit"; - } - if (arch == JVMArch.BIT64) { - return "64-bit"; - } - if (arch == JVMArch.OTHER) { - return "Other arch"; - } - return "Unknown"; - } - }); - variables.put("UnsupportedStrJVMArch", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - JVMArch arch = (JVMArch) input[ValueArrayInfo.JVMARCH.getIndex()]; - JVMType type = (JVMType) input[ValueArrayInfo.JVMTYPE.getIndex()]; - String archStr = getLocalizedArchStr(arch, type); - if (archStr == null) { - return ""; //$NON-NLS-1$ - } - return "[" + archStr + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - private String getLocalizedArchStr(JVMArch arch, JVMType type) { - JVMArch thisArch = JVMArch.getCurrentJVMArch(); - if (arch == thisArch) { - return null; - } - if (arch == JVMArch.BIT32) { - return "32-bit"; - } - if (arch == JVMArch.BIT64) { - return "64-bit"; - } - if (arch == JVMArch.OTHER) { - return null; - } - // Avoid showing double [Unknown] - return type == JVMType.UNKNOWN ? null : "Unknown"; - } - }); - variables.put("StrDebug", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - return "true".equals(input[ValueArrayInfo.DEBUG.getIndex()]) ? "[Debug]" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - : ""; //$NON-NLS-1$ - } - }); - variables.put("StrJDK", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - String version = (String) input[ValueArrayInfo.JAVAVERSION.getIndex()]; - return version == null ? "" : "[" + version + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - }); - variables.put("JVMArgs", new IVariableEvaluator() { //$NON-NLS-1$ - @Override - public String evaluate(Object[] input) { - return (String) input[ValueArrayInfo.JVMARGS.getIndex()]; - } - }); - } - - public static Variables getInstance() { - return instance; - } - - public boolean containsVariable(String content) { - return variables.containsKey(content); - } - - public IVariableEvaluator getVariable(String content) { - return variables.get(content); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/resource/IImageResource.java b/src/main/java/org/openjdk/jmc/ui/common/resource/IImageResource.java deleted file mode 100644 index eb0d15ab..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/resource/IImageResource.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.resource; - -/** - * Interface for classes that can provide an image resource. - */ -public interface IImageResource { - - public Resource getImageResource(); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/resource/Resource.java b/src/main/java/org/openjdk/jmc/ui/common/resource/Resource.java deleted file mode 100644 index cca0617f..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/resource/Resource.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.resource; - -/** - * Class identifying a resource in an Eclipse plugin. - */ -public class Resource { - - private final String pluginId; - private final String resource; - - /** - * @param pluginId - * id of the Eclipse plugin containing the resource - * @param resource - * resource path within the Eclipse plugin - */ - public Resource(String pluginId, String resource) { - this.pluginId = pluginId; - this.resource = resource; - } - - public String getPluginId() { - return pluginId; - } - - public String getResourcePath() { - return resource; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/ActionNotGrantedException.java b/src/main/java/org/openjdk/jmc/ui/common/security/ActionNotGrantedException.java deleted file mode 100644 index a95ddff9..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/ActionNotGrantedException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -/** - * Exception thrown when an action is not permitted - */ -public class ActionNotGrantedException extends SecurityException { - - private static final long serialVersionUID = 4241246317937726872L; - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/CredentialsNotAvailableException.java b/src/main/java/org/openjdk/jmc/ui/common/security/CredentialsNotAvailableException.java deleted file mode 100644 index d648649d..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/CredentialsNotAvailableException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -/** - * Exception thrown when credentials cannot be loaded - */ -public class CredentialsNotAvailableException extends SecurityException { - - private static final long serialVersionUID = -8098399684811165719L; - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/FailedToSaveException.java b/src/main/java/org/openjdk/jmc/ui/common/security/FailedToSaveException.java deleted file mode 100644 index b5b199d2..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/FailedToSaveException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -public class FailedToSaveException extends SecurityException { - private static final long serialVersionUID = 8887494261316929780L; - - public FailedToSaveException(Throwable t) { - super(t); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/ICredentials.java b/src/main/java/org/openjdk/jmc/ui/common/security/ICredentials.java deleted file mode 100644 index 390ff633..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/ICredentials.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -/** - * An object holding a username and a password. - */ -public interface ICredentials { - - /** - * @return the username - */ - public String getUsername() throws SecurityException; - - /** - * @return the password - */ - public String getPassword() throws SecurityException; - - /** - * @return the id of the exported credentials, or null if the object is not exported. - */ - public String getExportedId(); - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/ISecurityManager.java b/src/main/java/org/openjdk/jmc/ui/common/security/ISecurityManager.java deleted file mode 100644 index 3a340931..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/ISecurityManager.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -import java.util.Set; - -/** - * This is the interface for the security manager used by Mission Control. It may seem like a - * security breach to use Strings for passwords (some may be concerned that they remain in the - * system, since they are immutable and can not be cleared in the same manner as for instance a char - * array). However, since the credentials must be made into strings to be passed into the JMX - * environment when establishing a connection I may as well use strings to make the API simpler to - * use. - */ -public interface ISecurityManager { - - /** - * Returns a stored object and removes it from the security manager - * - * @param key - * the key of the stored object - * @return the stored value, or null if the store is locked. Will be a String[] or a byte[] - * depending on which store method it was inserted with. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - Object withdraw(String key) throws SecurityException; - - /** - * When the store is accessible, all objects belonging to {@code family} that is not identified - * by {@code keys} will be removed - * - * @param family - * the family to clear - * @param keys - * the keys of the objects to keep - */ - void clearFamily(String family, Set keys) throws FailedToSaveException; - - /** - * Returns a stored object - * - * @param key - * the key of the stored object - * @return the stored value. Will be a String[] or a byte[] depending on which store method it - * was inserted with. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - Object get(String key) throws SecurityException; - - /** - * @param key - * the key of the object - * @param value - * the value to store secure. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - void storeWithKey(String key, byte ... value) throws SecurityException; - - /** - * @param key - * the key of the object - * @param value - * the value to store secure. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - void storeWithKey(String key, String ... value) throws SecurityException; - - /** - * @param family - * the family to which the object belongs. - * @param value - * the value to store secure. - * @return the key of the stored object. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - String storeInFamily(String family, byte ... value) throws SecurityException; - - /** - * @param family - * the family to which the object belongs. - * @param value - * the value to store secure. - * @return the key of the stored object. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - String storeInFamily(String family, String ... value) throws SecurityException; - - /** - * @param value - * the value to store secure. - * @return the key of the stored object. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - String store(byte ... value) throws SecurityException; - - /** - * @param value - * the value to store secure. - * @return the key of the stored object. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - String store(String ... value) throws SecurityException; - - /** - * Unlocks the storage if it is locked - * - * @throws ActionNotGrantedException - * if the master password was not given. - */ - void unlock() throws ActionNotGrantedException; - - /** - * @return true if the store is locked, false otherwise. - */ - boolean isLocked(); - - /** - * @param key - * the key of the stored object - * @return true if the key exists, false otherwise. - */ - boolean hasKey(String key); - - /** - * @return the supported encryption ciphers. - */ - Set getEncryptionCiphers(); - - /** - * @return the currently used encryption cipher. - */ - String getEncryptionCipher(); - - /** - * Sets the encryption ciphers to use. - * - * @param encryptionCipher - * the encryption cipher to use. - * @throws CipherNotAvailableException - * if the provided cipher is not available. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - void setEncryptionCipher(String encryptionCipher) throws SecurityException; - - /** - * Triggers a change of the master password. - * - * @throws CipherNotAvailableException - * if no cipher is available. - * @throws ActionNotGrantedException - * if the master password was not given. - * @throws SecurityException - * for other security problems. - */ - void changeMasterPassword() throws SecurityException; - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/InMemoryCredentials.java b/src/main/java/org/openjdk/jmc/ui/common/security/InMemoryCredentials.java deleted file mode 100644 index 1cbc2148..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/InMemoryCredentials.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -/** - * Credentials only stored in memory - */ -public class InMemoryCredentials implements ICredentials { - private final String username; - private final String password; - - public InMemoryCredentials(String username, String password) { - this.username = username; - this.password = password; - } - - @Override - public String getUsername() { - return username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getExportedId() { - return null; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/PersistentCredentials.java b/src/main/java/org/openjdk/jmc/ui/common/security/PersistentCredentials.java deleted file mode 100644 index fb0b506d..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/PersistentCredentials.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * {@link ICredentials} stored in the {@link ISecurityManager}. The username and password are lazy - * loaded on demand. - */ -public class PersistentCredentials implements ICredentials { - - private final String id; - private String[] wrapped; - - private static final Pattern PASSWORD_PATTERN = Pattern - .compile("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#(&)[{-}]:;',?/*~$^+=<>]).{8,20}$"); //$NON-NLS-1$ - - public PersistentCredentials(String id) { - this.id = id; - } - - public PersistentCredentials(String username, String password) throws SecurityException { - this(username, password, null); - } - - public PersistentCredentials(String username, String password, String family) throws SecurityException { - wrapped = new String[] {username, password}; - id = SecurityManagerFactory.getSecurityManager().storeInFamily(family, wrapped); - } - - @Override - public String getUsername() throws SecurityException { - return getCredentials()[0]; - } - - @Override - public String getPassword() throws SecurityException { - return getCredentials()[1]; - } - - private String[] getCredentials() throws SecurityException { - if (wrapped == null) { - wrapped = (String[]) SecurityManagerFactory.getSecurityManager().get(id); - } - if (wrapped == null || wrapped.length != 2) { - throw new CredentialsNotAvailableException(); - } - return wrapped; - } - - @Override - public String getExportedId() { - return id; - } - - public static boolean isPasswordValid(final String password) { - Matcher matcher = PASSWORD_PATTERN.matcher(password); - return matcher.matches(); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/SecurelyStoredByteArray.java b/src/main/java/org/openjdk/jmc/ui/common/security/SecurelyStoredByteArray.java deleted file mode 100644 index 2309dfba..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/SecurelyStoredByteArray.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -public class SecurelyStoredByteArray { - - private final String id; - - public SecurelyStoredByteArray(String id) { - this.id = id; - } - - public boolean exists() { - return SecurityManagerFactory.getSecurityManager().hasKey(id); - } - - public byte[] get() throws Exception { - return (byte[]) SecurityManagerFactory.getSecurityManager().get(id); - } - - public void set(byte ... value) throws Exception { - SecurityManagerFactory.getSecurityManager().storeWithKey(id, value); - } - - public void remove() throws Exception { - SecurityManagerFactory.getSecurityManager().withdraw(id); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/SecurityException.java b/src/main/java/org/openjdk/jmc/ui/common/security/SecurityException.java deleted file mode 100644 index 2647b4eb..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/SecurityException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -/** - * This is the main exception thrown by the Security API. - */ -public class SecurityException extends Exception { - private static final long serialVersionUID = 6644781676988195632L; - - public SecurityException() { - super(); - } - - public SecurityException(String message, Throwable cause) { - super(message); - initCause(cause); - } - - public SecurityException(String message) { - super(message); - } - - public SecurityException(Throwable cause) { - initCause(cause); - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/security/SecurityManagerFactory.java b/src/main/java/org/openjdk/jmc/ui/common/security/SecurityManagerFactory.java deleted file mode 100644 index fe600854..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/security/SecurityManagerFactory.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.security; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * This is the global security manager factory for Mission Control. You can only have one - * SecurityManager, and it is initialized at start. It can not be changed once initialized. The only - * way to change security manager is to set the system property - * org.openjdk.jmc.rjmx.security.manager=<class> before this factory class is instantiated. - * The class must implement ISecurityManager, and it must have a default constructor. - */ -public final class SecurityManagerFactory { - private final static Logger LOGGER = Logger.getLogger("org.openjdk.jmc.ui.common.security"); //$NON-NLS-1$ - - private static ISecurityManager instance; - - static { - String className = System.getProperty("org.openjdk.jmc.common.security.manager"); //$NON-NLS-1$ - try { - if (className != null) { - Class c = Class.forName(className); - instance = (ISecurityManager) c.newInstance(); - } - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Could not create Security manager for className. Using default! Exception was:", //$NON-NLS-1$ - e); - } - } - - public synchronized final static void setDefaultSecurityManager(ISecurityManager manager) { - if (instance == null) { - instance = manager; - } - } - - public synchronized final static ISecurityManager getSecurityManager() { - return instance; - } - - private SecurityManagerFactory() { - throw new AssertionError("This class is not to be instantiated!"); //$NON-NLS-1$ - } - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/tree/IArray.java b/src/main/java/org/openjdk/jmc/ui/common/tree/IArray.java deleted file mode 100644 index 0ffaa9f7..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/tree/IArray.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.tree; - -/** - * Interface for objects that can be viewed as an array. - * - * @param - * object type of the array elements - */ -public interface IArray { - - /** - * @return {@code true} if {@link #elements()} would return an array with length zero - */ - boolean isEmpty(); - - /** - * @return an array representation of this object - */ - T[] elements(); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/tree/IParent.java b/src/main/java/org/openjdk/jmc/ui/common/tree/IParent.java deleted file mode 100644 index 7fc5dec5..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/tree/IParent.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.tree; - -import java.util.Collection; - -/** - * An interface for objects that are parents of other objects. - * - * @param - * child object type - */ -public interface IParent { - /** - * @return {@code true} if {@link #getChildren()} would return a non-empty collection - */ - boolean hasChildren(); - - /** - * @return a collection with the child objects - */ - Collection getChildren(); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/util/Environment.java b/src/main/java/org/openjdk/jmc/ui/common/util/Environment.java deleted file mode 100644 index 1fa747d8..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/util/Environment.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.util; - -import java.lang.management.ManagementFactory; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Class that returns information about the OS and other things related to the local environment - */ -public class Environment { - /** - * Known OS types. - */ - public enum OSType { - WINDOWS, MAC, SOLARIS, LINUX, UNKNOWN_UNIX, UNKNOWN; - - @Override - public String toString() { - return name().toLowerCase(); - } - } - - private static final String OS_NAME = System.getProperty("os.name"); //$NON-NLS-1$ - private static final OSType OS_TYPE = determineOSType(getFullOSName()); - private static final boolean IS_DEBUG = Boolean.getBoolean("org.openjdk.jmc.debug"); //$NON-NLS-1$ - private static final int LOCAL_PID; // The PID of the JVM running this mission control. - - static { - LOCAL_PID = initPID(); - if (LOCAL_PID != 0) { - Logger.getLogger("org.openjdk.jmc.common.mbean").log(Level.FINE, //$NON-NLS-1$ - "Acquired local PID. PID resolved to " + LOCAL_PID); //$NON-NLS-1$ - } - } - - /** - * Tell if this Mission Control instance is in debug mode, i.e. was started up with the debug - * flag {@code -Dmcdebug=true}. - * - * @return {@code true} if in debug mode - */ - public static boolean isDebug() { - return IS_DEBUG; - } - - /** - * @return the full OS name found from the system property "os.name" - */ - public static String getFullOSName() { - return OS_NAME; - } - - /** - * @return the OS type - */ - public static OSType getOSType() { - return OS_TYPE; - } - - /** - * @return the "normal" 100% scaled DPI setting of the OS, 96 for Windows & Linux and 72 for - * MacOS. - */ - public static double getNormalDPI() { - return OS_TYPE.equals(OSType.MAC) ? 72d : 96d; - } - - /** - * @return the OS type - */ - private static OSType determineOSType(String os) { - if (os == null) { - return OSType.UNKNOWN; - } - os = os.toLowerCase(); - - if (os.contains("win")) { //$NON-NLS-1$ - return OSType.WINDOWS; - } - if (os.contains("mac")) { //$NON-NLS-1$ - return OSType.MAC; - } - if (os.contains("sunos")) { //$NON-NLS-1$ - return OSType.SOLARIS; - } - if (os.contains("linux")) { //$NON-NLS-1$ - return OSType.LINUX; - } - if (os.contains("nix") || os.contains("nux")) { //$NON-NLS-1$ //$NON-NLS-2$ - return OSType.UNKNOWN_UNIX; - } - return OSType.UNKNOWN; - } - - /** - * @return the PID of this JVM, or 0 if no PID could be determined - */ - public static int getThisPID() { - return LOCAL_PID; - } - - private static int initPID() { - try { - String name = ManagementFactory.getRuntimeMXBean().getName(); - if (name != null) { - String s = name.split("@")[0]; //$NON-NLS-1$ - return Integer.parseInt(s); - } - } catch (Exception e) { - Logger.getLogger("org.openjdk.jmc.common.mbean").log(Level.FINE, //$NON-NLS-1$ - "Could not retrieve PID of this running jvm instance", e); //$NON-NLS-1$ - } - return 0; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/util/Filename.java b/src/main/java/org/openjdk/jmc/ui/common/util/Filename.java deleted file mode 100644 index 66ac93e0..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/util/Filename.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.util; - -import java.text.SimpleDateFormat; -import java.util.Random; - -/** - * Class for handling file names. Primarily used for creating unique file names. - */ -public class Filename { - - private static Random RAND = new Random(); - private final String name; - private final String ext; - - public Filename(String name, String ext) { - this.name = name; - this.ext = ext; - } - - public String getName() { - return name; - } - - public String getExtension() { - return ext; - } - - public Filename asRandomFilename() { - int nextInt = RAND.nextInt(); - SimpleDateFormat sf = new SimpleDateFormat("_yyyy-MM-dd_HH-mm-ss_"); //$NON-NLS-1$ - return new Filename(name + sf.format(System.currentTimeMillis()) + Integer.toHexString(nextInt), ext); - } - - @Override - public String toString() { - return ext.isEmpty() ? name : name + "." + ext; //$NON-NLS-1$ - } - - public static Filename splitFilename(String name) { - int lastPeriod = name.lastIndexOf('.'); - if (lastPeriod < 0) { - return new Filename(name, ""); //$NON-NLS-1$ - } else { - return new Filename(name.substring(0, lastPeriod), name.substring(lastPeriod + 1)); - } - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/util/ICopyable.java b/src/main/java/org/openjdk/jmc/ui/common/util/ICopyable.java deleted file mode 100644 index eadb8103..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/util/ICopyable.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.util; - -/** - * Interface for objects that may be copied. This is similar to {@link Cloneable}, but with the - * addition of {@link ICopyable#isCopyable()} that can tell if the object is truly copyable or not. - */ -public interface ICopyable { - - /** - * @return {@code true} if this object can be copied - */ - boolean isCopyable(); - - /** - * Create a deep copy of this object. If the object is not copyable, then the behavior is - * undefined. {@link ICopyable#isCopyable()} should be called before copying to determine - * whether it is safe. - * - * @return a deep copy of this object - */ - Object copy(); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/util/IObservable.java b/src/main/java/org/openjdk/jmc/ui/common/util/IObservable.java deleted file mode 100644 index dee94e15..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/util/IObservable.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.util; - -import java.util.Observable; -import java.util.Observer; - -/** - * An observable object. This is a solution to make interface observable since {@link Observable} is - * not an interface. Actual instance will probably (but not necessarily) extend the class - * {@link Observable}. - */ -public interface IObservable { - - /** - * Adds an observer to the set of observers. The order in which notifications will be delivered - * to multiple observers is not specified. - * - * @param o - * an observer to be added - */ - void addObserver(Observer o); - - /** - * Deletes an observer from the set of observers. - * - * @param o - * the observer to be deleted - */ - void deleteObserver(Observer o); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/xydata/DataSeries.java b/src/main/java/org/openjdk/jmc/ui/common/xydata/DataSeries.java deleted file mode 100644 index c445baa6..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/xydata/DataSeries.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.xydata; - -import java.util.Iterator; - -/** - * Interface for objects that can produce a series of data points arranged on an X axis. - * - * @param - * Data type of the data points. In order to implement the interval checking of - * {@link #createIterator(long, long)}, it can be desirable that an X value can somehow - * be retrieved from the objects of this type. - */ -public interface DataSeries { - /** - * Return an iterator with data points matching a specified X interval. The X interval is only a - * hint and the iterator may contain data points outside of the interval. - * - * @param min - * the minimum X value of returned data points - * @param max - * the maximum X value of returned data points - * @return an iterator of data points - */ - Iterator createIterator(long min, long max); -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultTimestampedData.java b/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultTimestampedData.java deleted file mode 100644 index 186af8f9..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultTimestampedData.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.xydata; - -import org.openjdk.jmc.common.collection.BoundedList; -import org.openjdk.jmc.common.collection.BoundedList.INode; - -/** - * A default implementation of {@link ITimestampedData} (which is an {@link IXYData} of epoch ns and - * natural numbers). - *

- * It implements {@link INode} in order to save some memory when placed in a {@link BoundedList} - * although this dependency is not really clean and should eventually be fixed. - */ -public class DefaultTimestampedData extends DefaultXYData - implements ITimestampedData, INode { - - private INode next; - - /** - * @param x - * a timestamp in epoch ns - * @param y - * a natural number - */ - public DefaultTimestampedData(Long x, Number y) { - super(x, y); - } - - @Override - public String toString() { - return "Time: " + getX() + " Y: " + getY(); //$NON-NLS-1$ //$NON-NLS-2$ - } - - @Override - public INode getNext() { - return next; - } - - @Override - public void setNext(INode next) { - this.next = next; - } - - @Override - public DefaultTimestampedData getValue() { - return this; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultXYData.java b/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultXYData.java deleted file mode 100644 index 1e4dfb9a..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/xydata/DefaultXYData.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.xydata; - -/** - * A default implementation of {@link IXYData} that simply holds a final value for X and Y. - */ -public class DefaultXYData implements IXYData { - private final X x; - private final Y y; - - public DefaultXYData(X x, Y y) { - this.x = x; - this.y = y; - } - - @Override - public X getX() { - return x; - } - - @Override - public Y getY() { - return y; - } -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/xydata/ITimestampedData.java b/src/main/java/org/openjdk/jmc/ui/common/xydata/ITimestampedData.java deleted file mode 100644 index 6970dc4b..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/xydata/ITimestampedData.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.xydata; - -/** - * A data point on an X/Y chart where the X axis is a timestamp in epoch ns and the Y axis is a - * natural number. - */ -public interface ITimestampedData extends IXYData { - -} diff --git a/src/main/java/org/openjdk/jmc/ui/common/xydata/IXYData.java b/src/main/java/org/openjdk/jmc/ui/common/xydata/IXYData.java deleted file mode 100644 index d62ad3c6..00000000 --- a/src/main/java/org/openjdk/jmc/ui/common/xydata/IXYData.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The contents of this file are subject to the terms of either the Universal Permissive License - * v 1.0 as shown at http://oss.oracle.com/licenses/upl - * - * or the following license: - * - * Redistribution and use in source and binary forms, with or without modification, are permitted - * provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions - * and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of - * conditions and the following disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY - * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.openjdk.jmc.ui.common.xydata; - -/** - * Interface for data points on an X/Y chart. - * - * @param - * X axis data type - * @param - * Y axis data type - */ -public interface IXYData { - - X getX(); - - Y getY(); - -} diff --git a/src/test/java/io/cryostat/core/EventOptionsCustomizerTest.java b/src/test/java/io/cryostat/core/EventOptionsCustomizerTest.java index f5e7ac5a..c1f89741 100644 --- a/src/test/java/io/cryostat/core/EventOptionsCustomizerTest.java +++ b/src/test/java/io/cryostat/core/EventOptionsCustomizerTest.java @@ -24,7 +24,7 @@ import org.openjdk.jmc.common.unit.IOptionDescriptor; import org.openjdk.jmc.flightrecorder.configuration.events.EventOptionID; import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeID; -import org.openjdk.jmc.rjmx.services.jfr.IEventTypeInfo; +import org.openjdk.jmc.flightrecorder.configuration.events.IEventTypeInfo; import io.cryostat.core.EventOptionsCustomizer.EventOptionException; import io.cryostat.core.EventOptionsCustomizer.EventTypeException; diff --git a/src/test/java/io/cryostat/core/net/JFRConnectionToolkitTest.java b/src/test/java/io/cryostat/core/net/JFRConnectionToolkitTest.java index 3ac13eb9..3ea8b9d3 100644 --- a/src/test/java/io/cryostat/core/net/JFRConnectionToolkitTest.java +++ b/src/test/java/io/cryostat/core/net/JFRConnectionToolkitTest.java @@ -21,7 +21,7 @@ import javax.management.remote.JMXServiceURL; -import org.openjdk.jmc.rjmx.internal.WrappedConnectionException; +import org.openjdk.jmc.rjmx.common.internal.WrappedConnectionException; import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem;