Class FilePool

java.lang.Object
net.simplace.sim.io.FilePool

public class FilePool extends Object
Pool of the files of a file interface. The file name may contain ${...} tokens, so each simulation or project may use another file; registerFile(FWSimVarMap) returns the FileData for the current values. For reading, up to pool size files are kept open (and their data cached); for writing, only the current file is open. Files already opened by another session are shared via the FilePoolManager. Instead of a file name the data can be given as content.

The pool has to be finalized at the end to close the files.

Author:
Andreas Enders
  • Constructor Details

    • FilePool

      public FilePool(String aFileName, String aContent, FWSimSession aCurrentSession, String aDivider, int aPoolSize, FWSimVariable.CONTENT_TYPE aContent_Type)
      Creates the pool.
      Parameters:
      aFileName - file name, may contain tokens; null if the content is given
      aContent - data as string instead of a file, may be null
      aCurrentSession - the session
      aDivider - column divider for CSV files, may be null
      aPoolSize - maximum number of open files for reading
      aContent_Type - res for reading, out for writing
  • Method Details

    • registerFile

      public FileData registerFile(FWSimVarMap aVarMap)
      Returns the file for the current token values. An already open file is reused; otherwise, for reading, the oldest file is dropped when the pool is full, and for writing the current file is closed. The data of an equal file registered by another session is shared. For content, a new file object with the tokens replaced is created.
      Parameters:
      aVarMap - variable map for replacing the tokens, may be null (tokens are not replaced, the pool's session is used)
      Returns:
      the file, or null if neither file name nor content is given
    • getContentType

      public FWSimVariable.CONTENT_TYPE getContentType()
      Returns:
      res for reading, out for writing
    • finalize

      public void finalize()
      Closes all open files (for output files an info message is logged).
      Overrides:
      finalize in class Object
    • toString

      public String toString()
      Returns the file name (with tokens).
      Overrides:
      toString in class Object
      See Also:
    • getRegisteredFiles

      public List<String> getRegisteredFiles()
      Returns:
      for an output pool all files registered since the pool was created (absolute paths, in the order of registration; a file may not exist if nothing was written to it), otherwise an empty list
    • isInitialized

      public boolean isInitialized()
      Returns:
      true if at least one file has been registered