interface that utilizes
a file per saved Session in a configured directory. Sessions that are
saved are still subject to being expired based on inactivity.
| Method from org.apache.catalina.session.FileStore Detail: |
public void clear() throws IOException {
String[] keys = keys();
for (int i = 0; i < keys.length; i++) {
remove(keys[i]);
}
}
Remove all of the Sessions in this Store. |
public String getDirectory() {
// ------------------------------------------------------------- Properties
return (directory);
}
Return the directory path for this Store. |
public String getInfo() {
return (info);
}
Return descriptive information about this Store implementation and
the corresponding version number, in the format
<description>/<version>. |
public int getSize() throws IOException {
// Acquire the list of files in our storage directory
File file = directory();
if (file == null) {
return (0);
}
String files[] = file.list();
// Figure out which files are sessions
int keycount = 0;
for (int i = 0; i < files.length; i++) {
if (files[i].endsWith(FILE_EXT)) {
keycount++;
}
}
return (keycount);
}
Return the number of Sessions present in this Store. |
public String getStoreName() {
return(storeName);
}
Return the name for this Store, used for logging. |
public String getThreadName() {
return(threadName);
}
Return the thread name for this Store. |
public String[] keys() throws IOException {
// Acquire the list of files in our storage directory
File file = directory();
if (file == null) {
return (new String[0]);
}
String files[] = file.list();
// Bugzilla 32130
if((files == null) || (files.length < 1)) {
return (new String[0]);
}
// Build and return the list of session identifiers
ArrayList list = new ArrayList();
int n = FILE_EXT.length();
for (int i = 0; i < files.length; i++) {
if (files[i].endsWith(FILE_EXT)) {
list.add(files[i].substring(0, files[i].length() - n));
}
}
return ((String[]) list.toArray(new String[list.size()]));
}
Return an array containing the session identifiers of all Sessions
currently saved in this Store. If there are no such Sessions, a
zero-length array is returned. |
public Session load(String id) throws IOException, ClassNotFoundException {
// Open an input stream to the specified pathname, if any
File file = file(id);
if (file == null) {
return (null);
}
if (! file.exists()) {
return (null);
}
if (manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(sm.getString(getStoreName()+".loading",
id, file.getAbsolutePath()));
}
FileInputStream fis = null;
ObjectInputStream ois = null;
Loader loader = null;
ClassLoader classLoader = null;
try {
fis = new FileInputStream(file.getAbsolutePath());
BufferedInputStream bis = new BufferedInputStream(fis);
Container container = manager.getContainer();
if (container != null)
loader = container.getLoader();
if (loader != null)
classLoader = loader.getClassLoader();
if (classLoader != null)
ois = new CustomObjectInputStream(bis, classLoader);
else
ois = new ObjectInputStream(bis);
} catch (FileNotFoundException e) {
if (manager.getContainer().getLogger().isDebugEnabled())
manager.getContainer().getLogger().debug("No persisted data file found");
return (null);
} catch (IOException e) {
if (ois != null) {
try {
ois.close();
} catch (IOException f) {
;
}
ois = null;
}
throw e;
}
try {
StandardSession session =
(StandardSession) manager.createEmptySession();
session.readObjectData(ois);
session.setManager(manager);
return (session);
} finally {
// Close the input stream
if (ois != null) {
try {
ois.close();
} catch (IOException f) {
;
}
}
}
}
Load and return the Session associated with the specified session
identifier from this Store, without removing it. If there is no
such stored Session, return null. |
public void remove(String id) throws IOException {
File file = file(id);
if (file == null) {
return;
}
if (manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(sm.getString(getStoreName()+".removing",
id, file.getAbsolutePath()));
}
file.delete();
}
Remove the Session with the specified session identifier from
this Store, if present. If no such Session is present, this method
takes no action. |
public void save(Session session) throws IOException {
// Open an output stream to the specified pathname, if any
File file = file(session.getIdInternal());
if (file == null) {
return;
}
if (manager.getContainer().getLogger().isDebugEnabled()) {
manager.getContainer().getLogger().debug(sm.getString(getStoreName()+".saving",
session.getIdInternal(), file.getAbsolutePath()));
}
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(file.getAbsolutePath());
oos = new ObjectOutputStream(new BufferedOutputStream(fos));
} catch (IOException e) {
if (oos != null) {
try {
oos.close();
} catch (IOException f) {
;
}
}
throw e;
}
try {
((StandardSession)session).writeObjectData(oos);
} finally {
oos.close();
}
}
Save the specified Session into this Store. Any previously saved
information for the associated session identifier is replaced. |
public void setDirectory(String path) {
String oldDirectory = this.directory;
this.directory = path;
this.directoryFile = null;
support.firePropertyChange("directory", oldDirectory,
this.directory);
}
Set the directory path for this Store. |