langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
35 import java.nio.channels.FileLockInterruptionException; |
35 import java.nio.channels.FileLockInterruptionException; |
36 import java.util.concurrent.Semaphore; |
36 import java.util.concurrent.Semaphore; |
37 |
37 |
38 import com.sun.tools.javac.util.Assert; |
38 import com.sun.tools.javac.util.Assert; |
39 import com.sun.tools.sjavac.Log; |
39 import com.sun.tools.sjavac.Log; |
|
40 import com.sun.tools.sjavac.client.PortFileInaccessibleException; |
40 |
41 |
41 /** |
42 /** |
42 * The PortFile class mediates access to a short binary file containing the tcp/ip port (for the localhost) |
43 * The PortFile class mediates access to a short binary file containing the tcp/ip port (for the localhost) |
43 * and a cookie necessary for the server answering on that port. The file can be locked using file system |
44 * and a cookie necessary for the server answering on that port. The file can be locked using file system |
44 * primitives to avoid race conditions when several javac clients are started at the same. Note that file |
45 * primitives to avoid race conditions when several javac clients are started at the same. Note that file |
78 |
79 |
79 /** |
80 /** |
80 * Create a new portfile. |
81 * Create a new portfile. |
81 * @param fn is the path to the file. |
82 * @param fn is the path to the file. |
82 */ |
83 */ |
83 public PortFile(String fn) throws FileNotFoundException { |
84 public PortFile(String fn) throws PortFileInaccessibleException { |
84 filename = fn; |
85 filename = fn; |
85 file = new File(filename); |
86 file = new File(filename); |
86 stopFile = new File(filename+".stop"); |
87 stopFile = new File(filename+".stop"); |
87 rwfile = new RandomAccessFile(file, "rw"); |
88 try { |
|
89 rwfile = new RandomAccessFile(file, "rw"); |
|
90 } catch (FileNotFoundException e) { |
|
91 // Reached if file for instance already exists and is a directory |
|
92 throw new PortFileInaccessibleException(e); |
|
93 } |
88 // The rwfile should only be readable by the owner of the process |
94 // The rwfile should only be readable by the owner of the process |
89 // and no other! How do we do that on a RandomAccessFile? |
95 // and no other! How do we do that on a RandomAccessFile? |
90 channel = rwfile.getChannel(); |
96 channel = rwfile.getChannel(); |
91 containsPortInfo = false; |
97 containsPortInfo = false; |
92 lock = null; |
98 lock = null; |