Skip to content

Commit

Permalink
OHFJIRA-30 - Nodes evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-havlicek committed Feb 24, 2017
1 parent 634940a commit aefe7c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
Expand Up @@ -163,9 +163,13 @@ public class Message implements HumanReadable {
@Transient
private int processingPriority;

@Column(name = "node_id", nullable = true)
@Column(name = "node_id", nullable = true, insertable = false, updatable = false)
private Long nodeId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "node_id", nullable = true)
private Node node;

/**
* Empty (default) constructor.
*/
Expand Down Expand Up @@ -775,12 +779,23 @@ public Long getNodeId() {
}

/**
* Sets identifier of node that process this message.
* Gets node that process this message.
*
* @return node, {@code NULL} no node process this message
*/
@Nullable
public Node getNode() {
return node;
}

/**
* Sets node that process this message.
*
* @param nodeId node identifier, {@code NULL} no node process this message
* @param node node, {@code NULL} no node process this message
*/
public void setNodeId(@Nullable Long nodeId) {
this.nodeId = nodeId;
public void setNode(@Nullable Node node) {
this.node = node;
this.nodeId = node == null ? null : node.getNodeId();
}

@Override
Expand Down
@@ -1,5 +1,7 @@
package org.openhubframework.openhub.api.entity;

import org.apache.commons.lang3.builder.ToStringBuilder;

/**
* Contains all states for {@link Node}
*
Expand Down Expand Up @@ -63,4 +65,14 @@ public boolean isProcessNewMessages() {
public boolean isProcessExistingMessages() {
return processExistingMessages;
}

//--------------------------------------------- TOSTRING / HASH / EQUALS -------------------------------------------

@Override
public String toString() {
return new ToStringBuilder(this)
.append("processNewMessages", processNewMessages)
.append("processExistingMessages", processExistingMessages)
.toString();
}
}
Expand Up @@ -152,7 +152,7 @@ public void setStateProcessing(Message msg) {
Date currDate = new Date();
msg.setStartProcessTimestamp(currDate);
msg.setLastUpdateTimestamp(currDate);
msg.setNodeId(nodeService.getActualNode().getNodeId());
msg.setNode(nodeService.getActualNode());

messageDao.update(msg);

Expand Down
Expand Up @@ -72,7 +72,7 @@ public final void configure() throws Exception {
.routeId(ROUTE_ID)

// allow only if ESB not stopping
.choice().when().method(ROUTE_BEAN, "isProcessExistingMessage")
.choice().when().method(ROUTE_BEAN, "isProcessingExistingMessage")
.bean("jobStarterForMessagePooling", "start")
.end();
}
Expand All @@ -83,7 +83,7 @@ public final void configure() throws Exception {
* @return {@code true} is process existing message, {@code false} - otherwise
*/
@Handler
public boolean isProcessExistingMessage() {
public boolean isProcessingExistingMessage() {
NodeService nodeService = getApplicationContext().getBean(NodeService.class);

boolean result = nodeService.getActualNode().isProcessExistingMessages();
Expand Down
Expand Up @@ -202,7 +202,7 @@ public boolean updateMessageProcessingUnderLock(Message msg, Node processingNode
Date currDate = new Date();
msg.setStartProcessTimestamp(currDate);
msg.setLastUpdateTimestamp(currDate);
msg.setNodeId(processingNode.getNodeId());
msg.setNode(processingNode);

update(msg);
result = true;
Expand All @@ -224,7 +224,7 @@ public boolean updateMessageInQueueUnderLock(Message msg, Node processingNode) {
Date currDate = new Date();
msg.setStartInQueueTimestamp(currDate);
msg.setLastUpdateTimestamp(currDate);
msg.setNodeId(processingNode.getNodeId());
msg.setNode(processingNode);

update(msg);
result = true;
Expand Down
Expand Up @@ -52,7 +52,7 @@ public class StopController {
public String getStoppingState(ModelMap model) {
addStoppingState(model);

if (isNodesInStopping()) {
if (isAllNodesInStopping()) {
addMsgCounts(model);
}

Expand Down Expand Up @@ -85,7 +85,7 @@ public String cancelStopEsb(ModelMap model) {
}

private void addStoppingState(ModelMap model) {
model.addAttribute("isStopping", isNodesInStopping());
model.addAttribute("isStopping", isAllNodesInStopping());
}

private void addMsgCounts(ModelMap model) {
Expand All @@ -98,7 +98,7 @@ private void addMsgCounts(ModelMap model) {
*
* @return {@code true} all node is in {@link NodeState#STOPPED}, {@code false} - otherwise
*/
private boolean isNodesInStopping() {
private boolean isAllNodesInStopping() {
for (Node node : nodeService.getAllNodes()) {
if (!node.isStopped()) {
return false;
Expand Down

0 comments on commit aefe7c9

Please sign in to comment.