/** * Updates the access time for the current connection. Used to keep Connections alive for * long-lived scanners. * @return whether we successfully updated the last access time */ public boolean updateConnectionAccessTime() { String userName = getEffectiveUser(); ConnectionInfo connInfo = connections.get(userName); if (connInfo != null) { return connInfo.updateAccessTime(); } return false; }
/** * Caller doesn't close the admin afterwards. * We need to manage it and close it properly. */ public Admin getAdmin() throws IOException { ConnectionInfo connInfo = getCurrentConnection(); if (connInfo.admin == null) { Lock lock = locker.acquireLock(getEffectiveUser()); try { if (connInfo.admin == null) { connInfo.admin = connInfo.connection.getAdmin(); } } finally { lock.unlock(); } } return connInfo.admin; }
/** * Get the cached connection for the current user. * If none or timed out, create a new one. */ ConnectionInfo getCurrentConnection() throws IOException { String userName = getEffectiveUser(); ConnectionInfo connInfo = connections.get(userName); if (connInfo == null || !connInfo.updateAccessTime()) { Lock lock = locker.acquireLock(userName); try { connInfo = connections.get(userName); if (connInfo == null) { UserGroupInformation ugi = realUser; if (!userName.equals(realUserName)) { ugi = UserGroupInformation.createProxyUser(userName, realUser); } User user = userProvider.create(ugi); Connection conn = ConnectionFactory.createConnection(conf, user); connInfo = new ConnectionInfo(conn, userName); connections.put(userName, connInfo); } } finally { lock.unlock(); } } return connInfo; }
/** * Caller doesn't close the admin afterwards. * We need to manage it and close it properly. */ public Admin getAdmin() throws IOException { ConnectionInfo connInfo = getCurrentConnection(); if (connInfo.admin == null) { Lock lock = locker.acquireLock(getEffectiveUser()); try { if (connInfo.admin == null) { connInfo.admin = connInfo.connection.getAdmin(); } } finally { lock.unlock(); } } return connInfo.admin; }
/** * Get the cached connection for the current user. * If none or timed out, create a new one. */ ConnectionInfo getCurrentConnection() throws IOException { String userName = getEffectiveUser(); ConnectionInfo connInfo = connections.get(userName); if (connInfo == null || !connInfo.updateAccessTime()) { Lock lock = locker.acquireLock(userName); try { connInfo = connections.get(userName); if (connInfo == null) { UserGroupInformation ugi = realUser; if (!userName.equals(realUserName)) { ugi = UserGroupInformation.createProxyUser(userName, realUser); } User user = userProvider.create(ugi); Connection conn = ConnectionFactory.createConnection(conf, user); connInfo = new ConnectionInfo(conn, userName); connections.put(userName, connInfo); } } finally { lock.unlock(); } } return connInfo; }