} else {
//Random optimistic unchoking
if (round == 0) {
- int j = 0, i;
+ int j = 0;
do {
- i = 0;
+ int i = 0;
int idChosen = stream.randInt(0,peers.size() - 1);
for (Connection connection : peers.values()) {
if (i == idChosen) {
return;
}
for (Integer piece : currentPieces) {
- //Getting the block to send.
- int blockIndex = -1, blockLength = 0;
- blockIndex = getFirstBlock(piece);
- blockLength = Common.PIECES_BLOCKS - blockIndex ;
+ //Getting the block to send.
+ int blockIndex = getFirstBlock(piece);
+ int blockLength = Common.PIECES_BLOCKS - blockIndex ;
blockLength = blockLength > Common.BLOCKS_REQUESTED ? Common.BLOCKS_REQUESTED : blockLength;
if (remotePeer.bitfield[piece] == '1') {
sendRequest(remotePeer.mailbox, piece, blockIndex, blockLength);
}
public void request(double CStime) throws MsgException {
RequestTask req = new RequestTask(getName());
- GrantTask grant= new GrantTask();;
+ GrantTask grant= new GrantTask();
Msg.info("Send a request to the coordinator");
req.send("coordinator");
Msg.info("Wait for a grant from the coordinator");
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
import org.simgrid.msg.Task;
-import org.simgrid.msg.Process;;
+import org.simgrid.msg.Process;
public class Master extends Process {
public Master(Host host, String name, String[]args) {
package async.dsend;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.Comm;
import org.simgrid.msg.Host;
import org.simgrid.msg.Task;
import org.simgrid.msg.Process;
import org.simgrid.msg.HostFailureException;
-import org.simgrid.msg.TaskCancelledException;
import org.simgrid.msg.TimeoutException;
import org.simgrid.msg.TransferFailureException;
* under the terms of the license (GNU LGPL) which comes with this package. */
package async.dsend;
-import java.util.ArrayList;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.Comm;
import org.simgrid.msg.Host;
import org.simgrid.msg.Task;
import org.simgrid.msg.Process;
package cloud.migration;
import org.simgrid.msg.Msg;
-import org.simgrid.msg.Host;
-import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.MsgException;
public class Main {
package cloud.migration;
-import java.util.Random;
-
import org.simgrid.msg.*;
import org.simgrid.msg.Process;
package dht.chord;
public class Common {
- public final static int COMM_SIZE = 10;
- public final static int COMP_SIZE = 0;
+ public static final int COMM_SIZE = 10;
+ public static final int COMP_SIZE = 0;
- public final static int NB_BITS = 24;
- public final static int NB_KEYS = 16777216;
- public final static int TIMEOUT = 50;
- public final static int MAX_SIMULATION_TIME = 1000;
- public final static int PERIODIC_STABILIZE_DELAY = 20;
- public final static int PERIODIC_FIX_FINGERS_DELAY = 120;
- public final static int PERIODIC_CHECK_PREDECESSOR_DELAY = 120;
- public final static int PERIODIC_LOOKUP_DELAY = 10;
+ public static final int NB_BITS = 24;
+ public static final int NB_KEYS = 16777216;
+ public static final int TIMEOUT = 50;
+ public static final int MAX_SIMULATION_TIME = 1000;
+ public static final int PERIODIC_STABILIZE_DELAY = 20;
+ public static final int PERIODIC_FIX_FINGERS_DELAY = 120;
+ public static final int PERIODIC_CHECK_PREDECESSOR_DELAY = 120;
+ public static final int PERIODIC_LOOKUP_DELAY = 10;
private Common() {
throw new IllegalAccessError("Utility class");
}
public class Common {
/* Common constants used all over the simulation */
- public final static int COMM_SIZE = 1;
- public final static int COMP_SIZE = 0;
+ public static final int COMM_SIZE = 1;
+ public static final int COMP_SIZE = 0;
- public final static int RANDOM_LOOKUP_INTERVAL = 100;
+ public static final int RANDOM_LOOKUP_INTERVAL = 100;
- public final static int alpha = 3;
+ public static final int alpha = 3;
- public final static int IDENTIFIER_SIZE = 32;
+ public static final int IDENTIFIER_SIZE = 32;
/* Maximum size of the buckets */
- public final static int BUCKET_SIZE = 20;
+ public static final int BUCKET_SIZE = 20;
/* Maximum number of trials for the "JOIN" request */
- public final static int MAX_JOIN_TRIALS = 4;
+ public static final int MAX_JOIN_TRIALS = 4;
/* Timeout for a "FIND_NODE" request to a node */
- public final static int FIND_NODE_TIMEOUT = 10;
+ public static final int FIND_NODE_TIMEOUT = 10;
/* Global timeout for a FIND_NODE request */
- public final static int FIND_NODE_GLOBAL_TIMEOUT = 50;
+ public static final int FIND_NODE_GLOBAL_TIMEOUT = 50;
/* Timeout for a "PING" request */
- public final static int PING_TIMEOUT = 35;
+ public static final int PING_TIMEOUT = 35;
- public final static int MAX_STEPS = 10;
- public final static int JOIN_BUCKETS_QUERIES = 1;
+ public static final int MAX_STEPS = 10;
+ public static final int JOIN_BUCKETS_QUERIES = 1;
private Common() {
throw new IllegalAccessError("Utility class");
}
/* Send a request to find a node in the node's routing table. */
public boolean findNode(int destination, boolean counts) {
- int queries, answers;
+ int queries;
+ int answers;
int nodesAdded = 0;
boolean destinationFound = false;
int steps = 0;
double timeBeginReceive;
- double timeout, globalTimeout = Msg.getClock() + Common.FIND_NODE_GLOBAL_TIMEOUT;
+ double timeout;
+ double globalTimeout = Msg.getClock() + Common.FIND_NODE_GLOBAL_TIMEOUT;
//Build a list of the closest nodes we already know.
Answer nodeList = table.findClosest(destination);
Msg.verb("Doing a FIND_NODE on " + destination);
* under the terms of the license (GNU LGPL) which comes with this package. */
package process.suspend;
-import org.simgrid.msg.Host;
import org.simgrid.msg.Msg;
import org.simgrid.msg.Process;
import org.simgrid.msg.MsgException;
* under the terms of the license (GNU LGPL) which comes with this package. */
package trace.pingpong;
-import org.simgrid.msg.Host;
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
import org.simgrid.msg.NativeException;
import org.simgrid.trace.Trace;
public class Receiver extends Process {
- private final double commSizeLat = 1;
- private final double commSizeBw = 100000000;
+ private static final double commSizeLat = 1;
+ private static final double commSizeBw = 100000000;
public Receiver(String hostname, String name, String[]args) throws HostNotFoundException, NativeException{
super(hostname,name,args);
private long bind;
- protected As() {
- };
+ protected As() {}
@Override
public String toString (){
package org.simgrid.msg;
public class File {
- public final int SEEK_SET = 0;
- public final int SEEK_CUR = 1;
- public final int SEEK_END = 2;
+ public static final int SEEK_SET = 0;
+ public static final int SEEK_CUR = 1;
+ public static final int SEEK_END = 2;
/**
* Represents the bind between the java comm and the
* native C comm. You must never access it, since it is
protected Host() {
this.bind = 0;
this.data = null;
- };
+ }
@Override
public String toString (){
* @exception HostNotFoundException if the name of the host is not valid.
* NativeException if the native version of this method failed.
*/
- public native static Host getByName(String name) throws HostNotFoundException, NullPointerException;
+ public static native Host getByName(String name) throws HostNotFoundException, NullPointerException;
/** Counts the installed hosts. */
- public native static int getCount();
+ public static native int getCount();
/** Returns the host of the current process. */
- public native static Host currentHost();
+ public static native Host currentHost();
/** Returns all hosts of the installed platform. */
- public native static Host[] all();
+ public static native Host[] all();
/**
* This static method sets a mailbox to receive in asynchronous mode.
* under the terms of the license (GNU LGPL) which comes with this package. */
package org.simgrid.msg;
-import org.simgrid.NativeLib;
-
public final class Msg {
* @param args
* @throws MsgException
*/
- static public void main(String[]args) throws MsgException {
+ public static void main(String[]args) throws MsgException {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
Msg.init(args);
*
* @return The count of the running processes
*/
- public native static int getCount();
+ public static native int getCount();
}
protected Storage() {
this.bind = 0;
this.data = null;
- };
+ }
@Override
public String toString (){
* @exception StorageNotFoundException if the name of the storage is not valid.
* @exception NativeException if the native version of this method failed.
*/
- public native static Storage getByName(String name)
+ public static native Storage getByName(String name)
throws HostNotFoundException, NullPointerException, NativeException, StorageNotFoundException;
/**
* @return An array containing all the storages installed.
*
*/
- public native static Storage[] all();
+ public static native Storage[] all();
/**
* Class initializer, to initialize various JNI stuff
* @param variable
* @param color
*/
- public final static native void hostVariableDeclareWithColor (String variable, String color);
+ public final static native void hostVariableDeclareWithColor (String variable, String color);
/**
* @param variable
* @param value
*/
- public final static native void hostVariableAdd (String host, String variable, double value);
+ public final static native void hostVariableAdd (String host, String variable, double value);
/**
* Subtract a value from a variable of a host.
* @param variable
* @param value
*/
- public final static native void hostVariableSub (String host, String variable, double value);
+ public final static native void hostVariableSub (String host, String variable, double value);
/**
* Set the value of a variable of a host at a given timestamp.
* @param variable
* @param value
*/
- public final static native void hostVariableSetWithTime (double time, String host, String variable, double value);
+ public final static native void hostVariableSetWithTime (double time, String host, String variable, double value);
/**
* Add a value to a variable of a host at a given timestamp.
* @param variable
* @param value
*/
- public final static native void hostVariableAddWithTime (double time, String host, String variable, double value);
+ public final static native void hostVariableAddWithTime (double time, String host, String variable, double value);
/**
* Subtract a value from a variable of a host at a given timestamp.
* @param variable
* @param value
*/
- public final static native void hostVariableSubWithTime (double time, String host, String variable, double value);
+ public final static native void hostVariableSubWithTime (double time, String host, String variable, double value);
/**
* Get declared user host variables.
*
* @param variable
*/
- public final static native void linkVariableDeclare (String variable);
+ public final static native void linkVariableDeclare (String variable);
/**
* Declare a new user variable associated to links with a color.
* @param variable
* @param color
*/
- public final static native void linkVariableDeclareWithColor (String variable, String color);
+ public final static native void linkVariableDeclareWithColor (String variable, String color);
/**
* Set the value of a variable of a link.
* @param variable
* @param value
*/
- public final static native void linkVariableSet (String link, String variable, double value);
+ public final static native void linkVariableSet (String link, String variable, double value);
/**
* Add a value to a variable of a link.
* @param variable
* @param value
*/
- public final static native void linkVariableAdd (String link, String variable, double value);
+ public final static native void linkVariableAdd (String link, String variable, double value);
/**
* Subtract a value from a variable of a link.
* @param variable
* @param value
*/
- public final static native void linkVariableSub (String link, String variable, double value);
+ public final static native void linkVariableSub (String link, String variable, double value);
/**
* Set the value of a variable of a link at a given timestamp.
* @param variable
* @param value
*/
- public final static native void linkVariableSetWithTime (double time, String link, String variable, double value);
+ public final static native void linkVariableSetWithTime (double time, String link, String variable, double value);
/**
* Add a value to a variable of a link at a given timestamp.
* @param variable
* @param value
*/
- public final static native void linkVariableAddWithTime (double time, String link, String variable, double value);
+ public final static native void linkVariableAddWithTime (double time, String link, String variable, double value);
/**
* @param variable
* @param value
*/
- public final static native void linkVariableSubWithTime (double time, String link, String variable, double value);
+ public final static native void linkVariableSubWithTime (double time, String link, String variable, double value);
/**
* Set the value of the variable present in the links connecting source and destination.
* @param variable
* @param value
*/
- public final static native void linkSrcDstVariableSet (String src, String dst, String variable, double value);
+ public final static native void linkSrcDstVariableSet (String src, String dst, String variable, double value);
/**
* Add a value to the variable present in the links connecting source and destination.
* @param variable
* @param value
*/
- public final static native void linkSrcDstVariableAdd (String src, String dst, String variable, double value);
+ public final static native void linkSrcDstVariableAdd (String src, String dst, String variable, double value);
/**
* Subtract a value from the variable present in the links connecting source and destination.
* @param variable
* @param value
*/
- public final static native void linkSrcDstVariableSub (String src, String dst, String variable, double value);
+ public final static native void linkSrcDstVariableSub (String src, String dst, String variable, double value);
/**
* Set the value of the variable present in the links connecting source and destination at a given timestamp.
* @param variable
* @param value
*/
- public final static native void linkSrcDstVariableSetWithTime (double time, String src, String dst, String variable, double value);
+ public final static native void linkSrcDstVariableSetWithTime (double time, String src, String dst, String variable, double value);
/**
* Add a value to the variable present in the links connecting source and destination at a given timestamp.
* @param variable
* @param value
*/
- public final static native void linkSrcdstVariableAddWithTime (double time, String src, String dst, String variable, double value);
+ public final static native void linkSrcdstVariableAddWithTime (double time, String src, String dst, String variable, double value);
/**
* Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
* @param variable
* @param value
*/
- public final static native void linkSrcDstVariableSubWithTime (double time, String src, String dst, String variable, double value);
+ public final static native void linkSrcDstVariableSubWithTime (double time, String src, String dst, String variable, double value);
/**
* Get declared user link variables.
*
* @param variable
*/
- public final static native void hostVariableDeclare (String variable);
+ public final static native void hostVariableDeclare (String variable);
/**
* @param variable
* @param value
*/
- public final static native void hostVariableSet (String host, String variable, double value);
+ public final static native void hostVariableSet (String host, String variable, double value);
/**
* Declare a new user variable associated to VMs.
*
* @param variable
*/
- public final static native void vmVariableDeclare (String variable);
+ public final static native void vmVariableDeclare (String variable);
/**
* @param variable
* @param value
*/
- public final static native void vmVariableSet (String vm, String variable, double value);
+ public final static native void vmVariableSet (String vm, String variable, double value);
}