com.realtime.crossfire.jxclient.faces
Class FileCacheFaceQueue

java.lang.Object
  extended by com.realtime.crossfire.jxclient.faces.AbstractFaceQueue
      extended by com.realtime.crossfire.jxclient.faces.FileCacheFaceQueue
All Implemented Interfaces:
FaceQueue

public class FileCacheFaceQueue
extends AbstractFaceQueue

A FaceQueue loading faces from ImageCache instances.


Nested Class Summary
private  class FileCacheFaceQueue.LoadTask
          A thread which loads one face from the caches.
private  class FileCacheFaceQueue.SaveTask
          A thread which saves one face to the caches.
 
Field Summary
private  java.util.concurrent.ExecutorService executorService
          The ExecutorService used to execute face loading.
private  int id
          Counts the number of calls to reset().
private  ImageCache imageCacheMagicMap
          The image cache used for loading magic map images.
private  ImageCache imageCacheOriginal
          The image cache used for loading original images.
private  ImageCache imageCacheScaled
          The image cache used for loading scaled images.
private  java.util.Collection<Face> pendingLoadFaces
          The faces for which loadFace(Face) has been called but that are not yet processed.
private  java.lang.Object sync
          The object used for synchronization.
 
Constructor Summary
FileCacheFaceQueue(ImageCache imageCacheOriginal, ImageCache imageCacheScaled, ImageCache imageCacheMagicMap)
          Creates a new instance.
 
Method Summary
 void loadFace(Face face)
          Request a face.
 void reset()
          Reset the processing: forget about pending faces.
 void saveFace(Face face, FaceImages faceImages)
          Saves a face to the caches.
 
Methods inherited from class com.realtime.crossfire.jxclient.faces.AbstractFaceQueue
addFaceQueueListener, fireFaceFailed, fireFaceLoaded, removeFaceQueueListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executorService

@NotNull
private final java.util.concurrent.ExecutorService executorService
The ExecutorService used to execute face loading. The pool consists of one thread; this means all requests are serialized.


id

private int id
Counts the number of calls to reset(). An ExecutorService does not allow to cancel scheduled but still pending requests. Therefore the thread checks if this ID matches the ID value at creation time. If the IDs do not match it exits.


imageCacheMagicMap

@NotNull
private final ImageCache imageCacheMagicMap
The image cache used for loading magic map images.


imageCacheOriginal

@NotNull
private final ImageCache imageCacheOriginal
The image cache used for loading original images.


imageCacheScaled

@NotNull
private final ImageCache imageCacheScaled
The image cache used for loading scaled images.


pendingLoadFaces

@NotNull
private final java.util.Collection<Face> pendingLoadFaces
The faces for which loadFace(Face) has been called but that are not yet processed.


sync

@NotNull
private final java.lang.Object sync
The object used for synchronization.

Constructor Detail

FileCacheFaceQueue

public FileCacheFaceQueue(@NotNull
                          ImageCache imageCacheOriginal,
                          @NotNull
                          ImageCache imageCacheScaled,
                          @NotNull
                          ImageCache imageCacheMagicMap)
Creates a new instance.

Parameters:
imageCacheOriginal - the image cache used for loading original image files
imageCacheScaled - the image cache used for loading scaled image files
imageCacheMagicMap - the image cache used for loading magic map image files
Method Detail

loadFace

public void loadFace(@NotNull
                     Face face)
Request a face. Must eventually call either FaceQueueListener.faceLoaded(Face, FaceImages) or FaceQueueListener.faceFailed(Face) for the face. Faces re-requested while still processing may be notified only once.

Parameters:
face - the requested face

reset

public void reset()
Reset the processing: forget about pending faces. This function is called whenever the server socket breaks, or when a new connection has been established.


saveFace

public void saveFace(@NotNull
                     Face face,
                     @NotNull
                     FaceImages faceImages)
Saves a face to the caches. This function returns immediately; the faces are written asynchronously.

Parameters:
face - the face to write
faceImages - the image information to write