001: /* ----- BEGIN LICENSE BLOCK -----
002: * Version: MPL 1.1
003: *
004: * The contents of this file are subject to the Mozilla Public License Version
005: * 1.1 (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS" basis,
010: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: * for the specific language governing rights and limitations under the
012: * License.
013: *
014: * The Original Code is the DataShare server.
015: *
016: * The Initial Developer of the Original Code is
017: * Ball Aerospace & Technologies Corp, Fairborn, Ohio
018: * Portions created by the Initial Developer are Copyright (C) 2001
019: * the Initial Developer. All Rights Reserved.
020: *
021: * Contributor(s): Charles Wood <cwood@ball.com>
022: *
023: * ----- END LICENSE BLOCK ----- */
024: /* RCS $Id: ConsumerInfo.java,v 1.2 2002/01/29 20:50:17 lizellaman Exp $
025: * $Log: ConsumerInfo.java,v $
026: * Revision 1.2 2002/01/29 20:50:17 lizellaman
027: * Added LoggingInterface, modified the PropertiesInterface implementation
028: *
029: * Revision 1.1.1.1 2001/10/23 13:37:19 lizellaman
030: * initial sourceforge release
031: *
032: */
033:
034: package org.datashare;
035:
036: import org.datashare.objects.DataShareConnectionDescriptor;
037: import org.datashare.objects.DefaultObjectInfo;
038: import java.util.Date;
039: import java.net.InetAddress;
040:
041: /**
042: * Holds information about a Consumer.
043: * For a consumer, the active boolean value represents whether or not the
044: * channel a consumer is in has been activated (so the server will send real-time data to it)
045: *
046: * @date March 01, 2001
047: * @author Charles Wood
048: * @version 1.0
049: */
050: public class ConsumerInfo extends DefaultObjectInfo implements
051: PersistDataCallbackInterface {
052: /**
053: * the ClientInfo for this Consumer
054: */
055: protected ClientInfo clientInfo = null;
056:
057: /**
058: * the Session this Consumer is in
059: */
060: protected SessionInfo sessionInfo = null;
061:
062: /**
063: * The channel this Consumer is in
064: */
065: protected ChannelInfo channelInfo = null;
066:
067: /**
068: * Class constructor, should not be used because it leaves attributes with null values
069: * and there are no methods to populate them.
070: */
071: private ConsumerInfo() {
072: originalType = CONSUMERTYPE;
073: }
074:
075: /**
076: * Class constructor
077: *
078: */
079: public ConsumerInfo(ClientInfo clientInfo, SessionInfo sessionInfo,
080: ChannelInfo channelInfo) {
081: this (); // set the type of DefaultObject and creation time
082: name = clientInfo.getName();
083: toString = clientInfo.getKeyValue();
084: this .keyValue = clientInfo.getKeyValue();
085: this .parentKeyValue = channelInfo.getKeyValue(); // consumer's channel
086: this .grandparentKeyValue = sessionInfo.getKeyValue(); // session channel is in
087: this .clientInfo = clientInfo;
088: this .sessionInfo = sessionInfo;
089: this .channelInfo = channelInfo;
090: this .clientRealName = clientInfo.getClientRealName();
091: this .clientClass = clientInfo.getClientClass();
092: }
093:
094: /**
095: * Retrieves a string containing 'Consumer'.
096: *
097: * @return fixed value of 'Consumer' for all instances
098: */
099: public String getType() {
100: return CONSUMERTYPE;
101: }
102:
103: /**
104: * Retrieves a description of this instance.
105: *
106: * @return client info
107: */
108: public String getInfo() {
109: return this .clientInfo.getInfo()
110: + "<tr><td>Joined function</td><td>"
111: + this .date.toString()
112: + "</td></tr><tr><td>Consumer activity</td><td>"
113: + (this .getActive() ? "Active" : "Inactive")
114: + "</td></tr>";
115: }
116:
117: /**
118: * the value to use for the key for this instance in the Hashtable of
119: * the Channel's ConsumerInfo instances
120: *
121: */
122: public String getKeyValue() {
123: return clientInfo.getKeyValue(); // this will be unique within our Channel
124: }
125:
126: /**
127: * Sets the ADSKey String for this instance to the provided parameter value.
128: * The ADSKey String is the value provided when the EJB was created for this instance.
129: *
130: * @param ak the value to save as the ID for this instance
131: */
132: public void setDatabaseID(String /* ADSKey */ak) {
133: SessionUtilities.getLoggingInterface().debugMsg(
134: SessionUtilities.getLoggingInterface().DEBUG,
135: SessionUtilities.getLoggingInterface().DATABASE,
136: "setDatabaseID(): EJB Key for " + this .getKeyValue()
137: + " has value of " + ak);
138: databaseID = ak;
139: waitingForKey = false;
140: keyHasBeenReturned = true;
141: }
142:
143: /**
144: * Retrieves the ADSKey String for this instance. Should always be checked for null.
145: * Also realize that this method may block until the ADSKey value is available.
146: *
147: * @return the ADSKey String that was previously set for this instance.
148: */
149: public String /* ADSKey */
150: getDatabaseID() {
151: String this Key = null;
152: if (this .clientInfo.saveData) {
153: if (databaseID != null)
154: this Key = databaseID;
155: else
156: this Key = retrieveEJB();
157: }
158: return this Key;
159: }
160:
161: /**
162: * used to return the ClientInfo that corresponds to this Consumer
163: */
164: public ClientInfo getClientInfo() {
165: return this.clientInfo;
166: }
167: }
|