You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/19 18:37:35 UTC
svn commit: r826716 - in
/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io:
Detachable.java FileLockImpl.java FileStream.java
Author: mturk
Date: Mon Oct 19 16:37:34 2009
New Revision: 826716
URL: http://svn.apache.org/viewvc?rev=826716&view=rev
Log:
Add Detachable interface
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java?rev=826716&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java Mon Oct 19 16:37:34 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime.io;
+
+/**
+ * The base class for all classes offerering
+ * detach method to it's child objects.
+ */
+public interface Detachable
+{
+
+ /**
+ * Detach {@code data} from it's container.
+ * <p>
+ * Called from the object that was created by {@code this}
+ * object informing it that it should destroy the reference
+ * to the {@code data} object.
+ * </p>
+ *
+ * @param data Object to detach.
+ */
+ public void detach(Object data);
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Detachable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java?rev=826716&r1=826715&r2=826716&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockImpl.java Mon Oct 19 16:37:34 2009
@@ -43,29 +43,37 @@
*/
private Descriptor fd;
+ /*
+ * FileLock container object
+ */
+ private Detachable container;
+
/**
* Create new {@code FileLock} that locks the entire file.
*
*/
- public FileLockImpl(Descriptor fd, EnumSet<FileLockType> mode)
+ public FileLockImpl(Detachable container, Descriptor fd,
+ EnumSet<FileLockType> mode)
{
super(mode);
- this.fd = fd;
- offset = 0;
- length = -1;
+ this.container = container;
+ this.fd = fd;
+ offset = 0;
+ length = -1;
}
/**
* Create new {@code FileLock} that locks the region of file.
*
*/
- public FileLockImpl(Descriptor fd, EnumSet<FileLockType> mode,
- long start, long len)
+ public FileLockImpl(Detachable container, Descriptor fd,
+ EnumSet<FileLockType> mode, long start, long len)
{
super(mode);
- this.fd = fd;
- offset = start;
- length = len;
+ this.container = container;
+ this.fd = fd;
+ offset = start;
+ length = len;
}
/**
@@ -144,6 +152,9 @@
FileWrapper.unlock(fd);
else
FileWrapper.unlock(fd, offset, length);
+ /* Detach from this locks container
+ */
+ container.detach(this);
fd = null;
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java?rev=826716&r1=826715&r2=826716&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java Mon Oct 19 16:37:34 2009
@@ -40,7 +40,7 @@
* position of the next read or write operation can be moved forwards and
* backwards after every operation.
*/
-public class FileStream extends Stream
+public class FileStream extends Stream implements Detachable
{
/* File's descriptor object
*/
@@ -53,6 +53,12 @@
*/
private Vector<FileLockImpl> locks = new Vector<FileLockImpl>(2);
+ public void detach(Object what)
+ {
+ FileLockImpl lck = (FileLockImpl)what;
+ locks.remove(lck);
+ }
+
/**
* Return the {@link Descriptor} accosicated with this file.
*
@@ -273,9 +279,6 @@
return true;
}
}
- else {
- locks.remove(lck);
- }
} catch (Throwable te) {
}
}
@@ -316,7 +319,7 @@
FileWrapper.lock(fd, type);
/* Create FileLock wrapper object
*/
- FileLockImpl lock = new FileLockImpl(fd, type);
+ FileLockImpl lock = new FileLockImpl(this, fd, type);
/* Add the FileLock to the list of locks
*/
locks.add(lock);
@@ -372,7 +375,7 @@
FileWrapper.lock(fd, type, offset, length);
/* Create FileLock wrapper object
*/
- FileLockImpl lock = new FileLockImpl(fd, type, offset, length);
+ FileLockImpl lock = new FileLockImpl(this, fd, type, offset, length);
/* Add the FileLock to the list of locks
*/
locks.add(lock);