The ONE使用笔记:设置文件添加自定义字段

The ONE初始化时,会将设置文件读入内存。本文介绍如何在The ONE设置文件添加自定义字段。

1. 添加自定义字段

The ONE设置文件是由一系列的键-值对(key-value pairs)组成。在设置文件添加自定义字段,举例如下:

# nc_settings.txt
Group.router = BubbleRapRouter
BubbleRapRouter.forwardAlgorithm = BUBBLE  # 这里,BubbleRapRouter是命名空间namespace

2. 使用自定义字段


public class BubbleRapRouter extends ActiveRouter {
    public static final String BUBBLERAP_NS = "BubbleRapRouter";  //BubbleRap router's setting namespace
    public static final String FORWARD_ALGORITHM_S = "forwardAlgorithm";
    private static String forwardAlgorithm;

    /*** BubbleRapRouter(Settings s) ***/
    Settings bubblerapSettings = new Settings(BUBBLERAP_NS);  
    forwardAlgorithm = bubblerapSettings.getSetting(FORWARD_ALGORITHM_S); //此时forwardAlgorithm为"BUBBLE"

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “The ONE使用笔记:设置文件添加自定义字段