com.jalios.jcms
Class QuotaManager

java.lang.Object
  extended by com.jalios.jcms.QuotaManager
All Implemented Interfaces:
AssociatedFilesEventListener, AlarmListener, JPropertiesListener

public class QuotaManager
extends Object
implements JPropertiesListener, AssociatedFilesEventListener, AlarmListener


Nested Class Summary
static class QuotaManager.WorkspaceNode
          Inner class to save a workspace and it's level in hierarchy
static class QuotaManager.WorkspaceNodeComparator
           
 
Field Summary
static String ADMIN_QUOTA_CHECK_SCHEDULE
           
static String ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD
           
static String ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA
           
static String ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT
           
static String ADMIN_QUOTA_MAXIMUM_SITE_QUOTA
           
static String ADMIN_QUOTA_SITE_ALERT_THRESHOLD
           
protected  ExecutorService analyzerThreadPool
           
protected  Map<String,FileSize> cacheFileSize
           
static String CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE
           
static String CHANNEL_QUOTA_MANAGEMENT_ENABLED
           
protected  WorkspaceFileAnalyzer channelFileAnalyzer
           
protected  QuotaElement channelQuotaAlert
           
protected  FileAnalyzerThread currentChannelAnalyzerThread
           
static int DEFAULT_ALERT_THRESHOLD
           
static long DEFAULT_DELAY
           
static long DEFAULT_SITE_QUOTA
           
static long DEFAULT_WORKSPACE_QUOTA
           
static boolean ENABLED_DEFAULT
           
protected  long lastChannelQuotaNotificationDate
           
protected  WorkspaceFileAnalyzer previousChannelFileAnalyzer
           
static String REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME
           
 
Fields inherited from interface com.jalios.util.JPropertiesListener
REVISION
 
Fields inherited from interface com.jalios.jdring.AlarmListener
REVISION
 
Method Summary
 void addDocumentToVersionCache(FileDocument fileDoc)
           
 void addDocumentVersionToVersionCache(FileDocument oldFileDoc, FileDocument fileDoc)
           
 void associatedFileEventFired(AssociatedFileEvent event)
          Trigger a quota refresh if a new associated file is added/updated or deleted
 void checkQuotas()
          Check all quotas and send notifications if needed, this method is called after the end of an analyzeThread.
static FileSize computeFileSizes(File realFile, AssociatedFilesManager afMgr)
          Compute file size (with and without associated files)
 AssociatedFilesEventListener createAssociatedFilesEventListener()
           
 void deleteDocumentFromVersionCache(FileDocument fileDoc)
           
 FileAnalyzerThread executeFileAnalyzerThread(Workspace workspace)
           
static List<QuotaManager.WorkspaceNode> generateWorkspaceTreeList()
          Generate Workspace List ordered by tree order and with Workspace.getNameComparator by level
 ExecutorService getAnalyzerThreadPool()
          get analyzer thread pool use to compute workspace file analyze in background mode
 List<String> getCachedVersionList(FileDocument fileDoc)
           
 FileSize getCacheFileSize(File file)
          get the cache file size with computed size
 QuotaElement getChannelQuotaAlert()
           
 FileAnalyzerThread getCurrentChannelAnalyzerThread()
          Return the current analyzer thread if analyze is in progress
 int getDefaultAlertThreshold()
           
 long getDefaultQuotaSize()
           
 QuotaElement getElement(Workspace wk)
          create a QuotaElement for a Workspace.
 Map<Workspace,QuotaElement> getElements()
          returns the Map with all QuotaElement per workspace, the value with the null key is for the whole site.
 WorkspaceFileAnalyzer getGlobalFileAnalyzer(boolean refresh)
          returns WorkspaceFileAnalyzer instance associated with this site.
static QuotaManager getInstance()
           
 long getLastChannelQuotaNotificationDate()
           
 QuotaElement getSiteElement()
          create a QuotaElement for a whiole site.
 void handleAlarm(AlarmEntry entry)
          Manage periodically quota refresh
 void handleFileAnalyzeEnd(WorkspaceFileAnalyzer fileAnalyzer)
          This method is called when global file analyzer has end
 boolean isQuotaEnabled()
           
 boolean isUploadAccepted(DocUploadInfo info)
          indicates if document can be uploaded (regarding the global site quota)
 boolean isUploadAccepted(DocUploadInfo info, Workspace wk)
          indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)
 boolean isUploadAccepted(long fileLength, Workspace wk)
          indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)
 boolean isUploadEnabled()
          indicates if upload is enabled for all the site
 boolean isUploadEnabled(Workspace wk)
          indicates if upload is enabled for all the site and provided workspace if not null
 void propertiesChange(JProperties properties)
          Invoked after properties have been modified in JCMS and save on disk.
protected  void readProperties()
           
 void setChannelQuotaAlert(QuotaElement channelQuotaAlert)
           
 void setDefaultAlertThreshold(int defaultAlertThreshold)
           
 void setDefaultQuotaSize(long defaultQuotaSize)
           
 void setLastChannelQuotaNotificationDate(long lastChannelQuotaNotificationDate)
           
 void shutdownThreads()
           
 void updateAfterFileChange(File file)
          update quota after a file change
 void updateAfterFileDocumentChange(FileDocument fileDoc)
          update quota after a filedocument change
 void updateCacheFileSize(File file, FileSize fileSizeObj)
          update the cache file size with computed size
 void updateQuota(Workspace wk)
          Update workspace quota in separate threads
 void updateWorkspacesQuota()
          Update all workspaces quota in separate threads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA

public static final String ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA
See Also:
Constant Field Values

ADMIN_QUOTA_MAXIMUM_SITE_QUOTA

public static final String ADMIN_QUOTA_MAXIMUM_SITE_QUOTA
See Also:
Constant Field Values

ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD

public static final String ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD
See Also:
Constant Field Values

ADMIN_QUOTA_SITE_ALERT_THRESHOLD

public static final String ADMIN_QUOTA_SITE_ALERT_THRESHOLD
See Also:
Constant Field Values

ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT

public static final String ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT
See Also:
Constant Field Values

ADMIN_QUOTA_CHECK_SCHEDULE

public static final String ADMIN_QUOTA_CHECK_SCHEDULE
See Also:
Constant Field Values

CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE

public static final String CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE
See Also:
Constant Field Values

CHANNEL_QUOTA_MANAGEMENT_ENABLED

public static final String CHANNEL_QUOTA_MANAGEMENT_ENABLED
See Also:
Constant Field Values

REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME

public static final String REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME
See Also:
Constant Field Values

DEFAULT_ALERT_THRESHOLD

public static final int DEFAULT_ALERT_THRESHOLD
See Also:
Constant Field Values

DEFAULT_WORKSPACE_QUOTA

public static final long DEFAULT_WORKSPACE_QUOTA

DEFAULT_SITE_QUOTA

public static final long DEFAULT_SITE_QUOTA

DEFAULT_DELAY

public static final long DEFAULT_DELAY
See Also:
Constant Field Values

ENABLED_DEFAULT

public static final boolean ENABLED_DEFAULT
See Also:
Constant Field Values

channelFileAnalyzer

protected transient WorkspaceFileAnalyzer channelFileAnalyzer

previousChannelFileAnalyzer

protected transient WorkspaceFileAnalyzer previousChannelFileAnalyzer

currentChannelAnalyzerThread

protected transient FileAnalyzerThread currentChannelAnalyzerThread

analyzerThreadPool

protected transient ExecutorService analyzerThreadPool

lastChannelQuotaNotificationDate

protected transient long lastChannelQuotaNotificationDate

channelQuotaAlert

protected transient QuotaElement channelQuotaAlert

cacheFileSize

protected transient Map<String,FileSize> cacheFileSize
Method Detail

getInstance

public static QuotaManager getInstance()

propertiesChange

public void propertiesChange(JProperties properties)
Description copied from interface: JPropertiesListener
Invoked after properties have been modified in JCMS and save on disk.

You cannot alter the value received in parameters.

Specified by:
propertiesChange in interface JPropertiesListener
Parameters:
properties - the properties which have been modified (may not contain all JCMS properties)

readProperties

protected void readProperties()

getElement

public QuotaElement getElement(Workspace wk)
create a QuotaElement for a Workspace. If the workspace has a running analyze thread, this method will return null

Parameters:
wk - the Workspace
Returns:
the QuotaElement

getSiteElement

public QuotaElement getSiteElement()
create a QuotaElement for a whiole site. If the site has a running analyze thread, this method will return null

Returns:
the QuotaElement

getElements

public Map<Workspace,QuotaElement> getElements()
returns the Map with all QuotaElement per workspace, the value with the null key is for the whole site. Values can be null is a running analyze thread exists for the workspace or site.

Returns:
the Map with all QuotaElement per workspace, the value with the null key is for the whole site. Values can be null is a running analyze thread exists for the workspace or site.

isQuotaEnabled

public boolean isQuotaEnabled()

getDefaultQuotaSize

public long getDefaultQuotaSize()

setDefaultQuotaSize

public void setDefaultQuotaSize(long defaultQuotaSize)

getDefaultAlertThreshold

public int getDefaultAlertThreshold()

setDefaultAlertThreshold

public void setDefaultAlertThreshold(int defaultAlertThreshold)

createAssociatedFilesEventListener

public AssociatedFilesEventListener createAssociatedFilesEventListener()

updateWorkspacesQuota

public void updateWorkspacesQuota()
Update all workspaces quota in separate threads


updateQuota

public void updateQuota(Workspace wk)
Update workspace quota in separate threads


associatedFileEventFired

public void associatedFileEventFired(AssociatedFileEvent event)
Trigger a quota refresh if a new associated file is added/updated or deleted

Specified by:
associatedFileEventFired in interface AssociatedFilesEventListener

updateAfterFileChange

public void updateAfterFileChange(File file)
update quota after a file change

Parameters:
file - the File

updateAfterFileDocumentChange

public void updateAfterFileDocumentChange(FileDocument fileDoc)
update quota after a filedocument change

Parameters:
fileDoc - the FileDocument

handleAlarm

public void handleAlarm(AlarmEntry entry)
Manage periodically quota refresh

Specified by:
handleAlarm in interface AlarmListener
Parameters:
entry - the AlarmEntry which has been triggered.

checkQuotas

public void checkQuotas()
Check all quotas and send notifications if needed, this method is called after the end of an analyzeThread.


executeFileAnalyzerThread

public FileAnalyzerThread executeFileAnalyzerThread(Workspace workspace)

getAnalyzerThreadPool

public ExecutorService getAnalyzerThreadPool()
get analyzer thread pool use to compute workspace file analyze in background mode

Returns:
the ExecutorService

getGlobalFileAnalyzer

public WorkspaceFileAnalyzer getGlobalFileAnalyzer(boolean refresh)
returns WorkspaceFileAnalyzer instance associated with this site. Note that as file analyze is down asynchronously, this method should returns null if an analyze is in progress (or if refresh is asked). In this case, user should ask getCurrentAnalyzerThread() to retrieve the analyze thread. getCompleteness() method on the thread can be used to know the state of the thread.

Parameters:
refresh - force to ignore data previously present in cache
Returns:
WorkspaceFileAnalyzer instance associated with this site or null if an analyze is in progress (or if refresh is asked).

getCurrentChannelAnalyzerThread

public FileAnalyzerThread getCurrentChannelAnalyzerThread()
Return the current analyzer thread if analyze is in progress

Returns:
the FileAnalyzerThread or null if no analyze is running

handleFileAnalyzeEnd

public void handleFileAnalyzeEnd(WorkspaceFileAnalyzer fileAnalyzer)
This method is called when global file analyzer has end


getLastChannelQuotaNotificationDate

public long getLastChannelQuotaNotificationDate()

setLastChannelQuotaNotificationDate

public void setLastChannelQuotaNotificationDate(long lastChannelQuotaNotificationDate)

getChannelQuotaAlert

public QuotaElement getChannelQuotaAlert()

setChannelQuotaAlert

public void setChannelQuotaAlert(QuotaElement channelQuotaAlert)

shutdownThreads

public void shutdownThreads()

updateCacheFileSize

public void updateCacheFileSize(File file,
                                FileSize fileSizeObj)
update the cache file size with computed size

Parameters:
file - the File used to generate map key
fileSizeObj - the FileSize to store

getCacheFileSize

public FileSize getCacheFileSize(File file)
get the cache file size with computed size

Parameters:
file - the File used to generate map key

computeFileSizes

public static FileSize computeFileSizes(File realFile,
                                        AssociatedFilesManager afMgr)
Compute file size (with and without associated files)

Parameters:
realFile - the File
afMgr - the current AssociatedFilesManager if any
Returns:
an array of long, the first element is the size without any associated files and the second with these files

generateWorkspaceTreeList

public static List<QuotaManager.WorkspaceNode> generateWorkspaceTreeList()
Generate Workspace List ordered by tree order and with Workspace.getNameComparator by level

Returns:
the Workspace List already sorted

getCachedVersionList

public List<String> getCachedVersionList(FileDocument fileDoc)

addDocumentToVersionCache

public void addDocumentToVersionCache(FileDocument fileDoc)

addDocumentVersionToVersionCache

public void addDocumentVersionToVersionCache(FileDocument oldFileDoc,
                                             FileDocument fileDoc)

deleteDocumentFromVersionCache

public void deleteDocumentFromVersionCache(FileDocument fileDoc)

isUploadEnabled

public boolean isUploadEnabled()
indicates if upload is enabled for all the site

Returns:
true is enabled, false otherwise. a warn JcmsMessage is available in JcmsContext if it's disabled and a request exists.

isUploadEnabled

public boolean isUploadEnabled(Workspace wk)
indicates if upload is enabled for all the site and provided workspace if not null

Parameters:
wk - the Workspace to check for quota
Returns:
true is enabled, false otherwise. a warn JcmsMessage is available in JcmsContext if it's disabled and a request exists.

isUploadAccepted

public boolean isUploadAccepted(DocUploadInfo info)
indicates if document can be uploaded (regarding the global site quota)

Parameters:
info - the DocUploadInfo used to compute new size
Returns:
true is accepted, false otherwise. a warn JcmsMessage is available in JcmsContext if it's disabled.

isUploadAccepted

public boolean isUploadAccepted(DocUploadInfo info,
                                Workspace wk)
indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)

Parameters:
info - the DocUploadInfo used to compute new size
wk - the Workspace to check for quota
Returns:
true is accepted, false otherwise. a warn JcmsMessage is available in JcmsContext if it's disabled.

isUploadAccepted

public boolean isUploadAccepted(long fileLength,
                                Workspace wk)
indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)

Parameters:
fileLength - the length of the file used to compute new size
wk - the Workspace to check for quota
Returns:
true is accepted, false otherwise. a warn JcmsMessage is available in JcmsContext if it's disabled.


Copyright © 2001-2010 Jalios SA. All Rights Reserved.