基于通配符的方式使用
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);
}
}