Skip to content

Commit

Permalink
Fix for SQL SELECT being issued even though nflow.autostart=false.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttiurani committed Aug 15, 2017
1 parent 012a32a commit 14cb185
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.sql.SQLException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.joda.time.DateTime;
Expand Down Expand Up @@ -55,7 +54,7 @@ public class ExecutorDao {
String executorGroupCondition;
int timeoutSeconds;
int executorId = -1;
int hostMaxLength;
int hostMaxLength = -1;

@Inject
public void setEnvironment(Environment env) {
Expand All @@ -75,9 +74,11 @@ public void setJdbcTemplate(@NFlow JdbcTemplate nflowJdbcTemplate) {
this.jdbc = nflowJdbcTemplate;
}

@PostConstruct
public void findHostMaxLength() {
hostMaxLength = jdbc.query("select host from nflow_executor where 1 = 0", firstColumnLengthExtractor);
private int getHostMaxLength() {
if (hostMaxLength == -1) {
hostMaxLength = jdbc.query("select host from nflow_executor where 1 = 0", firstColumnLengthExtractor);
}
return hostMaxLength;
}

private static String createWhereCondition(String group) {
Expand Down Expand Up @@ -123,7 +124,7 @@ private int allocateExecutorId() {
final String host;
final int pid;
try {
host = left(getLocalHost().getCanonicalHostName(), hostMaxLength);
host = left(getLocalHost().getCanonicalHostName(), getHostMaxLength());
pid = Integer.parseInt(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
} catch (UnknownHostException | NumberFormatException ex) {
throw new RuntimeException("Failed to obtain host name and pid of running jvm", ex);
Expand Down

0 comments on commit 14cb185

Please sign in to comment.