KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > UniqueID


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core;
32
33 import org.apache.log4j.Logger;
34
35 /**
36  * <p>
37  * UniqueID is a unique object identifier across all jvm. It is made of a unique VMID combined
38  * with a unique UID on that VM.
39  * </p><p>
40  * The UniqueID is used to identify object globally, even in case of migration.
41  * </p>
42  * @author ProActive Team
43  * @version 1.0, 2001/10/23
44  * @since ProActive 0.9
45  *
46  */

47 public class UniqueID implements java.io.Serializable JavaDoc {
48
49   private java.rmi.server.UID JavaDoc id;
50   private java.rmi.dgc.VMID JavaDoc vmID;
51
52   //the Unique ID of the JVM
53
private static java.rmi.dgc.VMID JavaDoc uniqueVMID = new java.rmi.dgc.VMID JavaDoc();
54   protected static Logger logger = Logger.getLogger(UniqueID.class.getName());
55   //
56
// -- CONSTRUCTORS -----------------------------------------------
57
//
58

59   /**
60    * Creates a new UniqueID
61    */

62   public UniqueID() {
63     this.id = new java.rmi.server.UID JavaDoc();
64     this.vmID = uniqueVMID;
65   }
66
67
68   //
69
// -- PUBLIC STATIC METHODS -----------------------------------------------
70
//
71

72   /**
73    * Returns the VMID of the current VM in which this class has been loaded.
74    * @return the VMID of the current VM
75    */

76   public static java.rmi.dgc.VMID JavaDoc getCurrentVMID() {
77     return uniqueVMID;
78   }
79
80
81
82   //
83
// -- PUBLIC METHODS -----------------------------------------------
84
//
85

86   /**
87    * Returns the VMID of this UniqueID. Note that the VMID of one UniqueID may differ
88    * from the local VMID (that one can get using <code>getCurrentVMID()</code> in case
89    * this UniqueID is attached to an object that has migrated.
90    * @return the VMID part of this UniqueID
91    */

92   public java.rmi.dgc.VMID JavaDoc getVMID() {
93     return vmID;
94   }
95
96
97   /**
98    * Returns the UID part of this UniqueID.
99    * @return the UID part of this UniqueID
100    */

101   public java.rmi.server.UID JavaDoc getUID() {
102     return id;
103   }
104
105
106   /**
107    * Returns a string representation of this UniqueID.
108    * @return a string representation of this UniqueID
109    */

110   public String JavaDoc toString() {
111     return "" + id + " " + vmID;
112   }
113
114
115   /**
116    * Overrides hashCode to take into account the two part of this UniqueID.
117    * @return the hashcode of this object
118    */

119   public int hashCode() {
120     return id.hashCode() + vmID.hashCode();
121   }
122
123
124   /**
125    * Overrides equals to take into account the two part of this UniqueID.
126    * @return the true if and only if o is an UniqueID equals to this UniqueID
127    */

128   public boolean equals(Object JavaDoc o) {
129     //System.out.println("Now checking for equality");
130
if (o instanceof UniqueID) {
131       return ((id.equals(((UniqueID)o).id)) && (vmID.equals(((UniqueID)o).vmID)));
132     } else
133       return false;
134   }
135              
136
137   /**
138    * for debug purpose
139    */

140   public void echo() {
141     logger.info("UniqueID The Id is " + id + " and the address is " + vmID);
142   }
143
144
145 }
146
147
148
Popular Tags