01: /**
02: * $Id: SessionTempDirCounter.java,v 1.6 2005/11/30 11:26:35 ss150821 Exp $
03: * Copyright 2002 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.netfile.servlet.java1;
14:
15: /**
16: *
17: * @author Suresh Yellamaraju
18: */
19:
20: import java.io.File;
21: import com.sun.portal.log.common.PortalLogger;
22:
23: public class SessionTempDirCounter {
24:
25: int i = 0;
26:
27: public synchronized void decrement(String token) {
28: if (i == -1) {
29: if (cleanup(token))
30: NetFileServlet.mapIDInUseCount.remove(token);
31: return;
32: }
33: --i;
34: }
35:
36: public synchronized boolean increment(String token) {
37: if (i == -1) {
38: if (cleanup(token))
39: NetFileServlet.mapIDInUseCount.remove(token);
40: return false;
41: }
42: ++i;
43: return true;
44: }
45:
46: public synchronized void invalidate() {
47: i = -1;
48: }
49:
50: boolean cleanup(String ssoToken) {
51: try {
52: String s_sso_token = ssoToken;
53: Object o_temp_directory = NetFileServlet.hm_session_to_temp_dir_mapping
54: .get(s_sso_token);
55: if (o_temp_directory != null) {
56: String s_temp_directory = (String) o_temp_directory;
57: File f_temp_directory = new File(s_temp_directory);
58: if (f_temp_directory.exists()) {
59: File[] filesList = f_temp_directory.listFiles();
60: for (int i = 0; i < filesList.length; i++) {
61: //tempFile = new File(filesList[i]);
62: File tempFile = filesList[i];
63: if (tempFile.exists())
64: if (!tempFile.delete()) {
65: continue;
66: }
67: tempFile = null;
68: }
69: if (!f_temp_directory.delete()) {
70: return false;
71: } else
72: NetFileServlet.hm_session_to_temp_dir_mapping
73: .remove(s_sso_token);
74: }
75: }
76: } catch (Exception e) {
77: return false;
78: }
79: return true;
80: }
81:
82: }
|