`
cunzhangok
  • 浏览: 66328 次
  • 性别: Icon_minigender_1
  • 来自: 江苏
社区版块
存档分类
最新评论

ListResourceBundle 使用

 
阅读更多
基于通配符的方式使用

import java.text.MessageFormat;
import java.util.ListResourceBundle;
import java.util.ResourceBundle;

import com.taobao.remoting.util.LogConstants;


/**
* 日志资源Bundle家族的默认成员。
*
*/
public class LogResources extends ListResourceBundle {

    static private final ResourceBundle logBundle = ResourceBundle.getBundle(LogResources.class.getName());


    static public final String CONNECT_FAIL = "connectFail";
    static public final String CONNECT_CANCEL = "connectCancelled";
    static public final String GET_CONNECT_FAIL = "getConnectFail"; // 从ClientManager取连接失败
    static public final String INIT_CLOSE_CONNECTION = "initCloseConnection";


    static public final String REQUEST_SEND_FAIL = "requestSendFail";
    static public final String RESP_TIMEOUT = "respTimeout";
    static public final String RESP_LOST_BY_CLOSED = "respLostBecauseConnectionClosed";
    static public final String CONNECTION_RESP_TIMEOUT = "connectionRespTimeout";
    static public final String CONNECTION_RESP_ERROR = "connectionRespError";
    static public final String CONNECTION_RESP_ERROR_STACK = "connectionRespErrorWithStack";

    static public final String CONNECTION_WRITE_TIMEOUT = "connectionWriteTimeoutException";
    static public final String CONNECTION_UNKNOWN_EXCEPTION = "connectionUnknownException";

    static public final String NO_RESP_RECEIVER = "noResponseReceiver";

    static public final String INVALID_SERIALIZE = "invalidSerializeType";
    static public final String INVALID_CONNECTION_GROUPING = "invalidConnectionGrouping";

    static public final String MAX_READ_IDLE_CLIENT = "clientExceedsMaxReadIdle";
    static public final String MAX_READ_IDLE_SERVER = "serverExceedsMaxReadIdle";

    static public final String IO_THREAD_CANNOT_CALLBACK = "ioThreadCannotCallback"; //IO线程不能回调上层业务
    static public final String IO_THREAD_CANNOT_DO_REQUEST = "ioThreadCannotDoRequest"; //IO线程不能处理请求

    static public final String REQUEST_PROCESSOR_NOT_FOUND = "requestProcessorNotFound";
    static public final String REQUEST_EXECUTOR_NOT_FOUND = "requestExecutorNotFound";


    static public final String SERVER_START_SUCCESS = "serverStartSuccess";
    static public final String SERVER_START_FAIL = "serverStartFail";
    static public final String SERVER_STOP_SUCCESS = "serverStopSuccess";
    static public final String SERVER_EMPTY_GROUP = "server_group_empty";

    static public final String RECONNECT_NEW_TASK = "reconnectNewTask";
    static public final String RECONNECT_TASK_RETRY = "reconnectTaskRetry";
    static public final String RECONNECT_TASK_SUCCESS = "reconnectTaskSuccess";
    static public final String RECONNECT_TASK_CANCELLED = "reconnectTaskCancelled";

    static public final String TIMEOUTSCAN_SLEEP_TOO_LONG = "timeoutScanSleepTooLong";


    static private final Object[][] contents = new Object[][] {
        {CONNECT_FAIL, "连接创建失败[{0}]."                     },
        {CONNECT_CANCEL, "连接创建操作被取消[{0}]."               },
        {GET_CONNECT_FAIL, "获取连接失败[{0}]."                 },
        {INIT_CLOSE_CONNECTION, LogConstants.PREFIX_IMPORTANT + "主动关闭连接[{0}]"    },

        {REQUEST_SEND_FAIL, "请求发送失败,失败原因[{0}], 源码位置[{1}]."},
        {RESP_TIMEOUT, "请求[{0}]的响应超时."},
        {RESP_LOST_BY_CLOSED, "由于连接关闭, 导致请求的响应丢失."},

        {CONNECTION_RESP_TIMEOUT, "等待响应超时, 等待时间=[{0}]ms."     },

        {CONNECTION_RESP_ERROR, "异常响应[{0}], 连接[{1}].\n"
                                  + "业务请求: [{2}].\n"
                                  + "原因: [{3}]."},

        {CONNECTION_RESP_ERROR_STACK, "异常响应[{0}], 连接[{1}].\n"
                                  + "业务请求: [{2}].\n"
                                  + "原因: [{3}].\n"
                                  + "异常堆栈:\n[{4}]."},

        {CONNECTION_WRITE_TIMEOUT, LogConstants.PREFIX_IMPORTANT + "出现写超时错误, 关闭连接[{0}]."},
        {CONNECTION_UNKNOWN_EXCEPTION, "出现未知错误,关闭连接[{0}]."},

        {NO_RESP_RECEIVER, "未找到响应requestId=[{0}]的消息接收者, 响应来自[{1}], 业务响应类型[{2}]."},
        {INVALID_SERIALIZE, "非法的序列化类型[{0}]."},

        {MAX_READ_IDLE_CLIENT, LogConstants.PREFIX_IMPORTANT + "由于读IDLE持续时间超过[{0}]s, 关闭客户端连接[{1}]."},
        {MAX_READ_IDLE_SERVER, LogConstants.PREFIX_IMPORTANT + "由于读IDLE持续时间超过[{0}]s, 关闭服务端连接[{1}]."},



        {REQUEST_PROCESSOR_NOT_FOUND, "未找到请求类[{0}]的处理器."        },
        {REQUEST_EXECUTOR_NOT_FOUND, "未找到请求类[{0}]的处理线程池."      },

        {IO_THREAD_CANNOT_CALLBACK, "不能由IO线程来回调上层业务, 回调被取消, 请求ID为[{0}]."},
        {IO_THREAD_CANNOT_DO_REQUEST, "不能由IO线程来处理请求,业务请求[ID={0}]被取消[{1}]."},


        {INVALID_CONNECTION_GROUPING, "由归组请求[{0}]计算得到的组名为NULL, 因此断开连接[{1}]."        },


        {SERVER_START_SUCCESS, "服务器成功启动: {0}"},
        {SERVER_START_FAIL, "服务器启动失败"},
        {SERVER_STOP_SUCCESS, "服务器成功关闭: {0}"},
        {SERVER_EMPTY_GROUP, "组[{0}]内没有可用连接."},

        {RECONNECT_NEW_TASK, "重连任务启动[{0}]."},
        {RECONNECT_TASK_RETRY, "重连任务失败, 等待[{1}]ms后再重试,任务[{0}]."},
        {RECONNECT_TASK_SUCCESS, "重连任务成功后退出[{0}]."},
        {RECONNECT_TASK_CANCELLED, "重连任务取消[{0}]."},

        {TIMEOUTSCAN_SLEEP_TOO_LONG, LogConstants.PREFIX_IMPORTANT + "响应超时扫描线程实际睡眠消耗[{0}]ms."},
    };



    @Override
    protected Object[][] getContents() {
        return contents;
    }

    /**
     * 取日志资源
     *
     * @param key
     * @param params
     * @return
     */
    static public String getLog(String key, Object... params) {
        String content = logBundle.getString(key);
        return MessageFormat.format(content, params);
    }

}
分享到:
评论

相关推荐

    JDK11-internationalization-guide.pdf

    JDK 11 中提供了多种消息和资源束,例如java.util.ResourceBundle、java.util.ListResourceBundle 等。开发者可以使用这些类和接口来实现软件的国际化。 JDK 11 国际化指南的应用 JDK 11 国际化指南的应用非常广泛...

    java国际化.ppt

    - `ListResourceBundle`适用于包含非字符串对象的资源,而`PropertyResourceBundle`仅处理字符串资源。 10. **本地化工具**: - `native2ascii`工具用于将本地编码的属性文件转换为ASCII格式,以便Java能正确读取...

    Java的i18n问题解决文档,代码

    - **ListResourceBundle类**:当需要存储更复杂的数据类型,如数字或自定义对象时,可以使用ListResourceBundle。它是一个继承自ResourceBundle的类,包含了键值对的二维Object数组。例如,`WebTaxResource_zh_...

    jQuery实现百度登录框的动态切换效果

    在本文中,我们将探讨如何使用jQuery来实现类似百度登录框的动态切换效果。这个效果通常涉及到用户界面中的多个状态或视图之间的平滑过渡,为用户提供更好的交互体验。以下是一步步实现这一效果的方法: 首先,我们...

    国际化编程

    在Java中,`java.util`包提供了处理国际化问题所需的主要工具,如Locale、ResourceBundle以及它们的子类,如ListResourceBundle和PropertyResourceBundle。这些类共同协作,为开发者提供了处理多语言环境所需的灵活...

    SerializerMessages_tr.rar_Windows编程_Unix_Linux_

    An instance of this class is a ListResourceBundle that has the required getContents() method that returns an array of message-key message associations.

    Properties2Java-开源

    Properties2Java是一项Ant任务,用于将Java“ .properties”文件自动转换为扩展java.util.ListResourceBundle的“ .java”文件。

    xalanjava源码-java-i18n:javai18n(主要是gui)

    ListResourceBundle 包括:com.sun.java.swing.plaf.gtk.resources.* com.sun.java.swing.plaf.motif.resources.* com.sun.java.swing.plaf.windows.resources.* 排除 com.sun.org.apache.* 包:...

    永中Office办公套件维文版的设计---多语言混合排版的设计* (2006年)

    本地化资源类如ResourceBundle以及其子类ListResourceBundle和PropertyResourceBundle,则帮助开发者封装和管理与Locale相关的本地化资源,使程序能够支持不同地区的特定资源需求。 永中Office办公套件维文版的设计...

Global site tag (gtag.js) - Google Analytics