edu.harvard.cfa.vo.tapclient.vosi
Class Availability

java.lang.Object
  extended by edu.harvard.cfa.vo.tapclient.vosi.Availability

public class Availability
extends java.lang.Object

The operability and reliability of a service for extended and scheduled requests.

 
    edu.harvard.cfa.vo.tapclient.tap.TapService tapService = new edu.harvard.cfa.vo.tapclient.tap.TapService(baseURL);
    Availability availability = tapService.getAvailability();
    if (! availability.isAvailable()) {
        System.out.println("Service is unavailable.");
        Calendar backAt = availability.getBackAt();
        if (availability.getBackAt() != null) {
            Calendar now = Calendar.getInstance();
            if (backAt.compareTo(now) >= 0) {
                System.out.println("Sleeping...");
                long delay = (backAt.getTimeInMillis()-now.getTimeInMillis())+5000;
                Thread.sleep(delay);
            }

            // Update the availability
            availability.update();

            System.out.println("Service is "+(availability.isAvailable() ? "available." : " not available."));
        } else {
            System.out.println("Service did not specify when it would be back.");
        }
    } else {
        System.out.println("Service is available");
    }

    for (String note: availability.getNotes()) {
        System.out.println("TAP service note: "+note);
    }
 
 


Constructor Summary
Availability(java.lang.String fullURL)
          Construct an Availability for the given Vosi.
 
Method Summary
 java.util.Calendar getBackAt()
          Returns the instant at which the service is scheduled to become available.
 java.util.Calendar getDownAt()
          Returns the instant at which the service is scheduled to be unavailable.
 java.util.List<java.lang.String> getNotes()
          Returns a list of notes, for example explaining the reason for unavailability.
 java.util.Calendar getUpSince()
          Returns the instant since which the service has been continuously available.
 boolean isAvailable()
          Returns true if the service is accepting requests.
 void list(java.io.PrintStream output)
           
 void list(java.io.PrintStream output, java.lang.String indent)
           
 void update()
          Updates this Availability object with the latest response from the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Availability

public Availability(java.lang.String fullURL)
Construct an Availability for the given Vosi.

Parameters:
fullURL - the full URL associated with this availability
Method Detail

isAvailable

public boolean isAvailable()
Returns true if the service is accepting requests. The value returned is current as of the last call to update.

Returns:
true if the service is accepting requests, false otherwise.
See Also:
update()

getUpSince

public java.util.Calendar getUpSince()
Returns the instant since which the service has been continuously available. The value returned is current as of the last call to update.

Returns:
the instant in time the service has been continuously available or null if the value was not provided by the service.
See Also:
update()

getDownAt

public java.util.Calendar getDownAt()
Returns the instant at which the service is scheduled to be unavailable. The value returned is current as of the last call to update.

Returns:
the instant at which the service is scheduled to be unavailable or null if the value was not provided by the service.
See Also:
update()

getBackAt

public java.util.Calendar getBackAt()
Returns the instant at which the service is scheduled to become available. The value returned is current as of the last call to update.

Returns:
the instant at which the service is scheduled to become available or null if the value was not provided by the service.
See Also:
update()

getNotes

public java.util.List<java.lang.String> getNotes()
Returns a list of notes, for example explaining the reason for unavailability. The value returned is current as of the last call to update.

Returns:
a list of notes or null if the value was not provided by the service.
See Also:
update()

update

public void update()
            throws HttpException,
                   ResponseFormatException,
                   java.io.IOException
Updates this Availability object with the latest response from the service. An HTTP request is made to the service associated with this Availability object.

Throws:
HttpException - if the service responses to the VOSI Availability request with an unexpected HTTP status.
ResponseFormatException - if an error occurs parsing the service response into an VOSI Availability document.
java.io.IOException - if an error occurs creating an input stream.

list

public void list(java.io.PrintStream output)

list

public void list(java.io.PrintStream output,
                 java.lang.String indent)