OSDN Git Service

* java/rmi/activation/Activatable.java,
[pf3gnuchains/gcc-fork.git] / libjava / java / rmi / server / ObjID.java
1 /*
2   Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 As a special exception, if you link this library with other files to
22 produce an executable, this library does not by itself cause the
23 resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why the
25 executable file might be covered by the GNU General Public License.
26  */
27
28 package java.rmi.server;
29
30 import java.io.Serializable;
31 import java.io.ObjectOutput;
32 import java.io.ObjectInput;
33 import java.io.IOException;
34 import java.lang.Math;
35 import java.io.DataInput;
36 import java.io.DataOutput;
37 import java.util.Random;
38
39 public final class ObjID
40         implements Serializable {
41
42 static final long serialVersionUID = -6386392263968365220L;
43
44 private static long next = 0x8000000000000000L;
45 private static final Object lock = ObjID.class;
46
47 public static final int REGISTRY_ID = 0;
48 public static final int ACTIVATOR_ID = 1;
49 public static final int DGC_ID = 2;
50
51 private long objNum;
52 private UID space;
53
54 public ObjID() {
55         synchronized (lock) {
56                 objNum = next++;
57         }
58         space = new UID();
59 }
60
61 public ObjID(int num) {
62         objNum = (long)num;
63         space = new UID((short)0);
64 }
65
66 public void write(ObjectOutput out) throws IOException {
67         DataOutput dout = (DataOutput)out;
68         dout.writeLong(objNum);
69         space.write(dout);
70 }
71
72 public static ObjID read(ObjectInput in) throws IOException {
73         DataInput din = (DataInput)in;
74         ObjID id = new ObjID();
75         id.objNum = din.readLong();
76         id.space = UID.read(din);
77         return (id);
78 }
79
80 public int hashCode() {
81         return ((int)objNum);
82 }
83
84 public boolean equals(Object obj) {
85         if (obj instanceof ObjID && this.objNum == ((ObjID)obj).objNum) {
86                 return (true);
87         }
88         return (false);
89 }
90
91 public String toString() {
92         return ("[objNum: " + objNum + ", " + space + "]");
93 }
94
95 }