Skip to content
Permalink
Browse files
Interim changes
Created MapHandleImpl
  • Loading branch information
leerho committed May 15, 2021
1 parent 625ffa0 commit 6ccfa2dccfd61f50dd897395b7e3c636c248d5ce
Show file tree
Hide file tree
Showing 42 changed files with 153 additions and 44 deletions.
@@ -17,7 +17,9 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

import org.apache.datasketches.memory.internal.WritableMemory;

/**
* This is a simple implementation of the MemoryRequestServer that creates space on the Java heap
@@ -17,7 +17,9 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

import org.apache.datasketches.memory.internal.Memory;

/**
* A handle for read-only resource.
@@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

/**
* Read only interface for a memory mapped file
@@ -26,7 +26,7 @@
* @author Lee Rhodes
* @author Praveenkumar Venkatesan
*/
interface Map extends AutoCloseable {
public interface Map extends AutoCloseable {

/**
* @see <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html#load--">
@@ -0,0 +1,47 @@
/*
* 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.datasketches.memory;

import org.apache.datasketches.memory.internal.Memory;


/**
* A Handle for a memory-mapped, read-only file resource. This
* joins a Read-only Handle with an AutoCloseable Map resource.
* Please read Javadocs for {@link Handle}.
*
* @author Lee Rhodes
* @author Roman Leventov
*/
public interface MapHandle extends Map, Handle {

@Override
Memory get();

@Override
void close();

@Override
void load();

@Override
boolean isLoaded();
}
@@ -17,7 +17,10 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

import org.apache.datasketches.memory.internal.WritableDirectHandle;
import org.apache.datasketches.memory.internal.WritableMemory;

/**
* The MemoryRequestServer is a callback interface to provide a means for a direct (off-heap),
@@ -17,7 +17,9 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

import org.apache.datasketches.memory.internal.WritableMemory;

/**
* A Handle for writable direct memory or a memory-mapped, writable file resource.
@@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.datasketches.memory.internal;
package org.apache.datasketches.memory;

/**
* Writable interface for a memory mapped file
@@ -26,7 +26,7 @@
* @author Lee Rhodes
* @author Praveenkumar Venkatesan
*/
interface WritableMap extends Map {
public interface WritableMap extends Map {

/**
* @see <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html#force--">
@@ -30,6 +30,7 @@
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import org.apache.datasketches.memory.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -21,6 +21,8 @@

import java.io.File;

import org.apache.datasketches.memory.WritableMap;

/**
* Allocates direct memory used to memory map files for write operations
* (including those &gt; 2GB).
@@ -28,6 +28,9 @@
import java.nio.ByteOrder;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Keeps key configuration state for Memory and Buffer plus some common static variables
* and check methods.
@@ -36,6 +36,8 @@
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;

import org.apache.datasketches.memory.MemoryRequestServer;

/*
* Developer notes: The heavier methods, such as put/get arrays, duplicate, region, clear, fill,
* compareTo, etc., use hard checks (checkValid*() and checkBounds()), which execute at runtime and
@@ -21,6 +21,8 @@

import java.nio.ByteOrder;

import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Implementation of {@link WritableBuffer} for direct memory, non-native byte order.
*
@@ -21,6 +21,8 @@

import java.nio.ByteOrder;

import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Implementation of {@link WritableMemory} for direct memory, non-native byte order.
*
@@ -21,6 +21,8 @@

import java.nio.ByteOrder;

import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Implementation of {@link WritableBuffer} for direct memory, native byte order.
*
@@ -21,6 +21,8 @@

import java.nio.ByteOrder;

import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Implementation of {@link WritableMemory} for direct memory, native byte order.
*
@@ -19,22 +19,17 @@

package org.apache.datasketches.memory.internal;

/**
* A Handle for a memory-mapped, read-only file resource.
* Please read Javadocs for {@link Handle}.
*
* @author Lee Rhodes
* @author Roman Leventov
*/
//Joins a Read-only Handle with an AutoCloseable Map resource.
public class MapHandle implements Map, Handle {
import org.apache.datasketches.memory.MapHandle;

public class MapHandleImpl implements MapHandle {

/**
* Having at least one final field makes this class safe for concurrent publication.
*/
final AllocateDirectMap dirMap;
private BaseWritableMemoryImpl wMem;

MapHandle(final AllocateDirectMap dirMap, final BaseWritableMemoryImpl wMem) {
MapHandleImpl(final AllocateDirectMap dirMap, final BaseWritableMemoryImpl wMem) {
this.dirMap = dirMap;
this.wMem = wMem;
}
@@ -29,6 +29,9 @@
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;

import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.MapHandle;

/**
* Provides read-only primitive and primitive array methods to any of the four resources
* mentioned in the package level documentation.
@@ -22,6 +22,9 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.MemoryRequestServer;

/**
* Provides read and write, positional primitive and primitive array access to any of the four
* resources mentioned at the package level.
@@ -19,6 +19,9 @@

package org.apache.datasketches.memory.internal;

import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.WritableHandle;

/**
* A Handle for a writable direct memory resource.
* Please read Javadocs for {@link Handle}.
@@ -19,6 +19,10 @@

package org.apache.datasketches.memory.internal;

import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.WritableMap;

/**
* A Handle for a memory-mapped, writable file resource.
* Please read Javadocs for {@link Handle}.
@@ -27,7 +31,7 @@
* @author Lee Rhodes
*/
//Joins a WritableHandle with an AutoCloseable WritableMap resource
public final class WritableMapHandle extends MapHandle implements WritableMap, WritableHandle {
public final class WritableMapHandle extends MapHandleImpl implements WritableMap, WritableHandle {

WritableMapHandle(final AllocateDirectWritableMap dirWmap,
final BaseWritableMemoryImpl wMem) {
@@ -28,6 +28,11 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableHandle;

/**
* Provides read and write primitive and primitive array access to any of the four resources
* mentioned at the package level.
@@ -84,7 +84,7 @@
*
* <p>An access API is joined with
* a resource either with a static factory method or in combination with a
* {@link org.apache.datasketches.memory.internal.Handle}, which is used exclusively for resources that are
* {@link org.apache.datasketches.memory.Handle}, which is used exclusively for resources that are
* external to the JVM, such as allocation of direct memory and memory-mapped files.</p>
*
* <p>The role of a Handle is to hold onto the reference of a resource that is outside the control
@@ -93,7 +93,7 @@
* <p>When a handle is extended for an AutoCloseable resource and then joined with an access API
* it becomes an <i>implementation handle</i>. There are 3 implementation handles:</p>
*
* <ul><li>{@link org.apache.datasketches.memory.internal.MapHandle}
* <ul><li>{@link org.apache.datasketches.memory.internal.MapHandleImpl}
* for read-only access to a memory-mapped file</li>
* <li>{@link org.apache.datasketches.memory.internal.WritableMapHandle}
* for writable access to a memory-mapped file</li>
@@ -0,0 +1,24 @@
/*
* 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.
*/

/**
* @author lrhodes
*
*/
package org.apache.datasketches.memory;
@@ -32,7 +32,7 @@
import java.io.File;
import java.nio.ByteOrder;

import org.apache.datasketches.memory.internal.MapHandle;
import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.internal.Memory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -26,10 +26,10 @@

import java.lang.reflect.InvocationTargetException;

import org.apache.datasketches.memory.internal.MemoryRequestServer;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableDirectHandle;
import org.apache.datasketches.memory.internal.WritableHandle;
import org.apache.datasketches.memory.internal.WritableMemory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
@@ -37,11 +37,11 @@
import java.lang.reflect.Method;
import java.nio.ByteOrder;

import org.apache.datasketches.memory.internal.MapHandle;
import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Memory;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableHandle;
import org.apache.datasketches.memory.internal.WritableMapHandle;
import org.apache.datasketches.memory.internal.WritableMemory;
import org.testng.annotations.AfterClass;
@@ -21,9 +21,9 @@

import static org.testng.Assert.fail;

import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.Memory;
import org.apache.datasketches.memory.internal.WritableHandle;
import org.apache.datasketches.memory.internal.WritableMemory;
import org.testng.annotations.Test;

@@ -24,9 +24,9 @@

import java.nio.ByteBuffer;

import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.WritableBuffer;
import org.apache.datasketches.memory.internal.WritableHandle;
import org.apache.datasketches.memory.internal.WritableMemory;
import org.testng.annotations.Test;

0 comments on commit 6ccfa2d

Please sign in to comment.