Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Dig through git history, and update copyright lines.
[simgrid.git] / examples / java / bittorrent / MessageTask.java
1 /*
2  * Copyright (c) 2006-2013. The SimGrid Team.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. 
7  */
8 package bittorrent;
9
10 import org.simgrid.msg.Task;
11 /**
12  * Tasks sent between peers
13  */
14 public class MessageTask extends Task {
15         public enum Type {
16                 HANDSHAKE,
17                 CHOKE,
18                 UNCHOKE,
19                 INTERESTED,
20                 NOTINTERESTED,
21                 HAVE,
22                 BITFIELD,
23                 REQUEST,
24                 PIECE
25         };
26         public Type type;
27         public String issuerHostname;
28         public String mailbox;
29         public int peerId;
30         public char bitfield[];
31         public int index;
32         public int blockIndex;
33         public int blockLength;
34         public boolean stalled;
35         /**
36          * Constructor, builds a value-less message
37          * @param type
38          * @param issuerHostname
39          * @param mailbox
40          * @param peerId
41          */
42         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
43                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
44         }
45         /**
46          * Constructor, builds a new "have/request/piece" message
47          * @param type
48          * @param issuerHostname
49          * @param mailbox
50          * @param peerId
51          * @param index
52          */
53         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) {
54                 this(type,issuerHostname,mailbox,peerId,index,false,-1,-1);
55         }
56         /**
57          * Constructor, builds a new bitfield message
58          */
59         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) {
60                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
61                 this.bitfield = bitfield;
62         }
63         /**
64          * Constructor, build a new "request"  message
65          */
66         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex, int blockLength) {
67                 this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength);
68         }
69         /**
70          * Constructor, build a new "piece" message
71          */
72         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled, int blockIndex, int blockLength) {
73                 this.type = type;
74                 this.issuerHostname = issuerHostname;
75                 this.mailbox = mailbox;
76                 this.peerId = peerId;
77                 this.index = index;
78                 this.stalled = stalled;
79                 this.blockIndex = blockIndex;
80                 this.blockLength = blockLength;
81         }       
82 }