📄 moscalar.java
字号:
MOChangeEvent event =
new MOChangeEvent(this, this, vb.getOid(), getValue(),
vb.getVariable(), false);
fireBeforeMOChange(event);
}
request.setUndoValue(getValue());
changeValue(vb.getVariable());
status.setPhaseComplete(true);
if (moChangeListeners != null) {
MOChangeEvent event =
new MOChangeEvent(this, this, request.getVariableBinding().getOid(),
(Variable)request.getUndoValue(),
vb.getVariable(), false);
fireAfterMOChange(event);
}
}
/**
* Changes the value of this scalar on behalf of a commit or undo operation.
* Overwrite this method for easy and simple instrumentation. By default
* {@link #setValue(Variable value)} is called.
* @param value
* the new value.
* @return
* a SNMP error status if the operation failed (should be avoided).
* @since 1.2
*/
protected int changeValue(Variable value) {
return setValue(value);
}
public void undo(SubRequest request) {
RequestStatus status = request.getStatus();
if ((request.getUndoValue() != null) &&
(request.getUndoValue() instanceof Variable)) {
int errorStatus = changeValue((Variable)request.getUndoValue());
status.setErrorStatus(errorStatus);
status.setPhaseComplete(true);
}
else {
status.setErrorStatus(SnmpConstants.SNMP_ERROR_UNDO_FAILED);
}
}
public void cleanup(SubRequest request) {
request.setUndoValue(null);
request.getStatus().setPhaseComplete(true);
}
/**
* Gets the instance OID of this scalar managed object.
* @return
* the instance OID (by reference).
*/
public OID getOid() {
return oid;
}
public OID getLowerBound() {
if (lowerBound == null) {
lowerBound = new OID(oid.getValue(), 0, oid.size()-1);
}
return lowerBound;
}
public OID getUpperBound() {
if (upperBound == null) {
upperBound = new OID(getLowerBound().nextPeer());
}
return upperBound;
}
public boolean isCovered(MOScope other) {
return (other.getLowerBound().startsWith(oid) &&
(other.getLowerBound().size() > oid.size() ||
other.isLowerIncluded())) &&
(other.getUpperBound().startsWith(oid) &&
((other.getUpperBound().size() > oid.size()) ||
other.isUpperIncluded()));
}
public boolean isLowerIncluded() {
return true;
}
public boolean isUpperIncluded() {
return false;
}
/**
* Returns the actual value of this scalar managed object. For a basic
* instrumentation, overwrite this method to provide always the actual
* value and/or to update the internal <code>value</code> member and
* call <code>super.</code>{@link #getValue()}.
*
* @return
* a non <code>null</code> Variable with the same syntax defined for
* this scalar object.
*/
public Variable getValue() {
return value;
}
public boolean isVolatile() {
return isVolatile;
}
/**
* Sets the value of this scalar managed object without checking it for
* the correct syntax.
* @param value
* a Variable with the with the same syntax defined for
* this scalar object (not checked).
* @return
* a SNMP error code (zero indicating success by default).
*/
public int setValue(Variable value) {
this.value = value;
return SnmpConstants.SNMP_ERROR_SUCCESS;
}
/**
* Sets the volatile flag for this instance.
* @param isVolatile
* if <code>true</code> the state of this object will not be persistently
* stored, otherwise the agent may save the state of this object
* persistently.
*/
public void setVolatile(boolean isVolatile) {
this.isVolatile = isVolatile;
}
public boolean isOverlapping(MOScope other) {
return DefaultMOScope.overlaps(this, other);
}
/**
* Adds a value validation listener to check new values.
* @param l
* a <code>MOValueValidationListener</code> instance.
*/
public synchronized void addMOValueValidationListener(
MOValueValidationListener l) {
if (moValueValidationListeners == null) {
moValueValidationListeners = new Vector(2);
}
moValueValidationListeners.add(l);
}
/**
* Removes a value validation listener
* @param l
* a <code>MOValueValidationListener</code> instance.
*/
public synchronized void removeMOValueValidationListener(
MOValueValidationListener l) {
if (moValueValidationListeners != null) {
moValueValidationListeners.remove(l);
}
}
protected void fireValidate(MOValueValidationEvent validationEvent) {
if (moValueValidationListeners != null) {
Vector listeners = moValueValidationListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
((MOValueValidationListener) listeners.elementAt(i)).validate(
validationEvent);
}
}
}
public OID getID() {
return getOid();
}
public synchronized void load(MOInput input) throws IOException {
Variable v = input.readVariable();
setValue(v);
}
public synchronized void save(MOOutput output) throws IOException {
output.writeVariable(value);
}
public boolean covers(OID oid) {
return oid.startsWith(this.oid);
}
public String toString() {
return getClass().getName()+"[oid="+getOid()+",access="+access+
",value="+getValue()+
",volatile="+isVolatile()+toStringDetails()+"]";
}
protected String toStringDetails() {
return "";
}
/**
* Adds a <code>MOChangeListener</code> that needs to be informed about
* state changes of this scalar.
* @param l
* a <code>MOChangeListener</code> instance.
* @since 1.1
*/
public synchronized void addMOChangeListener(MOChangeListener l) {
if (moChangeListeners == null) {
moChangeListeners = new Vector(2);
}
moChangeListeners.add(l);
}
/**
* Removes a <code>MOChangeListener</code>.
* @param l
* a <code>MOChangeListener</code> instance.
* @since 1.1
*/
public synchronized void removeMOChangeListener(MOChangeListener l) {
if (moChangeListeners != null) {
moChangeListeners.remove(l);
}
}
protected void fireBeforePrepareMOChange(MOChangeEvent changeEvent) {
if (moChangeListeners != null) {
Vector listeners = moChangeListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
((MOChangeListener) listeners.get(i)).beforePrepareMOChange(
changeEvent);
}
}
}
protected void fireAfterPrepareMOChange(MOChangeEvent changeEvent) {
if (moChangeListeners != null) {
Vector listeners = moChangeListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
((MOChangeListener) listeners.get(i)).afterPrepareMOChange(changeEvent);
}
}
}
protected void fireBeforeMOChange(MOChangeEvent changeEvent) {
if (moChangeListeners != null) {
Vector listeners = moChangeListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
((MOChangeListener) listeners.get(i)).beforeMOChange(changeEvent);
}
}
}
protected void fireAfterMOChange(MOChangeEvent changeEvent) {
if (moChangeListeners != null) {
Vector listeners = moChangeListeners;
int count = listeners.size();
for (int i = 0; i < count; i++) {
((MOChangeListener) listeners.get(i)).afterMOChange(changeEvent);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -