ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject incubator-ignite git commit: IGNITE-651 - Persistance for marshaller cache
Date Tue, 31 Mar 2015 21:50:37 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-651 ea7d24856 -> 00c934cc3


IGNITE-651 - Persistance for marshaller cache


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/00c934cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/00c934cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/00c934cc

Branch: refs/heads/ignite-651
Commit: 00c934cc3921d05f92e1c0f7400ae9253b779b01
Parents: ea7d248
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Tue Mar 31 14:52:31 2015 -0700
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Tue Mar 31 14:52:31 2015 -0700

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  | 31 ++++++++++++++++----
 1 file changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00c934cc/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index 4a27222..d5a0526 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -23,6 +23,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 
 import javax.cache.event.*;
 import java.io.*;
+import java.nio.channels.*;
 import java.util.concurrent.*;
 
 /**
@@ -124,8 +125,18 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
         if (clsName == null) {
             File file = new File(workDir, id + ".classname");
 
-            try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
-                clsName = reader.readLine();
+            try (
+                FileInputStream in = new FileInputStream(file);
+                BufferedReader reader = new BufferedReader(new InputStreamReader(in))
+            ) {
+                FileLock lock = in.getChannel().lock(0, Long.MAX_VALUE, true);
+
+                try {
+                    clsName = reader.readLine();
+                }
+                finally {
+                    lock.release();
+                }
             }
             catch (IOException e) {
                 throw new IgniteCheckedException("Failed to read class name from file [id="
+ id +
@@ -162,10 +173,20 @@ public class MarshallerContextImpl extends MarshallerContextAdapter
{
 
                 File file = new File(workDir, evt.getKey() + ".classname");
 
-                try (Writer writer = new FileWriter(file)) {
-                    writer.write(evt.getValue());
+                try (
+                    FileOutputStream out = new FileOutputStream(file);
+                    Writer writer = new OutputStreamWriter(out)
+                ) {
+                    FileLock lock  = out.getChannel().lock();
+
+                    try {
+                        writer.write(evt.getValue());
 
-                    writer.flush();
+                        writer.flush();
+                    }
+                    finally {
+                        lock.release();
+                    }
                 }
                 catch (IOException e) {
                     U.error(log, "Failed to write class name to file [id=" + evt.getKey()
+


Mime
View raw message