org.apache.wicket.protocol.http.pagestore
Class FileChannelPool

java.lang.Object
  extended by org.apache.wicket.protocol.http.pagestore.FileChannelPool

public class FileChannelPool
extends Object

Thread safe pool of FileChannel objects.

Opening and closing file is an expensive operation and under certain circumstances this can significantly harm performances, because on every close the file system cache might be flushed.

To minimize the negative impact opened files can be pooled, which is a responsibility of FileChannelPool class.

FileChannelPool allows to specify maximum number of opened FileChannels.

Note that under certain circumstances (when there are no empty slots in pool) the initial capacity can be exceeded (more files are opened then the specified capacity is). If this happens, a warning is written to log, as this probably means that there is a problem with page store.

Author:
Matej Knopp

Constructor Summary
FileChannelPool(int capacity)
          Construct.
 
Method Summary
 void closeAndDeleteFileChannel(String name)
          Closes the file channel with given name and removes it from pool.
 void destroy()
          Destroys the FileChannel pool and closes all opened channels.
 FileChannel getFileChannel(String fileName, boolean createIfDoesNotExist)
          Returns a channel for given file.
 void returnFileChannel(FileChannel channel)
          Returns the channel to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileChannelPool

public FileChannelPool(int capacity)
Construct.

Parameters:
capacity - Maximum number of opened file channels.
Method Detail

getFileChannel

public FileChannel getFileChannel(String fileName,
                                  boolean createIfDoesNotExist)
Returns a channel for given file. If the file doesn't exist, the createIfDoesNotExit attribute specifies if the file should be created. Do NOT call close on the returned chanel. Instead call returnFileChannel(FileChannel)

Parameters:
fileName -
createIfDoesNotExist -
Returns:
file channel

returnFileChannel

public void returnFileChannel(FileChannel channel)
Returns the channel to the pool. It is necessary to call this for every channel obtained by calling getFileChannel(String, boolean).

Parameters:
channel -

closeAndDeleteFileChannel

public void closeAndDeleteFileChannel(String name)
Closes the file channel with given name and removes it from pool. Also removes the file from file system. If the channel is in use, the pool first waits until the chanel is returned to the pool and then closes it.

Parameters:
name -

destroy

public void destroy()
Destroys the FileChannel pool and closes all opened channels.



Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.