com.sun.jini.mercury
Class StreamPool

java.lang.Object
  extended by com.sun.jini.mercury.StreamPool

 class StreamPool
extends Object

This class provides a pool of LogStream objects. Each LogStream has an associated FileDescriptor, which is the system resource we are trying to manage. This pool limits the (user configurable) number of concurrent, open FileDescriptors.

Since:
1.1
Author:
Sun Microsystems, Inc.

Field Summary
private  LinkedList freeList
          Holds stream references in least recently used (released) order.
private  int maxPoolSize
          Maximum limit for the number of concurrent LogStreams in the stream pool.
private static Logger persistenceLogger
          Logger for lease related messages
private  HashMap pool
          Holds stream references by associated key
 
Constructor Summary
StreamPool(int size)
          Simple constructor that creates a pool of given size.
 
Method Summary
(package private)  void dump()
           
private  void ensurePoolSpace()
          Ensures that room is available in the pool.
(package private)  ControlLog getControlLog(File file)
          Returns a ControlLog object for the specified file from the pool if it already exists.
(package private)  int getFreeSize()
           
(package private)  LogInputStream getLogInputStream(File file, long offset)
          Returns a LogInputStream object from the pool if it already exists.
(package private)  LogOutputStream getLogOutputStream(File file, long offset)
          Returns a LogOutputStream object for the specified file from the pool if it already exists.
(package private)  int getPoolSize()
           
(package private)  void releaseLogStream(LogStream stream)
          Marks a stream as available for closing.
(package private)  void removeLogStream(LogStream stream)
          Removes the given LogStream from the pool and closes it, if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistenceLogger

private static final Logger persistenceLogger
Logger for lease related messages


maxPoolSize

private final int maxPoolSize
Maximum limit for the number of concurrent LogStreams in the stream pool.


pool

private final HashMap pool
Holds stream references by associated key


freeList

private final LinkedList freeList
Holds stream references in least recently used (released) order. It's used in order determine which stream to discard upon reaching the maximum pool limit.

Constructor Detail

StreamPool

StreamPool(int size)
Simple constructor that creates a pool of given size.

Throws:
IllegalArgumentException - Thrown if the value of maxPoolSize is less than 1.
Method Detail

getControlLog

ControlLog getControlLog(File file)
                   throws IOException
Returns a ControlLog object for the specified file from the pool if it already exists. Otherwise, it creates a new instance and adds it to the pool.

Throws:
IOException - if an I/O error occurs

getLogInputStream

LogInputStream getLogInputStream(File file,
                                 long offset)
                           throws IOException
Returns a LogInputStream object from the pool if it already exists. Otherwise, it creates a new instance and adds it to the pool.

Throws:
IOException - if an I/O error occurs

getLogOutputStream

LogOutputStream getLogOutputStream(File file,
                                   long offset)
                             throws IOException
Returns a LogOutputStream object for the specified file from the pool if it already exists. Otherwise, it creates a new instance and adds it to the pool.

Throws:
IOException - if an I/O error occurs

ensurePoolSpace

private void ensurePoolSpace()
                      throws IOException
Ensures that room is available in the pool. If the pool is currently full, then the least recently used LogStream will be removed and closed to make room. This method will block if the pool is full and no LogStream objects can be closed.

Throws:
IOException - if an I/O error occurs

releaseLogStream

void releaseLogStream(LogStream stream)
Marks a stream as available for closing. A log will only be closed if a new log is requested and the pool has reached its maximum size.


removeLogStream

void removeLogStream(LogStream stream)
Removes the given LogStream from the pool and closes it, if possible. The intent is for this method to be called for unusable logs so that they will no longer be returned by a subsequent call to one of the "get" methods.


getPoolSize

int getPoolSize()

getFreeSize

int getFreeSize()

dump

void dump()


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.