Java 类ch.qos.logback.core.spi.ContextAware 实例源码

项目:bartleby    文件:SSLContextFactoryBean.java   
/**
 * 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();
}
项目:bartleby    文件:SSLContextFactoryBean.java   
/**
 * 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();
}
项目:bugsnag-logback    文件:Configuration.java   
/**
 * @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.");
    }
}
项目:logback-flume-appender    文件:FlumeAvroManager.java   
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;
}
项目:logback-flume-appender    文件:FlumeAvroManager.java   
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();
}
项目:konker-platform    文件:KonkerStatusListenerConfigHelper.java   
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);
    }

}
项目:bartleby    文件:ConverterUtil.java   
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();
  }
}
项目:bartleby    文件:StringToObjectConverter.java   
/**
 * 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;
}
项目:bartleby    文件:StringToObjectConverter.java   
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;
  }
}
项目:bartleby    文件:StringToObjectConverter.java   
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;
  }
}
项目:bartleby    文件:StatusListenerAction.java   
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);
  }

}
项目:bartleby    文件:OptionHelper.java   
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);
  }
}
项目:bartleby    文件:OptionHelper.java   
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);
  }
}
项目:bartleby    文件:SSLContextFactoryBean.java   
private SecureRandom createSecureRandom(ContextAware context) 
    throws NoSuchProviderException, NoSuchAlgorithmException {

  SecureRandom secureRandom = getSecureRandom().createSecureRandom();
  context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm()
      + "' provider '" + secureRandom.getProvider() + "'");

  return secureRandom;
}
项目:bartleby    文件:LoggerContextListenerAction.java   
@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);
  }
}
项目:bartleby    文件:StatusListenerConfigHelper.java   
private static void initAndAddListener(LoggerContext loggerContext, StatusListener listener) {
  if (listener != null) {
    if(listener instanceof ContextAware) // LOGBACK-767
      ((ContextAware) listener).setContext(loggerContext);
    if(listener instanceof LifeCycle)  // LOGBACK-767
      ((LifeCycle) listener).start();
    loggerContext.getStatusManager().add(listener);
  }
}
项目:bartleby    文件:MockSSLConfiguration.java   
@Override
public SSLContext createContext(ContextAware context)
    throws NoSuchProviderException, NoSuchAlgorithmException,
    KeyManagementException, UnrecoverableKeyException, KeyStoreException,
    CertificateException {
  contextCreated = true;
  return super.createContext(context);
}
项目:sdcct    文件:LoggingInitializerRunListener.java   
@Override
protected ContextAware postProcessBeforeInitializationInternal(ContextAware bean, String beanName) throws Exception {
    bean.setContext(LoggingInitializerRunListener.this.loggerContext);

    if (bean instanceof LoggerContextAware) {
        ((LoggerContextAware) bean).setLoggerContext(LoggingInitializerRunListener.this.loggerContext);
    }

    return bean;
}
项目:sdcct    文件:LoggingInitializerRunListener.java   
private <T extends LifeCycle> T buildLifeCycle(T lifeCycle, boolean start) {
    if (lifeCycle instanceof ContextAware) {
        ((ContextAware) lifeCycle).setContext(this.loggerContext);
    }

    if (start) {
        lifeCycle.start();
    }

    return lifeCycle;
}
项目:bugsnag-logback    文件:Sender.java   
/**
 * Starts the sender with the given {@code configuration} and {@code contextAware}.
 *
 * @param configuration the {@link Configuration} to apply
 * @param contextAware the {@link ContextAware} to use for error reporting
 */
public void start(final Configuration configuration, final ContextAware contextAware) {
    this.endpoint = configuration.getEndpointWithProtocol();
    this.contextAware = contextAware;
    this.gsonProvider = new GsonProvider(configuration);
    this.client = createClient();
    this.started = true;
}
项目:bugsnag-logback    文件:ConfigurationTest.java   
@Test
public void addsNoErrorsForValidConfiguration() {
    // given
    configuration.setApiKey("someKey");
    final ContextAware contextAware = mock(ContextAware.class);

    // when
    configuration.addErrors(contextAware);

    // then
    verifyZeroInteractions(contextAware);
}
项目:bugsnag-logback    文件:ConfigurationTest.java   
@Test
public void addsErrorWhenEndpointIsInvalid() {
    // given
    configuration.setApiKey("someKey");
    configuration.setEndpoint(null);
    final ContextAware contextAware = mock(ContextAware.class);

    // when
    configuration.addErrors(contextAware);

    // then
    verify(contextAware).addError("endpoint must not be null nor empty");
}
项目:bugsnag-logback    文件:ConfigurationTest.java   
@Test
public void addsErrorWhenApiKeyIsInvalid() {
    // given
    configuration.setApiKey(null);
    final ContextAware contextAware = mock(ContextAware.class);

    // when
    configuration.addErrors(contextAware);

    // then
    verify(contextAware).addError("apiKey must not be null nor empty");
}
项目:bugsnag-logback    文件:ConfigurationTest.java   
@Test
public void addsErrorWhenReleaseStageIsInvalid() {
    // given
    configuration.setApiKey("someKey");
    configuration.setReleaseStage(null);
    final ContextAware contextAware = mock(ContextAware.class);

    // when
    configuration.addErrors(contextAware);

    // then
    verify(contextAware).addError("releaseStage must not be null nor empty");
}
项目:bugsnag-logback    文件:ConfigurationTest.java   
@Test
public void addsErrorWhenProviderClassNameIsInvalid() {
    // given
    configuration.setApiKey("someKey");
    configuration.setMetaDataProviderClassName("foo.bar.SomeRandomClass");
    final ContextAware contextAware = mock(ContextAware.class);

    // when
    configuration.addErrors(contextAware);

    // then
    verify(contextAware).addError("Could not instantiate class: foo.bar.SomeRandomClass. " +
            "Make sure that you provided the fully qualified class name and that the class " +
            "has a public accessible default constructor.");
}
项目:logback-flume-appender    文件:EventReporter.java   
public EventReporter(final Properties properties, final ContextAware context,
                     final int maximumThreadPoolSize, final int maxQueueSize) {
  BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(maxQueueSize);
  this.connectionProps = properties;
  this.loggingContext = context;

  int corePoolSize = 1;
  TimeUnit threadKeepAliveUnits = TimeUnit.SECONDS;
  int threadKeepAliveTime = 30;
  RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();

  this.es = new ThreadPoolExecutor(corePoolSize, maximumThreadPoolSize, threadKeepAliveTime,
          threadKeepAliveUnits, blockingQueue, handler);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LogbackConfigurator.java   
public void start(LifeCycle lifeCycle) {
    if (lifeCycle instanceof ContextAware) {
        ((ContextAware) lifeCycle).setContext(this.context);
    }
    lifeCycle.start();
}
项目:spring-boot-concourse    文件:LogbackConfigurator.java   
public void start(LifeCycle lifeCycle) {
    if (lifeCycle instanceof ContextAware) {
        ((ContextAware) lifeCycle).setContext(this.context);
    }
    lifeCycle.start();
}
项目:bartleby    文件:StringToObjectConverter.java   
@SuppressWarnings("unchecked")
private static Object convertToEnum(ContextAware ca, String val,
    Class<? extends Enum> enumType) {
  return Enum.valueOf(enumType, val);
}
项目:bartleby    文件:NestedComplexPropertyIA.java   
public void begin(InterpretationContext ec, String localName,
    Attributes attributes) {
  // LogLog.debug("in NestComponentIA begin method");
  // get the action data object pushed in isApplicable() method call
  IADataForComplexProperty actionData = (IADataForComplexProperty) actionDataStack
      .peek();

  String className = attributes.getValue(CLASS_ATTRIBUTE);
  // perform variable name substitution
  className = ec.subst(className);

  Class<?> componentClass = null;
  try {

    if (!OptionHelper.isEmpty(className)) {
      componentClass = Loader.loadClass(className, context);
    } else {
      // guess class name via implicit rules
      PropertySetter parentBean = actionData.parentBean;
      componentClass = parentBean.getClassNameViaImplicitRules(actionData
          .getComplexPropertyName(), actionData.getAggregationType(), ec
          .getDefaultNestedComponentRegistry());
    }

    if (componentClass == null) {
      actionData.inError = true;
      String errMsg = "Could not find an appropriate class for property ["
          + localName + "]";
      addError(errMsg);
      return;
    }

    if (OptionHelper.isEmpty(className)) {
      addInfo("Assuming default type [" + componentClass.getName()
          + "] for [" + localName + "] property");
    }

    actionData.setNestedComplexProperty(componentClass.newInstance());

    // pass along the repository
    if (actionData.getNestedComplexProperty() instanceof ContextAware) {
      ((ContextAware) actionData.getNestedComplexProperty())
          .setContext(this.context);
    }
    //addInfo("Pushing component [" + localName
    //    + "] on top of the object stack.");
    ec.pushObject(actionData.getNestedComplexProperty());

  } catch (Exception oops) {
    actionData.inError = true;
    String msg = "Could not create component [" + localName + "] of type ["
        + className + "]";
    addError(msg, oops);
  }

}
项目:bartleby    文件:SSLContextFactoryBean.java   
/**
 * Creates a new {@link SSLContext} using the receiver's configuration.
 * @param context context for status messages
 * @return {@link SSLContext} object
 * @throws NoSuchProviderException if a provider specified for one of the
 *    JCA or JSSE components utilized in creating the context is not
 *    known to the platform
 * @throws NoSuchAlgorithmException if a JCA or JSSE algorithm, protocol, 
 *    or type name specified for one of the context's components is not
 *    known to a given provider (or platform default provider for the
 *    component)
 * @throws KeyManagementException if an error occurs in creating a 
 *    {@link KeyManager} for the context
 * @throws UnrecoverableKeyException if a private key needed by a 
 *    {@link KeyManager} cannot be obtained from a key store
 * @throws KeyStoreException if an error occurs in reading the
 *    contents of a key store
 * @throws CertificateException if an error occurs in reading the
 *    contents of a certificate
 */
public SSLContext createContext(ContextAware context) throws NoSuchProviderException, 
    NoSuchAlgorithmException, KeyManagementException, 
    UnrecoverableKeyException, KeyStoreException, CertificateException {

  SSLContext sslContext = getProvider() != null ?
      SSLContext.getInstance(getProtocol(), getProvider())
      : SSLContext.getInstance(getProtocol());

  context.addInfo("SSL protocol '" + sslContext.getProtocol() 
      + "' provider '" + sslContext.getProvider() + "'");

  KeyManager[] keyManagers = createKeyManagers(context);
  TrustManager[] trustManagers = createTrustManagers(context);
  SecureRandom secureRandom = createSecureRandom(context);
  sslContext.init(keyManagers, trustManagers, secureRandom);
  return sslContext;
}
项目:contestparser    文件:LogbackConfigurator.java   
public void start(LifeCycle lifeCycle) {
    if (lifeCycle instanceof ContextAware) {
        ((ContextAware) lifeCycle).setContext(this.context);
    }
    lifeCycle.start();
}
项目:sdcct    文件:LoggingInitializerRunListener.java   
public LoggerContextAwareBeanPostProcessor() {
    super(ContextAware.class);
}
项目:bugsnag-logback    文件:SenderTest.java   
@Test
public void isStartedAfterStart() {
    sender.start(mock(Configuration.class), mock(ContextAware.class));
    assertThat(sender.isStarted(), is(true));
}
项目:bugsnag-logback    文件:SenderTest.java   
@Test
public void isStoppedAfterStop() {
    sender.start(mock(Configuration.class), mock(ContextAware.class));
    sender.stop();
    assertThat(sender.isStopped(), is(true));
}
项目:logback-ext    文件:DisruptorAppender.java   
public LogExceptionHandler(ContextAware context) {
    this.context = context;
}
项目:logback-ext    文件:LoggingEventHandler.java   
public LoggingEventHandler(ContextAware contextAware, CountDownLatch latch, String errorMessage) {
    this.contextAware = contextAware;
    this.latch = latch;
    this.errorMessage = errorMessage;
}
项目:logback-ext    文件:ContextAwareExecutorService.java   
public ContextAwareExecutorService(ContextAware contextAware) {
    this.contextAware = contextAware;
}