AbstractLogWriter.java 文件源码

java
阅读 21 收藏 0 点赞 0 评论 0

项目:log4j-aws-appenders 作者:
/**
 *  Attempts to use a factory method to create the service client.
 *
 *  @param  clientFactoryName   Fully qualified name of a static factory method.
 *                              If empty or null, this function returns null (used
 *                              to handle optionally-configured factories).
 *  @param  expectedClientClass The interface fullfilled by this client.
 *  @param  rethrow             If true, any reflection exceptions will be wrapped
 *                              and rethrown; if false, exceptions return null
 */
protected <T> T tryClientFactory(String clientFactoryName, Class<T> expectedClientClass, boolean rethrow)
{
    if ((clientFactoryName == null) || clientFactoryName.isEmpty())
        return null;

    try
    {
        int methodIdx = clientFactoryName.lastIndexOf('.');
        if (methodIdx < 0)
            throw new RuntimeException("invalid AWS client factory specified: " + clientFactoryName);
        Class<?> factoryKlass = Class.forName(clientFactoryName.substring(0, methodIdx));
        Method factoryMethod = factoryKlass.getDeclaredMethod(clientFactoryName.substring(methodIdx + 1));
        T client = expectedClientClass.cast(factoryMethod.invoke(null));
        factoryMethodUsed = clientFactoryName;
        LogLog.debug(getClass().getSimpleName() + ": created client from factory: " + clientFactoryName);
        return client;
    }
    catch (Exception ex)
    {
        if (rethrow)
            throw new RuntimeException("unable to invoke AWS client factory", ex);
        else
            return null;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号