net.jini.core.constraint
Class ConnectionRelativeTime

java.lang.Object
  extended by net.jini.core.constraint.ConnectionRelativeTime
All Implemented Interfaces:
Serializable, InvocationConstraint, RelativeTimeConstraint

public final class ConnectionRelativeTime
extends Object
implements RelativeTimeConstraint, Serializable

Represents a constraint on the maximum amount of time to wait for a network connection to be established. The precise meaning of this will vary across communication mechanisms, but in the typical case of Socket-based communication, the intention is that this constraint controls the timeout parameter of the connect method.

The duration is translated into an absolute end time at the point of a remote call by adding the caller's current time.

Since:
2.0
Author:
Sun Microsystems, Inc.
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
           
private  long time
          The maximum connection duration in milliseconds.
 
Constructor Summary
ConnectionRelativeTime(long time)
          Creates a constraint with the specified duration.
 
Method Summary
private static long add(long dur, long time)
           
 boolean equals(Object obj)
          Two instances of this class are equal if both have the same duration.
 long getTime()
          Returns the maximum connection duration in milliseconds.
 int hashCode()
          Returns a hash code value for this object.
 InvocationConstraint makeAbsolute(long baseTime)
          Returns a ConnectionAbsoluteTime instance with time obtained by adding the specified base time argument to the duration value from this instance.
private  void readObject(ObjectInputStream s)
          Verifies that time is greater than or equal to zero.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

time

private final long time
The maximum connection duration in milliseconds.

Constructor Detail

ConnectionRelativeTime

public ConnectionRelativeTime(long time)
Creates a constraint with the specified duration.

Parameters:
time - the maximum connection duration in milliseconds
Throws:
IllegalArgumentException - if the argument is less than zero
Method Detail

getTime

public long getTime()
Returns the maximum connection duration in milliseconds.

Returns:
the maximum connection duration in milliseconds

makeAbsolute

public InvocationConstraint makeAbsolute(long baseTime)
Returns a ConnectionAbsoluteTime instance with time obtained by adding the specified base time argument to the duration value from this instance. If the addition results in overflow, a time value of Long.MAX_VALUE is used.

Specified by:
makeAbsolute in interface RelativeTimeConstraint
Parameters:
baseTime - an absolute time, specified in milliseconds from midnight, January 1, 1970 UTC
Returns:
a constraint that has the relative times converted to absolute times by adding the specified absolute time to each relative time

add

private static long add(long dur,
                        long time)

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Two instances of this class are equal if both have the same duration.

Overrides:
equals in class Object

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Verifies that time is greater than or equal to zero.

Throws:
InvalidObjectException - if time is less than zero
IOException
ClassNotFoundException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.