public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) { if (minEvictableIdleTimeMillis < 1000 * 30) { LOG.error("minEvictableIdleTimeMillis should be greater than 30000"); } this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; }
Properties loadPropertyFromConfigFile(Properties connectionProperties) { String configFile = connectionProperties.getProperty(CONFIG_FILE); if (configFile == null) { configFile = System.getProperty(SYS_PROP_CONFIG_FILE); } if (configFile != null && configFile.length() > 0) { if (LOG.isInfoEnabled()) { LOG.info("DruidDataSource Config File load from : " + configFile); } Properties info = loadConfig(configFile); if (info == null) { throw new IllegalArgumentException("Cannot load remote config file from the [config.file=" + configFile + "]."); } return info; } return null; }
@Override public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { if (server != null) { try { if (server.isRegistered(name)) { server.unregisterMBean(name); } } catch (Exception ex) { LOG.warn("DruidDataSource preRegister error", ex); } } return name; }
public Map<String, DataSource> createMap(HighAvailableDataSource haDataSource) throws SQLException { Map<String, DataSource> map = new ConcurrentHashMap<String, DataSource>(); if (nameList == null || nameList.isEmpty()) { LOG.error("No DataSource will be created!"); return map; } for (String n : nameList) { String url = properties.getProperty(n + ".url"); String username = properties.getProperty(n + ".username"); String password = properties.getProperty(n + ".password"); LOG.info("Creating " + n + " with url[" + url + "] and username[" + username + "]."); DruidDataSource dataSource = create(n, url, username, password, haDataSource); map.put(n, dataSource); } LOG.info(map.size() + " DruidDataSource(s) created. "); return map; }
LOG.debug("Trying to load " + file + " from FileSystem."); is = new FileInputStream(file); } catch(FileNotFoundException e) { LOG.debug("Trying to load " + file + " from Classpath."); try { is = DataSourceCreator.class.getResourceAsStream(file); } catch (Exception ex) { LOG.warn("Can not load resource " + file, ex); this.properties = properties; } catch(Exception e) { LOG.error("Exception occurred while loading " + file, e); } finally { if (is != null) { LOG.warn("File " + file + " can't be loaded!");
holder = new DruidConnectionHolder(this, pyConnInfo); } catch (SQLException e) { LOG.error("fill connection error, url: " + this.jdbcUrl, e); connectErrorCountUpdater.incrementAndGet(this); throw e; if (!this.isFillable(toCount)) { JdbcUtils.close(holder.getConnection()); LOG.info("fill connections skip."); break; if (LOG.isInfoEnabled()) { LOG.info("fill " + fillCount + " connections");
LOG.warn("connectionHolder is null"); return; LOG.warn("get/close not same thread"); if (LOG.isWarnEnabled()) { LOG.warn("remove abandonded failed. activeConnections.size " + activeConnections.size()); LOG.info("connection recyle failed."); LOG.error("recyle error", e); recycleErrorCountUpdater.incrementAndGet(this);
physicalConnection.close(); } catch (Exception ex) { LOG.warn("close connection error", ex); if (LOG.isInfoEnabled()) { LOG.info("{dataSource-" + this.getID() + "} closed");
if (notFullTimeoutRetryCnt <= this.notFullTimeoutRetryCount && !isFull()) { notFullTimeoutRetryCnt++; if (LOG.isWarnEnabled()) { LOG.warn("get connection timeout retry : " + notFullTimeoutRetryCnt); boolean validate = testConnectionInternal(poolableConnection.holder, poolableConnection.conn); if (!validate) { if (LOG.isDebugEnabled()) { LOG.debug("skip not validate connection."); boolean validate = testConnectionInternal(poolableConnection.holder, poolableConnection.conn); if (!validate) { if (LOG.isDebugEnabled()) { LOG.debug("skip not validate connection.");
wr.flush(); if (LOG.isDebugEnabled()) { reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); responseBuilder = new StringBuilder(); responseBuilder.append(line).append("\n"); LOG.debug(responseBuilder.toString()); LOG.error("", e); } finally { wr.close(); } catch (IOException e) { LOG.error("close error", e); reader.close(); } catch (IOException e) { LOG.error("close error", e);
/** * 调用service,返回数据 * * @param url service的地址 * @param conn MBeanServerConnection对象 * @return 调用service后返回的数据 * @throws Exception */ public static Object getData(String url, MBeanServerConnection conn) throws Exception { Object o = null; ObjectName name = new ObjectName(DruidStatService.MBEAN_NAME); String result = (String) conn.invoke(name, "service", new String[] { url }, new String[] { String.class.getName() }); o = JSONUtils.parse(result); if (LOG.isDebugEnabled()) { LOG.debug(o.toString()); } return o; }
LOG.warn("connectionHolder is null"); return; LOG.warn("get/close not same thread"); Object oldInfo = activeConnections.remove(pooledConnection); if (oldInfo == null) { if (LOG.isWarnEnabled()) { LOG.warn("remove abandonded failed. activeConnections.size " + activeConnections.size()); LOG.error("recyle error", e); recycleErrorCount.incrementAndGet();
public static boolean registerDriver(Driver driver) { try { DriverManager.registerDriver(driver); try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(MBEAN_NAME); if (!mbeanServer.isRegistered(objectName)) { mbeanServer.registerMBean(instance, objectName); } } catch (Exception ex) { getLog().warn("register druid-driver mbean error", ex); } return true; } catch (Exception e) { getLog().error("registerDriver error", e); } return false; }
killQueryStmt.execute(killQuery); if (LOG.isDebugEnabled()) { LOG.debug(killQuery + " success."); LOG.warn(killQuery + " error.", ex); } finally { JdbcUtils.close(killQueryStmt);
public void log(String value) { logger.info(value); }
private void tryOneDataSource(DruidDataSource dataSource) { if (dataSource == null) { return; } Connection connection = null; try { connection = dataSource.getConnection(); dataSource.validateConnection(connection); LOG.info(dataSource.getName() + " is available now."); selector.removeBlacklist(dataSource); } catch(Exception e) { LOG.warn("DataSource[" + dataSource.getName() + "] is still unavailable. Exception: " + e.getMessage()); if (connection != null) { dataSource.discardConnection(connection); } } finally { JdbcUtils.close(connection); } }
public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException { int notFullTimeoutRetryCnt = 0; for (; ; ) { // handle notFullTimeoutRetry DruidPooledConnection poolableConnection; try { poolableConnection = getConnectionInternal(maxWaitMillis); } catch (GetConnectionTimeoutException ex) { if (notFullTimeoutRetryCnt <= this.notFullTimeoutRetryCount && !isFull()) { notFullTimeoutRetryCnt++; if (LOG.isWarnEnabled()) { LOG.warn("not full timeout retry : " + notFullTimeoutRetryCnt); } continue; } throw ex; } if (isRemoveAbandoned()) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); poolableConnection.setConnectStackTrace(stackTrace); poolableConnection.setConnectedTimeNano(); poolableConnection.setTraceEnable(true); synchronized (activeConnections) { activeConnections.put(poolableConnection, PRESENT); } } return poolableConnection; } }
private boolean check(String name, DruidDataSource dataSource) { boolean result = true; Driver driver = dataSource.getRawDriver(); Properties info = new Properties(dataSource.getConnectProperties()); String username = dataSource.getUsername(); String password = dataSource.getPassword(); String url = dataSource.getUrl(); // We can't use rawUrl here, because the schema maybe set in url. Connection conn = null; if (info.getProperty("user") == null && username != null) { info.setProperty("user", username); } if (info.getProperty("password") == null && password != null) { info.setProperty("password", password); } try { LOG.debug("Validating " + name + " every " + sleepSeconds + " seconds."); conn = driver.connect(url, info); dataSource.validateConnection(conn); } catch (SQLException e) { LOG.warn("Validation FAILED for " + name + " with url [" + url + "] and username [" + info.getProperty("user") + "]. Exception: " + e.getMessage()); result = false; } finally { JdbcUtils.close(conn); } return result; }
public String getPrincipal(HttpServletRequest httpRequest) { if (principalSessionName != null) { HttpSession session = httpRequest.getSession(createSession); if (session == null) { return null; } Object sessionValue = null; try { sessionValue = session.getAttribute(principalSessionName); } catch (Exception ex) { if (LOG.isErrorEnabled()) { LOG.error("session.getAttribute error", ex); } } if (sessionValue == null) { return null; } return sessionValue.toString(); } if (principalCookieName != null && httpRequest.getCookies() != null) { for (Cookie cookie : httpRequest.getCookies()) { if (principalCookieName.equals(cookie.getName())) { return cookie.getValue(); } } } return null; }
public boolean isLogEnable() { return logger.isInfoEnabled(); }