KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > datashare > objects > DataShareObject


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: DataShareObject.java,v 1.3 2002/02/20 14:16:59 lizellaman Exp $
25  * $Log: DataShareObject.java,v $
26  * Revision 1.3 2002/02/20 14:16:59 lizellaman
27  * changes to improve history retrieval
28  *
29  * Revision 1.2 2002/01/20 23:33:22 lizellaman
30  * add new 'keepalive' packets for if/when DataShare server decides that a connection has been idle too long
31  *
32  * Revision 1.1.1.1 2001/10/23 13:37:20 lizellaman
33  * initial sourceforge release
34  *
35  */

36
37 package org.datashare.objects;
38
39 import java.util.Date JavaDoc;
40
41 /**
42  * This is the DataShare data object (as a byte array) that is sent between clients/server (ONLY DataShareObjects
43  * are sent between clients and the DataShareServer). It contains info about who the object should be sent to
44  * ('sendToOthers', 'sendToAll', 'sendToClient'- includes a client), but is is only applicable to data channels. This object
45  * can be
46  * sent over the Data or CommandStatus Channels of the DataShare server and clients.
47  */

48 public class DataShareObject implements java.io.Serializable JavaDoc
49    {
50    /**
51     * this allows us to serialize this class without 'marshalling' errors.
52     */

53    static final long serialVersionUID = 9030536576476457607L;
54
55    public int type;
56    public static final int SENDTOOTHERS = 0;
57    public static final int SENDTOALL = 1;
58    public static final int SENDTOCLIENT = 2;
59    public static final int KEEPALIVE = 9999; // sent by server to clients when TCPSocketTimeout is used and the read has timed out
60

61    /**
62     * when this instance was created
63     */

64    private Date JavaDoc date;
65
66    /**
67     * the object that is to sent on to clients (the real data of the object)
68     */

69    public byte[] objectBytes = null;
70
71    /**
72     * the client that is sending the data
73     */

74    public String JavaDoc sendingClientKey = null;
75
76    /**
77     * necessary only with SENDTOCLIENT,indicates which client to send data to
78     */

79    public String JavaDoc destinationClientKey = null;
80
81    /**
82     * set only when this instance is used to pass control information in a Data channel,
83     * such as when this instance contains a RequestHistory object or an ActivateConnectionObject.
84     */

85    public boolean isControlObject = false;
86
87    /**
88     * set only when this instance is retreived from the history of a channel,
89     * and not when the data has just been generated by an active client
90     */

91    public boolean isFromHistory = false;
92    
93    /**
94     * constructor, used to insert creation time for this instance, do not use for DataShareObjects
95     * used to provide real data
96     */

97    public DataShareObject()
98       {
99       date = new Date JavaDoc(); // new GregorianCalendar().getTime();
100
type = KEEPALIVE;
101       }
102
103    /**
104     * Constructor, used when creating an object that is going to one specific client
105     */

106    public DataShareObject(byte[] objectBytes,
107                           //int sendToClientType,
108
String JavaDoc sendingClientKey,
109                           String JavaDoc destinationClientKey)
110       {
111       this(); // makes it clear what is happening
112
this.objectBytes = objectBytes;
113       this.type = this.SENDTOCLIENT; // should be SENDTOCLIENT, etc.
114
this.sendingClientKey = sendingClientKey;
115       this.destinationClientKey = destinationClientKey;
116       }
117
118    /**
119     * Constructor, used when creating an object that is going to all or others
120     */

121    public DataShareObject(byte[] objectBytes,
122                           int type,
123                           String JavaDoc sendingClientKey)
124       {
125       this(); // makes it clear what is happening
126
this.objectBytes = objectBytes;
127       this.type = type; // should be SENDTOOTHERS or SENDTOALL
128
this.sendingClientKey = sendingClientKey;
129       }
130
131    /**
132     * returns the creation date for this instance
133     */

134    public Date JavaDoc
135    getCreationDate()
136       {
137       return date;
138       }
139
140    }
141
Popular Tags