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

📄 crfpserver.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/corba/com/bbn/openmap/layer/rpf/corba/CRFPServer.java,v $// $RCSfile: CRFPServer.java,v $// $Revision: 1.3.2.3 $// $Date: 2005/08/11 21:03:34 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.rpf.corba;import java.awt.event.ActionListener;import java.util.Enumeration;import java.util.Hashtable;import java.util.StringTokenizer;import java.util.Vector;import javax.swing.Timer;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.image.JPEGHelper;import com.bbn.openmap.layer.rpf.RpfCacheHandler;import com.bbn.openmap.layer.rpf.RpfColortable;import com.bbn.openmap.layer.rpf.RpfCoverageBox;import com.bbn.openmap.layer.rpf.RpfFrameCacheHandler;import com.bbn.openmap.layer.rpf.RpfIndexedImageData;import com.bbn.openmap.layer.rpf.RpfSubframe;import com.bbn.openmap.layer.rpf.RpfTocHandler;import com.bbn.openmap.layer.rpf.RpfViewAttributes;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPCADRGProjection;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPCoverageBox;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.CRFPViewAttributes;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.RawImage;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.ServerPOA;import com.bbn.openmap.layer.rpf.corba.CRpfFrameProvider.XYPoint;import com.bbn.openmap.proj.CADRG;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.corba.CORBASupport;/** * The CRFPServer is a server implementation of the * CorbaRpfFrameProvider.idl. It realy implements most of the fuctions * of the RpfFrameProvider, but is not one. The CRFPClient is the * RpfFrameProvider. *  * <P> * This server requires the com.sun.image.codec.jpeg package. */public class CRFPServer extends ServerPOA implements ActionListener {    protected static String iorfile = null;    protected static String naming = null;    /** A cache for every client. */    Hashtable caches;    /** View Attributes for every client. */    Hashtable viewAttributeLists;    /** The cache for the current client. */    protected RpfFrameCacheHandler currentCache;    /** The view attrbutes for the current client. */    protected RpfViewAttributes currentViewAttributes;    /** The paths to the RPF directories. */    protected String[] rpfpaths;    /** The Rpf Table of Contents handlers for the data. */    protected RpfTocHandler[] tocs;    /** Hashtable to keep track of how old certain caches are. */    Hashtable timestamps;    /**     * Timer for clearing out caches from sloppy clients. It's only     * enabled when the -timewindow flag is used.     */    Timer timer;    /** 10, or the default number of active caches kept. */    public final static int DEFAULT_MAX_USERS = 10;    /** The number of caches kept by the server. */    protected int maxUsers = DEFAULT_MAX_USERS;    /** 5 minutes. The default timer cycle. */    public final static int DEFAULT_TIME_WINDOW = 1000 * 60 * 5; // 5                                                                 // minutes    /**     * The amount of time (milliseconds) reflecting how long an     * inactive cache is kept     */    protected long timeWindow = DEFAULT_TIME_WINDOW;    /**     * Default Constructor.     */    public CRFPServer() {        this("Default");    }    /**     * The constructor that you should use.     *      * @param name the identifying name for persistance.     */    public CRFPServer(String name) {        super();        caches = new Hashtable();        viewAttributeLists = new Hashtable();        timestamps = new Hashtable();    }    /**     * Get the current cache given a unique ID. If a cache is not     * here, create it.     *      * @param uniqueID a unique identifier.     */    protected RpfFrameCacheHandler getCurrentCache(String uniqueID) {        RpfFrameCacheHandler cache = (RpfFrameCacheHandler) caches.get(uniqueID);        if (cache == null && tocs != null) {            Debug.message("crfp", "CRFPServer: Creating cache for new client");            cache = new RpfFrameCacheHandler(tocs);            caches.put(uniqueID, cache);        }        timestamps.put(uniqueID, new Long(System.currentTimeMillis()));        return cache;    }    /**     * Get rid of any cache that is older than the time window.     */    protected void cleanCache(long timeWindow) {        // OK, we need to get rid of one.        long currentTime = System.currentTimeMillis();        Enumeration keys = timestamps.keys();        while (keys.hasMoreElements()) {            Object tester = keys.nextElement();            Long time = (Long) timestamps.get(tester);            if ((currentTime - time.longValue()) >= timeWindow) {                caches.remove(tester);                timestamps.remove(tester);                viewAttributeLists.remove(tester);                if (Debug.debugging("crfp")) {                    Debug.output("Expired cache, removing, have "                            + caches.size() + " caches left.");                }            }        }    }    /**     * Create a spot in the cache for a new entry. If something is     * removed from the cache, it is returned here.     */    protected RpfCacheHandler sweepCaches() {        if (caches.size() < maxUsers) {            return null;        }        // OK, we need to get rid of one.        long diff = Long.MAX_VALUE;        Enumeration keys = timestamps.keys();        Object getRid = null;        while (keys.hasMoreElements()) {            Object tester = keys.nextElement();            Long time = (Long) timestamps.get(tester);            if (time.longValue() < diff) {                getRid = tester;                diff = time.longValue();            }        }        boolean DEBUG = false;        if (getRid != null) {            if (Debug.debugging("crfp")) {                DEBUG = true;            }            if (DEBUG)                Debug.output("Removing cache for new user, was "                        + caches.size());            caches.remove(getRid);            timestamps.remove(getRid);            viewAttributeLists.remove(getRid);            if (DEBUG)                Debug.output("  now " + caches.size());        }        if (caches.size() >= maxUsers) {            return sweepCaches();        } else {            return (RpfCacheHandler) getRid;        }    }    /**     * Get the current view attributes given a unique ID. If view     * attributes are not here, create them.     *      * @param uniqueID a client-unique identifier.     */    protected RpfViewAttributes getCurrentViewAttributes(String uniqueID) {        RpfViewAttributes va = (RpfViewAttributes) viewAttributeLists.get(uniqueID);        if (va == null) {            Debug.message("crfp",                    "CRFPServer: Creating attributes for new client");            va = new RpfViewAttributes();            viewAttributeLists.put(uniqueID, va);        }        return va;    }    /**     * Set the view attributtes for the current client.     *      * @param va the view attribute settings.     * @param uniqueID a client-unique identifier.     */    public void setViewAttributes(CRFPViewAttributes va, String uniqueID) {        currentViewAttributes = getCurrentViewAttributes(uniqueID);        currentViewAttributes.numberOfColors = (int) va.numberOfColors;        currentViewAttributes.opaqueness = (int) va.opaqueness;        currentViewAttributes.scaleImages = va.scaleImages;        currentViewAttributes.imageScaleFactor = va.imageScaleFactor;        currentViewAttributes.chartSeries = va.chartSeries;        if (Debug.debugging("crfp")) {            Debug.output("CRFPServer: Setting attributes for client:\n    "                    + currentViewAttributes);        }    }    /**     * Get the Coverage Boxes that fit the geographical area given.     *      * @param ullat NW latitude.     * @param ullon NW longitude     * @param lrlat SE latitude     * @param lrlon SE longitude     * @param p a CADRG projection     * @param uniqueID a client-unique identifier.     */    public CRFPCoverageBox[] getCoverage(float ullat, float ullon, float lrlat,                                         float lrlon, CRFPCADRGProjection p,                                         String uniqueID) {        Debug.message("crfp",                "CRFPServer: Handling coverage request for client");        currentCache = getCurrentCache(uniqueID);        currentViewAttributes = getCurrentViewAttributes(uniqueID);        currentCache.setViewAttributes(currentViewAttributes);        LatLonPoint llpoint = new LatLonPoint(p.center.lat, p.center.lon);        CADRG proj = new CADRG(llpoint, p.scale, p.width, p.height);        Vector vector = currentCache.getCoverage(ullat,                ullon,                lrlat,                lrlon,                proj);        return vectorToCRFPCoverageBoxes(vector);    }    /**     * Method that provides all the coverage boxes that could provide     * coverage over the given area.     *      * @param ullat NW latitude.     * @param ullon NW longitude     * @param lrlat SE latitude     * @param lrlon SE longitude     * @param p a CADRG projection     * @param uniqueID a client-unique identifier.     */    public CRFPCoverageBox[] getCatalogCoverage(float ullat, float ullon,                                                float lrlat, float lrlon,                                                CRFPCADRGProjection p,                                                String chartSeriesCode,                                                String uniqueID) {        Debug.message("crfp", "CRFPServer: handling catalog request for client");        currentCache = getCurrentCache(uniqueID);        currentViewAttributes = getCurrentViewAttributes(uniqueID);        currentCache.setViewAttributes(currentViewAttributes);        LatLonPoint llpoint = new LatLonPoint(p.center.lat, p.center.lon);        CADRG proj = new CADRG(llpoint, p.scale, p.width, p.height);        Vector vector = currentCache.getCatalogCoverage(ullat,                ullon,                lrlat,                lrlon,                proj,                chartSeriesCode);        return vectorToCRFPCoverageBoxes(vector);    }    /**     * Convert a Vector of RpfCoverageBox to a CRFPCoverageBox array.     *      * @param vector vector of RpfCoverageBox.     * @return array of CRFPCoverageBox.     */    protected CRFPCoverageBox[] vectorToCRFPCoverageBoxes(Vector vector) {        int size = vector.size();        CRFPCoverageBox[] rets = new CRFPCoverageBox[size];        for (int i = 0; i < size; i++) {            RpfCoverageBox box = (RpfCoverageBox) vector.elementAt(i);            if (box != null) {                rets[i] = new CRFPCoverageBox((float) box.nw_lat, (float) box.nw_lon, (float) box.se_lat, (float) box.se_lon, box.subframeLatInterval, box.subframeLonInterval, box.chartCode, (short) box.zone, new XYPoint((short) box.startIndexes.x, (short) box.startIndexes.y), new XYPoint((short) box.endIndexes.x, (short) box.endIndexes.y), (short) box.tocNumber, (short) box.entryNumber, box.scale, box.percentCoverage);            }        }        return rets;

⌨️ 快捷键说明

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