KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > SocketAdapter


1 /* ----- BEGIN LICENSE BLOCK -----
2  * Version: MPL 1.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is the DataShare server.
15  *
16  * The Initial Developer of the Original Code is
17  * Ball Aerospace & Technologies Corp, Fairborn, Ohio
18  * Portions created by the Initial Developer are Copyright (C) 2001
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s): Charles Wood <cwood@ball.com>
22  *
23  * ----- END LICENSE BLOCK ----- */

24 /* RCS $Id: SocketAdapter.java,v 1.3 2002/02/04 19:34:57 lizellaman Exp $
25  * $Log: SocketAdapter.java,v $
26  * Revision 1.3 2002/02/04 19:34:57 lizellaman
27  * correct spelling of privilege
28  *
29  * Revision 1.2 2002/01/29 20:50:17 lizellaman
30  * Added LoggingInterface, modified the PropertiesInterface implementation
31  *
32  * Revision 1.1.1.1 2001/10/23 13:37:18 lizellaman
33  * initial sourceforge release
34  *
35  */

36
37 package org.datashare;
38
39 import java.net.InetAddress JavaDoc;
40 import org.datashare.objects.DataShareObject;
41 import java.util.Date JavaDoc;
42 import java.util.GregorianCalendar JavaDoc;
43
44 /**
45  * @date March 01, 2001
46  */

47 public abstract class SocketAdapter
48    {
49    protected String JavaDoc clientKey = ""; // unique string for this sockets client
50
protected String JavaDoc clientClass = "";
51    protected boolean admin = false; // set to true if this client has admin privileges
52
private boolean active = false;
53    protected String JavaDoc keyValue = ""; // uniqe string for this socket
54
protected InetAddress JavaDoc remoteIP = null;
55    protected int remotePort;
56    protected InetAddress JavaDoc localIP = null;
57    protected int localPort;
58    protected DataReceiverInterface dri = null;
59    private Date JavaDoc creationDate = null;
60
61    /**
62     * constructor for abstract class
63     */

64    SocketAdapter()
65       {
66       creationDate = new GregorianCalendar JavaDoc().getTime();
67       }
68
69    /**
70     * call this method when data is to be sent over this connection,
71     * this will buffer the data and schedule it for transmission
72     */

73    abstract void sendData(DataShareObject dsObject);
74
75    /**
76     * this is the method that actually sends the data
77     */

78    abstract void xmitData(DataShareObject dsObject);
79
80    /**
81     * returns the type for this instance, should come from the selections in ChannelDescription class
82     */

83    abstract int getType();
84
85    /**
86     * close the socket, stop any threads, and inform the server
87     */

88    abstract void close();
89
90    /**
91     * returns the data/time this socket was established
92     */

93    Date JavaDoc getCreationDate()
94       {
95       return creationDate;
96       }
97
98    /**
99     * retrieves this sockets client key
100     */

101    String JavaDoc getClientKey()
102       {
103       return clientKey;
104       }
105
106    /**
107     * sets the clientKey (if param is not blank)
108     */

109    void setClientKey(String JavaDoc clientKey)
110       {
111       if(!clientKey.equals(""))
112          this.clientKey = clientKey;
113       }
114
115    /**
116     * retrieves this sockets client class
117     */

118    String JavaDoc getClientClass()
119       {
120       return clientClass;
121       }
122
123    /**
124     * sets the clientClass (if param is not blank)
125     */

126    void setClientClass(String JavaDoc clientClass)
127       {
128       if(!clientClass.equals(""))
129          this.clientClass = clientClass;
130       }
131
132    /**
133     * returns true if client has provided its clientKey (so we know who this connection is for)
134     */

135    boolean getActive()
136       {
137       return active;
138       }
139
140    /**
141     * set to true if the client has sent its client key for this connection
142     */

143    void setActive(boolean active)
144       {
145       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
146          SessionUtilities.getLoggingInterface().NETWORK,
147          "Setting SocketAdapter.active to " + (active?"true":"false") + " for " + this.getKeyValue());
148       this.active = active;
149       }
150
151    /**
152     * set to true if the client has admin privileges
153     */

154    void setAdmin(boolean admin)
155       {
156       this.admin = admin;
157       }
158
159    /**
160     * returns true if client has admin privileges, default if false
161     */

162    boolean getAdmin()
163       {
164       return admin;
165       }
166
167    /**
168     * retrieves this sockets key
169     */

170    String JavaDoc getKeyValue()
171       {
172       return keyValue;
173       }
174
175    /**
176     * sets the keyValue (but only if the parameter is not blank)
177     */

178    void setKeyValue(String JavaDoc keyValue)
179       {
180       if(!keyValue.equals(""))
181          this.keyValue = keyValue;
182       }
183
184    /**
185     * retrieves the remote IP address for this connection
186     */

187    InetAddress JavaDoc getRemoteIP()
188       {
189       return remoteIP;
190       }
191
192    /**
193     * sets the remote IP for this connection
194     */

195    void setRemoteIP(InetAddress JavaDoc remoteIP)
196       {
197       this.remoteIP = remoteIP;
198       }
199
200    /**
201     * retrieves the local address for this connection
202     */

203    InetAddress JavaDoc getLocalIP()
204       {
205       return localIP;
206       }
207
208    /**
209     * sets the local IP for this connection
210     */

211    void setLocalIP(InetAddress JavaDoc localIP)
212       {
213       this.localIP = localIP;
214       }
215
216    /**
217     * retrieves the remote port for this connection
218     */

219    int getRemotePort()
220       {
221       return remotePort;
222       }
223
224    /**
225     * sets the remote port for this connection
226     */

227    void setRemotePort(int remotePort)
228       {
229       this.remotePort = remotePort;
230       }
231
232    /**
233     * retrieves the local port for this connection
234     */

235    int getLocalPort()
236       {
237       return localPort;
238       }
239
240    /**
241     * sets the local port for this connection
242     */

243    void setLocalPort(int localPort)
244       {
245       this.localPort = localPort;
246       }
247    }
248
Popular Tags