You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/04/08 17:27:04 UTC
[10/50] incubator-ignite git commit: # IGNITE-679: Applied patch from
Ivan V.
# IGNITE-679: Applied patch from Ivan V.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bed567f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bed567f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bed567f9
Branch: refs/heads/ignite-30
Commit: bed567f9e468b2aa6b752475cc2936cb6c0dc6a3
Parents: f0bcbc9
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Apr 7 14:37:36 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Apr 7 14:37:36 2015 +0300
----------------------------------------------------------------------
.../ipc/shmem/IpcSharedMemoryNativeLoader.java | 48 ++++++++++++++------
1 file changed, 35 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bed567f9/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java
index ef9f46a..dc00ca6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java
@@ -33,18 +33,15 @@ import static org.apache.ignite.internal.IgniteVersionUtils.*;
*/
@SuppressWarnings("ErrorNotRethrown")
public class IpcSharedMemoryNativeLoader {
- /** Loaded flag. */
- private static volatile boolean loaded;
-
/** Library name base. */
private static final String LIB_NAME_BASE = "igniteshmem";
- /** Lock file path. */
- private static final File LOCK_FILE = new File(System.getProperty("java.io.tmpdir"), "igniteshmem.lock");
-
/** Library name. */
static final String LIB_NAME = LIB_NAME_BASE + "-" + VER_STR;
+ /** Loaded flag. */
+ private static volatile boolean loaded;
+
/**
* @return Operating system name to resolve path to library.
*/
@@ -121,16 +118,20 @@ public class IpcSharedMemoryNativeLoader {
errs.add(e);
}
+ File tmpDir = getUserSpecificTempDir();
+
+ File lockFile = new File(tmpDir, "igniteshmem.lock");
+
// Obtain lock on file to prevent concurrent extracts.
- try (RandomAccessFile randomAccessFile = new RandomAccessFile(LOCK_FILE, "rws");
+ try (RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rws");
FileLock ignored = randomAccessFile.getChannel().lock()) {
- if (extractAndLoad(errs, platformSpecificResourcePath()))
+ if (extractAndLoad(errs, tmpDir, platformSpecificResourcePath()))
return;
- if (extractAndLoad(errs, osSpecificResourcePath()))
+ if (extractAndLoad(errs, tmpDir, osSpecificResourcePath()))
return;
- if (extractAndLoad(errs, resourcePath()))
+ if (extractAndLoad(errs, tmpDir, resourcePath()))
return;
// Failed to find the library.
@@ -139,11 +140,32 @@ public class IpcSharedMemoryNativeLoader {
throw new IgniteCheckedException("Failed to load native IPC library: " + errs);
}
catch (IOException e) {
- throw new IgniteCheckedException("Failed to obtain file lock: " + LOCK_FILE, e);
+ throw new IgniteCheckedException("Failed to obtain file lock: " + lockFile, e);
}
}
/**
+ * Gets temporary directory unique for each OS user.
+ * The directory guaranteed to exist, though may not be empty.
+ */
+ private static File getUserSpecificTempDir() throws IgniteCheckedException {
+ String tmp = System.getProperty("java.io.tmpdir");
+
+ String userName = System.getProperty("user.name");
+
+ File tmpDir = new File(tmp, userName);
+
+ if (!tmpDir.exists())
+ //noinspection ResultOfMethodCallIgnored
+ tmpDir.mkdirs();
+
+ if (!(tmpDir.exists() && tmpDir.isDirectory()))
+ throw new IgniteCheckedException("Failed to create temporary directory [dir=" + tmpDir + ']');
+
+ return tmpDir;
+ }
+
+ /**
* @return OS resource path.
*/
private static String osSpecificResourcePath() {
@@ -181,13 +203,13 @@ public class IpcSharedMemoryNativeLoader {
* @param rsrcPath Path.
* @return {@code True} if library was found and loaded.
*/
- private static boolean extractAndLoad(Collection<Throwable> errs, String rsrcPath) {
+ private static boolean extractAndLoad(Collection<Throwable> errs, File tmpDir, String rsrcPath) {
ClassLoader clsLdr = U.detectClassLoader(IpcSharedMemoryNativeLoader.class);
URL rsrc = clsLdr.getResource(rsrcPath);
if (rsrc != null)
- return extract(errs, rsrc, new File(System.getProperty("java.io.tmpdir"), mapLibraryName(LIB_NAME)));
+ return extract(errs, rsrc, new File(tmpDir, mapLibraryName(LIB_NAME)));
else {
errs.add(new IllegalStateException("Failed to find resource with specified class loader " +
"[rsrc=" + rsrcPath + ", clsLdr=" + clsLdr + ']'));