Skip to content

Commit

Permalink
Temporary removing logic to retrieve application name (#29)
Browse files Browse the repository at this point in the history
* Removed logic to retrieve application name from the OS.

* Update jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java

* Update jdbc/src/main/java/software/amazon/timestream/jdbc/TimestreamDriver.java
  • Loading branch information
alexey-temnikov authored Dec 23, 2022
1 parent cd42056 commit fe9ad68
Showing 1 changed file with 2 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,9 @@ public boolean jdbcCompliant() {
* @return the name of the currently running application.
*/
private static String getApplicationName() {
// What we do is get the process ID of the current process, then check the set of running processes and pick out
// Currently not supported.
// Need to implement logic to get the process ID of the current process, then check the set of running processes and pick out
// the one that matches the current process. From there we can grab the name of what is running the process.
try {
final String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
final boolean isWindows = System.getProperty("os.name").startsWith("Windows");

if (isWindows) {
final Process process = Runtime.getRuntime()
.exec("tasklist /fi \"PID eq " + pid + "\" /fo csv /nh");
try (BufferedReader input = new BufferedReader(
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
final String line = input.readLine();
if (line != null) {
// Omit the surrounding quotes.
return line.substring(1, line.indexOf(",") - 1);
}
}
} else {
final Process process = Runtime.getRuntime().exec("ps -eo pid,comm");
try (BufferedReader input = new BufferedReader(
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = input.readLine()) != null) {
line = line.trim();
if (line.startsWith(pid)) {
return line.substring(line.indexOf(" ") + 1);
}
}
}
}
} catch (Exception err) {
// Eat the exception and fall through.
LOGGER.warning(
"An exception has occurred and ignored while retrieving the caller application name: "
+ err.getLocalizedMessage());
}

return "Unknown";
}

Expand Down

0 comments on commit fe9ad68

Please sign in to comment.