KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > ConsumerInfo


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: ConsumerInfo.java,v 1.2 2002/01/29 20:50:17 lizellaman Exp $
25  * $Log: ConsumerInfo.java,v $
26  * Revision 1.2 2002/01/29 20:50:17 lizellaman
27  * Added LoggingInterface, modified the PropertiesInterface implementation
28  *
29  * Revision 1.1.1.1 2001/10/23 13:37:19 lizellaman
30  * initial sourceforge release
31  *
32  */

33
34 package org.datashare;
35
36 import org.datashare.objects.DataShareConnectionDescriptor;
37 import org.datashare.objects.DefaultObjectInfo;
38 import java.util.Date JavaDoc;
39 import java.net.InetAddress JavaDoc;
40
41
42 /**
43  * Holds information about a Consumer.
44  * For a consumer, the active boolean value represents whether or not the
45  * channel a consumer is in has been activated (so the server will send real-time data to it)
46  *
47  * @date March 01, 2001
48  * @author Charles Wood
49  * @version 1.0
50  */

51 public class ConsumerInfo extends DefaultObjectInfo implements PersistDataCallbackInterface
52    {
53    /**
54     * the ClientInfo for this Consumer
55     */

56    protected ClientInfo clientInfo = null;
57
58    /**
59     * the Session this Consumer is in
60     */

61    protected SessionInfo sessionInfo = null;
62
63    /**
64     * The channel this Consumer is in
65     */

66    protected ChannelInfo channelInfo = null;
67
68    /**
69     * Class constructor, should not be used because it leaves attributes with null values
70     * and there are no methods to populate them.
71     */

72    private ConsumerInfo()
73      {
74      originalType = CONSUMERTYPE;
75      }
76
77    /**
78     * Class constructor
79     *
80     */

81    public ConsumerInfo(ClientInfo clientInfo,
82                        SessionInfo sessionInfo,
83                        ChannelInfo channelInfo)
84      {
85      this(); // set the type of DefaultObject and creation time
86
name = clientInfo.getName();
87      toString = clientInfo.getKeyValue();
88      this.keyValue = clientInfo.getKeyValue();
89      this.parentKeyValue = channelInfo.getKeyValue(); // consumer's channel
90
this.grandparentKeyValue = sessionInfo.getKeyValue(); // session channel is in
91
this.clientInfo = clientInfo;
92      this.sessionInfo = sessionInfo;
93      this.channelInfo = channelInfo;
94      this.clientRealName = clientInfo.getClientRealName();
95      this.clientClass = clientInfo.getClientClass();
96      }
97
98    /**
99     * Retrieves a string containing 'Consumer'.
100     *
101     * @return fixed value of 'Consumer' for all instances
102     */

103    public String JavaDoc
104    getType()
105       {
106       return CONSUMERTYPE;
107       }
108
109    /**
110     * Retrieves a description of this instance.
111     *
112     * @return client info
113     */

114    public String JavaDoc
115    getInfo()
116       {
117       return this.clientInfo.getInfo() + "<tr><td>Joined function</td><td>" + this.date.toString() +
118              "</td></tr><tr><td>Consumer activity</td><td>" + (this.getActive()?"Active":"Inactive") + "</td></tr>";
119       }
120
121    /**
122     * the value to use for the key for this instance in the Hashtable of
123     * the Channel's ConsumerInfo instances
124     *
125     */

126    public String JavaDoc
127    getKeyValue()
128       {
129       return clientInfo.getKeyValue(); // this will be unique within our Channel
130
}
131
132    /**
133     * Sets the ADSKey String for this instance to the provided parameter value.
134     * The ADSKey String is the value provided when the EJB was created for this instance.
135     *
136     * @param ak the value to save as the ID for this instance
137     */

138    public void
139    setDatabaseID(String JavaDoc /* ADSKey */ ak)
140       {
141       SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG,
142          SessionUtilities.getLoggingInterface().DATABASE,
143          "setDatabaseID(): EJB Key for " + this.getKeyValue() + " has value of " + ak);
144       databaseID = ak;
145       waitingForKey = false;
146       keyHasBeenReturned = true;
147       }
148
149    /**
150     * Retrieves the ADSKey String for this instance. Should always be checked for null.
151     * Also realize that this method may block until the ADSKey value is available.
152     *
153     * @return the ADSKey String that was previously set for this instance.
154     */

155    public String JavaDoc /* ADSKey */
156    getDatabaseID()
157       {
158       String JavaDoc thisKey = null;
159       if(this.clientInfo.saveData)
160          {
161          if(databaseID != null)
162             thisKey = databaseID;
163          else
164             thisKey = retrieveEJB();
165          }
166       return thisKey;
167       }
168
169    /**
170     * used to return the ClientInfo that corresponds to this Consumer
171     */

172    public ClientInfo
173    getClientInfo()
174       {
175       return this.clientInfo;
176       }
177    }
178
Popular Tags