-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.java
More file actions
104 lines (80 loc) · 2.67 KB
/
Device.java
File metadata and controls
104 lines (80 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package network;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.Thread.sleep;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Device extends Thread{
private String name ;
private String type;
public int assign;
//public int wait=0;
public static Router router;
public Device(String name , String type,Router r) {
router=r;
this.name=name;
this.type=type;
}
public void setname(String name){
this.name = name;
}
public void setType(String type){
this.type = type;
}
public String getname(){
return this.name;
}
public String gettype(){
return this.type;
}
public int getassign(){
return this.assign;
}
public String connect(){
return (name +" Occupied");
}
public String performActivity(){
return (name +" performs online activity");
}
public String logout(){
return(name+" Logged out");
}
@Override
public void run(){
//router.connectsem.P();
// try {
// File file=new File("D:\\OS.txt");
// FileWriter fileWriter = new FileWriter(file, true); //Set true for append mode
// PrintWriter printWriter = new PrintWriter(fileWriter);
try {
// assign=router.occupy(this);
String str=("connection " + this.assign + ": " + router.occupy(this));
sleep(800);
System.out.println(str);
// printWriter.println(str);
}catch (InterruptedException e) {
e.printStackTrace();}
try {
String str2=("connection " + this.assign + ": " + router.serve(this));
sleep(2000);
System.out.println(str2);
// printWriter.println(str2);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
String str3=("connection " + this.assign + ": " + router.release(this));
System.out.println(str3);
// printWriter.println(str3);
} catch (InterruptedException e) {
e.printStackTrace();
}
// router.connectsem.V();
// printWriter.close();
// } catch (IOException ex) {
// Logger.getLogger(Device.class.getName()).log(Level.SEVERE, null, ex);
// }
}
}