org.zhangmz.pickles.helper.AdminMainHelper.java Source code

Java tutorial

Introduction

Here is the source code for org.zhangmz.pickles.helper.AdminMainHelper.java

Source

/*******************************************************************************
 * Copyright (c) 2015, 2016  104446930@qq.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package org.zhangmz.pickles.helper;

import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.zhangmz.pickles.helper.vo.MainInfo;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

/**
 * Title:AdminMainHelper.java
 * Description:pickles?
 * Company: DigitalChina 2016
 * @author:
 * @date:2016126 ?8:53:10
 * pickles?
 *       ?admin/main???
 */
@Component
public class AdminMainHelper {
    private static Logger logger = LoggerFactory.getLogger(AdminMainHelper.class);

    // ?  30  5X60=300
    @Value("${app.loginTimeoutSecs:300}")
    private int loginTimeoutSecs;

    // guava cache
    private Cache<String, MainInfo> mainInfos;

    @PostConstruct
    public void init() {
        logger.debug("?? " + loginTimeoutSecs);
        // CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(loginTimeoutSecs, TimeUnit.SECONDS).build();
        mainInfos = CacheBuilder.newBuilder().maximumSize(1000)
                .expireAfterAccess(loginTimeoutSecs, TimeUnit.SECONDS).build();
    }

    /**
     * 
     * @Title: getMainInfo 
     * @Description: ???
     * @param token
     * @return
     * @throws 
     * :
     * :2016126 ?9:07:27
     * ???
     */
    public MainInfo getMainInfo(String token) {
        MainInfo mf = mainInfos.getIfPresent(token);

        if (null == mf) {
            mf = getMainInfoDB(token);
            mainInfos.put(token, mf);
        }

        return mf;
    }

    /**
     * 
     * @Title: getMainInfoDB 
     * @Description: ????
     * @param token
     * @return
     * @throws 
     * :
     * :2016126 ?9:07:59
     * ????
     */
    public MainInfo getMainInfoDB(String token) {
        // TODO @Service????
        // ?MainInfo
        MainInfo mf = new MainInfo();

        logger.debug(token + "???? " + mf.toString());
        return mf;
    }
}