-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProductIDServer.java
More file actions
66 lines (57 loc) · 1.61 KB
/
ProductIDServer.java
File metadata and controls
66 lines (57 loc) · 1.61 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
package com.company;
import java.io.*;
public class ProductIDServer implements Serializable {
private int idCounter;
private static ProductIDServer server;
private ProductIDServer() {
idCounter = 1;
}
public static ProductIDServer instance() {
if (server == null) {
return (server = new ProductIDServer());
}
else {
return server;
}
}
public int getID() {
return idCounter++;
}
public String toString() {
return ("IdServer" + idCounter);
}
public static void retrieve(ObjectInputStream input) {
try {
server = (ProductIDServer) 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 = (ProductIDServer) input.readObject();
}
else {
input.readObject();
}
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
}