当前位置: 首页>>代码示例>>Java>>正文


Java ContextAware类代码示例

本文整理汇总了Java中ch.qos.logback.core.spi.ContextAware的典型用法代码示例。如果您正苦于以下问题:Java ContextAware类的具体用法?Java ContextAware怎么用?Java ContextAware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContextAware类属于ch.qos.logback.core.spi包,在下文中一共展示了ContextAware类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createKeyManagers

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
/**
 * Creates key managers using the receiver's key store configuration.
 * @param context context for status messages
 * @return an array of key managers or {@code null} if no key store
 *    configuration was provided
 * @throws NoSuchProviderException if a provider specified for one
 *    of the key manager components is not known to the platform
 * @throws NoSuchAlgorithmException if an algorithm specified for
 *    one of the key manager components is not known to the relevant
 *    provider
 * @throws KeyStoreException if an error occurs in reading a key store
 */
private KeyManager[] createKeyManagers(ContextAware context) 
    throws NoSuchProviderException, NoSuchAlgorithmException, 
    UnrecoverableKeyException, KeyStoreException {
  
  if (getKeyStore() == null) return null;
  
  KeyStore keyStore = getKeyStore().createKeyStore();
  context.addInfo(
      "key store of type '" + keyStore.getType() 
      + "' provider '" + keyStore.getProvider()
      + "': " + getKeyStore().getLocation());          

  KeyManagerFactory kmf = getKeyManagerFactory().createKeyManagerFactory();
  context.addInfo("key manager algorithm '" + kmf.getAlgorithm() 
      + "' provider '" + kmf.getProvider() + "'");
  
  char[] passphrase = getKeyStore().getPassword().toCharArray();
  kmf.init(keyStore, passphrase);
  return kmf.getKeyManagers();
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:33,代码来源:SSLContextFactoryBean.java

示例2: createTrustManagers

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
/**
 * Creates trust managers using the receiver's trust store configuration.
 * @param context context for status messages
 * @return an array of trust managers or {@code null} if no trust store
 *    configuration was provided
 * @throws NoSuchProviderException if a provider specified for one
 *    of the trust manager components is not known to the platform
 * @throws NoSuchAlgorithmException if an algorithm specified for
 *    one of the trust manager components is not known to the relevant
 *    provider
 * @throws KeyStoreException if an error occurs in reading a key
 *    store containing trust anchors 
 */
private TrustManager[] createTrustManagers(ContextAware context) 
    throws NoSuchProviderException, NoSuchAlgorithmException, 
    KeyStoreException {
  
  if (getTrustStore() == null) return null;
  
  KeyStore trustStore = getTrustStore().createKeyStore();
  context.addInfo(
      "trust store of type '" + trustStore.getType() 
      + "' provider '" + trustStore.getProvider()
      + "': " + getTrustStore().getLocation());          
  
  TrustManagerFactory tmf = getTrustManagerFactory()
      .createTrustManagerFactory();
  context.addInfo("trust manager algorithm '" + tmf.getAlgorithm() 
      + "' provider '" + tmf.getProvider() + "'");
  
  tmf.init(trustStore);
  return tmf.getTrustManagers();
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:34,代码来源:SSLContextFactoryBean.java

示例3: addErrors

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
/**
 * @param contextAware the {@link ContextAware} implementation to which potential errors will be added
 */
public void addErrors(final ContextAware contextAware) {
    if (isEndpointInvalid()) {
        contextAware.addError("endpoint must not be null nor empty");
    }

    if (isApiKeyInvalid()) {
        contextAware.addError("apiKey must not be null nor empty");
    }

    if (isReleaseStageInvalid()) {
        contextAware.addError("releaseStage must not be null nor empty");
    }

    if (isMetaProviderClassNameInValid()) {
        contextAware.addError("Could not instantiate class: " + getMetaDataProviderClassName().get() + ". " +
                "Make sure that you provided the fully qualified class name and that the class has a public " +
                "accessible default constructor.");
    }
}
 
开发者ID:codereligion,项目名称:bugsnag-logback,代码行数:23,代码来源:Configuration.java

示例4: create

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
public static FlumeAvroManager create(
    final List<RemoteFlumeAgent> agents,
    final Properties overrides,
    final Integer batchSize,
    final Long reportingWindow,
    final Integer reporterMaxThreadPoolSize,
    final Integer reporterMaxQueueSize,
    final ContextAware context) {

    if (agents != null && agents.size() > 0) {
      Properties props = buildFlumeProperties(agents);
      props.putAll(overrides);
      return new FlumeAvroManager(props, reportingWindow, batchSize, reporterMaxThreadPoolSize, reporterMaxQueueSize, context);
    } else {
      context.addError("No valid agents configured");
    }

  return null;
}
 
开发者ID:gilt,项目名称:logback-flume-appender,代码行数:20,代码来源:FlumeAvroManager.java

示例5: FlumeAvroManager

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
private FlumeAvroManager(final Properties props,
                         final Long reportingWindowReq,
                         final Integer batchSizeReq,
                         final Integer reporterMaxThreadPoolSizeReq,
                         final Integer reporterMaxQueueSizeReq,
                         final ContextAware context) {
  this.loggingContext = context;

  final int reporterMaxThreadPoolSize = reporterMaxThreadPoolSizeReq == null ?
          DEFAULT_REPORTER_MAX_THREADPOOL_SIZE : reporterMaxThreadPoolSizeReq;
  final int reporterMaxQueueSize = reporterMaxQueueSizeReq == null ?
          DEFAULT_REPORTER_MAX_QUEUE_SIZE : reporterMaxQueueSizeReq;

  this.reporter = new EventReporter(props, loggingContext, reporterMaxThreadPoolSize, reporterMaxQueueSize);
  this.evQueue = new ArrayBlockingQueue<Event>(1000);
  final long reportingWindow = hamonizeReportingWindow(reportingWindowReq);
  final int batchSize = batchSizeReq == null ? DEFAULT_BATCH_SIZE : batchSizeReq;
  this.asyncThread = new AsyncThread(evQueue, batchSize, reportingWindow);
  loggingContext.addInfo("Created a new flume agent with properties: " + props.toString());
  asyncThread.start();
}
 
开发者ID:gilt,项目名称:logback-flume-appender,代码行数:22,代码来源:FlumeAvroManager.java

示例6: initAndAddListener

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
private static void initAndAddListener(KonkerLoggerContext loggerContext, StatusListener listener) {
    if(listener != null) {
        if(listener instanceof ContextAware) {
            ((ContextAware)listener).setContext(loggerContext);
        }

        if(listener instanceof LifeCycle) {
            ((LifeCycle)listener).start();
        }

        loggerContext.getStatusManager().add(listener);
    }

}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:15,代码来源:KonkerStatusListenerConfigHelper.java

示例7: setContextForConverters

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
public static <E> void setContextForConverters(Context context, Converter<E> head) {
  Converter<E> c = head;
  while (c != null) {
    if (c instanceof ContextAware) {
      ((ContextAware) c).setContext(context);
    }
    c = c.getNext();
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:10,代码来源:ConverterUtil.java

示例8: convertArg

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
/**
 * Convert <code>val</code> a String parameter to an object of a given type.
 */
@SuppressWarnings("unchecked")
public static Object convertArg(ContextAware ca, String val, Class<?> type) {
  if (val == null) {
    return null;
  }
  String v = val.trim();
  if (String.class.isAssignableFrom(type)) {
    return v;
  } else if (Integer.TYPE.isAssignableFrom(type)) {
    return new Integer(v);
  } else if (Long.TYPE.isAssignableFrom(type)) {
    return new Long(v);
  } else if (Float.TYPE.isAssignableFrom(type)) {
    return new Float(v);
  } else if (Double.TYPE.isAssignableFrom(type)) {
    return new Double(v);
  } else if (Boolean.TYPE.isAssignableFrom(type)) {
    if ("true".equalsIgnoreCase(v)) {
      return Boolean.TRUE;
    } else if ("false".equalsIgnoreCase(v)) {
      return Boolean.FALSE;
    }
  } else if (type.isEnum()) {
    return convertToEnum(ca, v, (Class<? extends Enum>) type);
  } else if (StringToObjectConverter.followsTheValueOfConvention(type)) {
    return convertByValueOfMethod(ca, type, v);
  } else if (isOfTypeCharset(type)) {
    return convertToCharset(ca, val);
  }

  return null;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:36,代码来源:StringToObjectConverter.java

示例9: convertToCharset

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
static private Charset convertToCharset(ContextAware ca, String val) {
  try {
    return Charset.forName(val);
  } catch (UnsupportedCharsetException e) {
    ca.addError("Failed to get charset [" + val + "]", e);
    return null;
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:9,代码来源:StringToObjectConverter.java

示例10: convertByValueOfMethod

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
private static Object convertByValueOfMethod(ContextAware ca, Class<?> type,
    String val) {
  try {
    Method valueOfMethod = type.getMethod(CoreConstants.VALUE_OF,
        STING_CLASS_PARAMETER);
    return valueOfMethod.invoke(null, val);
  } catch (Exception e) {
    ca.addError("Failed to invoke " + CoreConstants.VALUE_OF
        + "{} method in class [" + type.getName() + "] with value [" + val
        + "]");
    return null;
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:14,代码来源:StringToObjectConverter.java

示例11: begin

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
  inError = false;
  String className = attributes.getValue(CLASS_ATTRIBUTE);
  if (OptionHelper.isEmpty(className)) {
    addError("Missing class name for statusListener. Near ["
            + name + "] line " + getLineNumber(ec));
    inError = true;
    return;
  }

  try {
    statusListener = (StatusListener) OptionHelper.instantiateByClassName(
            className, StatusListener.class, context);
    ec.getContext().getStatusManager().add(statusListener);
    if (statusListener instanceof ContextAware) {
      ((ContextAware) statusListener).setContext(context);
    }
    addInfo("Added status listener of type [" + className + "]");
    ec.pushObject(statusListener);
  } catch (Exception e) {
    inError = true;
    addError(
            "Could not create an StatusListener of type [" + className + "].", e);
    throw new ActionException(e);
  }

}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:28,代码来源:StatusListenerAction.java

示例12: setSystemProperties

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
public static void setSystemProperties(ContextAware contextAware, Properties props) {
  for (Object o : props.keySet()) {
    String key = (String) o;
    String value = props.getProperty(key);
    setSystemProperty(contextAware, key, value);
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:8,代码来源:OptionHelper.java

示例13: setSystemProperty

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
public static void setSystemProperty(ContextAware contextAware, String key, String value) {
  try {
    System.setProperty(key, value);
  } catch (SecurityException e) {
    contextAware.addError("Failed to set system property [" + key + "]", e);
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:8,代码来源:OptionHelper.java

示例14: createSecureRandom

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
private SecureRandom createSecureRandom(ContextAware context) 
    throws NoSuchProviderException, NoSuchAlgorithmException {
  
  SecureRandom secureRandom = getSecureRandom().createSecureRandom();
  context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm()
      + "' provider '" + secureRandom.getProvider() + "'");
  
  return secureRandom;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:10,代码来源:SSLContextFactoryBean.java

示例15: begin

import ch.qos.logback.core.spi.ContextAware; //导入依赖的package包/类
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes)
        throws ActionException {

  inError = false;

  String className = attributes.getValue(CLASS_ATTRIBUTE);
  if (OptionHelper.isEmpty(className)) {
    addError("Mandatory \"" + CLASS_ATTRIBUTE
            + "\" attribute not set for <loggerContextListener> element");
    inError = true;
    return;
  }

  try {
    lcl = (LoggerContextListener) OptionHelper.instantiateByClassName(
            className, LoggerContextListener.class, context);

    if(lcl instanceof ContextAware) {
      ((ContextAware) lcl).setContext(context);
    }

    ec.pushObject(lcl);
    addInfo("Adding LoggerContextListener of type [" + className
            + "] to the object stack");

  } catch (Exception oops) {
    inError = true;
    addError("Could not create LoggerContextListener of type " + className + "].", oops);
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:32,代码来源:LoggerContextListenerAction.java


注:本文中的ch.qos.logback.core.spi.ContextAware类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。