-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab5.java
More file actions
138 lines (131 loc) · 4.97 KB
/
Copy pathlab5.java
File metadata and controls
138 lines (131 loc) · 4.97 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package lab5;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.*;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.logging.*;
import lab5.Human.Author;
public class lab5 {
public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException{
// TODO Auto-generated method stub
Server client = new Server(6666);
client.listen();
ConcurrentLinkedDeque<Jar> JarDeque = new <Jar>ConcurrentLinkedDeque();
Manager z = new Manager();
z.setColl(JarDeque);
class ShutdownHook extends Thread {
public void run() {
if (z.fi != ""){
z.ex_port();
System.out.println("Çàâåðøåíèå ïðîãðàììû");
} else {
System.out.println("Çàâåðøåíèå ïðîãðàììû");
}
}
}
ShutdownHook shutdownHook = new ShutdownHook();
Runtime.getRuntime().addShutdownHook(shutdownHook);
/*Logger log = Logger.getLogger("my.logger");
log.setLevel(Level.ALL);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
handler.setFormatter(new SimpleFormatter());
log.addHandler(handler);*/
Human Alisa = new Human (false, "Alisa", "Good");
Well BigWell = new Well ("Dark", "Well");
Wall LongWall = new Wall (BigWell, "Wall");
Shelf OneOfTheShelves = new Shelf (LongWall, "One of the shelves", 0);
Shelf AnotherShelf = new Shelf (LongWall, "Another shelf", 1);
Cupboard Cupboard = new Cupboard (LongWall, false, "Cupboard");
Jar OrangeJar = new Jar ("Orange", "Jam", true, OneOfTheShelves, "Jar");
Paper Map = new Paper (LongWall, "Geographic Map");
Paper Picture = new Paper (LongWall, "Picture");
Human.Author Author = new Human.Author ("Lewis Caroll");
/*try {
Wall.class.getInterfaces()[0].getMethod("Suck").invoke(new Wall(BigWell, "Lol"));
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Alisa.LookAt(Dir.down);
Alisa.Understand(", where she was flyuing to.");
System.out.println("But it was too " + BigWell.Atmosphere + " in the " + BigWell.Name + ".");
Alisa.Explore(BigWell, LongWall);
Alisa.Match(AnotherShelf, Cupboard, LongWall, Map, Picture);
try{
Alisa.Take(OrangeJar, OneOfTheShelves);
}
catch (JarException a){
System.out.println("No Jars Avaiable:(");
}
Jar.IAmEmpty(OrangeJar);
try{
Alisa.Take(OrangeJar, OneOfTheShelves);
}
catch (JarException a){
System.out.println("No Jars Avaiable:(");
}
Alisa.Mood = "Sad";
System.out.print(Alisa.Name + " was " + Alisa.Mood + " and wondered if ");
Alisa.Throw(OrangeJar);
System.out.print("But " + Alisa.Name + " was " + Alisa.Mood + ", so ");
Alisa.Put(OrangeJar, AnotherShelf);
Scanner in = new Scanner(System.in);
System.out.println("Ïåðåéòè â ðåæèì óïðàâëåíèÿ êîëëåêöèåé?");
String l = in.nextLine();
if (l.equals("Äà") || l.equals("Yes") || l.equals("äà") || l.equals("yes")) {
//log.fine("Ðåæèì óïðàâëåíèÿ êîëëåêöèåé àêòèâèðîâàí");
System.out.println("Äîñòóïíûå êîìàíäû");
System.out.println("import {String path}: äîáàâèòü â êîëëåêöèþ âñå äàííûå èç ôàéëà\n" +
"load: ïåðå÷èòàòü êîëëåêöèþ èç ôàéëà\n" +
"add{element}: äîáàâèòü íîâûé ýëåìåíò â êîëëåêèöþ\n" +
"add_if_max {element}: äîáàâèòü íîâûé ýëåìåíò â êîëëåêöèþ, åñëè åãî çíà÷åíèå ïðåâûøàåò çíà÷åíèå íàèáîëüøåãî ýëåìåíòà ýòîé êîëëåêöèè");*/
boolean ter = true;
try{
while (ter) {
String ini = msg;
if (ini.equals("terminate")) {
System.exit(0);
}
z.Analyze(ini);
//
for (Jar i:JarDeque){
System.out.println(i.Name);
}
}}catch(NoSuchElementException h){System.exit(0);};
} else {
System.out.println ("Âîò è ñêàçî÷êè êîíåö!");
}
ServerSocket srvSocket = null;
try {
try {
int i = 0; // Ñ÷¸ò÷èê ïîäêëþ÷åíèé
// Ïîäêëþ÷åíèå ñîêåòà ê localhost
InetAddress ia = InetAddress.getByName("localhost");
srvSocket = new ServerSocket(6666, 0, ia);
System.out.println("Server started\n\n");
while(true) {
// îæèäàíèå ïîäêëþ÷åíèÿ
Socket socket = srvSocket.accept();
System.err.println("Client accepted");
// Ñòàðòóåì îáðàáîòêó êëèåíòà â îòäåëüíîì ïîòîêå
new Server().setSocket(i++, socket);
}
} catch(Exception e) {
System.out.println("Exception : " + e);
}
} finally {
try {
if (srvSocket != null)
srvSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.exit(0);
}
}