Author: cziegeler Date: Fri Sep 22 08:57:59 2017 New Revision: 1809281 URL: http://svn.apache.org/viewvc?rev=1809281&view=rev Log: FELIX-5696 : Separate metatype provider from managed service
Added: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java - copied, changed from r1809280, felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java (with props) Removed: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java Modified: felix/trunk/osgi-r7/scr/changelog.txt felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceServiceFactory.java Modified: felix/trunk/osgi-r7/scr/changelog.txt URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/changelog.txt?rev=1809281&r1=1809280&r2=1809281&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/changelog.txt (original) +++ felix/trunk/osgi-r7/scr/changelog.txt Fri Sep 22 08:57:59 2017 @@ -1,8 +1,37 @@ -Changes from 2.0.8 to 2.1.0 ---------------------------- +Changes from 2.0.12 to 2.1.0 +---------------------------- ** Improvement * [FELIX-5458] Improved ConfigurationPlugin Support (OSGi R7) * [FELIX-5454] Service properties for ComponentFactory (OSGi R7) + * [FELIX-5456] Field injection of component activation objects (OSGi R7) + * [FELIX-5457] Logger support (OSGi R7) + * [FELIX-5456] DTO Updates (OSGi R7) + * [FELIX-5559] Add change count property to runtime service (OSGi R7) + * [FELIX-5590] Add support for single value annotations and new key mapping (OSGi R7) + * [FELIX-5557] Updates to section 112.8.2.2 Coercing Component Property Values + * [FELIX-5695] Use Java 7 as base version + * [FELIX-5696] Separate metatype provider from managed service +** Bug + * [FELIX-5507] ConfigurationAdmin might not be visible to SCR implementation + * [FELIX-5543] Component property types must implement java.lang.annotation.Annotation methods properly + + +Changes from 2.0.10 to 2.0.12 +----------------------------- +** Bug + * [FELIX-5416] Endless loop throwing InterruptedException when shutting down framework + * [FELIX-5627] Class loading issues while finding fields causes an NPE + * [FELIX-5628] Global lock in FieldHandler.NotResolved::resolve method can cause deadlock + + +Changes from 2.0.8 to 2.0.10 +---------------------------- +** Improvement + * [FELIX-5568] SCR contains compact3 profile code +** Bug + * [FELIX-5572] Reference target filter fails when using field strategy for multiple cardinality reference with multiple component instances + * [FELIX-5615] Global lock in BaseMethod.NotResolved::resolve method can cause deadlock + * [FELIX-5613] SCR bundle fails to start without Config Admin Changes from 2.0.6 to 2.0.8 Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java?rev=1809281&r1=1809280&r2=1809281&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java Fri Sep 22 08:57:59 2017 @@ -28,7 +28,6 @@ import org.apache.felix.scr.impl.manager import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedService; import org.osgi.service.log.LogService; @@ -87,9 +86,11 @@ public class ScrConfigurationImpl implem private Boolean globalExtender; - private BundleContext bundleContext; + private volatile BundleContext bundleContext; - private ServiceRegistration<ManagedService> managedService; + private volatile ServiceRegistration<?> managedServiceRef; + + private volatile ServiceRegistration<?> metatypeProviderRef; private ScrCommand scrCommand; @@ -98,7 +99,6 @@ public class ScrConfigurationImpl implem this.activator = activator; } - @SuppressWarnings("unchecked") public void start(final BundleContext bundleContext) { this.bundleContext = bundleContext; @@ -116,19 +116,30 @@ public class ScrConfigurationImpl implem // configuration may be delivered asynchronously configure( null, false ); - managedService = ( ServiceRegistration<ManagedService> ) bundleContext.registerService("org.osgi.service.cm.ManagedService", new ScrManagedServiceServiceFactory(this, activator), + managedServiceRef = bundleContext.registerService("org.osgi.service.cm.ManagedService", new ScrManagedServiceServiceFactory(this), props); + + metatypeProviderRef = bundleContext.registerService("org.osgi.service.metatype.MetaTypeProvider", new ScrMetaTypeProviderServiceFactory(this), + props); } - public void stop() { - if (this.managedService != null) { - this.managedService.unregister(); - this.managedService = null; + public void stop() + { + if (this.managedServiceRef != null) + { + this.managedServiceRef.unregister(); + this.managedServiceRef = null; + } + + if (this.metatypeProviderRef != null) + { + this.metatypeProviderRef.unregister(); + this.metatypeProviderRef = null; } this.bundleContext = null; } - + public void setScrCommand(ScrCommand scrCommand) { this.scrCommand = scrCommand; @@ -201,33 +212,39 @@ public class ScrConfigurationImpl implem * Returns the current log level. * @return */ + @Override public int getLogLevel() { return logLevel; } + @Override public boolean isFactoryEnabled() { return factoryEnabled; } + @Override public boolean keepInstances() { return keepInstances; } - + + @Override public boolean infoAsService() { return infoAsService; } + @Override public long lockTimeout() { return lockTimeout; } + @Override public long stopTimeout() { return stopTimeout; @@ -254,7 +271,7 @@ public class ScrConfigurationImpl implem { return getLogLevel( bundleContext.getProperty( PROP_LOGLEVEL ) ); } - + private boolean getDefaultInfoAsService() { return VALUE_TRUE.equalsIgnoreCase( bundleContext.getProperty( PROP_INFO_SERVICE) ); Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java?rev=1809281&r1=1809280&r2=1809281&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedService.java Fri Sep 22 08:57:59 2017 @@ -40,17 +40,13 @@ public class ScrManagedService implement private final ScrConfigurationImpl scrConfiguration; - protected final ScrConfigurationImpl getScrConfiguration() - { - return scrConfiguration; - } - public ScrManagedService(final ScrConfigurationImpl scrConfiguration) { this.scrConfiguration = scrConfiguration; } - public void updated(Dictionary<String, ?> properties) throws ConfigurationException + @Override + public void updated(final Dictionary<String, ?> properties) throws ConfigurationException { this.scrConfiguration.configure(properties, true); } Modified: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceServiceFactory.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceServiceFactory.java?rev=1809281&r1=1809280&r2=1809281&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceServiceFactory.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceServiceFactory.java Fri Sep 22 08:57:59 2017 @@ -18,54 +18,37 @@ */ package org.apache.felix.scr.impl.config; -import org.apache.felix.scr.impl.helper.SimpleLogger; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.log.LogService; /** - * The <code>ScrManagedServiceServiceFactory</code> is the ServiceFactory - * registered on behalf of the {@link ScrManagedService} (or - * {@link ScrManagedServiceMetaTypeProvider}, resp.) to create the instance on - * demand once it is used by the Configuration Admin Service or the MetaType - * Service. + * The {@code ScrManagedServiceServiceFactory} is a {@code ServiceFactory} registered + * on behalf of {@link ScrManagedService} to create a managed service instance + * on demand once it is used by the Configuration Admin Service. * <p> - * In contrast to the {@link ScrManagedService} and - * {@link ScrManagedServiceMetaTypeProvider} classes, this class only requires + * In contrast to the {@link ScrManagedService} class, this class only requires * core OSGi API and thus may be instantiated without the Configuration Admin - * and/or MetaType Service API actually available at the time of instantiation. + * actually available at the time of instantiation. */ -public class ScrManagedServiceServiceFactory implements ServiceFactory<ScrManagedService> +@SuppressWarnings("rawtypes") +public class ScrManagedServiceServiceFactory implements ServiceFactory { private final ScrConfigurationImpl scrConfiguration; - private final SimpleLogger logger; - public ScrManagedServiceServiceFactory(final ScrConfigurationImpl scrConfiguration, final SimpleLogger logger) + public ScrManagedServiceServiceFactory(final ScrConfigurationImpl scrConfiguration) { this.scrConfiguration = scrConfiguration; - this.logger = logger; } - public ScrManagedService getService(Bundle bundle, ServiceRegistration<ScrManagedService> registration) + @Override + public Object getService(final Bundle bundle, final ServiceRegistration registration) { - try - { - return ScrManagedServiceMetaTypeProvider.create( this.scrConfiguration ); - } - catch ( Throwable t ) - { - // assume MetaType Service API not available - logger - .log( - LogService.LOG_INFO, - "Cannot create MetaType providing ManagedService; not providing Metatype information but just accepting configuration", - null ); - } return new ScrManagedService( this.scrConfiguration ); } - public void ungetService(Bundle bundle, ServiceRegistration<ScrManagedService> registration, ScrManagedService service) + @Override + public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service) { // nothing really todo; GC will do the rest } Copied: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java (from r1809280, felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java) URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java?p2=felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java&p1=felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java&r1=1809280&r2=1809281&rev=1809281&view=diff ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java (original) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java Fri Sep 22 08:57:59 2017 @@ -29,34 +29,30 @@ import org.osgi.service.metatype.ObjectC /** * The <code>ScrManagedServiceMetaTypeProvider</code> receives the Declarative * Services Runtime configuration (by extending the {@link ScrManagedService} - * class but also provides a MetaType Service ObjectClassDefinition. + * class. * <p> * This class is instantiated in a ServiceFactory manner by the * {@link ScrManagedServiceServiceFactory} when the Configuration Admin service - * implementation and API is available and if the Metatype Service API is also - * available. + * implementation and API is available * <p> * Requires OSGi Metatype Service API available * * @see ScrManagedServiceServiceFactory */ -class ScrManagedServiceMetaTypeProvider extends ScrManagedService - implements MetaTypeProvider +class ScrMetaTypeProvider implements MetaTypeProvider { - static ScrManagedService create(final ScrConfigurationImpl scrConfiguration) - { - return new ScrManagedServiceMetaTypeProvider(scrConfiguration); - } + private final ScrConfiguration configuration; - private ScrManagedServiceMetaTypeProvider(final ScrConfigurationImpl scrConfiguration) + public ScrMetaTypeProvider(final ScrConfiguration scrConfiguration) { - super(scrConfiguration); + this.configuration = scrConfiguration; } /** * @see org.osgi.service.metatype.MetaTypeProvider#getLocales() */ + @Override public String[] getLocales() { return null; @@ -65,6 +61,7 @@ class ScrManagedServiceMetaTypeProvider /** * @see org.osgi.service.metatype.MetaTypeProvider#getObjectClassDefinition(java.lang.String, java.lang.String) */ + @Override public ObjectClassDefinition getObjectClassDefinition( String id, String locale ) { if ( !ScrConfiguration.PID.equals( id ) ) @@ -78,7 +75,7 @@ class ScrManagedServiceMetaTypeProvider "Allows limiting the amount of logging information sent to the OSGi LogService." + " Supported values are DEBUG, INFO, WARN, and ERROR. Default is ERROR.", AttributeDefinition.INTEGER, new String[] - { String.valueOf(this.getScrConfiguration().getLogLevel()) }, 0, new String[] + { String.valueOf(this.configuration.getLogLevel()) }, 0, new String[] { "Debug", "Information", "Warnings", "Error" }, new String[] { "4", "3", "2", "1" })); @@ -90,7 +87,7 @@ class ScrManagedServiceMetaTypeProvider + " This is an Apache Felix SCR specific extension, explicitly not supported by the Declarative Services " + "specification. Reliance on this feature prevent the component from being used with other Declarative " + "Services implementations. The default value is false to disable this feature.", this - .getScrConfiguration().isFactoryEnabled())); + .configuration.isFactoryEnabled())); adList.add( new AttributeDefinitionImpl( ScrConfiguration.PROP_DELAYED_KEEP_INSTANCES, @@ -100,14 +97,14 @@ class ScrManagedServiceMetaTypeProvider + "if there is not used any longer. Setting this flag causes the components to not be disposed off " + "and thus prevent them from being constantly recreated if often used. Examples of such components " + "may be EventHandler services. The default is to dispose of unused components.", this - .getScrConfiguration().keepInstances() ) ); + .configuration.keepInstances() ) ); adList.add( new AttributeDefinitionImpl( ScrConfiguration.PROP_LOCK_TIMEOUT, "Lock timeout milliseconds", "How long a lock is held before releasing due to suspected deadlock", AttributeDefinition.LONG, - new String[] { String.valueOf(this.getScrConfiguration().lockTimeout())}, + new String[] { String.valueOf(this.configuration.lockTimeout())}, 0, null, null) ); adList.add( new AttributeDefinitionImpl( @@ -115,7 +112,7 @@ class ScrManagedServiceMetaTypeProvider "Stop timeout milliseconds", "How long stopping a bundle is waited for before continuing due to suspected deadlock", AttributeDefinition.LONG, - new String[] { String.valueOf(this.getScrConfiguration().stopTimeout())}, + new String[] { String.valueOf(this.configuration.stopTimeout())}, 0, null, null) ); adList.add( new AttributeDefinitionImpl( @@ -130,27 +127,32 @@ class ScrManagedServiceMetaTypeProvider private final AttributeDefinition[] attrs = adList .toArray(new AttributeDefinition[adList.size()]); + @Override public String getName() { return "Apache Felix Declarative Service Implementation"; } + @Override public InputStream getIcon(int arg0) { return null; } + @Override public String getID() { return ScrConfiguration.PID; } + @Override public String getDescription() { return "Configuration for the Apache Felix Declarative Services Implementation." + " This configuration overwrites configuration defined in framework properties of the same names."; } + @Override public AttributeDefinition[] getAttributeDefinitions(int filter) { return (filter == OPTIONAL) ? null : attrs; @@ -192,54 +194,63 @@ class ScrManagedServiceMetaTypeProvider } + @Override public int getCardinality() { return cardinality; } + @Override public String[] getDefaultValue() { return defaultValues; } + @Override public String getDescription() { return description; } + @Override public String getID() { return id; } + @Override public String getName() { return name; } + @Override public String[] getOptionLabels() { return optionLabels; } + @Override public String[] getOptionValues() { return optionValues; } + @Override public int getType() { return type; } + @Override public String validate( String arg0 ) { return null; Added: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java?rev=1809281&view=auto ============================================================================== --- felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java (added) +++ felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java Fri Sep 22 08:57:59 2017 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.scr.impl.config; + +import org.apache.felix.scr.impl.manager.ScrConfiguration; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceFactory; +import org.osgi.framework.ServiceRegistration; + +/** + * The {@code ScrMetaTypeProviderServiceFactory} is a {@code ServiceFactory} registered + * on behalf of {@link ScrConfiguration} to create a metatype provider instance + * on demand once it is used by the Metatype Service. + * <p> + * In contrast to the {@link ScrMetaTypeProvider} class, this class only requires + * core OSGi API and thus may be instantiated without the MetaType Service API actually available + * at the time of instantiation. + */ +@SuppressWarnings("rawtypes") +public class ScrMetaTypeProviderServiceFactory implements ServiceFactory +{ + private final ScrConfiguration scrConfiguration; + + public ScrMetaTypeProviderServiceFactory(final ScrConfiguration scrConfiguration) + { + this.scrConfiguration = scrConfiguration; + } + + @Override + public Object getService(final Bundle bundle, final ServiceRegistration registration) + { + return new ScrMetaTypeProvider( this.scrConfiguration ); + } + + @Override + public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service) + { + // nothing really todo; GC will do the rest + } + +} Propchange: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/osgi-r7/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProviderServiceFactory.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url