KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > ChannelInfo


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: ChannelInfo.java,v 1.3 2002/02/20 14:10:09 lizellaman Exp $
25  * $Log: ChannelInfo.java,v $
26  * Revision 1.3 2002/02/20 14:10:09 lizellaman
27  * changes to improve history retrieval
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:19 lizellaman
33  * initial sourceforge release
34  *
35  */

36
37 package org.datashare;
38
39
40 import java.util.Date JavaDoc;
41 import java.util.Hashtable JavaDoc;
42 import org.datashare.objects.ChannelDescription;
43 import org.datashare.objects.DefaultObjectInfo;
44 import org.datashare.objects.DataShareConnectionDescriptor;
45
46 /**
47  * Holds information about a Channel. The keyValue for ChannelInfo is the
48  * Channel's name.
49  * Note that this class is not serializable.
50  *
51  * @date March 01, 2001
52  * @author Charles Wood
53  * @version 2.0
54  */

55 public class ChannelInfo extends DefaultObjectInfo implements PersistDataCallbackInterface,
56                                                               java.io.Serializable JavaDoc
57    {
58    /**
59     * this allows us to serialize this class without 'marshalling' errors.
60     *
61     */

62    static final long serialVersionUID = 9030593814524545453L;
63
64    /**
65     *
66     */

67    transient private DataReceiverAdapter dataReceiverAdapter = null;
68
69    /**
70     *
71     */

72    private DataShareConnectionDescriptor connectionDescriptor = null;
73
74    /**
75     * reference to the parent Session, may be null
76     *
77     */

78    transient private SessionInfo parentSession = null; // must be set if this instance retrieved from persistence
79

80    /**
81     * contains all Consumer/Clients for this Channel
82     *
83     */

84    transient private Hashtable JavaDoc consumerTable = new Hashtable JavaDoc(); // ConsumerInfo objects, index by keyValue
85

86    /**
87     * indicates if EJBs should be attempted for this channel, should not be true if server not creating beans
88     *
89     */

90    private boolean saveData = true;
91
92    /**
93     * empty class constuctor
94     *
95     */

96    private ChannelInfo()
97       {
98       originalType = CHANNELTYPE;
99       }
100
101    /**
102     * class constructor, not for general use
103     *
104     * @param name
105     */

106    private ChannelInfo(String JavaDoc name)
107       {
108       this();
109       this.name = name;
110       keyValue = name;
111       toString = name;
112       }
113
114    /**
115     * Class constructor
116     */

117    public ChannelInfo(DataShareConnectionDescriptor connectionDescriptor,
118                       DataReceiverAdapter dataReceiverAdapter,
119                       SessionInfo parentSession,
120                       boolean tryToSaveData)
121       {
122       this(connectionDescriptor.name);
123       this.connectionDescriptor = connectionDescriptor;
124       this.parentSession = parentSession;
125       this.parentKeyValue = parentSession.getKeyValue();
126       this.dataReceiverAdapter = dataReceiverAdapter;
127       this.ownerName = parentSession.getOwnerName();
128       if(connectionDescriptor.channelDescription.allowPersistSelection)
129          this.saveData = connectionDescriptor.channelDescription.persist && tryToSaveData;
130       else
131          this.saveData = false;
132       this.clientClass = parentSession.getClientClass();
133       }
134
135    /**
136     * Retrieves the Channel descriptor (so an instance of a DataShareConnection can be created),
137     * can return a null.
138     */

139    public DataShareConnectionDescriptor
140    getConnectionDescriptor()
141       {
142       return connectionDescriptor;
143       }
144
145    /**
146     * Retrieves the DataReceiverAdapter for this Channel
147     */

148    public DataReceiverAdapter
149    getDataReceiverAdapter()
150       {
151       return dataReceiverAdapter;
152       }
153
154    /**
155     * Retrieves the Channel's parent Session, may be null depending on which
156     * constructor was used to create this instance.
157     *
158     * @return a reference to this Channel's parent Session (may be null)
159     */

160    public SessionInfo
161    getSessionInfo()
162       {
163       return parentSession;
164       }
165
166    /**
167     * Sets the Channel's parent Session, only used when this ChannelInfo instance
168     * is retrieved from persistence because normally the sessionInfo would have been
169     * set by the constructor
170     *
171     * @param sessionInfo reference to this Channel's parent Session
172     */

173    public void
174    setSessionInfo(SessionInfo sessionInfo)
175       {
176       parentSession = sessionInfo;
177       }
178
179    /**
180     * Retrieves an Object reference of this instance, used when this class
181     * is cast to the parent class for common handling of DSObjectInfo objects. May return
182     * null if constructor that does not have Channel as parameter was used to construct this
183     * instance.
184     *
185     * @return the Channel instance as an Object (may be null)
186     */

187    public Object JavaDoc
188    getObject()
189       {
190       return connectionDescriptor;
191       }
192
193    /**
194     * Retrieves a string containing 'Channel'.
195     *
196     * @return fixed value of 'Channel' for all instances, used when this class
197     * is referenced by it's parent class so all subclasses have a common
198     * method that can be used to test for the instance type.
199     */

200    public String JavaDoc
201    getType()
202       {
203       return CHANNELTYPE;
204       }
205
206    /**
207     * Shuts down all the sockets associate with this Channel
208     */

209    public void
210    shutDown()
211       {
212       this.dataReceiverAdapter.removeAllConsumerConnections();
213       this.dataReceiverAdapter.getSocketServer().close();
214       this.setActive(false);
215       }
216
217    /**
218     * Determines what type of HC function this Channel should be used for. The
219     * correct answers are one of the 'supported' HC Functions
220     *
221     * @return the HC Function that would normally use a Channel by this name
222     */

223    public String JavaDoc
224    getFunction()
225       {
226       return name;
227       }
228
229    /**
230     * Retrieves a description of this instance.
231     *
232     * @return information about this instance
233     */

234    public String JavaDoc
235    getInfo()
236       {
237       String JavaDoc filename = "";
238       if(this.connectionDescriptor.channelDescription.channelJarFileName.equals(""))
239          filename = "";
240       else
241          filename = "<tr><td>Jar Filename</td><td>" + this.connectionDescriptor.channelDescription.channelJarFileName + "</td></tr>";
242
243       return "<tr><td>Function Name</td><td>" + this.name + "</td></tr>" +
244              "<tr><td>Description</td><td>" + this.connectionDescriptor.channelDescription.channelDescription + "</td></tr>" +
245              filename +
246              "<tr><td>Socket type</td><td>" + ChannelDescription.validTypes[this.connectionDescriptor.type] + "</td></tr>" +
247              "<tr><td>Server port</td><td>" + this.connectionDescriptor.serverPort + "</td></tr>" +
248              "<tr><td>Data persistance</td><td>" + (this.getSaveDataForThisChannel() ? "Data is " : "Data is not ") + "being saved</td></tr>" +
249              "<tr><td>Allowed to record history</td><td>"+(this.connectionDescriptor.channelDescription.allowPersistSelection? "Yes":"No") +"</td></tr>" +
250              "<tr><td>Creation date</td><td>" + this.getDate().toString() +"</td></tr>";
251       }
252
253    /**
254     * adds a Client/Consumer to this Channel
255     *
256     * @param consumer the consumer to add
257     */

258    public void
259    addConsumerClient(ConsumerInfo consumer)
260       {
261       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
262          SessionUtilities.getLoggingInterface().CLIENT,
263          "channelInfo.addConsumerClient (" + consumer.getKeyValue() +
264          ") to Session " + this.parentSession.getName() + ", Channel " +
265          this.toString() + " table of Consumers");
266
267       // if this object was retrieved from persistenceInterface, the table will be null the first time...
268
if(consumerTable == null)
269          consumerTable = new Hashtable JavaDoc();
270
271       consumerTable.put(consumer.getKeyValue(), consumer);
272       }
273
274    /**
275     * removes a Client/Consumer from this Channel
276     *
277     * @param consumer the consumer to remove
278     */

279    public void
280    removeConsumerClient(ConsumerInfo consumer)
281       {
282       // make sure connections are gone/closed
283
this.dataReceiverAdapter.removeConsumerConnection(consumer.getKeyValue());
284
285       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
286          SessionUtilities.getLoggingInterface().CLIENT,
287          "Removing consumer (" + consumer.getKeyValue() +
288          ") from Session " + this.parentSession.getName() + ", Channel " +
289          this.toString() + " ChannelInfo table of consumers");
290       consumerTable.remove(consumer.getKeyValue());
291       }
292
293    /**
294     * checks to see if a Consumer is already in this Channel
295     */

296    public boolean
297    checkForConsumer(ConsumerInfo consumer)
298       {
299       boolean retValue = false;
300       if(consumerTable.contains(consumer.getKeyValue()))
301          retValue = true;
302       return retValue;
303       }
304
305    /**
306     * returns the Hashtable of Consumers for this Channel
307     *
308     * @return the list of consumers, keyed by name
309     */

310    public Hashtable JavaDoc
311    getConsumerTable()
312       {
313       return consumerTable;
314       }
315
316    /**
317     * sets the indicator for whether or not EJBs should be used for this Channel's Data.
318     * Default value is true.
319     *
320     * @param useBeans true if beans are to be used, false otherwise
321     */

322    public void
323    setSaveDataForThisChannel(boolean saveData)
324       {
325       this.saveData = saveData;
326       }
327
328    /**
329     * returns an indicator for whether or not EJBs are saved for this Channel's data
330     *
331     * @return returns true if beans are in use for this channel
332     */

333    public boolean
334    getSaveDataForThisChannel()
335       {
336       return saveData;
337       }
338
339    /**
340     * Sets the ADSKey String for this instance to the provided parameter value.
341     * The ADSKey String is the value provided when the EJB was created for this instance.
342     *
343     * @param ak the value to save as the ID for this instance
344     */

345    public void
346    setDatabaseID(String JavaDoc /* ADSKey */ ak)
347       {
348       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
349          SessionUtilities.getLoggingInterface().DATABASE,
350          "setDatabaseID(): EJB Key for " + this.getKeyValue() + " has value of " + ak);
351       databaseID = ak;
352       waitingForKey = false;
353       keyHasBeenReturned = true;
354       }
355
356    /**
357     * Retrieves the ADSKey String for this instance. Should always be checked for null.
358     * Also realize that this method may block until the ADSKey value is available.
359     *
360     * @return the ADSKey String that was previously set for this instance.
361     */

362    public String JavaDoc /* ADSKey */
363    getDatabaseID()
364       {
365       String JavaDoc thisKey = null;
366       if(this.saveData)
367          if(this.databaseID != null)
368             thisKey = databaseID;
369          else
370             thisKey = retrieveEJB();
371       return thisKey;
372       }
373
374    }
375
Popular Tags