Author: marrs
Date: Mon Apr 11 20:46:19 2011
New Revision: 1091200
URL: http://svn.apache.org/viewvc?rev=1091200&view=rev
Log:
Applied patches in FELIX-2911 with some small changes. Should compile without
problems now.
Removed:
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/ActivatorTest.java
Modified:
felix/trunk/deviceaccess/pom.xml
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
Modified: felix/trunk/deviceaccess/pom.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/pom.xml?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
--- felix/trunk/deviceaccess/pom.xml (original)
+++ felix/trunk/deviceaccess/pom.xml Mon Apr 11 20:46:19 2011
@@ -23,8 +23,8 @@
<parent>
<groupId>org.apache.felix</groupId>
- <artifactId>felix</artifactId>
- <version>1.0.5-SNAPSHOT</version>
+ <artifactId>felix-parent</artifactId>
+ <version>2-SNAPSHOT</version>
<relativePath>../pom/pom.xml</relativePath>
</parent>
@@ -38,33 +38,32 @@
Implementation of the OSGi Device Access Specification 1.1
</description>
- <dependencies>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>1.6.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>1.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>1.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>${pom.groupId}</groupId>
- <artifactId>org.apache.felix.dependencymanager</artifactId>
- <version>2.0.1</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>1.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.dependencymanager</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
<build>
<plugins>
<plugin>
Modified:
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/Activator.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
--- felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
(original)
+++ felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/Activator.java
Mon Apr 11 20:46:19 2011
@@ -19,21 +19,18 @@
package org.apache.felix.das;
+import org.apache.felix.das.util.Util;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-
import org.osgi.service.device.Device;
import org.osgi.service.device.Driver;
import org.osgi.service.device.DriverLocator;
import org.osgi.service.device.DriverSelector;
import org.osgi.service.log.LogService;
-import org.apache.felix.dependencymanager.DependencyActivatorBase;
-import org.apache.felix.dependencymanager.DependencyManager;
-import org.apache.felix.dependencymanager.Service;
-
-import org.apache.felix.das.util.Util;
-
/**
* TODO: add javadoc
@@ -71,37 +68,39 @@ public class Activator extends Dependenc
// the real device manager
startDeviceManager();
- // the analyzers to inform the user (and me) if something is wrong
- // startAnalyzers();
-
}
- private void startDeviceManager()
- {
+ private void startDeviceManager() {
- final String driverFilter = Util.createFilterString(
"(&(%s=%s)(%s=%s))", new String[]
- { Constants.OBJECTCLASS, Driver.class.getName(),
org.osgi.service.device.Constants.DRIVER_ID, "*" } );
+ final String driverFilter = Util.createFilterString( "(%s=%s)", new
String[]
+ { org.osgi.service.device.Constants.DRIVER_ID, "*" } );
- final String deviceFilter = Util.createFilterString(
"(|(%s=%s)(%s=%s))", new String[]
- { Constants.OBJECTCLASS, Device.class.getName(),
org.osgi.service.device.Constants.DEVICE_CATEGORY, "*" } );
+ final String deviceFilter = Util.createFilterString(
"(|(%s=%s)(&(%s=%s)(%s=%s)))", new String[]
+ {
+ Constants.OBJECTCLASS, Device.class.getName(),
+ Constants.OBJECTCLASS, "*",
+ org.osgi.service.device.Constants.DEVICE_CATEGORY, "*"
+ } );
- Service svc = createService();
+ Component svc = createComponent();
svc.setImplementation( m_deviceManager );
svc.add( createServiceDependency().setService( LogService.class
).setRequired( false ) );
- svc.add( createServiceDependency().setService( DriverSelector.class
).setRequired( false )
- .setAutoConfig( false ) );
+ svc.add( createServiceDependency().setService( DriverSelector.class
).setRequired( false ).setAutoConfig( false )
+ .setCallbacks( "selectorAdded", "selectorRemoved" ) );
svc.add( createServiceDependency().setService( DriverLocator.class
).setRequired( false ).setAutoConfig( false )
.setCallbacks( "locatorAdded", "locatorRemoved" ) );
- svc.add( createServiceDependency().setService( Driver.class,
driverFilter ).setRequired( false ).setCallbacks(
- "driverAdded", "driverRemoved" ) );
- svc.add( createServiceDependency().setService( Device.class,
deviceFilter ).setRequired( false ).setCallbacks(
- "deviceAdded", "deviceModified", "deviceRemoved" ) );
-
+
+ svc.add( createServiceDependency().setService( Driver.class,
driverFilter ).setRequired( false )
+ .setCallbacks( "driverAdded", "driverRemoved" ) );
+
+ svc.add( createServiceDependency().setService( deviceFilter
).setRequired( false )
+ .setCallbacks( "deviceAdded", "deviceModified", "deviceRemoved"
) );
+
m_manager.add( svc );
}
Modified:
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
(original)
+++
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
Mon Apr 11 20:46:19 2011
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -53,7 +54,9 @@ import org.osgi.service.log.LogService;
/**
- * TODO: add javadoc
+ * This class represents the Apache Felix implementation of the device access
specification.
+ * It is based on version 1.1 of the spec.
+ *
*
* @author <a href="mailto:[email protected]">Felix Project Team</a>
*/
@@ -63,13 +66,13 @@ public class DeviceManager implements Lo
private final long DEFAULT_TIMEOUT_SEC = 1;
// the logger
- private LogService m_log;
+ private volatile LogService m_log;
// the bundle context
private final BundleContext m_context;
// the driver selector
- private DriverSelector m_selector;
+ private volatile DriverSelector m_selector;
// the driver locators
private List<DriverLocator> m_locators;
@@ -86,11 +89,19 @@ public class DeviceManager implements Lo
// used to add delayed actions
private ScheduledExecutorService m_delayed;
+ //the devices filter
private Filter m_deviceImplFilter;
+ //the drivers filter
private Filter m_driverImplFilter;
+ /**
+ * Public constructor. Used by the Activator in this <code>Bundle</code>
+ * to instantiate one instance.
+ *
+ * @param context the <code>BundleContext</code>
+ */
public DeviceManager( BundleContext context )
{
m_context = context;
@@ -165,6 +176,19 @@ public class DeviceManager implements Lo
// callback methods
+ public void selectorAdded( DriverSelector selector )
+ {
+ m_selector = selector;
+ debug( "driver selector appeared" );
+ }
+
+
+ public void selectorRemoved( DriverSelector selector )
+ {
+ m_selector = null;
+ debug( "driver selector lost" );
+ }
+
public void locatorAdded( DriverLocator locator )
{
m_locators.add( locator );
@@ -185,6 +209,9 @@ public class DeviceManager implements Lo
m_drivers.put( ref, new DriverAttributes( ref, driver ) );
debug( "driver appeared: " + Util.showDriver( ref ) );
+
+ //immediately check for idle devices
+// submit( new CheckForIdleDevices() );
}
@@ -532,7 +559,7 @@ public class DeviceManager implements Lo
// if there are no driver locators
// we'll have to do with the drivers that where
// added 'manually'
- List<String> driverIds = m_driverLoader.findDrivers( m_locators,
dict );
+ Set<String> driverIds = m_driverLoader.findDrivers( m_locators,
dict );
// remove the driverIds that are already available
for ( DriverAttributes da : m_drivers.values() )
@@ -542,6 +569,7 @@ public class DeviceManager implements Lo
driverIds.removeAll( m_drivers.keySet() );
try
{
+ debug("entering attach phase for " + Util.showDevice( m_ref ) );
return driverAttachment( dict, driverIds.toArray( new
String[0] ) );
}
finally
@@ -564,7 +592,7 @@ public class DeviceManager implements Lo
// now load the drivers
List<ServiceReference> driverRefs = m_driverLoader.loadDrivers(
m_locators, driverIds );
// these are the possible driver references that have been added
- // add the to the list of included drivers
+ // add them to the list of included drivers
for ( ServiceReference serviceReference : driverRefs )
{
DriverAttributes da = m_drivers.get( serviceReference );
@@ -582,8 +610,10 @@ public class DeviceManager implements Lo
try
{
int match = driver.match( m_ref );
- if ( match <= Device.MATCH_NONE )
+ if ( match <= Device.MATCH_NONE )
+ {
continue;
+ }
mi.add( match, driver );
}
catch ( Throwable t )
@@ -593,15 +623,20 @@ public class DeviceManager implements Lo
}
// get the best match
- Match bestMatch;
+ Match bestMatch = null;
// local copy
final DriverSelector selector = m_selector;
+
if ( selector != null )
{
bestMatch = mi.selectBestMatch( m_ref, selector );
+ if (bestMatch != null) {
+ debug(String.format("DriverSelector (%s) found best
match: %s", selector.getClass().getName(),
Util.showDriver(bestMatch.getDriver())));
+ }
}
- else
+
+ if (bestMatch == null)
{
bestMatch = mi.getBestMatch();
}
Modified:
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
(original)
+++
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverAnalyzer.java
Mon Apr 11 20:46:19 2011
@@ -50,7 +50,7 @@ public class DriverAnalyzer
}
if ( String.class.isInstance( driverId ) )
{
- String value = String.class.cast( driverId );
+ String value = (String)( driverId );
if ( value.length() == 0 )
{
m_log.log( LogService.LOG_ERROR, "invalid driver: empty driver
id: " + Util.showDriver( ref ) );
Modified:
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
(original)
+++
felix/trunk/deviceaccess/src/main/java/org/apache/felix/das/util/DriverLoader.java
Mon Apr 11 20:46:19 2011
@@ -24,7 +24,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.felix.das.DriverAttributes;
import org.apache.felix.das.Log;
@@ -65,9 +67,9 @@ public class DriverLoader
@SuppressWarnings("all")
- public List<String> findDrivers( Collection<DriverLocator> locators,
Dictionary dict )
+ public Set<String> findDrivers( Collection<DriverLocator> locators,
Dictionary dict )
{
- final List<String> list = new ArrayList<String>();
+ final Set<String> list = new HashSet<String>();
for ( DriverLocator locator : locators )
{
list.addAll( findDrivers( locator, dict ) );
Modified:
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
--- felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
(original)
+++ felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/OSGiMock.java
Mon Apr 11 20:46:19 2011
@@ -100,6 +100,8 @@ public class OSGiMock
Mockito.when( m_context.getService( ref ) ).thenReturn( impl );
+ Mockito.when( ref.getUsingBundles() ).thenReturn( new Bundle[0] );
+
m_references.put( impl, ref );
return ref;
Modified: felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/Utils.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
--- felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/Utils.java
(original)
+++ felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/Utils.java Mon
Apr 11 20:46:19 2011
@@ -49,7 +49,7 @@ public class Utils
}
- public static void inject( Object target, Class<?> clazz, Object
injectable )
+ public static void inject( Object target, Class clazz, Object injectable )
{
Field[] fields = target.getClass().getDeclaredFields();
Modified:
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
(original)
+++
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverAnalyzerTest.java
Mon Apr 11 20:46:19 2011
@@ -1,3 +1,21 @@
+/*
+ * 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.das.util;
Modified:
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
(original)
+++
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/DriverLoaderTest.java
Mon Apr 11 20:46:19 2011
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import org.apache.felix.das.DeviceManager;
import org.junit.Assert;
@@ -90,7 +91,7 @@ public class DriverLoaderTest
List<DriverLocator> locators = new ArrayList<DriverLocator>();
- List<String> driverIds = m_loader.findDrivers( locators, new
Properties() );
+ Set<String> driverIds = m_loader.findDrivers( locators, new
Properties() );
Assert.assertTrue( "should be an empty list", driverIds.size() == 0 );
}
@@ -113,7 +114,7 @@ public class DriverLoaderTest
locators.add( dl );
Properties dict = new Properties();
- List<String> driverIds = m_loader.findDrivers( locators, dict );
+ Set<String> driverIds = m_loader.findDrivers( locators, dict );
Assert.assertEquals( "should not be an empty list", 2,
driverIds.size());
@@ -144,7 +145,7 @@ public class DriverLoaderTest
Properties dict = new Properties();
- List<String> driverIds = m_loader.findDrivers( locators, dict );
+ Set<String> driverIds = m_loader.findDrivers( locators, dict );
Assert.assertEquals( "should not be an empty list", 4,
driverIds.size() );
@@ -163,7 +164,7 @@ public class DriverLoaderTest
Mockito.when( dl.findDrivers( Mockito.eq( dict ) ) ).thenThrow( new
RuntimeException( "test exception" ) );
- List<String> driverIds = m_loader.findDrivers( locators, dict );
+ Set<String> driverIds = m_loader.findDrivers( locators, dict );
Assert.assertTrue( "should be an empty list", driverIds.size() == 0 );
Modified:
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java?rev=1091200&r1=1091199&r2=1091200&view=diff
==============================================================================
---
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
(original)
+++
felix/trunk/deviceaccess/src/test/java/org/apache/felix/das/util/UtilTest.java
Mon Apr 11 20:46:19 2011
@@ -60,7 +60,8 @@ public class UtilTest
@Before
public void before() throws Exception
{
-
+ System.setProperty("org.osgi.vendor.framework",
"org.apache.felix.framework");
+
MockitoAnnotations.initMocks(this);
m_devA = new DeviceAnalyzer( m_context );