00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.migration;
00032
00033 import org.apache.log4j.Logger;
00034 import org.objectweb.proactive.core.util.log.Loggers;
00035 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00036
00037
00043 public class MigrationStrategyImpl implements java.io.Serializable,
00044 MigrationStrategy {
00045 static Logger logger = ProActiveLogger.getLogger(Loggers.MIGRATION);
00046 private java.util.Vector<Destination> table;
00047 private int index;
00048
00052 public MigrationStrategyImpl() {
00053 super();
00054 table = new java.util.Vector<Destination>();
00055 index = -1;
00056 }
00057
00063 public MigrationStrategyImpl(String filename) {
00064 super();
00065 table = new java.util.Vector<Destination>();
00066 index = -1;
00067 String s;
00068 java.io.FileReader f_in = null;
00069 try {
00070 f_in = new java.io.FileReader(filename);
00071 } catch (java.io.FileNotFoundException e) {
00072 logger.error("File not Found");
00073 }
00074
00075
00076 java.io.BufferedReader _in = new java.io.BufferedReader(f_in);
00077
00078
00079
00080 try {
00081
00082 while (_in.ready()) {
00083
00084 s = _in.readLine();
00085 java.util.StringTokenizer tokens = new java.util.StringTokenizer(s,
00086 " ");
00087 this.add(new NodeDestination(new String(tokens.nextToken()),
00088 tokens.nextToken()));
00089 }
00090 }
00091 catch (Exception e) {
00092 }
00093
00094 try {
00095 _in.close();
00096 } catch (java.io.IOException e) {
00097 }
00098 }
00099
00103 public void add(Destination r) {
00104 table.addElement(r);
00105 }
00106
00107 public void add(String nodeURL, String method) {
00108 table.addElement(new NodeDestination(nodeURL, method));
00109 }
00110
00115 public void addNext(Destination r) {
00116 if ((index == -1) || (index == (table.size() - 1))) {
00117 table.addElement(r);
00118 } else {
00119 table.add(index + 1, r);
00120 }
00121 }
00122
00123 public void addNext(String nodeURL, String method) {
00124 if ((index == -1) || (index == (table.size() - 1))) {
00125 table.addElement(new NodeDestination(nodeURL, method));
00126 } else {
00127 table.add(index + 1, new NodeDestination(nodeURL, method));
00128 }
00129 }
00130
00131 public void remove(String nodeURL, String method) {
00132 removeFromItinerary(new NodeDestination(nodeURL, method));
00133 }
00134
00135 public void remove(Destination d) {
00136 removeFromItinerary(d);
00137 }
00138
00139
00140 private void removeFromItinerary(Destination r) {
00141
00142 int i = 0;
00143 Destination r2;
00144 while (i < table.size()) {
00145 r2 = table.elementAt(i);
00146 if ((r2.getDestination().equals(r.getDestination())) &&
00147 (r2.getMethodName().equals(r.getMethodName()))) {
00148 table.removeElementAt(i);
00149
00150 if (i < index) {
00151 index--;
00152 }
00153 return;
00154 }
00155 i++;
00156 }
00157 }
00158
00163 public Destination next() {
00164 index++;
00165 if (index < table.size()) {
00166 Destination r = table.elementAt(index);
00167
00168
00169 return (r);
00170 } else {
00171
00172 return (null);
00173 }
00174 }
00175
00180 public Destination getCurrentDestination() {
00181 if ((index < table.size()) && (index >= 0)) {
00182 Destination r = table.elementAt(index);
00183 return (r);
00184 } else
00185 {
00186 return (null);
00187 }
00188 }
00189
00193 public Destination getNextExcept(String s) {
00194 Destination temp;
00195 if (s == null) {
00196 return next();
00197 }
00198 while ((temp = next()) != null) {
00199 if (!temp.getDestination().equals(s)) {
00200 return temp;
00201 }
00202 }
00203 return null;
00204 }
00205
00206 public int size() {
00207 return table.size();
00208 }
00209
00210 public void decrease() {
00211 if (index >= 0) {
00212 index--;
00213 }
00214 }
00215
00216 public void reset() {
00217 index = -1;
00218 }
00219
00223 public java.util.Vector<String> toVector() {
00224 java.util.Vector<String> temp = new java.util.Vector<String>();
00225 for (int i = 0; i < table.size(); i++) {
00226 temp.add(table.elementAt(i).getDestination());
00227 }
00228 return temp;
00229 }
00230 }