Package com.jalios.jcms.quota
Class QuotaManager
- java.lang.Object
-
- com.jalios.jcms.quota.QuotaManager
-
- All Implemented Interfaces:
AssociatedFilesEventListener,AlarmListener,JPropertiesListener
public class QuotaManager extends java.lang.Object implements JPropertiesListener, AssociatedFilesEventListener, AlarmListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQuotaManager.WorkspaceNodeInner class to save a workspace and it's level in hierarchystatic classQuotaManager.WorkspaceNodeComparator
-
Field Summary
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDocumentToVersionCache(FileDocument fileDoc)Add the current filename of the specified FileDocument to the cache.voidaddDocumentVersionToVersionCache(FileDocument oldFileDoc, FileDocument fileDoc)Add the current filename of the new FileDocument version to the cache.voidassociatedFileEventFired(AssociatedFileEvent event)Trigger a quota refresh if a new associated file is added/updated or deletedvoidcheckQuotas()Check all quotas and send notifications if needed.voidcheckQuotas(Workspace workspace)Check workspace quota and send notifications if needed, this method is called after the end of an analyzeThread.static FileSizecomputeFileSizes(java.io.File realFile, AssociatedFilesManager afMgr)Compute file size (with and without associated files)AssociatedFilesEventListenercreateAssociatedFilesEventListener()voiddeleteDocumentFromVersionCache(FileDocument fileDoc)Remove filename of the specified FileDocument from the cache.FileAnalyzerThreadexecuteFileAnalyzerThread(Workspace workspace)static java.util.List<QuotaManager.WorkspaceNode>generateWorkspaceTreeList()java.util.concurrent.ExecutorServicegetAnalyzerThreadPool()get analyzer thread pool use to count real file size in background modejava.util.List<java.lang.String>getCachedVersionList(FileDocument fileDoc)Retrieve all filename previously cached for the specified FileDocument.FileSizegetCacheFileSize(java.io.File file)get the cache file size with computed sizeQuotaElementgetChannelQuotaAlert()FileAnalyzerThreadgetCurrentChannelAnalyzerThread()Return the current analyzer thread if analyze is in progressintgetDefaultAlertThreshold()longgetDefaultQuotaSize()QuotaElementgetElement(Workspace wk)create aQuotaElementfor aWorkspace.java.util.Map<Workspace,QuotaElement>getElements()returns theMapwith allQuotaElementper workspace, the value with the null key is for the whole site.java.util.Map<Workspace,QuotaElement>getElements(Workspace workspace)returns theMapwith allQuotaElementper workspace, the value with the null key is for the whole site.static FileQuotaInfosgetFileQuotaInfos(FileDocument fileDoc)FileQuotaInfosgetFileQuotaInfos(java.io.File file)WorkspaceFileSizeResultgetGlobalFileAnalyzer(boolean refresh)returnsWorkspaceFileSizeResultinstance associated with this site.static QuotaManagergetInstance()longgetLastChannelQuotaNotificationDate()QuotaElementgetSiteElement()create aQuotaElementfor a whiole site.voidhandleAlarm(AlarmEntry entry)Manage periodically quota refreshvoidhandleFileAnalyzeEnd(WorkspaceFileSizeResult fileAnalyzer)This method is called when global file analyzer has endbooleanisQuotaEnabled()booleanisQuotaFeatureEnabled()booleanisUploadAccepted(long fileLength, Workspace wk)indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)booleanisUploadAccepted(DocUploadInfo info)indicates if document can be uploaded (regarding the global site quota)booleanisUploadAccepted(DocUploadInfo info, Workspace wk)indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)ControllerStatusisUploadEnabled()indicates if upload is enabled for all the siteControllerStatusisUploadEnabled(Workspace wk)indicates if upload is enabled for all the site and provided workspace if not nullvoidpropertiesChange(JProperties properties)Invoked after properties have been modified in JCMS and save on disk.protected voidreadProperties()voidsetChannelQuotaAlert(QuotaElement channelQuotaAlert)voidsetDefaultAlertThreshold(int defaultAlertThreshold)voidsetDefaultQuotaSize(long defaultQuotaSize)voidsetLastChannelQuotaNotificationDate(long lastChannelQuotaNotificationDate)voidshutdownThreads()voidupdateAfterFileChange(java.io.File file)update quota after a file changevoidupdateAfterFileDocumentChange(FileDocument fileDoc)update quota after a filedocument changevoidupdateAfterFileDocumentChange(FileQuotaInfos fileQuotaInfos)update quota after a filedocument changevoidupdateAfterFileDocumentDelete(FileDocument fileDoc)update quota after a filedocument changevoidupdateAfterFileDocumentDelete(FileQuotaInfos fileQuotaInfos)update quota after a filedocument deletevoidupdateCacheFileSize(java.io.File file, FileSize fileSizeObj)update the cache file size with computed sizevoidupdateQuota(Workspace wk)Update workspace quota in separate threadsvoidupdateWorkspacesQuota()Update all workspaces quota in separate threads
-
-
-
Field Detail
-
ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA
public static final java.lang.String ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA
- See Also:
- Constant Field Values
-
ADMIN_QUOTA_MAXIMUM_SITE_QUOTA
public static final java.lang.String ADMIN_QUOTA_MAXIMUM_SITE_QUOTA
- See Also:
- Constant Field Values
-
ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD
public static final java.lang.String ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD
- See Also:
- Constant Field Values
-
ADMIN_QUOTA_SITE_ALERT_THRESHOLD
public static final java.lang.String ADMIN_QUOTA_SITE_ALERT_THRESHOLD
- See Also:
- Constant Field Values
-
ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT
public static final java.lang.String ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT
- See Also:
- Constant Field Values
-
ADMIN_QUOTA_CHECK_SCHEDULE
public static final java.lang.String ADMIN_QUOTA_CHECK_SCHEDULE
- See Also:
- Constant Field Values
-
CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE
public static final java.lang.String CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE
- See Also:
- Constant Field Values
-
CHANNEL_WS_UPDATER_THREAD_POOL_SIZE
public static final java.lang.String CHANNEL_WS_UPDATER_THREAD_POOL_SIZE
- See Also:
- Constant Field Values
-
CHANNEL_QUOTA_MANAGEMENT_ENABLED
public static final java.lang.String CHANNEL_QUOTA_MANAGEMENT_ENABLED
- See Also:
- Constant Field Values
-
REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME
public static final java.lang.String REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME
- See Also:
- Constant Field Values
-
CHANNEL_QUOTA_FEATURE
public static final java.lang.String CHANNEL_QUOTA_FEATURE
- 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
-
channelFileAnalyzer
protected transient WorkspaceFileSizeResult channelFileAnalyzer
-
previousChannelFileAnalyzer
protected transient WorkspaceFileSizeResult previousChannelFileAnalyzer
-
currentChannelAnalyzerThread
protected transient FileAnalyzerThread currentChannelAnalyzerThread
-
analyzerThreadPool
protected transient java.util.concurrent.ExecutorService analyzerThreadPool
-
wsUpdaterThreadPool
protected transient java.util.concurrent.ExecutorService wsUpdaterThreadPool
-
lastChannelQuotaNotificationDate
protected transient long lastChannelQuotaNotificationDate
-
channelQuotaAlert
protected transient QuotaElement channelQuotaAlert
-
cacheFileSize
protected transient java.util.Map<java.lang.String,FileSize> cacheFileSize
-
uploadErrorMessageTL
protected java.lang.ThreadLocal<JcmsMessage> uploadErrorMessageTL
-
-
Method Detail
-
getInstance
public static QuotaManager getInstance()
-
propertiesChange
public void propertiesChange(JProperties properties)
Description copied from interface:JPropertiesListenerInvoked after properties have been modified in JCMS and save on disk.You cannot alter the value received in parameters.
Note that properties parameter may be null, a limited set of site properties, or all site properties.
To check that a property has been modified, reload the "current" property instead using
channel.getPropertiesorchannel.getProperty.- Specified by:
propertiesChangein interfaceJPropertiesListener- Parameters:
properties- the properties which have been submitted to change
-
readProperties
protected void readProperties()
-
isQuotaFeatureEnabled
public boolean isQuotaFeatureEnabled()
-
getElement
public QuotaElement getElement(Workspace wk)
create aQuotaElementfor aWorkspace. If the workspace has a running analyze thread, this method will return null- Parameters:
wk- theWorkspace- Returns:
- the
QuotaElement
-
getSiteElement
public QuotaElement getSiteElement()
create aQuotaElementfor a whiole site. If the site has a running analyze thread, this method will return null- Returns:
- the
QuotaElement
-
getElements
public java.util.Map<Workspace,QuotaElement> getElements()
returns theMapwith allQuotaElementper 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
Mapwith allQuotaElementper 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.
-
getElements
public java.util.Map<Workspace,QuotaElement> getElements(Workspace workspace)
returns theMapwith allQuotaElementper 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.- Parameters:
workspace- the workspace used to filter elements (if null, global element are returned)- Returns:
- the
Mapwith allQuotaElementper 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- Parameters:
wk- the workspace
-
associatedFileEventFired
public void associatedFileEventFired(AssociatedFileEvent event)
Trigger a quota refresh if a new associated file is added/updated or deleted- Specified by:
associatedFileEventFiredin interfaceAssociatedFilesEventListener
-
updateAfterFileChange
public void updateAfterFileChange(java.io.File file)
update quota after a file change- Parameters:
file- theFile
-
getFileQuotaInfos
public static FileQuotaInfos getFileQuotaInfos(FileDocument fileDoc)
-
getFileQuotaInfos
public FileQuotaInfos getFileQuotaInfos(java.io.File file)
-
updateAfterFileDocumentChange
public void updateAfterFileDocumentChange(FileDocument fileDoc)
update quota after a filedocument change- Parameters:
fileDoc- theFileDocument
-
updateAfterFileDocumentChange
public void updateAfterFileDocumentChange(FileQuotaInfos fileQuotaInfos)
update quota after a filedocument change- Parameters:
fileQuotaInfos- theFileQuotaInfos
-
updateAfterFileDocumentDelete
public void updateAfterFileDocumentDelete(FileDocument fileDoc)
update quota after a filedocument change- Parameters:
fileDoc- theFileDocument
-
updateAfterFileDocumentDelete
public void updateAfterFileDocumentDelete(FileQuotaInfos fileQuotaInfos)
update quota after a filedocument delete- Parameters:
fileQuotaInfos- theFileQuotaInfos
-
handleAlarm
public void handleAlarm(AlarmEntry entry)
Manage periodically quota refresh- Specified by:
handleAlarmin interfaceAlarmListener- Parameters:
entry- the AlarmEntry which has been triggered.
-
checkQuotas
public void checkQuotas()
Check all quotas and send notifications if needed.
-
checkQuotas
public void checkQuotas(Workspace workspace)
Check workspace quota and send notifications if needed, this method is called after the end of an analyzeThread.- Parameters:
workspace- the workspace to check, or null for the global sire
-
executeFileAnalyzerThread
public FileAnalyzerThread executeFileAnalyzerThread(Workspace workspace)
-
getAnalyzerThreadPool
public java.util.concurrent.ExecutorService getAnalyzerThreadPool()
get analyzer thread pool use to count real file size in background mode- Returns:
- the
ExecutorService
-
getGlobalFileAnalyzer
public WorkspaceFileSizeResult getGlobalFileAnalyzer(boolean refresh)
returnsWorkspaceFileSizeResultinstance 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:
WorkspaceFileSizeResultinstance 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
FileAnalyzerThreador null if no analyze is running
-
handleFileAnalyzeEnd
public void handleFileAnalyzeEnd(WorkspaceFileSizeResult fileAnalyzer)
This method is called when global file analyzer has end- Parameters:
fileAnalyzer- a WorkspaceFileAnalyzer
-
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(java.io.File file, FileSize fileSizeObj)update the cache file size with computed size- Parameters:
file- theFileused to generate map keyfileSizeObj- theFileSizeto store
-
getCacheFileSize
public FileSize getCacheFileSize(java.io.File file)
get the cache file size with computed size- Parameters:
file- theFileused to generate map key- Returns:
- the size stored for this file or 0L if the file cannot be found.
-
computeFileSizes
public static FileSize computeFileSizes(java.io.File realFile, AssociatedFilesManager afMgr)
Compute file size (with and without associated files)- Parameters:
realFile- theFileafMgr- the currentAssociatedFilesManagerif 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 java.util.List<QuotaManager.WorkspaceNode> generateWorkspaceTreeList()
- Returns:
- the
WorkspaceListalready sorted
-
getCachedVersionList
public java.util.List<java.lang.String> getCachedVersionList(FileDocument fileDoc)
Retrieve all filename previously cached for the specified FileDocument.- Parameters:
fileDoc- the FileDocument for which filename cache must be retrieved- Returns:
- a List of filename, may return null if no filename was ever cached for the specified FileDocument
- See Also:
addDocumentToVersionCache(FileDocument),addDocumentVersionToVersionCache(FileDocument, FileDocument),deleteDocumentFromVersionCache(FileDocument)
-
addDocumentToVersionCache
public void addDocumentToVersionCache(FileDocument fileDoc)
Add the current filename of the specified FileDocument to the cache.- Parameters:
fileDoc- the FileDocument whose filename must be cached
-
addDocumentVersionToVersionCache
public void addDocumentVersionToVersionCache(FileDocument oldFileDoc, FileDocument fileDoc)
Add the current filename of the new FileDocument version to the cache.- Parameters:
oldFileDoc- Previous document (ignored in current implementation)fileDoc- the new FileDocument whose filename must be cached
-
deleteDocumentFromVersionCache
public void deleteDocumentFromVersionCache(FileDocument fileDoc)
Remove filename of the specified FileDocument from the cache.- Parameters:
fileDoc- FileDocument whose filename must be removed
-
isUploadEnabled
public ControllerStatus isUploadEnabled()
indicates if upload is enabled for all the site- Returns:
- ControllerStatus.OK if it is enabled, false otherwise. a warn
JcmsMessageis available in status message.
-
isUploadEnabled
public ControllerStatus isUploadEnabled(Workspace wk)
indicates if upload is enabled for all the site and provided workspace if not null- Parameters:
wk- theWorkspaceto check for quota- Returns:
- ControllerStatus.OK if it is enabled, false otherwise. a warn
JcmsMessageis available in status message.
-
isUploadAccepted
public boolean isUploadAccepted(DocUploadInfo info)
indicates if document can be uploaded (regarding the global site quota)- Parameters:
info- theDocUploadInfoused to compute new size- Returns:
- true is accepted, false otherwise. a warn
JcmsMessageis available inJcmsContextif 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- theDocUploadInfoused to compute new sizewk- theWorkspaceto check for quota- Returns:
- true is accepted, false otherwise. a warn
JcmsMessageis available inJcmsContextif 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 sizewk- theWorkspaceto check for quota- Returns:
- true is accepted, false otherwise. a warn
JcmsMessageis available inJcmsContextif it's disabled.
-
-