/** * @param cls Class. * @param e Exception. */ private static void logResolveFailed(Class cls, Exception e) { warn(null, "Failed to resolve IGNITE_HOME automatically for class codebase " + "[class=" + cls + (e == null ? "" : ", e=" + e.getMessage()) + ']'); }
/** * Depending on whether or not log is provided and quiet mode is enabled logs given * messages as quiet message or normal log WARN message. If {@code log} is {@code null} * or in QUIET mode it will add {@code (wrn)} prefix to the message. * * @param log Optional logger to use when QUIET mode is not enabled. * @param msg Message to log. */ public static void warn(@Nullable IgniteLogger log, Object msg) { assert msg != null; String s = msg.toString(); warn(log, s, null); }
/** * Rollbacks JDBC connection logging possible checked exception. * * @param rsrc JDBC connection to rollback. If connection is {@code null}, it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void rollbackConnection(@Nullable Connection rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { rsrc.rollback(); } catch (SQLException e) { warn(log, "Failed to rollback JDBC connection: " + e.getMessage()); } }
/** * Closes given resource logging possible checked exception. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable AutoCloseable rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { rsrc.close(); } catch (Exception e) { warn(log, "Failed to close resource: " + e.getMessage()); } }
/** * Closes given resource logging possible checked exception. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable Context rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { rsrc.close(); } catch (NamingException e) { warn(log, "Failed to close resource: " + e.getMessage()); } }
/** * Closes given resource logging possible checked exception. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable Selector rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { if (rsrc.isOpen()) rsrc.close(); } catch (IOException e) { warn(log, "Failed to close resource: " + e.getMessage()); } }
/** * Closes class loader logging possible checked exception. * * @param clsLdr Class loader. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable URLClassLoader clsLdr, @Nullable IgniteLogger log) { if (clsLdr != null) { try { clsLdr.close(); } catch (Exception e) { warn(log, "Failed to close resource: " + e.getMessage()); } } }
/** * Waits for completion of a given thread. If thread is {@code null} then * this method returns immediately returning {@code true} * * @param t Thread to join. * @param log Logger for logging errors. * @param timeout Join timeout. * @return {@code true} if thread has finished, {@code false} otherwise. */ public static boolean join(@Nullable Thread t, @Nullable IgniteLogger log, long timeout) { if (t != null) { try { t.join(timeout); return !t.isAlive(); } catch (InterruptedException ignore) { warn(log, "Got interrupted while waiting for completion of a thread: " + t); Thread.currentThread().interrupt(); return false; } } return true; }
/** * Joins runnable. * * @param w Worker to join. * @param log The logger to possible exception. * @return {@code true} if worker has not been interrupted, {@code false} if it was interrupted. */ public static boolean join(@Nullable GridWorker w, @Nullable IgniteLogger log) { if (w != null) try { w.join(); } catch (InterruptedException ignore) { warn(log, "Got interrupted while waiting for completion of runnable: " + w); Thread.currentThread().interrupt(); return false; } return true; }
/** * Dumps stack trace of the thread to the given log at warning level. * * @param t Thread to be dumped. * @param log Logger. */ public static void dumpThread(Thread t, @Nullable IgniteLogger log) { ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); GridStringBuilder sb = new GridStringBuilder(); printThreadInfo(mxBean.getThreadInfo(t.getId()), sb, Collections.emptySet()); warn(log, sb.toString()); }
/** * Logs warning message in both verbose and quiet modes. * * @param log Logger to use. * @param shortMsg Short message. * @param msg Message to log. */ public static void quietAndWarn(IgniteLogger log, Object msg, Object shortMsg) { warn(log, msg); if (log.isQuiet()) quiet(false, shortMsg); }
/** * Shutdowns given {@code ExecutorService} and wait for executor service to stop. * * @param owner The ExecutorService owner. * @param exec ExecutorService to shutdown. * @param log The logger to possible exceptions and warnings. */ public static void shutdownNow(Class<?> owner, @Nullable ExecutorService exec, @Nullable IgniteLogger log) { if (exec != null) { List<Runnable> tasks = exec.shutdownNow(); if (!F.isEmpty(tasks)) U.warn(log, "Runnable tasks outlived thread pool executor service [owner=" + getSimpleName(owner) + ", tasks=" + tasks + ']'); try { exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } catch (InterruptedException ignored) { warn(log, "Got interrupted while waiting for executor service to stop."); exec.shutdownNow(); // Preserve interrupt status. Thread.currentThread().interrupt(); } } }
/** * Performs thread dump and prints all available info to the given log. * * @param log Logger. */ public static void dumpThreads(@Nullable IgniteLogger log) { ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); final Set<Long> deadlockedThreadsIds = getDeadlockedThreadIds(mxBean); if (deadlockedThreadsIds.isEmpty()) warn(log, "No deadlocked threads detected."); else warn(log, "Deadlocked threads detected (see thread dump below) " + "[deadlockedThreadsCnt=" + deadlockedThreadsIds.size() + ']'); ThreadInfo[] threadInfos = mxBean.dumpAllThreads(mxBean.isObjectMonitorUsageSupported(), mxBean.isSynchronizerUsageSupported()); GridStringBuilder sb = new GridStringBuilder("Thread dump at ") .a(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z").format(new Date(U.currentTimeMillis()))).a(NL); for (ThreadInfo info : threadInfos) { printThreadInfo(info, sb, deadlockedThreadsIds); sb.a(NL); if (info.getLockedSynchronizers() != null && info.getLockedSynchronizers().length > 0) { printSynchronizersInfo(info.getLockedSynchronizers(), sb); sb.a(NL); } } sb.a(NL); warn(log, sb.toString()); }
/** * @param cls Class. * @param e Exception. */ private static void logResolveFailed(Class cls, Exception e) { warn(null, "Failed to resolve IGNITE_HOME automatically for class codebase " + "[class=" + cls + (e == null ? "" : ", e=" + e.getMessage()) + ']'); }
/** * Depending on whether or not log is provided and quiet mode is enabled logs given * messages as quiet message or normal log WARN message. If {@code log} is {@code null} * or in QUIET mode it will add {@code (wrn)} prefix to the message. * * @param log Optional logger to use when QUIET mode is not enabled. * @param msg Message to log. */ public static void warn(@Nullable IgniteLogger log, Object msg) { assert msg != null; String s = msg.toString(); warn(log, s, null); }
/** * Closes given resource logging possible checked exception. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable Context rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { rsrc.close(); } catch (NamingException e) { warn(log, "Failed to close resource: " + e.getMessage()); } }
/** * Rollbacks JDBC connection logging possible checked exception. * * @param rsrc JDBC connection to rollback. If connection is {@code null}, it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void rollbackConnection(@Nullable Connection rsrc, @Nullable IgniteLogger log) { if (rsrc != null) try { rsrc.rollback(); } catch (SQLException e) { warn(log, "Failed to rollback JDBC connection: " + e.getMessage()); } }
/** * Closes class loader logging possible checked exception. * * @param clsLdr Class loader. If it's {@code null} - it's no-op. * @param log Logger to log possible checked exception with (optional). */ public static void close(@Nullable URLClassLoader clsLdr, @Nullable IgniteLogger log) { if (clsLdr != null) { try { clsLdr.close(); } catch (Exception e) { warn(log, "Failed to close resource: " + e.getMessage()); } } }
/** * Dumps stack trace of the thread to the given log at warning level. * * @param t Thread to be dumped. * @param log Logger. */ public static void dumpThread(Thread t, @Nullable IgniteLogger log) { ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); GridStringBuilder sb = new GridStringBuilder(); printThreadInfo(mxBean.getThreadInfo(t.getId()), sb, Collections.emptySet()); warn(log, sb.toString()); }
/** * Logs warning message in both verbose and quiet modes. * * @param log Logger to use. * @param shortMsg Short message. * @param msg Message to log. */ public static void quietAndWarn(IgniteLogger log, Object msg, Object shortMsg) { warn(log, msg); if (log.isQuiet()) quiet(false, shortMsg); }