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: DataShareObject.java,v 1.3 2002/02/20 14:16:59 lizellaman Exp $
025: * $Log: DataShareObject.java,v $
026: * Revision 1.3 2002/02/20 14:16:59 lizellaman
027: * changes to improve history retrieval
028: *
029: * Revision 1.2 2002/01/20 23:33:22 lizellaman
030: * add new 'keepalive' packets for if/when DataShare server decides that a connection has been idle too long
031: *
032: * Revision 1.1.1.1 2001/10/23 13:37:20 lizellaman
033: * initial sourceforge release
034: *
035: */
036:
037: package org.datashare.objects;
038:
039: import java.util.Date;
040:
041: /**
042: * This is the DataShare data object (as a byte array) that is sent between clients/server (ONLY DataShareObjects
043: * are sent between clients and the DataShareServer). It contains info about who the object should be sent to
044: * ('sendToOthers', 'sendToAll', 'sendToClient'- includes a client), but is is only applicable to data channels. This object
045: * can be
046: * sent over the Data or CommandStatus Channels of the DataShare server and clients.
047: */
048: public class DataShareObject implements java.io.Serializable {
049: /**
050: * this allows us to serialize this class without 'marshalling' errors.
051: */
052: static final long serialVersionUID = 9030536576476457607L;
053:
054: public int type;
055: public static final int SENDTOOTHERS = 0;
056: public static final int SENDTOALL = 1;
057: public static final int SENDTOCLIENT = 2;
058: public static final int KEEPALIVE = 9999; // sent by server to clients when TCPSocketTimeout is used and the read has timed out
059:
060: /**
061: * when this instance was created
062: */
063: private Date date;
064:
065: /**
066: * the object that is to sent on to clients (the real data of the object)
067: */
068: public byte[] objectBytes = null;
069:
070: /**
071: * the client that is sending the data
072: */
073: public String sendingClientKey = null;
074:
075: /**
076: * necessary only with SENDTOCLIENT,indicates which client to send data to
077: */
078: public String destinationClientKey = null;
079:
080: /**
081: * set only when this instance is used to pass control information in a Data channel,
082: * such as when this instance contains a RequestHistory object or an ActivateConnectionObject.
083: */
084: public boolean isControlObject = false;
085:
086: /**
087: * set only when this instance is retreived from the history of a channel,
088: * and not when the data has just been generated by an active client
089: */
090: public boolean isFromHistory = false;
091:
092: /**
093: * constructor, used to insert creation time for this instance, do not use for DataShareObjects
094: * used to provide real data
095: */
096: public DataShareObject() {
097: date = new Date(); // new GregorianCalendar().getTime();
098: type = KEEPALIVE;
099: }
100:
101: /**
102: * Constructor, used when creating an object that is going to one specific client
103: */
104: public DataShareObject(byte[] objectBytes,
105: //int sendToClientType,
106: String sendingClientKey, String destinationClientKey) {
107: this (); // makes it clear what is happening
108: this .objectBytes = objectBytes;
109: this .type = this .SENDTOCLIENT; // should be SENDTOCLIENT, etc.
110: this .sendingClientKey = sendingClientKey;
111: this .destinationClientKey = destinationClientKey;
112: }
113:
114: /**
115: * Constructor, used when creating an object that is going to all or others
116: */
117: public DataShareObject(byte[] objectBytes, int type,
118: String sendingClientKey) {
119: this (); // makes it clear what is happening
120: this .objectBytes = objectBytes;
121: this .type = type; // should be SENDTOOTHERS or SENDTOALL
122: this .sendingClientKey = sendingClientKey;
123: }
124:
125: /**
126: * returns the creation date for this instance
127: */
128: public Date getCreationDate() {
129: return date;
130: }
131:
132: }
|