This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Patch: java.nio - beginning of record locking
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 14 May 2003 08:40:13 +0200
- Subject: FYI: Patch: java.nio - beginning of record locking
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commited the attached patch to trunk to introduce some stuff needed
for record locking in files. This patch also reformats some stuff and
adds "throws IOException" to some methods.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+weTRWSOgCCdjSDsRAsTHAJ0UZd20lsWIQH4z1EidMwNFv2yf3ACfYoz/
GW8aDu2NWGSSl7JY0pAHdLk=
=EAas
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1894
diff -u -b -B -r1.1894 ChangeLog
--- ChangeLog 13 May 2003 20:11:01 -0000 1.1894
+++ ChangeLog 14 May 2003 06:33:42 -0000
@@ -1,3 +1,26 @@
+2003-05-14 Michael Koch <konqueror@gmx.de>
+
+ * gnu/java/nio/FileLockImpl.java
+ (released): New member variable.
+ (FileLockImpl): Initialize released.
+ (releaseImpl): New native method.
+ (release): Implemented.
+ * gnu/java/nio/SelectorImpl.java: Reformatted.
+ * gnu/java/nio/SelectionKeyImpl.java: Reformatted.
+ * gnu/java/nio/ServerSocketChannelImpl.java: Reformatted.
+ (accept): Throws IOException.
+ * gnu/java/nio/SocketChannelImpl.java: Reformatted.
+ (implConfigureBlocking): Throws IOException.
+ (connect): Likewise.
+ (read): Likewise.
+ (write): Likewise.
+ * gnu/java/nio/natFileLockImpl.cc: New file.
+ * java/nio/channels/FileLock.java: Reformatted.
+ * Makefile.am:
+ (ordinary_java_source_files): Added gnu/java/nio/FileLockImpl.java.
+ (nat_source_files): Added gnu/java/nio/natFileLockImpl.cc.
+ * Makefile.in: Regenerated.
+
2003-05-13 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/CharViewBufferImpl.java
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.295
diff -u -b -B -r1.295 Makefile.am
--- Makefile.am 13 May 2003 06:04:18 -0000 1.295
+++ Makefile.am 14 May 2003 06:33:45 -0000
@@ -2104,6 +2104,7 @@
gnu/java/nio/DoubleBufferImpl.java \
gnu/java/nio/DoubleViewBufferImpl.java \
gnu/java/nio/FileChannelImpl.java \
+gnu/java/nio/FileLockImpl.java \
gnu/java/nio/FloatBufferImpl.java \
gnu/java/nio/FloatViewBufferImpl.java \
gnu/java/nio/IntBufferImpl.java \
@@ -2564,6 +2565,7 @@
gnu/gcj/runtime/natVMClassLoader.cc \
gnu/java/nio/natDirectByteBufferImpl.cc \
gnu/java/nio/natFileChannelImpl.cc \
+gnu/java/nio/natFileLockImpl.cc \
gnu/java/nio/natMappedByteFileBuffer.cc \
gnu/java/nio/natSelectorImpl.cc \
gnu/java/nio/natSocketChannelImpl.cc \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.317
diff -u -b -B -r1.317 Makefile.in
--- Makefile.in 13 May 2003 06:04:18 -0000 1.317
+++ Makefile.in 14 May 2003 06:33:46 -0000
@@ -1866,6 +1866,7 @@
gnu/java/nio/DoubleBufferImpl.java \
gnu/java/nio/DoubleViewBufferImpl.java \
gnu/java/nio/FileChannelImpl.java \
+gnu/java/nio/FileLockImpl.java \
gnu/java/nio/FloatBufferImpl.java \
gnu/java/nio/FloatViewBufferImpl.java \
gnu/java/nio/IntBufferImpl.java \
@@ -2325,6 +2326,7 @@
gnu/gcj/runtime/natVMClassLoader.cc \
gnu/java/nio/natDirectByteBufferImpl.cc \
gnu/java/nio/natFileChannelImpl.cc \
+gnu/java/nio/natFileLockImpl.cc \
gnu/java/nio/natMappedByteFileBuffer.cc \
gnu/java/nio/natSelectorImpl.cc \
gnu/java/nio/natSocketChannelImpl.cc \
@@ -2500,7 +2502,7 @@
gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \
gnu/gcj/runtime/natVMClassLoader.lo \
gnu/java/nio/natDirectByteBufferImpl.lo \
-gnu/java/nio/natFileChannelImpl.lo \
+gnu/java/nio/natFileChannelImpl.lo gnu/java/nio/natFileLockImpl.lo \
gnu/java/nio/natMappedByteFileBuffer.lo gnu/java/nio/natSelectorImpl.lo \
gnu/java/nio/natSocketChannelImpl.lo java/io/natFile.lo \
java/io/natFileDescriptor.lo java/io/natObjectInputStream.lo \
@@ -2970,7 +2972,7 @@
.deps/gnu/java/nio/DirectByteBufferImpl.P \
.deps/gnu/java/nio/DoubleBufferImpl.P \
.deps/gnu/java/nio/DoubleViewBufferImpl.P \
-.deps/gnu/java/nio/FileChannelImpl.P \
+.deps/gnu/java/nio/FileChannelImpl.P .deps/gnu/java/nio/FileLockImpl.P \
.deps/gnu/java/nio/FloatBufferImpl.P \
.deps/gnu/java/nio/FloatViewBufferImpl.P \
.deps/gnu/java/nio/IntBufferImpl.P \
@@ -2995,6 +2997,7 @@
.deps/gnu/java/nio/charset/UTF_8.P \
.deps/gnu/java/nio/natDirectByteBufferImpl.P \
.deps/gnu/java/nio/natFileChannelImpl.P \
+.deps/gnu/java/nio/natFileLockImpl.P \
.deps/gnu/java/nio/natMappedByteFileBuffer.P \
.deps/gnu/java/nio/natSelectorImpl.P \
.deps/gnu/java/nio/natSocketChannelImpl.P \
Index: gnu/java/nio/FileLockImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/FileLockImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 FileLockImpl.java
--- gnu/java/nio/FileLockImpl.java 11 Feb 2003 06:47:50 -0000 1.2
+++ gnu/java/nio/FileLockImpl.java 14 May 2003 06:33:46 -0000
@@ -35,29 +35,41 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package gnu.java.nio;
+import java.io.FileDescriptor;
+import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
/**
* @author Michael Koch
+ * @since 1.4
*/
public class FileLockImpl extends FileLock
{
- public FileLockImpl (FileChannel channel, long position, long size,
- boolean shared)
+ private FileDescriptor fd;
+ private boolean released;
+
+ public FileLockImpl (FileDescriptor fd, FileChannel channel, long position,
+ long size, boolean shared)
{
super (channel, position, size, shared);
+ this.fd = fd;
+ this.released = false;
}
public boolean isValid ()
{
- throw new Error ("Not implemented");
+ return (released || !channel.isOpen ());
}
- public void release ()
+ private native void releaseImpl () throws IOException;
+
+ public synchronized void release () throws IOException
{
- throw new Error ("Not implemented");
+ releaseImpl ();
+ released = true;
}
}
Index: gnu/java/nio/SelectionKeyImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SelectionKeyImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 SelectionKeyImpl.java
--- gnu/java/nio/SelectionKeyImpl.java 29 Nov 2002 09:57:05 -0000 1.2
+++ gnu/java/nio/SelectionKeyImpl.java 14 May 2003 06:33:46 -0000
@@ -50,7 +50,7 @@
SelectorImpl impl;
SelectableChannel ch;
- public SelectionKeyImpl(SelectableChannel ch, SelectorImpl impl, int fd)
+ public SelectionKeyImpl (SelectableChannel ch, SelectorImpl impl, int fd)
{
this.ch = ch;
this.impl = impl;
Index: gnu/java/nio/SelectorImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SelectorImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 SelectorImpl.java
Index: gnu/java/nio/ServerSocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/ServerSocketChannelImpl.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 ServerSocketChannelImpl.java
--- gnu/java/nio/ServerSocketChannelImpl.java 14 Feb 2003 12:07:31 -0000 1.4
+++ gnu/java/nio/ServerSocketChannelImpl.java 14 May 2003 06:33:46 -0000
@@ -76,7 +76,7 @@
{
try
{
- close();
+ close ();
}
catch (Exception e)
{
@@ -91,12 +91,12 @@
fd = SocketChannelImpl.SocketCreate ();
}
- protected void implConfigureBlocking (boolean block) throws IOException
+ protected void implConfigureBlocking (boolean blocking) throws IOException
{
- blocking = block;
+ this.blocking = blocking;
}
- public SocketChannel accept ()
+ public SocketChannel accept () throws IOException
{
SocketChannelImpl result = new SocketChannelImpl (provider ());
result.sa = new InetSocketAddress (0);
Index: gnu/java/nio/SocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SocketChannelImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 SocketChannelImpl.java
--- gnu/java/nio/SocketChannelImpl.java 29 Nov 2002 09:57:05 -0000 1.2
+++ gnu/java/nio/SocketChannelImpl.java 14 May 2003 06:33:46 -0000
@@ -83,7 +83,7 @@
{
try
{
- close();
+ close ();
}
catch (Exception e)
{
@@ -91,25 +91,24 @@
}
}
- protected void implCloseSelectableChannel()
+ protected void implCloseSelectableChannel () throws IOException
{
connected = false;
SocketClose(fd);
fd = SocketCreate();
}
- protected void implConfigureBlocking(boolean block)
+ protected void implConfigureBlocking (boolean blocking) throws IOException
{
- if (blocking == block)
+ if (this.blocking == blocking)
return;
}
- public boolean connect(SocketAddress remote)
- throws IOException
+ public boolean connect (SocketAddress remote) throws IOException
{
if (connected)
{
- throw new AlreadyConnectedException();
+ throw new AlreadyConnectedException ();
}
// ok, lets connect !
@@ -130,17 +129,17 @@
return blocking;
}
- public boolean finishConnect()
+ public boolean finishConnect ()
{
return false;
}
- public boolean isConnected()
+ public boolean isConnected ()
{
return connected;
}
- public boolean isConnectionPending()
+ public boolean isConnectionPending ()
{
if (blocking)
return true;
@@ -148,7 +147,7 @@
return false;
}
- public Socket socket()
+ public Socket socket ()
{
if (sock_object != null)
{
@@ -158,7 +157,7 @@
return sock_object;
}
- public int read(ByteBuffer dst)
+ public int read (ByteBuffer dst) throws IOException
{
int bytes = 0;
int len = 1024;
@@ -176,19 +175,21 @@
return bytes;
}
- public long read(ByteBuffer[] dsts, int offset, int length)
+ public long read (ByteBuffer[] dsts, int offset, int length)
+ throws IOException
{
long bytes = 0;
- for (int i=offset; i<length; i++)
+ for (int i = offset; i < length; i++)
{
- bytes += read(dsts[i]);
+ bytes += read (dsts [i]);
}
return bytes;
}
- public int write(ByteBuffer src)
+ public int write (ByteBuffer src)
+ throws IOException
{
int bytes = 0;
int len = src.position();
@@ -210,12 +211,13 @@
}
public long write (ByteBuffer[] srcs, int offset, int length)
+ throws IOException
{
long bytes = 0;
- for (int i=offset; i<length; i++)
+ for (int i = offset; i < length; i++)
{
- bytes += write(srcs[i]);
+ bytes += write (srcs [i]);
}
return bytes;
Index: gnu/java/nio/natFileLockImpl.cc
===================================================================
RCS file: gnu/java/nio/natFileLockImpl.cc
diff -N gnu/java/nio/natFileLockImpl.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/natFileLockImpl.cc 14 May 2003 06:33:46 -0000
@@ -0,0 +1,25 @@
+// natFileLockImpl.cc
+
+/* Copyright (C) 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <jvm.h>
+#include <errno.h>
+
+#include <gnu/java/nio/FileLockImpl.h>
+#include <java/io/FileDescriptor.h>
+#include <java/io/IOException.h>
+
+void
+gnu::java::nio::FileLockImpl::releaseImpl ()
+{
+ throw new ::java::io::IOException
+ (JvNewStringUTF ("releaseImpl not implemented"));
+}
Index: java/nio/channels/FileLock.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/FileLock.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 FileLock.java
--- java/nio/channels/FileLock.java 11 Feb 2003 06:47:50 -0000 1.2
+++ java/nio/channels/FileLock.java 14 May 2003 06:33:46 -0000
@@ -101,7 +101,7 @@
*/
public final boolean overlaps (long position, long size)
{
- if (position > this.position +this.size)
+ if (position > this.position + this.size)
return false;
if (position + size < this.position)