org.apache.hadoop.hdfs
Class ShortCircuitShm

java.lang.Object
  extended by org.apache.hadoop.hdfs.ShortCircuitShm
Direct Known Subclasses:
DfsClientShm

public class ShortCircuitShm
extends Object

A shared memory segment used to implement short-circuit reads.


Nested Class Summary
static class ShortCircuitShm.ShmId
          Identifies a DfsClientShm.
 class ShortCircuitShm.Slot
          A slot containing information about a replica.
static class ShortCircuitShm.SlotId
          Uniquely identifies a slot.
 class ShortCircuitShm.SlotIterator
           
 
Field Summary
protected static int BYTES_PER_SLOT
           
 
Constructor Summary
ShortCircuitShm(ShortCircuitShm.ShmId shmId, FileInputStream stream)
          Create the ShortCircuitShm.
 
Method Summary
 ShortCircuitShm.Slot allocAndRegisterSlot(ExtendedBlockId blockId)
          Allocate a new slot and register it.
 void free()
           
 ShortCircuitShm.ShmId getShmId()
           
 ShortCircuitShm.Slot getSlot(int slotIdx)
           
 boolean isEmpty()
          Determine if this shared memory object is empty.
 boolean isFull()
          Determine if this shared memory object is full.
 ShortCircuitShm.Slot registerSlot(int slotIdx, ExtendedBlockId blockId)
          Register a slot.
 ShortCircuitShm.SlotIterator slotIterator()
          Iterate over all allocated slots.
 String toString()
           
 void unregisterSlot(int slotIdx)
          Unregisters a slot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTES_PER_SLOT

protected static final int BYTES_PER_SLOT
See Also:
Constant Field Values
Constructor Detail

ShortCircuitShm

public ShortCircuitShm(ShortCircuitShm.ShmId shmId,
                       FileInputStream stream)
                throws IOException
Create the ShortCircuitShm.

Parameters:
shmId - The ID to use.
stream - The stream that we're going to use to create this shared memory segment. Although this is a FileInputStream, we are going to assume that the underlying file descriptor is writable as well as readable. It would be more appropriate to use a RandomAccessFile here, but that class does not have any public accessor which returns a FileDescriptor, unlike FileInputStream.
Throws:
IOException
Method Detail

getShmId

public final ShortCircuitShm.ShmId getShmId()

isEmpty

public final boolean isEmpty()
Determine if this shared memory object is empty.

Returns:
True if the shared memory object is empty.

isFull

public final boolean isFull()
Determine if this shared memory object is full.

Returns:
True if the shared memory object is full.

allocAndRegisterSlot

public final ShortCircuitShm.Slot allocAndRegisterSlot(ExtendedBlockId blockId)
Allocate a new slot and register it. This function chooses an empty slot, initializes it, and then returns the relevant Slot object.

Returns:
The new slot.

getSlot

public final ShortCircuitShm.Slot getSlot(int slotIdx)
                                   throws org.apache.hadoop.fs.InvalidRequestException
Throws:
org.apache.hadoop.fs.InvalidRequestException

registerSlot

public final ShortCircuitShm.Slot registerSlot(int slotIdx,
                                               ExtendedBlockId blockId)
                                        throws org.apache.hadoop.fs.InvalidRequestException
Register a slot. This function looks at a slot which has already been initialized (by another process), and registers it with us. Then, it returns the relevant Slot object.

Returns:
The slot.
Throws:
org.apache.hadoop.fs.InvalidRequestException - If the slot index we're trying to allocate has not been initialized, or is already in use.

unregisterSlot

public final void unregisterSlot(int slotIdx)
Unregisters a slot. This doesn't alter the contents of the slot. It just means

Parameters:
slotIdx - Index of the slot to unregister.

slotIterator

public ShortCircuitShm.SlotIterator slotIterator()
Iterate over all allocated slots. Note that this method isn't safe if

Returns:
The slot iterator.

free

public void free()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 Apache Software Foundation. All Rights Reserved.