commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (CONFIGURATION-203) Make Configuration Serializable
Date Sun, 21 Jun 2009 22:38:07 GMT

    [ https://issues.apache.org/jira/browse/CONFIGURATION-203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12409852#action_12409852
] 

Emmanuel Bourg edited comment on CONFIGURATION-203 at 6/21/09 3:36 PM:
-----------------------------------------------------------------------

This is not as trivial as I thought initially... I made FileConfiguration
extends Serializable and wrote a test case serializing a PropertiesConfiguration
to a file. This led me to the following changes:

- make ReloadingStrategy extend Serializable as well
- change the type of the reloadLock in AbtractFileConfiguration to something
else than Object that is serializable. I picked String. I tried to make it
transient, but it resulted in a NullPointerException when accessing the
deserialized configuration because it was not initialized. I tried to move the
initialization in the no arg constructor but it didn't work, I'm not sure to
understand why this constructor isn't called when the deserialized instance is
build.

It still failed after these changes, because the deserialized configuration was
actually empty. It appears that the Map in BaseConfiguration is not serialized.
I put a similar Map in AbstractFileConfiguration and it got serialized property,
but by simply moving this Map to BaseConfiguration it disappeared from the
serialized file, I have no idea why.

I tested with the JDK 1.4.2_08.

Here is the test added to TestPropertiesConfiguration:

{code:java}
    public void testSerialization() throws Exception {
        // remove the previous serialization file
        File file = new File("target/configuration.ser");
        if (file.exists()) {
            file.delete();
        }

        // write the configuration to the configuration.ser file
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
        out.writeObject(conf);
        out.close();

        // load the configuration from the file
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
        PropertiesConfiguration conf2 = (PropertiesConfiguration) in.readObject();
        in.close();

        // check the deserialized configuration
        assertNotNull("deserialized configuration null", conf2);
        assertEquals("filename", conf.getFileName(), conf2.getFileName());
        assertEquals("basepath", conf.getBasePath(), conf2.getBasePath());
        assertEquals("header", conf.getHeader(), conf2.getHeader());

        assertFalse("deserialized configuration empty", conf2.isEmpty());
        Iterator keys = conf.getKeys();
        while (keys.hasNext())
        {
            String key = (String) keys.next();
            assertTrue("missing key from the deserialized configuration : " +
key, conf2.containsKey(key));
            assertEquals("wrong value in the deserialized configuration for the
key " + key, conf.getProperty(key), conf2.getProperty(key));
        }
    }
{code}

      was (Author: ebourg):
    This is not as trivial as I thought initially... I made FileConfiguration
extends Serializable and wrote a test case serializing a PropertiesConfiguration
to a file. This led me to the following changes:

- make ReloadingStrategy extend Serializable as well
- change the type of the reloadLock in AbtractFileConfiguration to something
else than Object that is serializable. I picked String. I tried to make it
transient, but it resulted in a NullPointerException when accessing the
deserialized configuration because it was not initialized. I tried to move the
initialization in the no arg constructor but it didn't work, I'm not sure to
understand why this constructor isn't called when the deserialized instance is
build.

It still failed after these changes, because the deserialized configuration was
actually empty. It appears that the Map in BaseConfiguration is not serialized.
I put a similar Map in AbstractFileConfiguration and it got serialized property,
but by simply moving this Map to BaseConfiguration it disappeared from the
serialized file, I have no idea why.

I tested with the JDK 1.4.2_08.

Here is the test added to TestPropertiesConfiguration:

    public void testSerialization() throws Exception {
        // remove the previous serialization file
        File file = new File("target/configuration.ser");
        if (file.exists()) {
            file.delete();
        }

        // write the configuration to the configuration.ser file
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
        out.writeObject(conf);
        out.close();

        // load the configuration from the file
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
        PropertiesConfiguration conf2 = (PropertiesConfiguration) in.readObject();
        in.close();

        // check the deserialized configuration
        assertNotNull("deserialized configuration null", conf2);
        assertEquals("filename", conf.getFileName(), conf2.getFileName());
        assertEquals("basepath", conf.getBasePath(), conf2.getBasePath());
        assertEquals("header", conf.getHeader(), conf2.getHeader());

        assertFalse("deserialized configuration empty", conf2.isEmpty());
        Iterator keys = conf.getKeys();
        while (keys.hasNext())
        {
            String key = (String) keys.next();
            assertTrue("missing key from the deserialized configuration : " +
key, conf2.containsKey(key));
            assertEquals("wrong value in the deserialized configuration for the
key " + key, conf.getProperty(key), conf2.getProperty(key));
        }
    }

  
> Make Configuration Serializable
> -------------------------------
>
>                 Key: CONFIGURATION-203
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-203
>             Project: Commons Configuration
>          Issue Type: Improvement
>    Affects Versions: 1.1
>            Reporter: Joe Wolf
>            Priority: Minor
>             Fix For: 2.0
>
>
> It would be nice if org.apache.commons.configuration.Configuration extended java.io.Serializable
and its implementations were serializable as well.  Theoretically, most configurations are
constructed from "serialized" data sources.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message