KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > CosTransactions > LogLSN


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28 //----------------------------------------------------------------------------
29
//
30
// Module: LogLSN.java
31
//
32
// Description: Log sequence number.
33
//
34
// Product: com.sun.jts.CosTransactions
35
//
36
// Author: Simon Holdsworth
37
//
38
// Date: March, 1997
39
//
40
// Copyright (c): 1995-1997 IBM Corp.
41
//
42
// The source code for this program is not published or otherwise divested
43
// of its trade secrets, irrespective of what has been deposited with the
44
// U.S. Copyright Office.
45
//
46
// This software contains confidential and proprietary information of
47
// IBM Corp.
48
//----------------------------------------------------------------------------
49

50 package com.sun.jts.CosTransactions;
51
52 // Import required classes
53

54 import java.io.*;
55
56 /**A structure containing 2 unsigned integers.
57  * extent: the extent file number
58  * offset: the offset within the extent file
59  *
60  * @version 0.01
61  *
62  * @author Simon Holdsworth, IBM Corporation
63  *
64  * @see
65 */

66 //----------------------------------------------------------------------------
67
// CHANGE HISTORY
68
//
69
// Version By Change Description
70
// 0.01 SAJH Initial implementation.
71
//-----------------------------------------------------------------------------
72

73 class LogLSN implements Serializable {
74
75     /**Constants for particular LSN values.
76      */

77     static final LogLSN HEAD_LSN = new LogLSN(0xFFFFFFFF, 0xFFFFFFFF);
78     static final LogLSN TAIL_LSN = new LogLSN(0xFFFFFFFF, 0xFFFFFFFE);
79     static final LogLSN NULL_LSN = new LogLSN(0x00000000, 0x00000000);
80     static final LogLSN FIRST_LSN = new LogLSN(0x00000001, 0x00000000);
81
82     /**This constant holds the size of the LogRecordEnding object.
83      */

84     static final int SIZEOF = 8;
85
86     /**Internal instance members.
87      */

88     int offset = 0;
89     int extent = 0;
90
91     /**Default LogLSN constructor
92      *
93      * @param
94      *
95      * @return
96      *
97      * @see
98      */

99     LogLSN() {
100         offset = 0;
101         extent = 0;
102     }
103
104     /**LogLSN constructor
105      *
106      * @param ext Extent for new LSN.
107      * @param off Offset for new LSN.
108      *
109      * @return
110      *
111      * @see
112      */

113     LogLSN( int ext,
114             int off ) {
115         offset = off;
116         extent = ext;
117     }
118
119     /**LogLSN constructor
120      *
121      * @param lsn Other LSN to be copied.
122      *
123      * @return
124      *
125      * @see
126      */

127     LogLSN( LogLSN lsn ) {
128         offset = lsn.offset;
129         extent = lsn.extent;
130     }
131
132     /**Constructs a LogLSN from the given byte array.
133      *
134      * @param bytes The array of bytes from which the LogLSN is to be constructed.
135      * @param index The index in the array where copy is to start.
136      *
137      * @return
138      *
139      * @see
140      */

141     LogLSN( byte[] bytes,
142             int index ) {
143         offset = (bytes[index++]&255) +
144             ((bytes[index++]&255) << 8) +
145             ((bytes[index++]&255) << 16) +
146             ((bytes[index++]&255) << 24);
147         extent = (bytes[index++]&255) +
148             ((bytes[index++]&255) << 8) +
149             ((bytes[index++]&255) << 16) +
150             ((bytes[index++]&255) << 24);
151     }
152
153     /**Determines whether the target LSN is NULL.
154      *
155      * @param
156      *
157      * @return
158      *
159      * @see
160      */

161     final boolean isNULL() {
162         return offset == 0 && extent == 0;
163     }
164
165     /**Determines whether the given LSN is equal to the target.
166      *
167      * @param other The other LogLSN to be compared.
168      *
169      * @return
170      *
171      * @see
172      */

173     final boolean equals( LogLSN other ) {
174         return offset == other.offset && extent == other.extent;
175     }
176
177     /**Determines whether the target LSN is less than the parameter.
178      *
179      * @param other The other LogLSN to be compared.
180      *
181      * @return
182      *
183      * @see
184      */

185     final boolean lessThan( LogLSN other ) {
186         return ( (offset < other.offset && extent == other.extent) ||
187                  extent < other.extent);
188     }
189
190     /**Determines whether the target LSN is greater than the parameter.
191      *
192      * @param other The other LogLSN to be compared.
193      *
194      * @return
195      *
196      * @see
197      */

198     final boolean greaterThan( LogLSN other ) {
199         return ( (offset > other.offset && extent == other.extent) ||
200                  extent > other.extent);
201     }
202
203     /**makes the target LSN a copy of the parameter.
204      *
205      * @param LogLSN The LSN to be copied.
206      *
207      * @return
208      *
209      * @see
210      */

211     final void copy( LogLSN other ) {
212         extent = other.extent;
213         offset = other.offset;
214     }
215
216     /**Makes a byte representation of the LogLSN.
217      *
218      * @param bytes The array of bytes into which the LogLSN is to be copied.
219      * @param index The index in the array where copy is to start.
220      *
221      * @return Number of bytes copied.
222      *
223      * @see
224      */

225     final int toBytes( byte[] bytes,
226                        int index ) {
227         bytes[index++] = (byte) offset;
228         bytes[index++] = (byte)(offset >> 8);
229         bytes[index++] = (byte)(offset >> 16);
230         bytes[index++] = (byte)(offset >> 24);
231         bytes[index++] = (byte) extent;
232         bytes[index++] = (byte)(extent >> 8);
233         bytes[index++] = (byte)(extent >> 16);
234         bytes[index++] = (byte)(extent >> 24);
235
236         return SIZEOF;
237     }
238
239     /**This method is called to direct the object to format its state to a String.
240      *
241      * @param
242      *
243      * @return The formatted representation of the object.
244      *
245      * @see
246      */

247     public final String JavaDoc toString() {
248         return "LSN(ext="/*#Frozen*/+extent+",off="/*#Frozen*/+offset+")"/*#Frozen*/;
249     }
250 }
251
Popular Tags