Skip to content

Commit

Permalink
0001000: Prevent null pointer if node channel control exists and chan…
Browse files Browse the repository at this point in the history
…nel does not.
  • Loading branch information
chenson42 committed Jan 22, 2013
1 parent 8778393 commit 918c227
Showing 1 changed file with 48 additions and 36 deletions.
Expand Up @@ -239,38 +239,45 @@ public List<NodeChannel> getNodeChannels(final String nodeId, boolean refreshExt
}

if (nodeId != null) {
nodeChannels = sqlTemplate.query(getSql("selectNodeChannelsSql"),
new ISqlRowMapper<NodeChannel>() {
public NodeChannel mapRow(Row row) {
NodeChannel nodeChannel = new NodeChannel();
nodeChannel.setChannelId(row.getString("channel_id"));
nodeChannel.setNodeId(nodeId);
nodeChannel.setIgnoreEnabled(row.getBoolean("ignore_enabled"));
nodeChannel.setSuspendEnabled(row.getBoolean("suspend_enabled"));
nodeChannel.setProcessingOrder(row.getInt("processing_order"));
nodeChannel.setMaxBatchSize(row.getInt("max_batch_size"));
nodeChannel.setEnabled(row.getBoolean("enabled"));
nodeChannel.setMaxBatchToSend(row.getInt("max_batch_to_send"));
nodeChannel.setMaxDataToRoute(row.getInt("max_data_to_route"));
nodeChannel.setUseOldDataToRoute(row
.getBoolean("use_old_data_to_route"));
nodeChannel.setUseRowDataToRoute(row
.getBoolean("use_row_data_to_route"));
nodeChannel.setUsePkDataToRoute(row
.getBoolean("use_pk_data_to_route"));
nodeChannel.setContainsBigLobs(row
.getBoolean("contains_big_lob"));
nodeChannel.setBatchAlgorithm(row.getString("batch_algorithm"));
nodeChannel.setLastExtractTime(row
.getDateTime("last_extract_time"));
nodeChannel.setExtractPeriodMillis(row
.getLong("extract_period_millis"));
nodeChannel.setDataLoaderType(row.getString("data_loader_type"));
return nodeChannel;
};
}, nodeId);
nodeChannelCache.put(nodeId, nodeChannels);
loaded = true;
nodeChannels = sqlTemplate.query(getSql("selectNodeChannelsSql"),
new ISqlRowMapper<NodeChannel>() {
public NodeChannel mapRow(Row row) {
NodeChannel nodeChannel = new NodeChannel();
nodeChannel.setChannelId(row.getString("channel_id"));
nodeChannel.setNodeId(nodeId);
nodeChannel.setIgnoreEnabled(row
.getBoolean("ignore_enabled"));
nodeChannel.setSuspendEnabled(row
.getBoolean("suspend_enabled"));
nodeChannel.setProcessingOrder(row
.getInt("processing_order"));
nodeChannel.setMaxBatchSize(row.getInt("max_batch_size"));
nodeChannel.setEnabled(row.getBoolean("enabled"));
nodeChannel.setMaxBatchToSend(row
.getInt("max_batch_to_send"));
nodeChannel.setMaxDataToRoute(row
.getInt("max_data_to_route"));
nodeChannel.setUseOldDataToRoute(row
.getBoolean("use_old_data_to_route"));
nodeChannel.setUseRowDataToRoute(row
.getBoolean("use_row_data_to_route"));
nodeChannel.setUsePkDataToRoute(row
.getBoolean("use_pk_data_to_route"));
nodeChannel.setContainsBigLobs(row
.getBoolean("contains_big_lob"));
nodeChannel.setBatchAlgorithm(row
.getString("batch_algorithm"));
nodeChannel.setLastExtractTime(row
.getDateTime("last_extract_time"));
nodeChannel.setExtractPeriodMillis(row
.getLong("extract_period_millis"));
nodeChannel.setDataLoaderType(row
.getString("data_loader_type"));
return nodeChannel;
};
}, nodeId);
nodeChannelCache.put(nodeId, nodeChannels);
loaded = true;
} else {
nodeChannels = new ArrayList<NodeChannel>(0);
}
Expand All @@ -279,9 +286,11 @@ public NodeChannel mapRow(Row row) {
}

if (!loaded && refreshExtractMillis) {
// need to read last extracted time from database regardless of
// whether we used the cache or not.
// locate the nodes in the cache, and update it.
/*
* need to read last extracted time from database regardless of
* whether we used the cache or not. locate the nodes in the cache,
* and update it.
*/
final Map<String, NodeChannel> nodeChannelsMap = new HashMap<String, NodeChannel>();

for (NodeChannel nc : nodeChannels) {
Expand All @@ -293,7 +302,10 @@ public NodeChannel mapRow(Row row) {
public Object mapRow(Row row) {
String channelId = row.getString("channel_id");
Date extractTime = row.getDateTime("last_extract_time");
nodeChannelsMap.get(channelId).setLastExtractTime(extractTime);
NodeChannel nodeChannel = nodeChannelsMap.get(channelId);
if (nodeChannel != null) {
nodeChannel.setLastExtractTime(extractTime);
}
return nodeChannelsMap;
};
}, nodeId);
Expand Down

0 comments on commit 918c227

Please sign in to comment.