Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / examples / java / bittorrent / MessageTask.java
1 /* Copyright (c) 2006-2014. 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 bittorrent;
8
9 import org.simgrid.msg.Task;
10 /**
11  * Tasks sent between peers
12  */
13 public class MessageTask extends Task {
14         public enum Type {
15                 HANDSHAKE,
16                 CHOKE,
17                 UNCHOKE,
18                 INTERESTED,
19                 NOTINTERESTED,
20                 HAVE,
21                 BITFIELD,
22                 REQUEST,
23                 PIECE
24         };
25         public Type type;
26         public String issuerHostname;
27         public String mailbox;
28         public int peerId;
29         public char bitfield[];
30         public int index;
31         public int blockIndex;
32         public int blockLength;
33         public boolean stalled;
34         /**
35          * Constructor, builds a value-less message
36          * @param type
37          * @param issuerHostname
38          * @param mailbox
39          * @param peerId
40          */
41         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
42                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
43         }
44         /**
45          * Constructor, builds a new "have/request/piece" message
46          * @param type
47          * @param issuerHostname
48          * @param mailbox
49          * @param peerId
50          * @param index
51          */
52         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) {
53                 this(type,issuerHostname,mailbox,peerId,index,false,-1,-1);
54         }
55         /**
56          * Constructor, builds a new bitfield message
57          */
58         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) {
59                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
60                 this.bitfield = bitfield;
61         }
62         /**
63          * Constructor, build a new "request"  message
64          */
65         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex, int blockLength) {
66                 this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength);
67         }
68         /**
69          * Constructor, build a new "piece" message
70          */
71         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled, int blockIndex, int blockLength) {
72                 this.type = type;
73                 this.issuerHostname = issuerHostname;
74                 this.mailbox = mailbox;
75                 this.peerId = peerId;
76                 this.index = index;
77                 this.stalled = stalled;
78                 this.blockIndex = blockIndex;
79                 this.blockLength = blockLength;
80         }       
81 }