-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionServer.java
More file actions
58 lines (50 loc) · 1.21 KB
/
TransactionServer.java
File metadata and controls
58 lines (50 loc) · 1.21 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
import java.io.*;
public class TransactionServer implements Serializable {
private int idCounter;
private static TransactionServer server;
private TransactionServer() {
idCounter = 1;
}
public static TransactionServer instance() {
if (server == null) {
return (server = new TransactionServer());
} else {
return server;
}
}
public int getId() {
return idCounter++;
}
public String toString() {
return ("IdServer" + idCounter);
}
public static void retrieve(ObjectInputStream input) {
try {
server = (TransactionServer) input.readObject();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (Exception cnfe) {
cnfe.printStackTrace();
}
}
private void writeObject(java.io.ObjectOutputStream output) throws IOException {
try {
output.defaultWriteObject();
output.writeObject(server);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void readObject(java.io.ObjectInputStream input) throws IOException, ClassNotFoundException {
try {
input.defaultReadObject();
if (server == null) {
server = (TransactionServer) input.readObject();
} else {
input.readObject();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}