1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.river.discovery;
20
21 import java.io.IOException;
22 import java.io.InvalidObjectException;
23 import java.io.ObjectInputStream;
24 import java.io.Serializable;
25 import net.jini.core.constraint.InvocationConstraint;
26 import org.apache.river.api.io.AtomicSerial;
27 import org.apache.river.api.io.AtomicSerial.GetArg;
28
29
30
31
32
33
34
35
36
37
38 @AtomicSerial
39 public final class UnicastSocketTimeout
40 implements InvocationConstraint, Serializable
41 {
42 private static final long serialVersionUID = 6500477426762925657L;
43
44
45
46
47
48
49 private final int timeout;
50
51
52
53
54
55
56
57
58 public UnicastSocketTimeout(int timeout) {
59 this(timeout, check(timeout));
60 }
61
62 UnicastSocketTimeout(GetArg arg) throws IOException {
63 this(arg.get("timeout", -1));
64 }
65
66 private UnicastSocketTimeout(int timeout, boolean check){
67 this.timeout = timeout;
68 }
69
70 private static boolean check(int timeout){
71 if (timeout < 0) {
72 throw new IllegalArgumentException("invalid timeout");
73 }
74 return true;
75 }
76
77
78
79
80
81
82 public int getTimeout() {
83 return timeout;
84 }
85
86 public int hashCode() {
87 return UnicastSocketTimeout.class.hashCode() + timeout;
88 }
89
90 public boolean equals(Object obj) {
91 return obj instanceof UnicastSocketTimeout &&
92 timeout == ((UnicastSocketTimeout) obj).timeout;
93 }
94
95 public String toString() {
96 return "UnicastSocketTimeout[" + timeout + "]";
97 }
98
99 private void readObject(ObjectInputStream in)
100 throws IOException, ClassNotFoundException
101 {
102 in.defaultReadObject();
103 if (timeout < 0) {
104 throw new InvalidObjectException("invalid timeout");
105 }
106 }
107 }