KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > protocol > ProcessImpl


1 /**
2  * Dream
3  * Copyright (C) 2003 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: vivien.quema@inrialpes.fr
20  *
21  * Initial developer(s): Vivien Quema
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.protocol;
26
27 import java.io.IOException JavaDoc;
28 import java.io.ObjectInput JavaDoc;
29 import java.io.ObjectOutput JavaDoc;
30 import java.io.Serializable JavaDoc;
31
32 /**
33  * Implementation of the {@link Process}interface. This class can be overriden
34  * to produce customized processes for particular protocols.
35  */

36 public class ProcessImpl implements Cloneable JavaDoc,
37  // Externalizable,
38
Serializable JavaDoc, Process JavaDoc, Comparable JavaDoc
39 {
40
41   // TODO change for transient
42
/**
43    * Identifier of the process.
44    */

45   protected short id;
46
47   /**
48    * Allocates a new ProcessImpl object.
49    *
50    * @param id the identifier of the process
51    */

52   public ProcessImpl(short id)
53   {
54     this.id = id;
55   }
56
57   // ---------------------------------------------------------------------------
58
// Implementation of the Process interface
59
// ---------------------------------------------------------------------------
60

61   /**
62    * Returns the identifier of the process.
63    *
64    * @return the identifier of the process.
65    */

66   public final short getId()
67   {
68     return id;
69   }
70
71   /**
72    * @see org.objectweb.dream.protocol.Process#setId(short)
73    */

74   public void setId(short id)
75   {
76     this.id = id;
77   }
78
79   /**
80    * @see java.lang.Object#clone()
81    */

82   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc
83   {
84     return super.clone();
85   }
86
87   // ---------------------------------------------------------------------------
88
// Implementation of the Externalizable interface
89
// ---------------------------------------------------------------------------
90

91   /**
92    * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
93    */

94   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
95   {
96     out.writeShort(id);
97   }
98
99   /**
100    * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
101    */

102   public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc,
103       ClassNotFoundException JavaDoc
104   {
105     id = in.readShort();
106   }
107
108   // ---------------------------------------------------------------------------
109
// Overriden methods
110
// ---------------------------------------------------------------------------
111

112   /**
113    * @see java.lang.Object#equals(java.lang.Object)
114    */

115   public boolean equals(Object JavaDoc arg0)
116   {
117     if (arg0 instanceof Process JavaDoc)
118     {
119       boolean res = ((ProcessImpl JavaDoc) arg0).id == id;
120       return res;
121     }
122     else
123     {
124       return false;
125     }
126   }
127
128   /**
129    * @see java.lang.Object#hashCode()
130    */

131   public int hashCode()
132   {
133     return id;
134   }
135
136   // ---------------------------------------------------------------------------
137
// Implementation of the Comparable interface
138
// ---------------------------------------------------------------------------
139

140   /**
141    * @see java.lang.Comparable#compareTo(java.lang.Object)
142    */

143   public int compareTo(Object JavaDoc o)
144   {
145     return (((Process JavaDoc) o).getId() - getId());
146   }
147
148 }
Popular Tags