felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1776255 - in /felix/trunk/configadmin/src/main/java/org/apache/felix/cm: file/ConfigurationHandler.java file/FilePersistenceManager.java impl/Activator.java impl/ConfigurationAdminFactory.java impl/ConfigurationManager.java
Date Wed, 28 Dec 2016 10:21:32 GMT
Author: cziegeler
Date: Wed Dec 28 10:21:32 2016
New Revision: 1776255

URL: http://svn.apache.org/viewvc?rev=1776255&view=rev
Log:
FELIX-5468 : Refactor persistence handling (WiP)

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminFactory.java
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java?rev=1776255&r1=1776254&r2=1776255&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java
Wed Dec 28 10:21:32 2016
@@ -102,8 +102,8 @@ public class ConfigurationHandler
     protected static final String INDENT = "  ";
     protected static final String COLLECTION_LINE_BREAK = " \\\r\n";
 
-    protected static final Map code2Type;
-    protected static final Map type2Code;
+    protected static final Map<Integer, Class<?>> code2Type;
+    protected static final Map<Class<?>, Integer> type2Code;
 
     // set of valid characters for "symblic-name"
     private static final BitSet NAME_CHARS;
@@ -111,7 +111,7 @@ public class ConfigurationHandler
 
     static
     {
-        type2Code = new HashMap();
+        type2Code = new HashMap<Class<?>, Integer>();
 
         // simple (exclusive String whose type code is not written)
         type2Code.put( Integer.class, new Integer( TOKEN_SIMPLE_INTEGER ) );
@@ -136,10 +136,9 @@ public class ConfigurationHandler
         // reverse map to map type codes to classes, string class mapping
         // to be added manually, as the string type code is not written and
         // hence not included in the type2Code map
-        code2Type = new HashMap();
-        for ( Iterator ti = type2Code.entrySet().iterator(); ti.hasNext(); )
+        code2Type = new HashMap<Integer, Class<?>>();
+        for(final Map.Entry<Class<?>, Integer> entry : type2Code.entrySet())
         {
-            Map.Entry entry = ( Map.Entry ) ti.next();
             code2Type.put( entry.getValue(), entry.getKey() );
         }
         code2Type.put( new Integer( TOKEN_SIMPLE_STRING ), String.class );
@@ -192,16 +191,17 @@ public class ConfigurationHandler
      * given <code>OutputStream</code>.
      * <p>
      * This method writes at the current location in the stream and does not
-     * close the outputstream.
+     * close the output stream.
      *
      * @param out
-     *            The <code>OutputStream</code> to write the configurtion data
+     *            The <code>OutputStream</code> to write the configuration data
      *            to.
      * @param properties
      *            The <code>Dictionary</code> to write.
      * @throws IOException
-     *             If an error occurrs writing to the output stream.
+     *             If an error occurs writing to the output stream.
      */
+    @SuppressWarnings("rawtypes")
     public static void write( OutputStream out, Dictionary properties ) throws IOException
     {
         BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( out, ENCODING ) );
@@ -230,6 +230,7 @@ public class ConfigurationHandler
      * @return An <code>Enumeration</code> that provides the keys of
      *         properties in an ordered manner.
      */
+    @SuppressWarnings("rawtypes")
     private static Enumeration orderedKeys(Dictionary properties) {
         String[] keyArray = new String[properties.size()];
         int i = 0;
@@ -247,7 +248,7 @@ public class ConfigurationHandler
      * Reads configuration data from the given <code>InputStream</code> and
      * returns a new <code>Dictionary</code> object containing the data.
      * <p>
-     * This method reads from the current location in the stream upto the end of
+     * This method reads from the current location in the stream up to the end of
      * the stream but does not close the stream at the end.
      *
      * @param ins
@@ -257,9 +258,10 @@ public class ConfigurationHandler
      *         data. This object may be empty if the stream contains no
      *         configuration data.
      * @throws IOException
-     *             If an error occurrs reading from the stream. This exception
+     *             If an error occurs reading from the stream. This exception
      *             is also thrown if a syntax error is encountered.
      */
+    @SuppressWarnings("rawtypes")
     public static Dictionary read( InputStream ins ) throws IOException
     {
         return new ConfigurationHandler().readInternal( ins );
@@ -280,7 +282,7 @@ public class ConfigurationHandler
     private int pos;
 
 
-    private Dictionary readInternal( InputStream ins ) throws IOException
+    private Dictionary<String, ?> readInternal( InputStream ins ) throws IOException
     {
         BufferedReader br = new BufferedReader( new InputStreamReader( ins, ENCODING ) );
         PushbackReader pr = new PushbackReader( br, 1 );
@@ -290,7 +292,7 @@ public class ConfigurationHandler
         line = 0;
         pos = 0;
 
-        Hashtable configuration = new Hashtable();
+        Dictionary<String, Object> configuration = new Hashtable<String, Object>();
         token = 0;
         while ( nextToken( pr, true ) == TOKEN_NAME )
         {
@@ -361,7 +363,7 @@ public class ConfigurationHandler
 
     private Object readArray( int typeCode, PushbackReader pr ) throws IOException
     {
-        List list = new ArrayList();
+        List<Object> list = new ArrayList<Object>();
         for ( ;; )
         {
             int c = ignorablePageBreakAndWhiteSpace( pr );
@@ -383,7 +385,7 @@ public class ConfigurationHandler
 
             if ( c == TOKEN_ARR_CLOS )
             {
-                Class type = ( Class ) code2Type.get( new Integer( typeCode ) );
+                Class<?> type = code2Type.get( new Integer( typeCode ) );
                 Object array = Array.newInstance( type, list.size() );
                 for ( int i = 0; i < list.size(); i++ )
                 {
@@ -403,9 +405,9 @@ public class ConfigurationHandler
     }
 
 
-    private Collection readCollection( int typeCode, PushbackReader pr ) throws IOException
+    private Collection<Object> readCollection( int typeCode, PushbackReader pr ) throws
IOException
     {
-        Collection collection = new ArrayList();
+        Collection<Object> collection = new ArrayList<Object>();
         for ( ;; )
         {
             int c = ignorablePageBreakAndWhiteSpace( pr );
@@ -704,14 +706,14 @@ public class ConfigurationHandler
 
     private static void writeValue( Writer out, Object value ) throws IOException
     {
-        Class clazz = value.getClass();
+        Class<?> clazz = value.getClass();
         if ( clazz.isArray() )
         {
             writeArray( out, value );
         }
         else if ( value instanceof Collection )
         {
-            writeCollection( out, ( Collection ) value );
+            writeCollection( out, ( Collection<?> ) value );
         }
         else
         {
@@ -736,7 +738,7 @@ public class ConfigurationHandler
     }
 
 
-    private static void writeCollection( Writer out, Collection collection ) throws IOException
+    private static void writeCollection( Writer out, Collection<?> collection ) throws
IOException
     {
         if ( collection.isEmpty() )
         {
@@ -746,7 +748,7 @@ public class ConfigurationHandler
         }
         else
         {
-            Iterator ci = collection.iterator();
+            Iterator<?> ci = collection.iterator();
             Object firstElement = ci.next();
 
             writeType( out, firstElement.getClass() );
@@ -772,9 +774,9 @@ public class ConfigurationHandler
     }
 
 
-    private static void writeType( Writer out, Class valueType ) throws IOException
+    private static void writeType( Writer out, Class<?> valueType ) throws IOException
     {
-        Integer code = ( Integer ) type2Code.get( valueType );
+        Integer code = type2Code.get( valueType );
         if ( code != null )
         {
             out.write( ( char ) code.intValue() );

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java?rev=1776255&r1=1776254&r2=1776255&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/FilePersistenceManager.java
Wed Dec 28 10:21:32 2016
@@ -454,6 +454,7 @@ public class FilePersistenceManager impl
      * @return an enumeration of configuration data returned as instances of
      *      the <code>Dictionary</code> class.
      */
+    @SuppressWarnings("rawtypes")
     @Override
     public Enumeration getDictionaries()
     {
@@ -482,7 +483,7 @@ public class FilePersistenceManager impl
 
     private void _privilegedDelete( final String pid )
     {
-        AccessController.doPrivileged( new PrivilegedAction()
+        AccessController.doPrivileged( new PrivilegedAction<Object>()
         {
             @Override
             public Object run()
@@ -525,10 +526,10 @@ public class FilePersistenceManager impl
 
     private boolean _privilegedExists( final String pid )
     {
-        final Object result = AccessController.doPrivileged( new PrivilegedAction()
+        final Object result = AccessController.doPrivileged( new PrivilegedAction<Boolean>()
         {
             @Override
-            public Object run()
+            public Boolean run()
             {
                 // FELIX-2771: Boolean.valueOf(boolean) is not in Foundation
                 return _exists( pid ) ? Boolean.TRUE : Boolean.FALSE;
@@ -557,6 +558,7 @@ public class FilePersistenceManager impl
      *      may be empty if the file contains no configuration information
      *      or is not properly formatted.
      */
+    @SuppressWarnings("rawtypes")
     @Override
     public Dictionary load( String pid ) throws IOException
     {
@@ -571,20 +573,21 @@ public class FilePersistenceManager impl
     }
 
 
+    @SuppressWarnings("rawtypes")
     private Dictionary _privilegedLoad( final File cfgFile ) throws IOException
     {
         try
         {
-            Object result = AccessController.doPrivileged( new PrivilegedExceptionAction()
+            Dictionary result = AccessController.doPrivileged( new PrivilegedExceptionAction<Dictionary>()
             {
                 @Override
-                public Object run() throws IOException
+                public Dictionary run() throws IOException
                 {
                     return _load( cfgFile );
                 }
             } );
 
-            return ( Dictionary ) result;
+            return result;
         }
         catch ( PrivilegedActionException pae )
         {
@@ -606,6 +609,7 @@ public class FilePersistenceManager impl
      * @throws IOException
      *             If an error occurrs reading the configuration file.
      */
+    @SuppressWarnings("rawtypes")
     Dictionary _load( File cfgFile ) throws IOException
     {
         // this method is not part of the API of this class but is made
@@ -654,6 +658,7 @@ public class FilePersistenceManager impl
      *
      * @throws IOException If an error occurrs writing the configuration data.
      */
+    @SuppressWarnings("rawtypes")
     @Override
     public void store( final String pid, final Dictionary props ) throws IOException
     {
@@ -668,11 +673,12 @@ public class FilePersistenceManager impl
     }
 
 
+    @SuppressWarnings("rawtypes")
     private void _privilegedStore( final String pid, final Dictionary props ) throws IOException
     {
         try
         {
-            AccessController.doPrivileged( new PrivilegedExceptionAction()
+            AccessController.doPrivileged( new PrivilegedExceptionAction<Object>()
             {
                 @Override
                 public Object run() throws IOException
@@ -690,6 +696,7 @@ public class FilePersistenceManager impl
     }
 
 
+    @SuppressWarnings("rawtypes")
     private void _store( final String pid, final Dictionary props ) throws IOException
     {
         OutputStream out = null;
@@ -786,9 +793,10 @@ public class FilePersistenceManager impl
      * This enumeration loads configuration lazily with a look ahead of one
      * dictionary.
      */
+    @SuppressWarnings("rawtypes")
     class DictionaryEnumeration implements Enumeration
     {
-        private Stack dirStack;
+        private Stack<File> dirStack;
         private File[] fileList;
         private int idx;
         private Dictionary next;
@@ -796,7 +804,7 @@ public class FilePersistenceManager impl
 
         DictionaryEnumeration()
         {
-            dirStack = new Stack();
+            dirStack = new Stack<File>();
             fileList = null;
             idx = 0;
 
@@ -839,15 +847,15 @@ public class FilePersistenceManager impl
 
         protected Dictionary _privilegedSeek()
         {
-            Object result = AccessController.doPrivileged( new PrivilegedAction()
+            Dictionary result = AccessController.doPrivileged( new PrivilegedAction<Dictionary>()
             {
                 @Override
-                public Object run()
+                public Dictionary run()
                 {
                     return _seek();
                 }
             } );
-            return ( Dictionary ) result;
+            return result;
         }
 
 
@@ -857,7 +865,7 @@ public class FilePersistenceManager impl
             {
                 if ( fileList == null || idx >= fileList.length )
                 {
-                    File dir = ( File ) dirStack.pop();
+                    File dir = dirStack.pop();
                     fileList = dir.listFiles();
                     idx = 0;
                 }

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java?rev=1776255&r1=1776254&r2=1776255&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java (original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java Wed Dec
28 10:21:32 2016
@@ -97,6 +97,7 @@ public class Activator implements Bundle
         // start configuration manager implementation
         this.manager = new ConfigurationManager();
         final ServiceReference<ConfigurationAdmin> ref = this.manager.start(dynamicBindings,
bundleContext);
+
         // update log
         Log.logger.set(ref);
     }

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminFactory.java?rev=1776255&r1=1776254&r2=1776255&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminFactory.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationAdminFactory.java
Wed Dec 28 10:21:32 2016
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -22,6 +22,7 @@ package org.apache.felix.cm.impl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 
 /**
@@ -30,7 +31,7 @@ import org.osgi.framework.ServiceRegistr
  * create the real <code>ConfiguratAdmin</code> instances returend to client
  * bundles. Each bundle gets a separate instance.
  */
-class ConfigurationAdminFactory implements ServiceFactory
+class ConfigurationAdminFactory implements ServiceFactory<ConfigurationAdmin>
 {
 
     // The configuration manager to which the configuration admin instances
@@ -48,7 +49,8 @@ class ConfigurationAdminFactory implemen
      * Returns a new instance of the {@link ConfigurationAdminImpl} class for
      * the given bundle.
      */
-    public Object getService( Bundle bundle, ServiceRegistration registration )
+    @Override
+    public ConfigurationAdmin getService( Bundle bundle, ServiceRegistration<ConfigurationAdmin>
registration )
     {
         return new ConfigurationAdminImpl( configurationManager, bundle );
     }
@@ -58,7 +60,8 @@ class ConfigurationAdminFactory implemen
      * Disposes off the given {@link ConfigurationAdminImpl} instance as the
      * given bundle has no use of it any more.
      */
-    public void ungetService( Bundle bundle, ServiceRegistration registration, Object service
)
+    @Override
+    public void ungetService( Bundle bundle, ServiceRegistration<ConfigurationAdmin>
registration, ConfigurationAdmin service )
     {
         ( ( ConfigurationAdminImpl ) service ).dispose();
     }

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=1776255&r1=1776254&r2=1776255&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
Wed Dec 28 10:21:32 2016
@@ -92,10 +92,10 @@ public class ConfigurationManager implem
     private volatile ServiceRegistration<ConfigurationAdmin> configurationAdminRegistration;
 
     // the ConfigurationEvent listeners
-    private ServiceTracker configurationListenerTracker;
+    private ServiceTracker<ConfigurationListener, ConfigurationListener> configurationListenerTracker;
 
     // the synchronous ConfigurationEvent listeners
-    private ServiceTracker syncConfigurationListenerTracker;
+    private ServiceTracker<SynchronousConfigurationListener, SynchronousConfigurationListener>
syncConfigurationListenerTracker;
 
     // service tracker for managed services
     private ManagedServiceTracker managedServiceTracker;
@@ -157,10 +157,10 @@ public class ConfigurationManager implem
         this.dynamicBindings = dynBin;
 
         // configurationlistener support
-        configurationListenerTracker = new ServiceTracker( bundleContext, ConfigurationListener.class.getName(),
null );
+        configurationListenerTracker = new ServiceTracker<ConfigurationListener, ConfigurationListener>(
bundleContext, ConfigurationListener.class, null );
         configurationListenerTracker.open();
-        syncConfigurationListenerTracker = new ServiceTracker( bundleContext,
-            SynchronousConfigurationListener.class.getName(), null );
+        syncConfigurationListenerTracker = new ServiceTracker<SynchronousConfigurationListener,
SynchronousConfigurationListener>( bundleContext,
+            SynchronousConfigurationListener.class, null );
         syncConfigurationListenerTracker.open();
 
         // initialize the asynchonous updater thread
@@ -184,10 +184,10 @@ public class ConfigurationManager implem
 
         // create and register configuration admin - start after PM tracker ...
         ConfigurationAdminFactory caf = new ConfigurationAdminFactory( this );
-        Hashtable props = new Hashtable();
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put( Constants.SERVICE_PID, "org.apache.felix.cm.ConfigurationAdmin" );
         props.put( Constants.SERVICE_DESCRIPTION, "Configuration Admin Service Specification
1.6 Implementation" );
-        props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
+        props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" );
         configurationAdminRegistration = bundleContext.registerService( ConfigurationAdmin.class,
caf, props );
 
         // start handling ManagedService[Factory] services
@@ -228,7 +228,7 @@ public class ConfigurationManager implem
         // clearing the field before actually unregistering the service
         // prevents IllegalStateException in getServiceReference() if
         // the field is not null but the service already unregistered
-        final ServiceRegistration caReg = configurationAdminRegistration;
+        final ServiceRegistration<ConfigurationAdmin> caReg = configurationAdminRegistration;
         configurationAdminRegistration = null;
         if ( caReg != null )
         {



Mime
View raw message