Skip to content

Commit

Permalink
speed up registration a bit by not reselecting nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 1, 2013
1 parent 9cb2605 commit 72e475b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Expand Up @@ -178,6 +178,8 @@ public void ignoreNodeChannelForExternalId(boolean ignore, String channelId,
* checked in for until it is considered offline
*/
public List<Node> findOfflineNodes(long minutesOffline);

public List<String> findOfflineNodeIds(long minutesOffline);

public void addOfflineServerListener(IOfflineServerListener listener);

Expand Down
Expand Up @@ -914,11 +914,14 @@ protected CsvData selectNext() {
this.targetTable = lookupAndOrderColumnsAccordingToTriggerHistory(
(String) data.getAttribute(CsvData.ATTRIBUTE_ROUTER_ID), history, true);
} else {
this.triggerRouter = this.currentInitialLoadEvent.getTriggerRouter();
NodeChannel channel = batch != null ? configurationService.getNodeChannel(
batch.getChannelId(), false) : new NodeChannel(this.triggerRouter
.getTrigger().getChannelId());
this.routingContext = new SimpleRouterContext(batch.getTargetNodeId(), channel);
this.triggerRouter = this.currentInitialLoadEvent.getTriggerRouter();
if (this.routingContext == null) {
NodeChannel channel = batch != null ? configurationService.getNodeChannel(
batch.getChannelId(), false) : new NodeChannel(this.triggerRouter
.getTrigger().getChannelId());
this.routingContext = new SimpleRouterContext(batch.getTargetNodeId(),
channel);
}
this.sourceTable = lookupAndOrderColumnsAccordingToTriggerHistory(
triggerRouter.getRouter().getRouterId(), history, false);
this.targetTable = lookupAndOrderColumnsAccordingToTriggerHistory(
Expand Down
Expand Up @@ -618,7 +618,6 @@ public List<Node> findOfflineNodes(long minutesOffline) {

List<Row> list = sqlTemplate.query(getSql("findOfflineNodesSql"), new Object[] {
myNode.getNodeId(), myNode.getNodeId()}, (int[])null);

for (Row node : list) {
String nodeId = node.getString("node_id");
Date time = node.getDateTime("heartbeat_time");
Expand All @@ -640,9 +639,43 @@ public List<Node> findOfflineNodes(long minutesOffline) {
}
}
}

log.info("Returning offline list");
return offlineNodeList;
}

public List<String> findOfflineNodeIds(long minutesOffline) {
List<String> offlineNodeList = new ArrayList<String>();
Node myNode = findIdentity();

if (myNode != null) {
long offlineNodeDetectionMillis = minutesOffline * 60 * 1000;

List<Row> list = sqlTemplate.query(getSql("findOfflineNodesSql"), new Object[] {
myNode.getNodeId(), myNode.getNodeId()}, (int[])null);
for (Row node : list) {
String nodeId = node.getString("node_id");
Date time = node.getDateTime("heartbeat_time");
String offset = node.getString("timezone_offset");
// Take the timezone of the client node into account when
// checking the hearbeat time.
Date clientNodeCurrentTime = null;
if (offset != null) {
clientNodeCurrentTime = AppUtils
.getLocalDateForOffset(offset);
} else {
clientNodeCurrentTime = new Date();
}
long cutOffTimeMillis = clientNodeCurrentTime.getTime()
- offlineNodeDetectionMillis;
if (time == null
|| time.getTime() < cutOffTimeMillis) {
offlineNodeList.add(nodeId);
}
}
}
log.info("Returning offline list");
return offlineNodeList;
}

public void setOfflineServerListeners(List<IOfflineServerListener> listeners) {
this.offlineServerListeners = listeners;
Expand Down
Expand Up @@ -58,6 +58,10 @@ public List<String> findAllExternalIds() {
public NetworkedNode getRootNetworkedNode() {
return null;
}

public List<String> findOfflineNodeIds(long minutesOffline) {
return null;
}

public boolean isRegistrationServer() {
return false;
Expand Down

0 comments on commit 72e475b

Please sign in to comment.