public void start(LifeCycle lifeCycle) { if (lifeCycle instanceof ContextAware) { ((ContextAware) lifeCycle).setContext(this.context); } lifeCycle.start(); }
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); } }
private SecureRandom createSecureRandom(ContextAware context) throws NoSuchProviderException, NoSuchAlgorithmException { SecureRandom secureRandom = getSecureRandom().createSecureRandom(); context.addInfo("secure random algorithm '" + secureRandom.getAlgorithm() + "' provider '" + secureRandom.getProvider() + "'"); return secureRandom; }
loggingContext.addWarn(ie.getLocalizedMessage(), ie); System.arraycopy(events, 0, batch, 0, count); loggingContext.addInfo("Sending " + count + " event(s) to the EventReporter"); try{ reporter.report(batch); } catch (RejectedExecutionException ex) { loggingContext.addError("Logging events batch rejected by EventReporter. Check reporter connectivity or " + "consider increasing reporterMaxThreadPoolSize or reporterMaxQueueSize", ex);
private synchronized RpcClient createClient() { if (client == null) { loggingContext.addInfo("Creating a new Flume Client with properties: " + connectionProps); try { client = RpcClientFactory.getInstance(connectionProps); } catch ( Exception e ) { loggingContext.addError(e.getLocalizedMessage(), e); } } return client; }
@Override public void execute(Runnable command) { contextAware.getContext().getExecutorService().execute(command); } }
@Override public void onError(Exception exception) { contextAware.addWarn(errorMessage, exception); latch.countDown(); }
@Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return contextAware.getContext().getExecutorService().awaitTermination(timeout, unit); }
@Override public void onError(Exception exception) { contextAware.addWarn(errorMessage, exception); latch.countDown(); }
@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); } }
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; } }
@Override public <T> Future<T> submit(Runnable task, T result) { return contextAware.getContext().getExecutorService().submit(task, result); }
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(); } } }
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; } }
@Override public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { return contextAware.getContext().getExecutorService().invokeAll(tasks); }
private static void initListener(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); } }
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); } }