1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package net.jini.core.constraint;
20
21 import java.io.IOException;
22 import java.io.Serializable;
23 import org.apache.river.api.io.AtomicSerial;
24 import org.apache.river.api.io.AtomicSerial.GetArg;
25
26 /**
27 * Represents a constraint on the absolute time by which a network connection
28 * must be established. The precise meaning of this will vary across
29 * communication mechanisms, but in the typical case of
30 * {@link java.net.Socket}-based communication, the intention is that this
31 * constraint controls the timeout parameter of the
32 * {@link java.net.Socket#connect(java.net.SocketAddress,int) connect} method.
33 *
34 * @author Sun Microsystems, Inc.
35 * @since 2.0
36 */
37 @AtomicSerial
38 public final class ConnectionAbsoluteTime
39 implements InvocationConstraint, Serializable
40 {
41 private static final long serialVersionUID = 8039977689366799322L;
42
43 /**
44 * Deadline for connection establishment in milliseconds from midnight,
45 * January 1, 1970 UTC.
46 *
47 * @serial
48 */
49 private final long time;
50
51 /**
52 * Creates a constraint with the specified deadline for connection
53 * establishment.
54 *
55 * @param time the deadline for connection establishment in milliseconds
56 * from midnight, January 1, 1970 UTC
57 */
58 public ConnectionAbsoluteTime(long time) {
59 this.time = time;
60 }
61
62 public ConnectionAbsoluteTime(GetArg arg) throws IOException{
63 this(arg.get("time", 0));
64 }
65
66 /**
67 * Returns the deadline for connection establishment.
68 *
69 * @return the deadline for connection establishment in milliseconds from
70 * midnight, January 1, 1970 UTC
71 */
72 public long getTime() {
73 return time;
74 }
75
76 /**
77 * Returns a hash code value for this object.
78 */
79 @Override
80 public int hashCode() {
81 return (int)(ConnectionAbsoluteTime.class.hashCode() + time);
82 }
83
84 /**
85 * Two instances of this class are equal if both have the same deadline.
86 */
87 @Override
88 public boolean equals(Object obj) {
89 if (!(obj instanceof ConnectionAbsoluteTime)) {
90 return false;
91 }
92 ConnectionAbsoluteTime cc = (ConnectionAbsoluteTime) obj;
93 return time == cc.time;
94 }
95
96 /**
97 * Returns a string representation of this object.
98 */
99 @Override
100 public String toString() {
101 return "ConnectionAbsoluteTime[" + time + "]";
102 }
103 }