Lock.java revision 2546
0N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @bug 4607272 6814948 6842687 0N/A * @summary Unit test for AsynchronousFileChannel#lock method 100N/A // create temporary file 0N/A // test locking protocol 0N/A // slave VM opens file and acquires exclusive lock 0N/A // this VM tries to acquire lock 0N/A // (lock should not be acquire until released by slave VM) 0N/A // slave VM releases lock 0N/A // this VM should now acquire lock 0N/A // slave VM acquires lock on range 0N/A // this VM acquires lock on non-overlapping range 0N/A // test close of channel with outstanding lock operation 0N/A // slave VM opens file and acquires exclusive lock 0N/A for (
int i=
0; i<
100; i++) {
0N/A // try to lock file (should not complete because file is locked by slave) 0N/A // close channel with lock operation outstanding 0N/A // operation should complete with AsynchronousCloseException 100N/A // starts a "lock slave" in another process, returning a mirror object to 0N/A // control the slave 100N/A // wait for slave to connect 100N/A // commands that the slave understands 0N/A // provides a proxy to a "lock slave" 0N/A // Helper class to direct process output to the parent System.out 0N/A byte b[] =
new byte[
100];
0N/A for (
int i=
0; i<n; i++) {
0N/A // slave process that responds to simple commands a socket connection 0N/A // establish connection to parent 0N/A // read command (ends with ";") 0N/A // decode into command and optional parameter