org.opennms.core.logging.Logging.getCopyOfContextMap()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.opennms.core.logging.Logging.getCopyOfContextMap()方法的一些代码示例,展示了Logging.getCopyOfContextMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logging.getCopyOfContextMap()方法的具体详情如下:
包路径:org.opennms.core.logging.Logging
类名称:Logging
方法名:getCopyOfContextMap

Logging.getCopyOfContextMap介绍

暂无

代码示例

代码示例来源:origin: OpenNMS/opennms

public static Runnable preserve(final Runnable runnable) {
  final Map<String, String> parentMdc = Logging.getCopyOfContextMap();
  return new Runnable() {
    @Override
    public void run() {
      final Map<String, String> localMdc = Logging.getCopyOfContextMap();
      try {
        Logging.setContextMap(parentMdc);
        runnable.run();
      } finally {
        Logging.setContextMap(localMdc);
      }
    }
  };
}

代码示例来源:origin: OpenNMS/opennms

private Object getArgument(Argument arg) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
  Class<?> argClass = Class.forName(arg.getType());
  Constructor<?> construct = argClass.getConstructor(new Class[] { String.class });
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  try {
    return construct.newInstance(new Object[] { arg.getValue().orElse(null) });
  } finally {
    Logging.setContextMap(mdc);
  }
}

代码示例来源:origin: OpenNMS/opennms

@Override
  public void run() {
    final Map<String, String> localMdc = Logging.getCopyOfContextMap();
    try {
      Logging.setContextMap(parentMdc);
      runnable.run();
    } finally {
      Logging.setContextMap(localMdc);
    }
  }
};

代码示例来源:origin: OpenNMS/opennms

public static <T> T withPrefix(final String prefix, final Callable<T> callable) throws Exception {
  final Map<String, String> mdc = Logging.getCopyOfContextMap();
  try {
    Logging.putPrefix(prefix);
    return callable.call();
  } finally {
    Logging.setContextMap(mdc);
  }
}

代码示例来源:origin: OpenNMS/opennms

public static void withPrefix(final String prefix, final Runnable runnable) {
  final Map<String, String> mdc = Logging.getCopyOfContextMap();
  try {
    Logging.putPrefix(prefix);
    runnable.run();
  } finally {
    Logging.setContextMap(mdc);
  }
}

代码示例来源:origin: OpenNMS/opennms

public static MDCCloseable withContextMapCloseable(final Map<String, String> contextMap) {
  final Map<String, String> mdc = Logging.getCopyOfContextMap();
  Logging.setContextMap(contextMap);
  return new MDCCloseable(mdc);
}

代码示例来源:origin: OpenNMS/opennms

public static MDCCloseable withPrefixCloseable(final String prefix) {
  final Map<String, String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix(prefix);
  return new MDCCloseable(mdc);
}

代码示例来源:origin: OpenNMS/opennms

public EngineAdapter(final CorrelationEngine engine) {
  m_engine = engine;
  m_name = m_engine.getClass().getSimpleName() + '-' + m_engine.getName() ;
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix(m_name);
  registerEventListeners();
  Logging.setContextMap(mdc);
}

代码示例来源:origin: org.opennms/opennms-correlator

public EngineAdapter(final CorrelationEngine engine) {
  m_engine = engine;
  m_name = m_engine.getClass().getSimpleName() + '-' + m_engine.getName() ;
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix(m_name);
  registerEventListeners();
  Logging.setContextMap(mdc);
}

代码示例来源:origin: OpenNMS/opennms

private Attribute getAttribute(org.opennms.netmgt.config.service.Attribute attrib) throws Exception {
  Class<?> attribClass = Class.forName(attrib.getValue().getType());
  Constructor<?> construct = attribClass.getConstructor(new Class[] { String.class });
  Object value;
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  try {
    value = construct.newInstance(new Object[] { attrib.getValue().getContent() });
  } finally {
    Logging.setContextMap(mdc);
  }
  return new Attribute(attrib.getName(), value);
}

代码示例来源:origin: OpenNMS/opennms

/**
   * Process the event depending on the UEI and update date
   */
  @Override
  public void run() {
    final Map<String,String> mdc = Logging.getCopyOfContextMap();

    try {
      Logging.putPrefix("rtc");
      processEvent();
    } catch (Throwable t) {
      LOG.warn("Unexpected exception processing event", t);
      Logging.setContextMap(mdc);
    }
  }
}

代码示例来源:origin: org.opennms/opennms-correlator

/**
 * Initialization.
 * 
 * Retrieves the Spring context for the correlator.
 */
@Override
public void init() {
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix("correlator");
  m_correlator = BeanUtils.getBean("correlatorContext", "correlator", org.opennms.netmgt.correlation.Correlator.class);
  Logging.setContextMap(mdc);
}

代码示例来源:origin: OpenNMS/opennms

/**
 * Initialization.
 * 
 * Retrieves the Spring context for the correlator.
 */
@Override
public void init() {
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix("correlator");
  m_correlator = BeanUtils.getBean("correlatorContext", "correlator", org.opennms.netmgt.correlation.Correlator.class);
  Logging.setContextMap(mdc);
}

代码示例来源:origin: OpenNMS/opennms

Map<String,String> mdc = Logging.getCopyOfContextMap();
try {
  object = getServer().invoke(mbean.getObjectName(), invoke.getMethod(), parms, sig);

代码示例来源:origin: org.opennms.features.events/org.opennms.features.events.daemon

@Override
  public void run() {
    try {
       if (LOG.isDebugEnabled()) LOG.debug("run: calling onEvent on {} for event {}", m_listener.getName(), event.toStringSimple());
      // Make sure we restore our log4j logging prefix after onEvent is called
      Map<String,String> mdc = Logging.getCopyOfContextMap();
      try {
        m_listener.onEvent(event);
      } finally {
        Logging.setContextMap(mdc);
      }
    } catch (Throwable t) {
      LOG.warn("run: an unexpected error occured during ListenerThread {}", m_listener.getName(), t);
    }
  }
}, m_delegateThread);

代码示例来源:origin: OpenNMS/opennms

@Override
  public void run() {
    try {
       if (LOG.isDebugEnabled()) LOG.debug("run: calling onEvent on {} for event {}", m_listener.getName(), event.toStringSimple());
      // Make sure we restore our log4j logging prefix after onEvent is called
      Map<String,String> mdc = Logging.getCopyOfContextMap();
      try {
        m_listener.onEvent(event);
      } finally {
        Logging.setContextMap(mdc);
      }
    } catch (Throwable t) {
      LOG.warn("run: an unexpected error occured during ListenerThread {}", m_listener.getName(), t);
    }
  }
}, m_delegateThread);

代码示例来源:origin: OpenNMS/opennms

/**
 * <p>run</p>
 */
@Override
public void run() {
  final Map<String,String> mdc = Logging.getCopyOfContextMap();
  Logging.putPrefix("vacuumd");
  Date startDate = new Date();
  LOG.debug("Start Scheduled automation {}", this);
  
  if (getAutomation() != null) {
    setReady(false);
    try {
      runAutomation();
    } catch (SQLException e) {
      LOG.warn("Error running automation: {}, {}", getAutomation().getName(), e.getMessage());
    } finally {
      setReady(true);
    }
  }
  LOG.debug("run: Finished automation {}, started at {}", m_automation.getName(), startDate);
  Logging.setContextMap(mdc);
}

代码示例来源:origin: OpenNMS/opennms

/**
 * <p>runReport</p>
 *
 * @param report a {@link org.opennms.netmgt.config.reportd.Report} object.
 */
public void runReport(Report report) {
  Map<String,String> mdc = Logging.getCopyOfContextMap();
  try {
    Logging.putPrefix(NAME);
    LOG.debug("reportd -- running job {}", report.getReportName());
    String fileName = m_reportService.runReport(report,reportDirectory);
    if (report.getRecipients().size() > 0) {
      LOG.debug("reportd -- delivering report {} to {} recipients", report.getReportName(), report.getRecipients().size());
      m_reportDeliveryService.deliverReport(report, fileName);
    } else {
      LOG.info("Skipped delivery of report {} because it has no recipients", report.getReportName());
    }
    LOG.debug("reportd -- done running job {}",report.getReportName());
  } catch (ReportRunException e) {
    createAndSendReportingEvent(EventConstants.REPORT_RUN_FAILED_UEI, report.getReportName(), e.getMessage());
  } catch (ReportDeliveryException e) {
    createAndSendReportingEvent(EventConstants.REPORT_DELIVERY_FAILED_UEI, report.getReportName(), e.getMessage());
  } finally {        
    Logging.setContextMap(mdc);
  }
}

代码示例来源:origin: OpenNMS/opennms

private PollStatus doRun(int timeout) {
  final Map<String, String> mdc = Logging.getCopyOfContextMap();
  try {
    Logging.putThreadContext("service", m_svcName);

代码示例来源:origin: OpenNMS/opennms

final Map<String,String> mdc = Logging.getCopyOfContextMap();
Logging.putPrefix("upgrade");
log("\n==============================================================================\n");

相关文章