KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > netbios > server > NetBIOSRequest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.netbios.server;
18
19 import org.alfresco.filesys.netbios.NetBIOSName;
20
21 /**
22  * NetBIOS Request Class
23  * <p>
24  * Contains the details of NetBIOS server request, such as an add name request.
25  */

26 class NetBIOSRequest
27 {
28
29     // Request types
30

31     public final static int AddName = 0;
32     public final static int DeleteName = 1;
33     public final static int RefreshName = 2;
34
35     // Default retry count and interval
36

37     public final static int DefaultRetries = 5;
38     public final static long DefaultInterval = 2000; // ms
39

40     // Requets type strings
41

42     private final static String JavaDoc[] _typeNames = { "AddName", "DelName", "RefreshName" };
43
44     // Request type
45

46     private int m_type;
47
48     // NetBIOS name details
49

50     private NetBIOSName m_nbName;
51
52     // Retry count and interval
53

54     private int m_retry;
55     private long m_retryIntvl;
56
57     // Response status
58

59     private boolean m_error;
60
61     // Transaction id for this request
62

63     private int m_tranId;
64
65     /**
66      * Class constructor
67      *
68      * @param typ int
69      * @param nbName NetBIOSName
70      * @param tranId int
71      */

72     public NetBIOSRequest(int typ, NetBIOSName nbName, int tranId)
73     {
74         m_type = typ;
75         m_nbName = nbName;
76         m_tranId = tranId;
77
78         m_retry = DefaultRetries;
79         m_retryIntvl = DefaultInterval;
80
81         m_error = false;
82     }
83
84     /**
85      * Class constructor
86      *
87      * @param typ int
88      * @param nbName NetBIOSName
89      * @param tranId int
90      * @param retry int
91      */

92     public NetBIOSRequest(int typ, NetBIOSName nbName, int tranId, int retry)
93     {
94         m_type = typ;
95         m_nbName = nbName;
96         m_tranId = tranId;
97
98         m_retry = retry;
99         m_retryIntvl = DefaultInterval;
100
101         m_error = false;
102     }
103
104     /**
105      * Return the request type
106      *
107      * @return int
108      */

109     public final int isType()
110     {
111         return m_type;
112     }
113
114     /**
115      * Return the type as a string
116      *
117      * @return String
118      */

119     public final String JavaDoc getTypeAsString()
120     {
121         if (m_type < 0 || m_type >= _typeNames.length)
122             return "";
123         return _typeNames[m_type];
124     }
125
126     /**
127      * Return the NetBIOS name details
128      *
129      * @return NetBIOSName
130      */

131     public final NetBIOSName getNetBIOSName()
132     {
133         return m_nbName;
134     }
135
136     /**
137      * Return the retry count
138      *
139      * @return int
140      */

141     public final int getRetryCount()
142     {
143         return m_retry;
144     }
145
146     /**
147      * Return the retry interval
148      *
149      * @return long
150      */

151     public final long getRetryInterval()
152     {
153         return m_retryIntvl;
154     }
155
156     /**
157      * Return the transaction id
158      *
159      * @return int
160      */

161     public final int getTransactionId()
162     {
163         return m_tranId;
164     }
165
166     /**
167      * Check if the request has an error status
168      *
169      * @return boolean
170      */

171     public final boolean hasErrorStatus()
172     {
173         return m_error;
174     }
175
176     /**
177      * Decrement the retry count
178      *
179      * @return int
180      */

181     protected final int decrementRetryCount()
182     {
183         return m_retry--;
184     }
185
186     /**
187      * Set the error status
188      *
189      * @param sts boolean
190      */

191     protected final void setErrorStatus(boolean sts)
192     {
193         m_error = sts;
194     }
195
196     /**
197      * Set the request retry count
198      *
199      * @param retry int
200      */

201     public final void setRetryCount(int retry)
202     {
203         m_retry = retry;
204     }
205
206     /**
207      * Set the retry interval, in milliseconds
208      *
209      * @param interval long
210      */

211     public final void setRetryInterval(long interval)
212     {
213         m_retryIntvl = interval;
214     }
215
216     /**
217      * Return the request as a string
218      *
219      * @return String
220      */

221     public String JavaDoc toString()
222     {
223         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
224
225         str.append("[");
226         str.append(getTypeAsString());
227         str.append(":");
228         str.append(getNetBIOSName());
229         str.append(",");
230         str.append(getRetryCount());
231         str.append(",");
232         str.append(getRetryInterval());
233         str.append(",");
234         str.append(getTransactionId());
235         str.append("]");
236
237         return str.toString();
238     }
239 }
240
Popular Tags