org.bidib.wizard.gateway.model.node.ProxyNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bidibwizard-gateway Show documentation
Show all versions of bidibwizard-gateway Show documentation
jBiDiB BiDiB Wizard Gateway POM
package org.bidib.wizard.gateway.model.node;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bidib.jbidibc.messages.SequenceNumberProvider;
import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.common.node.Node;
/**
* The {@code ProxyNode} is an extension of a wizard node that has attributes for protocol specific data (sendNum and
* things like that).
*
*/
public class ProxyNode extends Node implements SequenceNumberProvider {
// private static final Logger LOGGER = LoggerFactory.getLogger(ProxyNode.class);
private static final long serialVersionUID = 1L;
private int currentFeature;
private int sendNum;
private int nodeTabVersion = 1;
private int localAddress = 0;
private boolean enabled;
private AtomicBoolean publishFeatures = new AtomicBoolean();
/**
* Create a new node with the associated bidib node.
*
* @param node
* the bidib node is mandatory
* @throws IllegalArgumentException
* if the bidib node is null
*/
public ProxyNode(org.bidib.jbidibc.messages.Node node) {
super(node);
}
/**
* @return the currentFeature
*/
public int getCurrentFeature() {
return currentFeature;
}
/**
* @return the next feature number
*/
public int getNextFeature() {
return currentFeature++;
}
/**
* @param currentFeature
* the currentFeature to set
*/
public void setCurrentFeature(int currentFeature) {
this.currentFeature = currentFeature;
}
/**
* @return the publishFeatures
*/
public AtomicBoolean getPublishFeatures() {
return publishFeatures;
}
/**
* @param publishFeatures
* the publishFeatures to set
*/
public void setPublishFeatures(boolean publishFeatures) {
this.publishFeatures.set(publishFeatures);
}
/**
* Reset the send message number.
*/
public void resetSendNum() {
LOGGER.info("Reset the sendNum to 0.");
sendNum = 0;
}
public int getCurrentSendNum() {
return sendNum;
}
@Override
public int getNextSendMessageNum() {
int nextSendMessageNum = sendNum;
sendNum++;
if (sendNum > 255) {
sendNum = 0;
}
LOGGER.info("Get the nextSendMessageNum: {}", nextSendMessageNum);
return nextSendMessageNum;
}
/**
* @return the nodeTabVersion
*/
public int getNodeTabVersion() {
return nodeTabVersion;
}
/**
* @param nodeTabVersion
* the nodeTabVersion to set
*/
public void setNodeTabVersion(int nodeTabVersion) {
this.nodeTabVersion = nodeTabVersion;
}
/**
* @return the localAddress
*/
public int getLocalAddress() {
return localAddress;
}
/**
* @param localAddress
* the localAddress to set
*/
public void setLocalAddress(int localAddress) {
this.localAddress = localAddress;
}
/**
* @return the enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @param enabled
* the enabled to set
*/
public void setEnabled(boolean enabled) {
LOGGER.info("Update the enabled state for node: {}, enabled: {}", this, enabled);
boolean oldValue = this.enabled;
this.enabled = enabled;
firePropertyChange(PROPERTY_ENABLED, oldValue, enabled);
}
@Override
public boolean equals(Object other) {
LOGGER.debug("equals, other: {}", other);
if (other != null) {
return other.hashCode() == hashCode();
}
return false;
}
@Override
public int hashCode() {
return super.hashCode();
}
/**
* Get the node as {@code ProxyNode} instance.
*
* @param node
* the node
* @return the node as {@code ProxyNode} instance or {@code null} if the node is not a {@code ProxyNode}.
*/
public static ProxyNode getProxyNode(final NodeInterface node) {
if (node instanceof ProxyNode) {
return (ProxyNode) node;
}
throw new IllegalArgumentException("The provided node is not a ProxyNode: " + node);
}
}