Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / contrib / psg / src / peersim / core / OracleIdleProtocol.java
1 /*
2  * Copyright (c) 2003-2005 The BISON Project
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  */
18                 
19 package peersim.core;
20
21 /**
22 * A protocol that does nothing but knows everything.
23 * It provides an interface which models a protocol that knows all nodes
24 * in the network, i.e. the neighborhood set of this protocol is always the
25 * whole node set. this protocol is also extremely cheap, in fact it
26 * has no data fields.
27 */
28 public final class OracleIdleProtocol implements Protocol, Linkable {
29
30 // =================== initialization, creation ======================
31 // ===================================================================
32
33
34 /** Does nothing */
35 public OracleIdleProtocol(String prefix) {}
36
37 // --------------------------------------------------------------------
38
39 /** Returns <tt>this</tt> to maximize memory saving. It contains no fields.*/
40 public Object clone() { return this; }
41
42
43 // ===================== public methods ===============================
44 // ====================================================================
45
46
47 /** This is an expensive operation, should not be used at all.
48 * It returns false only if the given node is not in the current network.
49 */
50 public boolean contains(Node n) {
51
52         final int len = Network.size();
53         for (int i=0; i < len; i++)
54         {
55                 if (Network.node[i] == n)
56                 return true;
57         }
58         return false;
59 }
60
61 // --------------------------------------------------------------------
62
63 /** Unsupported operation */
64 public boolean addNeighbor(Node n) {
65
66         throw new UnsupportedOperationException();
67 }
68
69 // --------------------------------------------------------------------
70   
71 /**
72 * The neighborhood contains the node itself, ie it contains the loop
73 * edge.
74 */
75 public Node getNeighbor(int i) {
76         
77         return Network.node[i];
78 }
79
80 // --------------------------------------------------------------------
81
82 public int degree() {
83         
84         return Network.size();
85 }
86
87 // --------------------------------------------------------------------
88
89 public void pack() {}  
90
91 // --------------------------------------------------------------------
92
93 public void onKill() {}
94
95 // --------------------------------------------------------------------
96
97 public String toString() {
98
99         return degree()+" [all the nodes of the overlay network]";
100 }
101
102 }
103