Example usage for org.apache.commons.collections.buffer SynchronizedBuffer decorate

List of usage examples for org.apache.commons.collections.buffer SynchronizedBuffer decorate

Introduction

In this page you can find the example usage for org.apache.commons.collections.buffer SynchronizedBuffer decorate.

Prototype

public static Buffer decorate(Buffer buffer) 

Source Link

Document

Factory method to create a synchronized buffer.

Usage

From source file:gsn.wrappers.SystemTime.java

public boolean initialize() {
    AddressBean addressBean = getActiveAddressBean();
    //  TODO: negative values?
    timer = new Timer(addressBean.getPredicateValueAsInt(CLOCK_PERIOD_KEY, DEFAULT_CLOCK_PERIODS), this);
    maximumDelay = addressBean.getPredicateValueAsInt(MAX_DELAY_KEY, DEFAULT_MAX_DELAY);
    if (maximumDelay > 0) {
        streamElementBuffer = SynchronizedBuffer.decorate(new UnboundedFifoBuffer());
        delayPostingElements = true;//from  w ww  . ja va2  s .c om
        if (timer.getDelay() < maximumDelay)
            logger.warn(
                    "Maximum delay is greater than element production interval. Running for a long time may lead to an OutOfMemoryException");
    }
    return true;
}

From source file:org.opencms.monitor.CmsMemoryMonitor.java

/**
 * Initializes the monitor with the provided configuration.<p>
 * /*from   w w w  . j  a va2  s.c o m*/
 * @param configuration the configuration to use
 */
public void initialize(CmsSystemConfiguration configuration) {

    CmsCacheSettings cacheSettings = configuration.getCacheSettings();

    m_memoryAverage = new CmsMemoryStatus();
    m_memoryCurrent = new CmsMemoryStatus();

    m_warningSendSinceLastStatus = false;
    m_warningLoggedSinceLastStatus = false;
    m_lastEmailWarning = 0;
    m_lastEmailStatus = 0;
    m_lastLogStatus = 0;
    m_lastLogWarning = 0;
    m_lastClearCache = 0;
    m_configuration = configuration.getCmsMemoryMonitorConfiguration();

    m_intervalWarning = 720 * 60000;
    m_maxUsagePercent = 90;

    m_intervalEmail = m_configuration.getEmailInterval() * 1000;
    m_intervalLog = m_configuration.getLogInterval() * 1000;

    if (m_configuration.getWarningInterval() > 0) {
        m_intervalWarning = m_configuration.getWarningInterval();
    }
    m_intervalWarning *= 1000;

    if (m_configuration.getMaxUsagePercent() > 0) {
        m_maxUsagePercent = m_configuration.getMaxUsagePercent();
    }

    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_INTERVAL_LOG_1,
                new Integer(m_intervalLog / 1000)));
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_INTERVAL_EMAIL_1,
                new Integer(m_intervalEmail / 1000)));
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_INTERVAL_WARNING_1,
                new Integer(m_intervalWarning / 1000)));
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_INTERVAL_MAX_USAGE_1,
                new Integer(m_maxUsagePercent)));

        if ((m_configuration.getEmailReceiver() == null) || (m_configuration.getEmailSender() == null)) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_EMAIL_DISABLED_0));
        } else {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_EMAIL_SENDER_1,
                    m_configuration.getEmailSender()));
            Iterator<String> i = m_configuration.getEmailReceiver().iterator();
            int n = 0;
            while (i.hasNext()) {
                CmsLog.INIT.info(Messages.get().getBundle().key(Messages.LOG_MM_EMAIL_RECEIVER_2,
                        new Integer(n + 1), i.next()));
                n++;
            }
        }
    }

    // create and register all system caches

    // temporary xml entities cache
    Map<String, byte[]> xmlTemporaryCache = CmsCollectionsGenericWrapper.createLRUMap(128);
    m_cacheXmlTemporaryEntity = Collections.synchronizedMap(xmlTemporaryCache);
    register(CmsXmlEntityResolver.class.getName() + ".xmlEntityTemporaryCache", m_cacheXmlTemporaryEntity);

    // permanent xml entities cache
    Map<String, byte[]> xmlPermanentCache = new HashMap<String, byte[]>(32);
    m_cacheXmlPermanentEntity = Collections.synchronizedMap(xmlPermanentCache);
    register(CmsXmlEntityResolver.class.getName() + ".xmlEntityPermanentCache", m_cacheXmlPermanentEntity);

    // xml content definitions cache
    Map<String, CmsXmlContentDefinition> contentDefinitionsCache = CmsCollectionsGenericWrapper
            .createLRUMap(64);
    m_cacheContentDefinitions = Collections.synchronizedMap(contentDefinitionsCache);
    register(CmsXmlEntityResolver.class.getName() + ".contentDefinitionsCache", m_cacheContentDefinitions);

    // lock cache
    Map<String, CmsLock> lockCache = new HashMap<String, CmsLock>();
    m_cacheLock = Collections.synchronizedMap(lockCache);
    register(CmsLockManager.class.getName(), lockCache);

    // locale cache
    Map<String, Locale> map = new HashMap<String, Locale>();
    m_cacheLocale = Collections.synchronizedMap(map);
    register(CmsLocaleManager.class.getName(), map);

    // permissions cache
    Map<String, I_CmsPermissionHandler.CmsPermissionCheckResult> lruPermissions = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getPermissionCacheSize());
    m_cachePermission = Collections.synchronizedMap(lruPermissions);
    register(CmsSecurityManager.class.getName(), lruPermissions);

    // user cache
    Map<String, CmsUser> lruUsers = CmsCollectionsGenericWrapper.createLRUMap(cacheSettings.getUserCacheSize());
    m_cacheUser = Collections.synchronizedMap(lruUsers);
    register(CmsDriverManager.class.getName() + ".userCache", lruUsers);

    // user list cache
    Map<String, List<CmsUser>> lruUserList = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getUserCacheSize());
    m_cacheUserList = Collections.synchronizedMap(lruUserList);
    register(CmsDriverManager.class.getName() + ".userListCache", lruUserList);

    // group cache
    Map<String, CmsGroup> lruGroup = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getGroupCacheSize());
    m_cacheGroup = Collections.synchronizedMap(lruGroup);
    register(CmsDriverManager.class.getName() + ".groupCache", lruGroup);

    // organizational unit cache
    Map<String, CmsOrganizationalUnit> lruOrgUnit = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getOrgUnitCacheSize());
    m_cacheOrgUnit = Collections.synchronizedMap(lruOrgUnit);
    register(CmsDriverManager.class.getName() + ".orgUnitCache", lruOrgUnit);

    // user groups list cache
    Map<String, List<CmsGroup>> lruUserGroups = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getUserGroupsCacheSize());
    m_cacheUserGroups = Collections.synchronizedMap(lruUserGroups);
    register(CmsDriverManager.class.getName() + ".userGroupsCache", lruUserGroups);

    // project cache
    Map<String, CmsProject> lruProjects = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getProjectCacheSize());
    m_cacheProject = Collections.synchronizedMap(lruProjects);
    register(CmsDriverManager.class.getName() + ".projectCache", lruProjects);

    // project resources cache cache
    Map<String, List<CmsResource>> lruProjectResources = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getProjectResourcesCacheSize());
    m_cacheProjectResources = Collections.synchronizedMap(lruProjectResources);
    register(CmsDriverManager.class.getName() + ".projectResourcesCache", lruProjectResources);

    // publish history
    int size = configuration.getPublishManager().getPublishHistorySize();
    Buffer buffer = CmsPublishHistory.getQueue(size);
    m_publishHistory = SynchronizedBuffer.decorate(buffer);
    register(CmsPublishHistory.class.getName() + ".publishHistory", buffer);

    // publish queue
    buffer = CmsPublishQueue.getQueue();
    m_publishQueue = SynchronizedBuffer.decorate(buffer);
    register(CmsPublishQueue.class.getName() + ".publishQueue", buffer);

    // resource cache
    Map<String, CmsResource> lruResources = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getResourceCacheSize());
    m_cacheResource = Collections.synchronizedMap(lruResources);
    register(CmsDriverManager.class.getName() + ".resourceCache", lruResources);

    // roles cache
    Map<String, Boolean> lruHasRoles = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getRolesCacheSize());
    m_cacheHasRoles = Collections.synchronizedMap(lruHasRoles);
    register(CmsDriverManager.class.getName() + ".rolesCache", lruHasRoles);

    // role lists cache
    Map<String, List<CmsRole>> lruRoleLists = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getRolesCacheSize());
    m_cacheRoleLists = Collections.synchronizedMap(lruRoleLists);
    register(CmsDriverManager.class.getName() + ".roleListsCache", lruRoleLists);

    // resource list cache
    Map<String, List<CmsResource>> lruResourceList = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getResourcelistCacheSize());
    m_cacheResourceList = Collections.synchronizedMap(lruResourceList);
    register(CmsDriverManager.class.getName() + ".resourceListCache", lruResourceList);

    // property cache
    Map<String, CmsProperty> lruProperty = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getPropertyCacheSize());
    m_cacheProperty = Collections.synchronizedMap(lruProperty);
    register(CmsDriverManager.class.getName() + ".propertyCache", lruProperty);

    // property list cache
    Map<String, List<CmsProperty>> lruPropertyList = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getPropertyListsCacheSize());
    m_cachePropertyList = Collections.synchronizedMap(lruPropertyList);
    register(CmsDriverManager.class.getName() + ".propertyListCache", lruPropertyList);

    // published resources list cache
    Map<String, List<CmsPublishedResource>> lruPublishedResources = CmsCollectionsGenericWrapper
            .createLRUMap(5);
    m_cachePublishedResources = Collections.synchronizedMap(lruPublishedResources);
    register(CmsDriverManager.class.getName() + ".publishedResourcesCache", lruPublishedResources);

    // acl cache
    Map<String, CmsAccessControlList> lruAcl = CmsCollectionsGenericWrapper
            .createLRUMap(cacheSettings.getAclCacheSize());
    m_cacheAccessControlList = Collections.synchronizedMap(lruAcl);
    register(CmsDriverManager.class.getName() + ".accessControlListCache", lruAcl);

    // vfs object cache
    Map<String, Object> vfsObjectCache = new HashMap<String, Object>();
    m_cacheVfsObject = Collections.synchronizedMap(vfsObjectCache);
    register(CmsVfsMemoryObjectCache.class.getName(), vfsObjectCache);

    // memory object cache
    Map<String, Object> memObjectCache = new HashMap<String, Object>();
    m_cacheMemObject = Collections.synchronizedMap(memObjectCache);
    register(CmsMemoryObjectCache.class.getName(), memObjectCache);

    if (LOG.isDebugEnabled()) {
        // this will happen only once during system startup
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_MM_CREATED_1,
                new Date(System.currentTimeMillis())));
    }
}

From source file:org.openiot.gsn.wrappers.SystemTime.java

public boolean initialize() {
    setName("LocalTimeWrapper-Thread" + (++threadCounter));
    AddressBean addressBean = getActiveAddressBean();
    //  TODO: negative values?
    timer = new Timer(addressBean.getPredicateValueAsInt(CLOCK_PERIOD_KEY, DEFAULT_CLOCK_PERIODS), this);
    maximumDelay = addressBean.getPredicateValueAsInt(MAX_DELAY_KEY, DEFAULT_MAX_DELAY);
    if (maximumDelay > 0) {
        streamElementBuffer = SynchronizedBuffer.decorate(new UnboundedFifoBuffer());
        delayPostingElements = true;//from  w ww  . jav a 2  s  .  c om
        if (timer.getDelay() < maximumDelay)
            logger.warn(
                    "Maximum delay is greater than element production interval. Running for a long time may lead to an OutOfMemoryException");
    }
    return true;
}