Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / examples / java / app / bittorrent / MessageTask.java
1 /* Copyright (c) 2006-2014, 2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package app.bittorrent;
8 import org.simgrid.msg.Task;
9
10 public class MessageTask extends Task {
11   public enum Type {
12     HANDSHAKE,
13     CHOKE,
14     UNCHOKE,
15     INTERESTED,
16     NOTINTERESTED,
17     HAVE,
18     BITFIELD,
19     REQUEST,
20     PIECE
21   }
22
23   protected Type type;
24   protected String issuerHostname;
25   protected String mailbox;
26   protected int peerId;
27   protected char[] bitfield;
28   protected int index;
29   protected int blockIndex;
30   protected int blockLength;
31   protected boolean stalled;
32
33   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
34     this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
35   }
36
37   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) {
38     this(type,issuerHostname,mailbox,peerId,index,false,-1,-1);
39   }
40
41   // builds a new bitfield message
42   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char[] bitfield) {
43     this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
44     this.bitfield = bitfield;
45   }
46
47   // build a new "request"  message
48   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex,
49                      int blockLength) {
50     this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength);
51   }
52
53   // build a new "piece" message
54   public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled,
55                      int blockIndex, int blockLength) {
56     this.type = type;
57     this.issuerHostname = issuerHostname;
58     this.mailbox = mailbox;
59     this.peerId = peerId;
60     this.index = index;
61     this.stalled = stalled;
62     this.blockIndex = blockIndex;
63     this.blockLength = blockLength;
64   }
65 }