KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > core > net > Link


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Coridan.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46 package org.mr.core.net;
47
48 import java.io.IOException JavaDoc;
49
50 import org.mr.core.util.byteable.Byteable;
51 import org.mr.core.util.byteable.ByteableInputStream;
52 import org.mr.core.util.byteable.ByteableOutputStream;
53 import org.mr.core.util.byteable.ByteableRegistry;
54
55
56 public class Link implements Byteable {
57     
58     String JavaDoc protocolType;
59     String JavaDoc localName;
60     String JavaDoc localIP;
61     int localPort;
62     long numberOfMsg;
63     long numberOfBytes;
64
65     String JavaDoc remoteName;
66     String JavaDoc remoteIP;
67     int remotePort;
68     private long fiveMinMessages;
69     private long fiveMinBytes;
70     
71     
72     public Link(){
73
74     }
75     
76     
77     public Link(String JavaDoc protocolType,
78                 String JavaDoc localName,String JavaDoc localIP,int localPort,
79                 String JavaDoc remoteName,String JavaDoc remoteIP,int remotePort,
80                 long numberOfMsg, long numberOfBytes, long fiveMinMessages,
81                 long fiveMinBytes)
82     {
83          this.protocolType = protocolType;
84          this.localName = localName;
85          this.localIP = localIP;
86          this.localPort = localPort;
87         
88          this.remoteName = remoteName;
89          this.remoteIP = remoteIP;
90          this.remotePort = remotePort;
91          this.numberOfMsg = numberOfMsg;
92          this.numberOfBytes = numberOfBytes;
93          this.fiveMinMessages = fiveMinMessages;
94          this.fiveMinBytes = fiveMinBytes;
95     }
96     /**
97      * @return Returns the localPort.
98      */

99     public int getLocalPort() {
100         return localPort;
101     }
102
103     /**
104      * @param localPort The localPort to set.
105      */

106     public void setLocalPort(int localPort) {
107         this.localPort = localPort;
108     }
109
110     /**
111      * @return Returns the remoteIP.
112      */

113     public String JavaDoc getRemoteIP() {
114         return remoteIP;
115     }
116
117     /**
118      * @param remoteIP The remoteIP to set.
119      */

120     public void setRemoteIP(String JavaDoc remoteIP) {
121         this.remoteIP = remoteIP;
122     }
123
124     /**
125      * @return Returns the remoteName.
126      */

127     public String JavaDoc getRemoteName() {
128         return remoteName;
129     }
130
131     /**
132      * @param remoteName The remoteName to set.
133      */

134     public void setRemoteName(String JavaDoc remoteName) {
135         this.remoteName = remoteName;
136     }
137
138     /**
139      * @return Returns the remotePort.
140      */

141     public int getRemotePort() {
142         return remotePort;
143     }
144
145     /**
146      * @param remotePort The remotePort to set.
147      */

148     public void setRemotePort(int remotePort) {
149         this.remotePort = remotePort;
150     }
151
152     /**
153      * @return Returns the type.
154      */

155     public String JavaDoc getProtocolType() {
156         return protocolType;
157     }
158
159     /**
160      * @param type The type to set.
161      */

162     public void setProtocolType(String JavaDoc type) {
163         this.protocolType = type;
164     }
165
166
167     
168     public void setNumOfMsg (long num){
169         numberOfMsg = num;
170     }
171     
172     public void setNumOfBytes (long num){
173         numberOfBytes = num;
174     }
175     
176     
177     public long getNumOfMsg(){
178         return numberOfMsg;
179     }
180     
181     public long getNumOfBytes(){
182         return numberOfBytes;
183     }
184     
185
186
187     public String JavaDoc toString() {
188         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
189         buf.append(protocolType).append(",");
190         buf.append(localName).append(",").append(localIP).append(",").
191             append(localPort).append(",");
192         buf.append(remoteName).append(",").append(remoteIP).append(",").
193             append(remotePort).append(",");
194         buf.append(numberOfMsg).append(",").append(numberOfBytes).append(",").
195             append(fiveMinMessages).append(",").append(fiveMinBytes);
196
197         return buf.toString();
198     }
199     
200     // implementation of interface Byteable
201
public String JavaDoc getByteableName() {
202         return "org.mr.api.console.gui.Link";
203     }
204
205     public void toBytes(ByteableOutputStream out) throws IOException JavaDoc {
206         out.writeASCIIString(this.protocolType);
207         out.writeASCIIString(this.localName);
208         out.writeASCIIString(this.localIP);
209         out.writeInt(this.localPort);
210         out.writeASCIIString(this.remoteName);
211         out.writeASCIIString(this.remoteIP);
212         out.writeInt(this.remotePort);
213         out.writeLong(this.numberOfMsg);
214         out.writeLong(this.numberOfBytes);
215         out.writeLong(this.fiveMinMessages);
216         out.writeLong(this.fiveMinBytes);
217     }
218
219     public Byteable createInstance(ByteableInputStream in) throws IOException JavaDoc {
220         Link l = new Link();
221         l.protocolType = in.readASCIIString();
222         l.localName = in.readASCIIString();
223         l.localIP = in.readASCIIString();
224         l.localPort = in.readInt();
225         l.remoteName = in.readASCIIString();
226         l.remoteIP = in.readASCIIString();
227         l.remotePort = in.readInt();
228         l.numberOfMsg = in.readLong();
229         l.numberOfBytes = in.readLong();
230         l.fiveMinMessages = in.readLong();
231         l.fiveMinBytes = in.readLong();
232         
233         return l;
234     }
235
236     public void registerToByteableRegistry() {
237         ByteableRegistry.registerByteableFactory(getByteableName(), this);
238     }
239
240     public static void register() {
241         Link l = new Link();
242         l.registerToByteableRegistry();
243     }
244     /**
245      * @return Returns the localName.
246      */

247     public String JavaDoc getLocalName() {
248         return localName;
249     }
250     /**
251      * @param localName The localName to set.
252      */

253     public void setLocalName(String JavaDoc localName) {
254         this.localName = localName;
255     }
256     /**
257      * @return Returns the localIP.
258      */

259     public String JavaDoc getLocalIP() {
260         return localIP;
261     }
262     /**
263      * @param localIP The localIP to set.
264      */

265     public void setLocalIP(String JavaDoc localIP) {
266         this.localIP = localIP;
267     }
268     /**
269      * @return Returns the fiveMinBytes.
270      */

271     public long getFiveMinBytes() {
272         return fiveMinBytes;
273     }
274     /**
275      * @return Returns the fiveMinMessages.
276      */

277     public long getFiveMinMessages() {
278         return fiveMinMessages;
279     }
280 }
Popular Tags