地图存储

基本信息

属性 值
抽象基类 org.dynmap.storage.MapStorage(storage/MapStorage.java,501 行)
图块抽象 MapStorageTile(storage/MapStorageTile.java,137 行)
后端工厂 DynmapCore.java:430-449
配置键 storage/type(configuration.txt:22-35)
仓库默认值 filetree(DynmapCore.java:430 默认参 + configuration.txt:24)
存储层总代码量 6238 行(storage/ 全部 13 个类)

功能

决定渲染好的地图图块存在哪里。工厂方法在 DynmapCore 初始化时按 storage/type 选择唯一默认后端;类型非法则记录 Invalid storage type for map data: <type> 并中止初始化(DynmapCore.java:446-448)。

storage/ 下的回调接口用于图块枚举/检索:MapStorageTileEnumCB(12 行)、MapStorageBaseTileEnumCB(12 行)、MapStorageTileSearchEndCB(8 行)。

后端

工厂按 storetype 字符串分派,共 5 个分支 → 5 个后端类(postgres 与 postgresql 两个名字映射到同一实现):

storage/type 值 实现类 包路径 行数 工厂行
filetree(默认) FileTreeMapStorage storage/filetree/ 691 DynmapCore.java:431-432
sqlite SQLiteMapStorage storage/sqllte/ 1088 DynmapCore.java:434-435
mysql MySQLMapStorage storage/mysql/ 1274 DynmapCore.java:437-438
mariadb MariaDBMapStorage storage/mariadb/ 24 DynmapCore.java:440-441
postgres / postgresql PostgreSQLMapStorage storage/postgresql/ 1195 DynmapCore.java:443-444
(无) MicrosoftSQLMapStorage storage/mssql/ 1133 未被工厂引用

两个需要指出的源码事实:

  1. SQLite 实现的包名拼写为 sqllte(storage/sqllte/SQLiteMapStorage.java),少一个 i。这是目录与包名的原文,照录不纠。
  2. MicrosoftSQLMapStorage(1133 行)存在但工厂从不实例化——DynmapCore.java:430-449 的 if-else 链中没有 mssql 分支。仓库内 configuration.txt:18-21 的注释也只列出 filetree / sqlite / mysql 三种。仓库中未找到注释说明该类为何保留,此处仅记录"存在但无注册路径"这一事实,不判定为缺陷。

MariaDBMapStorage 仅 24 行,因为它 extends MySQLMapStorage(MariaDBMapStorage.java:6)且只覆写 checkDriver()(:12-23)——换用 jdbc:mariadb:// 前缀并检测 org.mariadb.jdbc.Driver;详见 数据库后端。

辅助类

类 行数 说明
filetree/TileHashManager 163 filetree 后端的图块哈希管理
MapStorage 501 抽象基类

数值

数值名 值
后端实现类数(含未注册) 6
工厂可分派的后端数 5
工厂接受的 storage/type 字符串数 6(postgres 与 postgresql 共用一个实现)
存在但未被工厂引用的后端 1(MicrosoftSQLMapStorage,1133 行)
storage/ 总行数 6238

交互

触发 行为
初始化 defaultStorage.init(this) 失败则记录 Map storage initialization failure 并中止(DynmapCore.java:450-453)
storage/type 非法 记录 Invalid storage type for map data 并中止
网页端请求图块 经 MapStorageResourceHandler 读默认后端

配置

configuration.txt:22-35 给出三种后端的完整示例键;仅 filetree 与 type: filetree 生效,其余均以 # 注释。仓库 README.md “Other tips” 一节另提示:文件开头的 port 键被注释,需用于 MySQL/MariaDB 一类数据库引擎存储地图数据。

相关条目