activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r881769 - in /activemq/sandbox/activemq-apollo/activemq-syscall: pom.xml src/main/java/org/apache/activemq/syscall/FileDescriptor.java src/main/java/org/apache/activemq/syscall/NativeAllocation.java
Date Wed, 18 Nov 2009 13:26:28 GMT
Author: chirino
Date: Wed Nov 18 13:26:28 2009
New Revision: 881769

URL: http://svn.apache.org/viewvc?rev=881769&view=rev
Log:
adding a FileDescriptor abstraction

Added:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/FileDescriptor.java
Modified:
    activemq/sandbox/activemq-apollo/activemq-syscall/pom.xml
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/pom.xml?rev=881769&r1=881768&r2=881769&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/pom.xml (original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/pom.xml Wed Nov 18 13:26:28 2009
@@ -61,6 +61,11 @@
       <artifactId>hawtjni-runtime</artifactId>
       <version>1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-util</artifactId>
+    </dependency>
+    
 
     <dependency>
       <groupId>junit</groupId>

Added: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/FileDescriptor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/FileDescriptor.java?rev=881769&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/FileDescriptor.java
(added)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/FileDescriptor.java
Wed Nov 18 13:26:28 2009
@@ -0,0 +1,79 @@
+/**
+ * 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.activemq.syscall;
+
+import java.io.IOException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+
+import org.apache.activemq.syscall.jni.IO;
+
+import static org.apache.activemq.syscall.jni.CLibrary.*;
+
+/**
+ * 
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+public class FileDescriptor {
+
+    private final int fd;
+    boolean opened;
+
+    public FileDescriptor(int fd) {
+        this.fd = fd;
+    }
+
+    public static FileDescriptor open(String path, int oflags, int mode) throws IOException
{
+        int fd = IO.open(path, oflags, mode);
+        if( fd== -1 ) {
+            throw new IOException(string(strerror(errno())));
+        }
+        FileDescriptor rc = new FileDescriptor(fd);
+        rc.opened = true;
+        return rc;
+    }
+    
+    public int dispose() {
+        if(closeCheck()) {
+            return IO.close(fd);
+        }
+        return 0;
+    }
+
+    public void close() throws IOException {
+        if( dispose() == -1 ) {
+            throw new IOException(string(strerror(errno())));
+        }
+    }
+
+    private boolean closeCheck() {
+        if( opened ) {
+            opened=false;
+            return true;
+        }
+        return false;
+    }
+    
+    int getFD() {
+        return fd;
+    }
+
+    public void write(NativeAllocation writeBuffer, Callable<Integer> callback) {
+        return;
+    }
+    
+}

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java?rev=881769&r1=881768&r2=881769&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
Wed Nov 18 13:26:28 2009
@@ -29,9 +29,10 @@
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
 public final class NativeAllocation {
-	
-    private long pointer;
-    private long length;
+
+    final private long pointer;
+    final private long length;
+    boolean allocated;
 
     public NativeAllocation(long pointer, long length) {
         if( pointer==NULL ) {
@@ -53,21 +54,25 @@
     }
     
     static public NativeAllocation allocate(long size) {
-        return new NativeAllocation(calloc(size,1), size);
+        NativeAllocation rc = new NativeAllocation(calloc(size,1), size);
+        rc.allocated = true;
+        return rc;
     }        
     
-    synchronized public void free() {
-        if( pointer!=NULL ) {
+    public void free() {
+        if( freeCheck() ) {
             CLibrary.free(pointer);
-            pointer = 0;
         }
     }
     
-    @Override
-    protected void finalize() throws Throwable {
-        free();
+    private boolean freeCheck() {
+        if( allocated ) {
+            allocated=false;
+            return true;
+        }
+        return false;
     }
-
+    
     public long pointer() {
         return pointer;
     }



Mime
View raw message