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 Object
implements JPropertiesListener, AssociatedFilesEventListener, AlarmListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class to save a workspace and it's level in hierarchystatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected ExecutorServicestatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected WorkspaceFileSizeResultprotected QuotaElementprotected FileAnalyzerThreadstatic final intstatic final longstatic final longstatic final longprotected longprotected WorkspaceFileSizeResultstatic final Stringprotected ThreadLocal<JcmsMessage> protected ExecutorService -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDocumentToVersionCache(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.voidTrigger a quota refresh if a new associated file is added/updated or deletedvoidCheck 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(File realFile, AssociatedFilesManager afMgr) Compute file size (with and without associated files)voidRemove filename of the specified FileDocument from the cache.executeFileAnalyzerThread(Workspace workspace) static List<QuotaManager.WorkspaceNode> get analyzer thread pool use to count real file size in background modegetCachedVersionList(FileDocument fileDoc) Retrieve all filename previously cached for the specified FileDocument.getCacheFileSize(File file) get the cache file size with computed sizeReturn the current analyzer thread if analyze is in progressintlonggetElement(Workspace wk) create aQuotaElementfor aWorkspace.returns theMapwith allQuotaElementper workspace, the value with the null key is for the whole site.getElements(Workspace workspace) returns theMapwith allQuotaElementper workspace, the value with the null key is for the whole site.static FileQuotaInfosgetFileQuotaInfos(FileDocument fileDoc) getFileQuotaInfos(File file) getGlobalFileAnalyzer(boolean refresh) returnsWorkspaceFileSizeResultinstance associated with this site.static QuotaManagerlongcreate aQuotaElementfor a whiole site.voidhandleAlarm(AlarmEntry entry) Manage periodically quota refreshvoidhandleFileAnalyzeEnd(WorkspaceFileSizeResult fileAnalyzer) This method is called when global file analyzer has endbooleanbooleanbooleanisUploadAccepted(long fileLength, Workspace wk) indicates if document can be uploaded (regarding the global site quota and provided workspace if not null)booleanindicates 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)indicates if upload is enabled for all the siteindicates 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 voidvoidsetChannelQuotaAlert(QuotaElement channelQuotaAlert) voidsetDefaultAlertThreshold(int defaultAlertThreshold) voidsetDefaultQuotaSize(long defaultQuotaSize) voidsetLastChannelQuotaNotificationDate(long lastChannelQuotaNotificationDate) voidvoidupdateAfterFileChange(File file) update quota after a file changevoidupdate quota after a filedocument changevoidupdateAfterFileDocumentChange(FileQuotaInfos fileQuotaInfos) update quota after a filedocument changevoidupdate quota after a filedocument changevoidupdateAfterFileDocumentDelete(FileQuotaInfos fileQuotaInfos) update quota after a filedocument deletevoidupdateCacheFileSize(File file, FileSize fileSizeObj) update the cache file size with computed sizevoidupdateQuota(Workspace wk) Update workspace quota in separate threadsvoidUpdate all workspaces quota in separate threads
-
Field Details
-
ADMIN_QUOTA_DEFAULT_WORKSPACE_QUOTA
- See Also:
-
ADMIN_QUOTA_MAXIMUM_SITE_QUOTA
- See Also:
-
ADMIN_QUOTA_DEFAULT_WORKSPACE_ALERT_THRESHOLD
- See Also:
-
ADMIN_QUOTA_SITE_ALERT_THRESHOLD
- See Also:
-
ADMIN_QUOTA_DELAY_BETWEEN_QUOTA_ALERT
- See Also:
-
ADMIN_QUOTA_CHECK_SCHEDULE
- See Also:
-
CHANNEL_FILE_ANALYZER_THREAD_POOL_SIZE
- See Also:
-
CHANNEL_WS_UPDATER_THREAD_POOL_SIZE
- See Also:
-
CHANNEL_QUOTA_MANAGEMENT_ENABLED
- See Also:
-
REJECT_UPLOAD_OVER_QUOTA_PROPERTIES_NAME
- See Also:
-
CHANNEL_QUOTA_FEATURE
- See Also:
-
DEFAULT_ALERT_THRESHOLD
public static final int DEFAULT_ALERT_THRESHOLD- See Also:
-
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:
-
channelFileAnalyzer
-
previousChannelFileAnalyzer
-
currentChannelAnalyzerThread
-
analyzerThreadPool
-
wsUpdaterThreadPool
-
lastChannelQuotaNotificationDate
protected transient long lastChannelQuotaNotificationDate -
channelQuotaAlert
-
cacheFileSize
-
uploadErrorMessageTL
-
-
Method Details
-
getInstance
-
propertiesChange
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
create aQuotaElementfor aWorkspace. If the workspace has a running analyze thread, this method will return null- Parameters:
wk- theWorkspace- Returns:
- the
QuotaElement
-
getSiteElement
create aQuotaElementfor a whiole site. If the site has a running analyze thread, this method will return null- Returns:
- the
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
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
-
updateWorkspacesQuota
public void updateWorkspacesQuota()Update all workspaces quota in separate threads -
updateQuota
Update workspace quota in separate threads- Parameters:
wk- the workspace
-
associatedFileEventFired
Trigger a quota refresh if a new associated file is added/updated or deleted- Specified by:
associatedFileEventFiredin interfaceAssociatedFilesEventListener
-
updateAfterFileChange
update quota after a file change- Parameters:
file- theFile
-
getFileQuotaInfos
-
getFileQuotaInfos
-
updateAfterFileDocumentChange
update quota after a filedocument change- Parameters:
fileDoc- theFileDocument
-
updateAfterFileDocumentChange
update quota after a filedocument change- Parameters:
fileQuotaInfos- theFileQuotaInfos
-
updateAfterFileDocumentDelete
update quota after a filedocument change- Parameters:
fileDoc- theFileDocument
-
updateAfterFileDocumentDelete
update quota after a filedocument delete- Parameters:
fileQuotaInfos- theFileQuotaInfos
-
handleAlarm
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
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
-
getAnalyzerThreadPool
get analyzer thread pool use to count real file size in background mode- Returns:
- the
ExecutorService
-
getGlobalFileAnalyzer
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
Return the current analyzer thread if analyze is in progress- Returns:
- the
FileAnalyzerThreador null if no analyze is running
-
handleFileAnalyzeEnd
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
-
setChannelQuotaAlert
-
shutdownThreads
public void shutdownThreads() -
updateCacheFileSize
update the cache file size with computed size -
getCacheFileSize
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
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
-
getCachedVersionList
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
Add the current filename of the specified FileDocument to the cache.- Parameters:
fileDoc- the FileDocument whose filename must be cached
-
addDocumentVersionToVersionCache
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
Remove filename of the specified FileDocument from the cache.- Parameters:
fileDoc- FileDocument whose filename must be removed
-
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
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
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
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
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.
-