KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > request > RequestStatus


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - RequestStatus.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## 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
22 package org.snmp4j.agent.request;
23
24 import java.util.*;
25
26 import org.snmp4j.mp.*;
27
28 /**
29  * @author Frank Fock
30  * @version 1.0
31  */

32 public class RequestStatus {
33
34   private int errorStatus = SnmpConstants.SNMP_ERROR_SUCCESS;
35   private boolean phaseComplete = false;
36   private boolean processed = false;
37   private transient Vector requestStatusListeners;
38
39   public RequestStatus() {
40   }
41
42   public int getErrorStatus() {
43     return errorStatus;
44   }
45
46   public void setErrorStatus(int errorStatus) {
47     this.errorStatus = errorStatus;
48     boolean error = (errorStatus != SnmpConstants.SNMP_ERROR_SUCCESS);
49     setPhaseComplete(error);
50     fireRequestStatusChanged(new RequestStatusEvent(this, this));
51   }
52
53   public boolean isPhaseComplete() {
54     return phaseComplete;
55   }
56
57   public boolean isProcessed() {
58     return processed;
59   }
60
61   public void setPhaseComplete(boolean completionStatus) {
62     this.phaseComplete = completionStatus;
63     this.processed |= completionStatus;
64   }
65
66   public void setProcessed(boolean processed) {
67     this.processed = processed;
68   }
69
70   public synchronized void addRequestStatusListener(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(RequestStatusListener l) {
78     if (this.requestStatusListeners != null) {
79       this.requestStatusListeners.remove(l);
80     }
81   }
82
83   protected void fireRequestStatusChanged(RequestStatusEvent event) {
84     if (requestStatusListeners != null) {
85       Vector listeners = requestStatusListeners;
86       int count = listeners.size();
87       for (int i = 0; i < count; i++) {
88         ((RequestStatusListener) listeners.elementAt(i)).requestStatusChanged(
89             event);
90       }
91     }
92   }
93
94 }
95
Popular Tags