tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: TAMAYA-34: Fixed serialization.
Date Fri, 26 Dec 2014 01:47:02 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 644a7b1de -> 986f99212


TAMAYA-34: Fixed serialization.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/986f9921
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/986f9921
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/986f9921

Branch: refs/heads/master
Commit: 986f99212a42a3ff7b4e267059d005631e1db031
Parents: 644a7b1
Author: anatole <anatole@apache.org>
Authored: Fri Dec 26 02:46:55 2014 +0100
Committer: anatole <anatole@apache.org>
Committed: Fri Dec 26 02:46:55 2014 +0100

----------------------------------------------------------------------
 .../core/config/DefaultConfiguredValue.java     | 26 +++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/986f9921/core/src/main/java/org/apache/tamaya/core/config/DefaultConfiguredValue.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/DefaultConfiguredValue.java
b/core/src/main/java/org/apache/tamaya/core/config/DefaultConfiguredValue.java
index eae4057..311fb19 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/DefaultConfiguredValue.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/DefaultConfiguredValue.java
@@ -4,6 +4,10 @@ import org.apache.tamaya.ConfiguredValue;
 import org.apache.tamaya.annotation.LoadPolicy;
 
 import java.beans.PropertyChangeEvent;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicLong;
@@ -15,7 +19,7 @@ import java.util.function.Supplier;
 /**
  * Implementation of a configured value (in progress).
  */
-public class DefaultConfiguredValue<T> implements ConfiguredValue<T>{
+public class DefaultConfiguredValue<T> implements ConfiguredValue<T>, Serializable{
 
     private LoadPolicy loadPolicy = LoadPolicy.INITIAL;
     private AtomicLong lastUpdate;
@@ -155,4 +159,24 @@ public class DefaultConfiguredValue<T> implements ConfiguredValue<T>{
     public Optional<T> toOptional(){
         return value;
     }
+
+    private void writeObject(ObjectOutputStream oos)throws IOException{
+        oos.writeLong(this.lastAccess.get());
+        oos.writeLong(this.lastUpdate.get());
+        if(isPresent()) {
+            oos.writeObject(this.value.get());
+        }
+        else{
+            oos.writeObject(null);
+        }
+    }
+
+    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
{
+        this.lastAccess.set(ois.readLong());
+        this.lastUpdate.set(ois.readLong());
+        if(isPresent()) {
+            this.value = Optional.of((T)ois.readObject());
+        }
+
+    }
 }


Mime
View raw message