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 MulticastTimeToLive
40 implements InvocationConstraint, Serializable
41 {
42 private static final long serialVersionUID = 8899039913861829419L;
43
44
45 public static final int MAX_TIME_TO_LIVE = 0xFF;
46
47
48
49
50
51
52 private final int ttl;
53
54
55
56
57
58
59
60
61
62 public MulticastTimeToLive(int ttl) {
63 this(ttl, check(ttl));
64 }
65
66 MulticastTimeToLive(GetArg arg)throws IOException{
67 this(arg.get("ttl", -1));
68 }
69
70 private MulticastTimeToLive(int ttl, boolean check){
71 this.ttl = ttl;
72 }
73
74 private static boolean check(int ttl){
75 if (ttl < 0 || ttl > MAX_TIME_TO_LIVE) {
76 throw new IllegalArgumentException("invalid time to live");
77 }
78 return true;
79 }
80
81
82
83
84
85
86 public int getTimeToLive() {
87 return ttl;
88 }
89
90 public int hashCode() {
91 return MulticastTimeToLive.class.hashCode() + ttl;
92 }
93
94 public boolean equals(Object obj) {
95 return obj instanceof MulticastTimeToLive &&
96 ttl == ((MulticastTimeToLive) obj).ttl;
97 }
98
99 public String toString() {
100 return "MulticastTimeToLive[" + ttl + "]";
101 }
102
103 private void readObject(ObjectInputStream in)
104 throws IOException, ClassNotFoundException
105 {
106 in.defaultReadObject();
107 if (ttl < 0 || ttl > MAX_TIME_TO_LIVE) {
108 throw new InvalidObjectException("invalid time to live");
109 }
110 }
111 }