⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wapsessionmanager.java

📁 封装了SQL、Socket、WAP、MIME等功能的通用组件
💻 JAVA
字号:
package org.lazybug.wap;

import java.util.HashMap;
import java.util.Iterator;

import org.lazybug.util.ConfigUtil;
import org.lazybug.util.Tools;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Kehaoinfo</p>
 *
 * @author David Lau
 * @version 1.0
 */
public class WAPSessionManager extends HashMap implements Runnable
{
    private static WAPSessionManager handle;
    private boolean isRunning;

    public static WAPSessionManager getInstance()
    {
        if( handle == null ) handle = new WAPSessionManager();
        return handle;
    }

    private WAPSessionManager()
    {
        start();
    }
    public WAPSession getSession(String sid)
    {
        return (WAPSession)get(sid);
    }

    public void start()
    {
        if( !isRunning )
        {
            isRunning = true;
            Thread t = new Thread(this);
            t.start();
        }
    }

    public void run()
    {
        while(isRunning)
        {
            synchronized( this ){
                try{
                    wait(60000);
                    clearExpiredSession();
                }
                catch(Exception e){
                }
            }
        }
    }

    private void clearExpiredSession()
    {
        Iterator iterator = this.values().iterator();
        while(iterator.hasNext())
        {
            WAPSession session = (WAPSession)iterator.next();
            if( session.getStartTime() <  ( System.currentTimeMillis() - Tools.MILLI_OF_MINUTE -
                    ConfigUtil.getInteger("session_expired")*Tools.MILLI_OF_MINUTE) )
            {
                this.remove(session.getRelUri());
                session.s_abort_ind();
            }
        }
    }


    public synchronized void writeUriLog(String url, String encoding)
    {
        try{
            File file = new File( ConfigUtil.APP_PATH + "log/log_url_decod.txt" );
            FileOutputStream out = new FileOutputStream( file, true );
            PrintStream printer = new PrintStream( out, true );
            printer.print(Tools.getFormatTime("[yyyy-MM-dd HH:mm:ss]",
                System.currentTimeMillis()));
            printer.println(url);
            if( encoding != null )
            {
                printer.print( Tools.getFormatTime( "[yyyy-MM-dd HH:mm:ss]",
                    System.currentTimeMillis() ) );
                printer.println( encoding );
            }
            out.close();
            printer.close();
        }
        catch(Exception e)
        {
        }
    }
    public synchronized void writeRequestLog( int port, String method, String url)
    {
        try
        {
            File file = new File( ConfigUtil.APP_PATH + "log/log_url_req.txt" );
            FileOutputStream out = new FileOutputStream( file, true );
            PrintStream printer = new PrintStream( out, true );
            printer.print(Tools.getFormatTime("[yyyy-MM-dd HH:mm:ss]",
                System.currentTimeMillis()));
            printer.print("[port:"+port+"]");
            printer.print("[method:"+method+"]");
            printer.println(url);
            out.close();
            printer.close();
        }
        catch(Exception e)
        {
        }
    }
    public synchronized void writeReplyLog(int port, int status, int size, String url, String headers )
    {
        try{
            File file = new File( ConfigUtil.APP_PATH + "log/log_url_reply.txt" );
            FileOutputStream out = new FileOutputStream( file, true );
            PrintStream printer = new PrintStream( out, true );
            printer.print(Tools.getFormatTime("[yyyy-MM-dd HH:mm:ss]",
                System.currentTimeMillis()));
            printer.print("[port:"+port+"]");
            printer.print("[status:"+status+"]");
            printer.print("[size:"+size+"]");
            printer.println(headers);
            printer.println(url);
            out.close();
            printer.close();
        }
        catch(Exception e)
        {
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -