01: /*_############################################################################
02: _##
03: _## SNMP4J-Agent - RequestStatus.java
04: _##
05: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
06: _##
07: _## Licensed under the Apache License, Version 2.0 (the "License");
08: _## you may not use this file except in compliance with the License.
09: _## You may obtain a copy of the License at
10: _##
11: _## http://www.apache.org/licenses/LICENSE-2.0
12: _##
13: _## Unless required by applicable law or agreed to in writing, software
14: _## distributed under the License is distributed on an "AS IS" BASIS,
15: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: _## See the License for the specific language governing permissions and
17: _## limitations under the License.
18: _##
19: _##########################################################################*/
20:
21: package org.snmp4j.agent.request;
22:
23: import java.util.*;
24:
25: import org.snmp4j.mp.*;
26:
27: /**
28: * @author Frank Fock
29: * @version 1.0
30: */
31: public class RequestStatus {
32:
33: private int errorStatus = SnmpConstants.SNMP_ERROR_SUCCESS;
34: private boolean phaseComplete = false;
35: private boolean processed = false;
36: private transient Vector requestStatusListeners;
37:
38: public RequestStatus() {
39: }
40:
41: public int getErrorStatus() {
42: return errorStatus;
43: }
44:
45: public void setErrorStatus(int errorStatus) {
46: this .errorStatus = errorStatus;
47: boolean error = (errorStatus != SnmpConstants.SNMP_ERROR_SUCCESS);
48: setPhaseComplete(error);
49: fireRequestStatusChanged(new RequestStatusEvent(this , this ));
50: }
51:
52: public boolean isPhaseComplete() {
53: return phaseComplete;
54: }
55:
56: public boolean isProcessed() {
57: return processed;
58: }
59:
60: public void setPhaseComplete(boolean completionStatus) {
61: this .phaseComplete = completionStatus;
62: this .processed |= completionStatus;
63: }
64:
65: public void setProcessed(boolean processed) {
66: this .processed = processed;
67: }
68:
69: public synchronized void addRequestStatusListener(
70: RequestStatusListener l) {
71: if (this .requestStatusListeners == null) {
72: this .requestStatusListeners = new Vector(2);
73: }
74: this .requestStatusListeners.add(l);
75: }
76:
77: public synchronized void removeRequestStatusListener(
78: RequestStatusListener l) {
79: if (this .requestStatusListeners != null) {
80: this .requestStatusListeners.remove(l);
81: }
82: }
83:
84: protected void fireRequestStatusChanged(RequestStatusEvent event) {
85: if (requestStatusListeners != null) {
86: Vector listeners = requestStatusListeners;
87: int count = listeners.size();
88: for (int i = 0; i < count; i++) {
89: ((RequestStatusListener) listeners.elementAt(i))
90: .requestStatusChanged(event);
91: }
92: }
93: }
94:
95: }
|