You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/09/20 09:55:17 UTC
svn commit: r1808980 - in /felix/trunk/osgi-r7/configadmin/src:
main/java/org/apache/felix/cm/ main/java/org/apache/felix/cm/impl/
main/java/org/apache/felix/cm/impl/persistence/
test/java/org/apache/felix/cm/impl/
Author: cziegeler
Date: Wed Sep 20 09:55:16 2017
New Revision: 1808980
URL: http://svn.apache.org/viewvc?rev=1808980&view=rev
Log:
FELIX-5693 : Improve persistent manager handling
Added:
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java (with props)
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java (with props)
Modified:
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/PersistenceManager.java
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/package-info.java
felix/trunk/osgi-r7/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java
Modified: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/PersistenceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/PersistenceManager.java?rev=1808980&r1=1808979&r2=1808980&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/PersistenceManager.java (original)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/PersistenceManager.java Wed Sep 20 09:55:16 2017
@@ -53,6 +53,11 @@ import org.osgi.annotation.versioning.Co
@ConsumerType
public interface PersistenceManager
{
+ /**
+ * Service registration property to define a unique name for the persistence manager.
+ * @since 1.2
+ */
+ String PROPERTY_NAME = "name";
/**
* Returns <code>true</code> if a persisted <code>Dictionary</code> exists
Modified: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java?rev=1808980&r1=1808979&r2=1808980&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java (original)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java Wed Sep 20 09:55:16 2017
@@ -26,6 +26,7 @@ import java.util.TreeMap;
import org.apache.felix.cm.PersistenceManager;
import org.apache.felix.cm.file.FilePersistenceManager;
+import org.apache.felix.cm.impl.persistence.LegacyPersistenceManagerTracker;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -56,13 +57,21 @@ public class Activator implements Bundle
{
/**
- * The name of the bundle context property defining the location for the
+ * The name of the framework context property defining the location for the
* configuration files (value is "felix.cm.dir").
*
* @see #start(BundleContext)
*/
private static final String CM_CONFIG_DIR = "felix.cm.dir";
+ /**
+ * The name of the framework context property defining the persistence
+ * managers to be used.
+ *
+ * @see #start(BundleContext)
+ */
+ private static final String CM_CONFIG_PMS = "felix.cm.pms";
+
private volatile ConfigurationManager manager;
// the service registration of the default file persistence manager
@@ -72,6 +81,8 @@ public class Activator implements Bundle
@SuppressWarnings("rawtypes")
private volatile ServiceTracker coordinatorTracker;
+ private volatile LegacyPersistenceManagerTracker legacyProvider;
+
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void start( final BundleContext bundleContext )
@@ -90,6 +101,7 @@ public class Activator implements Bundle
props.put( Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager" );
props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
props.put( Constants.SERVICE_RANKING, new Integer( Integer.MIN_VALUE ) );
+ props.put( PersistenceManager.PROPERTY_NAME, "file");
filepmRegistration = bundleContext.registerService( PersistenceManager.class, fpm, props );
// setup dynamic configuration bindings
@@ -156,7 +168,9 @@ public class Activator implements Bundle
});
coordinatorTracker.open();
// start configuration manager implementation
- final ServiceReference<ConfigurationAdmin> ref = this.manager.start(dynamicBindings, bundleContext);
+ legacyProvider = new LegacyPersistenceManagerTracker();
+ legacyProvider.start(bundleContext);
+ final ServiceReference<ConfigurationAdmin> ref = this.manager.start(dynamicBindings, legacyProvider, bundleContext);
// update log
Log.logger.set(ref);
@@ -176,6 +190,12 @@ public class Activator implements Bundle
this.manager = null;
}
+ if ( this.legacyProvider != null )
+ {
+ legacyProvider.stop();
+ legacyProvider = null;
+ }
+
// stop coordinator tracker
if ( this.coordinatorTracker != null )
{
Modified: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=1808980&r1=1808979&r2=1808980&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java (original)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java Wed Sep 20 09:55:16 2017
@@ -32,7 +32,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
-import org.apache.felix.cm.NotCachablePersistenceManager;
import org.apache.felix.cm.PersistenceManager;
import org.apache.felix.cm.impl.helper.BaseTracker;
import org.apache.felix.cm.impl.helper.ConfigurationMap;
@@ -41,7 +40,7 @@ import org.apache.felix.cm.impl.helper.M
import org.apache.felix.cm.impl.helper.TargetedPID;
import org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy;
import org.apache.felix.cm.impl.persistence.ExtPersistenceManager;
-import org.apache.felix.cm.impl.persistence.PersistenceManagerProxy;
+import org.apache.felix.cm.impl.persistence.PersistenceManagerProvider;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -109,9 +108,6 @@ public class ConfigurationManager implem
// service tracker for managed service factories
private ManagedServiceFactoryTracker managedServiceFactoryTracker;
- // PersistenceManager services
- private ServiceTracker<PersistenceManager, PersistenceManager> persistenceManagerTracker;
-
// the thread used to schedule tasks required to run asynchronously
private UpdateThread updateThread;
@@ -119,16 +115,9 @@ public class ConfigurationManager implem
private UpdateThread eventThread;
/**
- * The actual list of {@link PersistenceManager persistence managers} to use
- * when looking for configuration data. This list is built from the
- * {@link #persistenceManagerMap}, which is ordered according to the
- * {@link RankingComparator}.
- */
- private ExtPersistenceManager[] persistenceManagers;
-
- // the persistenceManagerTracker.getTrackingCount when the
- // persistenceManagers were last got
- private int pmtCount;
+ * The persistence manager provider
+ */
+ private PersistenceManagerProvider persistenceManagerProvider;
// the cache of Factory instances mapped by their factory PID
private final HashMap<String, Factory> factories = new HashMap<String, Factory>();
@@ -159,7 +148,10 @@ public class ConfigurationManager implem
// Coordinator service if available
private volatile Object coordinator;
- public ServiceReference<ConfigurationAdmin> start( final DynamicBindings dynBin, BundleContext bundleContext )
+ public ServiceReference<ConfigurationAdmin> start(
+ final DynamicBindings dynBin,
+ final PersistenceManagerProvider provider,
+ final BundleContext bundleContext )
{
// set up some fields
this.bundleContext = bundleContext;
@@ -183,9 +175,7 @@ public class ConfigurationManager implem
bundleContext.addBundleListener( this );
// get all persistence managers to begin with
- pmtCount = 1; // make sure to get the persistence managers at least once
- persistenceManagerTracker = new ServiceTracker<PersistenceManager, PersistenceManager>( bundleContext, PersistenceManager.class.getName(), null );
- persistenceManagerTracker.open();
+ this.persistenceManagerProvider = provider;
// consider alive now (before clients use Configuration Admin
// service registered in the next step)
@@ -248,9 +238,6 @@ public class ConfigurationManager implem
// unregistration the manager is still alive and can react
isActive = false;
- // don't care for PersistenceManagers any more
- persistenceManagerTracker.close();
-
// stop listening for events
bundleContext.removeBundleListener( this );
@@ -493,7 +480,7 @@ public class ConfigurationManager implem
return config;
}
- PersistenceManager[] pmList = getPersistenceManagers();
+ PersistenceManager[] pmList = this.persistenceManagerProvider.getPersistenceManagers();
for ( int i = 0; i < pmList.length; i++ )
{
if ( pmList[i].exists( pid ) )
@@ -557,7 +544,7 @@ public class ConfigurationManager implem
List<ConfigurationImpl> configList = new ArrayList<ConfigurationImpl>();
- ExtPersistenceManager[] pmList = getPersistenceManagers();
+ ExtPersistenceManager[] pmList = this.persistenceManagerProvider.getPersistenceManagers();
for ( int i = 0; i < pmList.length; i++ )
{
Collection<Dictionary> configs = pmList[i].getDictionaries(filter );
@@ -735,76 +722,6 @@ public class ConfigurationManager implem
// ---------- internal -----------------------------------------------------
- private ExtPersistenceManager[] getPersistenceManagers()
- {
- int currentPmtCount = persistenceManagerTracker.getTrackingCount();
- if ( persistenceManagers == null || currentPmtCount > pmtCount )
- {
-
- ExtPersistenceManager[] pm;
-
- ServiceReference<PersistenceManager>[] refs = persistenceManagerTracker.getServiceReferences();
- if ( refs == null || refs.length == 0 )
- {
- pm = new ExtPersistenceManager[0];
- }
- else
- {
- List<ExtPersistenceManager> pmList = new ArrayList<ExtPersistenceManager>();
- // sort the references according to the cmRanking property
- if ( refs.length > 1 )
- {
- Arrays.sort( refs, RankingComparator.SRV_RANKING );
- }
-
- // create the service array from the sorted set of references
- for ( int i = 0; i < refs.length; i++ )
- {
- PersistenceManager service = persistenceManagerTracker.getService( refs[i] );
- if ( service != null )
- {
- // check for existing proxy
- final ExtPersistenceManager pmProxy = getProxyForPersistenceManager(service);
- if ( pmProxy != null )
- {
- pmList.add(pmProxy);
- }
- else
- {
- if ( service instanceof NotCachablePersistenceManager )
- {
- pmList.add( new PersistenceManagerProxy( service ) );
- }
- else
- {
- pmList.add(new CachingPersistenceManagerProxy(service));
- }
- }
- }
- }
-
- pm = pmList.toArray( new ExtPersistenceManager[pmList.size()] );
- }
-
- pmtCount = currentPmtCount;
- persistenceManagers = pm;
- }
-
- return persistenceManagers;
- }
-
- private ExtPersistenceManager getProxyForPersistenceManager(final PersistenceManager pm)
- {
- if (persistenceManagers != null) {
- for (final ExtPersistenceManager pmProxy : persistenceManagers) {
- if (pmProxy.getDelegatee() == pm) {
- return pmProxy;
- }
- }
- }
- return null;
- }
-
private ServiceReference<ConfigurationAdmin> getServiceReference()
{
ServiceRegistration<ConfigurationAdmin> reg = configurationAdminRegistration;
@@ -917,7 +834,7 @@ public class ConfigurationManager implem
{
Log.logger.log( LogService.LOG_DEBUG, "createConfiguration({0}, {1}, {2})", new Object[]
{ pid, factoryPid, bundleLocation } );
- return new ConfigurationImpl( this, getPersistenceManagers()[0], pid, factoryPid, bundleLocation );
+ return new ConfigurationImpl( this, this.persistenceManagerProvider.getPersistenceManagers()[0], pid, factoryPid, bundleLocation );
}
@@ -1014,7 +931,7 @@ public class ConfigurationManager implem
}
// try to load factory from persistence
- PersistenceManager[] pmList = getPersistenceManagers();
+ PersistenceManager[] pmList = this.persistenceManagerProvider.getPersistenceManagers();
for ( int i = 0; i < pmList.length; i++ )
{
if ( Factory.exists( pmList[i], factoryPid ) )
@@ -1035,7 +952,7 @@ public class ConfigurationManager implem
*/
Factory createFactory( String factoryPid )
{
- Factory factory = new Factory( this, getPersistenceManagers()[0], factoryPid );
+ Factory factory = new Factory( this, this.persistenceManagerProvider.getPersistenceManagers()[0], factoryPid );
cacheFactory( factory );
return factory;
}
Added: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java?rev=1808980&view=auto
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java (added)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java Wed Sep 20 09:55:16 2017
@@ -0,0 +1,140 @@
+/*
+ * 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.cm.impl.persistence;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.felix.cm.NotCachablePersistenceManager;
+import org.apache.felix.cm.PersistenceManager;
+import org.apache.felix.cm.impl.RankingComparator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+
+public class LegacyPersistenceManagerTracker implements PersistenceManagerProvider
+{
+ // PersistenceManager services
+ private ServiceTracker<PersistenceManager, PersistenceManager> persistenceManagerTracker;
+
+ /**
+ * The actual list of {@link PersistenceManager persistence managers} to use
+ * when looking for configuration data. This list is built from the
+ * {@link #persistenceManagerMap}, which is ordered according to the
+ * {@link RankingComparator}.
+ */
+ private ExtPersistenceManager[] persistenceManagers;
+
+ // the persistenceManagerTracker.getTrackingCount when the
+ // persistenceManagers were last got
+ private int pmtCount;
+
+ public void start( final BundleContext bundleContext )
+ {
+ // get all persistence managers to begin with
+ pmtCount = 1; // make sure to get the persistence managers at least once
+ persistenceManagerTracker = new ServiceTracker<PersistenceManager, PersistenceManager>( bundleContext, PersistenceManager.class.getName(), null );
+ persistenceManagerTracker.open();
+ }
+
+
+ public void stop( )
+ {
+ // don't care for PersistenceManagers any more
+ persistenceManagerTracker.close();
+ }
+
+ @Override
+ public ExtPersistenceManager[] getPersistenceManagers()
+ {
+ int currentPmtCount = persistenceManagerTracker.getTrackingCount();
+ if ( persistenceManagers == null || currentPmtCount > pmtCount )
+ {
+
+ ExtPersistenceManager[] pm;
+
+ ServiceReference<PersistenceManager>[] refs = persistenceManagerTracker.getServiceReferences();
+ if ( refs == null || refs.length == 0 )
+ {
+ pm = new ExtPersistenceManager[0];
+ }
+ else
+ {
+ List<ExtPersistenceManager> pmList = new ArrayList<ExtPersistenceManager>();
+ // sort the references according to the cmRanking property
+ if ( refs.length > 1 )
+ {
+ Arrays.sort( refs, RankingComparator.SRV_RANKING );
+ }
+
+ // create the service array from the sorted set of references
+ for ( int i = 0; i < refs.length; i++ )
+ {
+ PersistenceManager service = persistenceManagerTracker.getService( refs[i] );
+ if ( service != null )
+ {
+ // check for existing proxy
+ final ExtPersistenceManager pmProxy = getProxyForPersistenceManager(service);
+ if ( pmProxy != null )
+ {
+ pmList.add(pmProxy);
+ }
+ else
+ {
+ if ( service instanceof NotCachablePersistenceManager )
+ {
+ pmList.add( new PersistenceManagerProxy( service ) );
+ }
+ else
+ {
+ pmList.add(new CachingPersistenceManagerProxy(service));
+ }
+ }
+ }
+ }
+
+ pm = pmList.toArray( new ExtPersistenceManager[pmList.size()] );
+ }
+
+ pmtCount = currentPmtCount;
+ persistenceManagers = pm;
+ }
+
+ return persistenceManagers;
+ }
+
+ private ExtPersistenceManager getProxyForPersistenceManager(final PersistenceManager pm)
+ {
+ if (persistenceManagers != null)
+ {
+ for (final ExtPersistenceManager pmProxy : persistenceManagers)
+ {
+ if (pmProxy.getDelegatee() == pm)
+ {
+ return pmProxy;
+ }
+ }
+ }
+ return null;
+ }
+}
+
Propchange: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/LegacyPersistenceManagerTracker.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java?rev=1808980&view=auto
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java (added)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java Wed Sep 20 09:55:16 2017
@@ -0,0 +1,26 @@
+/*
+ * 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.cm.impl.persistence;
+
+public interface PersistenceManagerProvider
+{
+
+ ExtPersistenceManager[] getPersistenceManagers();
+}
+
Propchange: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerProvider.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified: felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/package-info.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/package-info.java?rev=1808980&r1=1808979&r2=1808980&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/package-info.java (original)
+++ felix/trunk/osgi-r7/configadmin/src/main/java/org/apache/felix/cm/package-info.java Wed Sep 20 09:55:16 2017
@@ -17,7 +17,7 @@
* under the License.
*/
-@org.osgi.annotation.versioning.Version("1.1.1")
+@org.osgi.annotation.versioning.Version("1.2.0")
package org.apache.felix.cm;
Modified: felix/trunk/osgi-r7/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java?rev=1808980&r1=1808979&r2=1808980&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java (original)
+++ felix/trunk/osgi-r7/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java Wed Sep 20 09:55:16 2017
@@ -36,6 +36,7 @@ import org.apache.felix.cm.MockPersisten
import org.apache.felix.cm.PersistenceManager;
import org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy;
import org.apache.felix.cm.impl.persistence.ExtPersistenceManager;
+import org.apache.felix.cm.impl.persistence.LegacyPersistenceManagerTracker;
import org.apache.felix.cm.impl.persistence.PersistenceManagerProxy;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
@@ -84,8 +85,13 @@ public class ConfigurationManagerTest ex
ConfigurationManager configMgr = new ConfigurationManager();
setServiceTrackerField( configMgr, "persistenceManagerTracker" );
- Field field = configMgr.getClass().getDeclaredField( "persistenceManagers" );
+ Field field1 = configMgr.getClass().getDeclaredField( "persistenceManagerProvider" );
+ field1.setAccessible( true );
+ final LegacyPersistenceManagerTracker lpmt = (LegacyPersistenceManagerTracker) field1.get(configMgr);
+
+ Field field = lpmt.getClass().getDeclaredField( "persistenceManagers" );
field.setAccessible( true );
+
CachingPersistenceManagerProxy[] persistenceManagers = new CachingPersistenceManagerProxy [1];
PersistenceManager pm =new MockPersistenceManager();
Dictionary dictionary = new Hashtable();
@@ -94,7 +100,7 @@ public class ConfigurationManagerTest ex
pm.store( pid, dictionary );
persistenceManagers[0] = new CachingPersistenceManagerProxy(pm);
- field.set(configMgr, persistenceManagers);
+ field.set(lpmt, persistenceManagers);
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
@@ -121,8 +127,13 @@ public class ConfigurationManagerTest ex
ConfigurationManager configMgr = new ConfigurationManager();
setServiceTrackerField( configMgr, "persistenceManagerTracker" );
- Field field = configMgr.getClass().getDeclaredField( "persistenceManagers" );
+ Field field1 = configMgr.getClass().getDeclaredField( "persistenceManagerProvider" );
+ field1.setAccessible( true );
+ final LegacyPersistenceManagerTracker lpmt = (LegacyPersistenceManagerTracker) field1.get(configMgr);
+
+ Field field = lpmt.getClass().getDeclaredField( "persistenceManagers" );
field.setAccessible( true );
+
ExtPersistenceManager[] persistenceManagers = new ExtPersistenceManager[1];
PersistenceManager pm = new MockNotCachablePersistenceManager();
Dictionary dictionary = new Hashtable();
@@ -131,7 +142,7 @@ public class ConfigurationManagerTest ex
pm.store( pid, dictionary );
persistenceManagers[0] = new PersistenceManagerProxy(pm);
- field.set(configMgr, persistenceManagers);
+ field.set(lpmt, persistenceManagers);
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
@@ -467,23 +478,49 @@ public class ConfigurationManagerTest ex
refMap.put( sref, svc );
}
- Field field = configMgr.getClass().getDeclaredField( fieldName );
- field.setAccessible( true );
- field.set( configMgr, new ServiceTracker( new MockBundleContext(), "", null )
- {
- @Override
- public ServiceReference[] getServiceReferences()
+ if ( "persistenceManagerTracker".equals(fieldName) ) {
+ final LegacyPersistenceManagerTracker lpmt = new LegacyPersistenceManagerTracker();
+ Field field = lpmt.getClass().getDeclaredField( fieldName );
+ field.setAccessible( true );
+ field.set( lpmt, new ServiceTracker( new MockBundleContext(), "", null )
{
- return refMap.keySet().toArray( new ServiceReference[0] );
- }
+ @Override
+ public ServiceReference[] getServiceReferences()
+ {
+ return refMap.keySet().toArray( new ServiceReference[0] );
+ }
- @Override
- public Object getService(ServiceReference reference)
+ @Override
+ public Object getService(ServiceReference reference)
+ {
+ return refMap.get( reference );
+ }
+ } );
+
+ Field field2 = configMgr.getClass().getDeclaredField( "persistenceManagerProvider" );
+ field2.setAccessible( true );
+ field2.set( configMgr, lpmt );
+ }
+ else
+ {
+ Field field = configMgr.getClass().getDeclaredField( fieldName );
+ field.setAccessible( true );
+ field.set( configMgr, new ServiceTracker( new MockBundleContext(), "", null )
{
- return refMap.get( reference );
- }
- } );
+ @Override
+ public ServiceReference[] getServiceReferences()
+ {
+ return refMap.keySet().toArray( new ServiceReference[0] );
+ }
+ @Override
+ public Object getService(ServiceReference reference)
+ {
+ return refMap.get( reference );
+ }
+ } );
+
+ }
return refMap.keySet().toArray(new ServiceReference[0]);
}
}