001: /*
002: * <copyright>
003: *
004: * Copyright 2003-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.servicediscovery.description;
027:
028: import java.io.Serializable;
029:
030: import org.cougaar.planning.ldm.plan.Role;
031: import org.cougaar.util.TimeSpan;
032:
033: /**
034: * Indicates a change in the availability or unavailability of a provider
035: * for a given role for a given period of time.
036: */
037: public class AvailabilityChangeMessage implements Serializable {
038: /** A change has been requested but not submited **/
039: public static final int REQUESTED = 1;
040: /** a change is pending **/
041: public static final int PENDING = 2;
042: /** a change has completed but not yet noticed **/
043: public static final int COMPLETED = 3;
044: /** a change is complete **/
045: public static final int DONE = 4;
046: /** a change caused an error **/
047: public static final int ERROR = 5;
048:
049: private Role role;
050: private boolean registryUpdated;
051: private int status;
052: // Time span representing the period of availability/unavailability
053: private TimeSpan span;
054: // Indicates whether the role is available or unavailable for the period
055: private boolean available;
056:
057: public AvailabilityChangeMessage(Role role,
058: boolean registryUpdated, TimeSpan span, boolean available) {
059: this .role = role;
060: this .span = span;
061: this .registryUpdated = registryUpdated;
062: status = REQUESTED;
063: this .available = available;
064: }
065:
066: // no-arg constructor
067: public AvailabilityChangeMessage() {
068: };
069:
070: public void setRole(Role role) {
071: this .role = role;
072: }
073:
074: public Role getRole() {
075: return role;
076: }
077:
078: public void setRegistryUpdated(boolean registryUpdated) {
079: this .registryUpdated = registryUpdated;
080: }
081:
082: public boolean isRegistryUpdated() {
083: return registryUpdated;
084: }
085:
086: public boolean isRequested() {
087: return status == REQUESTED;
088: }
089:
090: public boolean isPending() {
091: return status == PENDING;
092: }
093:
094: public boolean isCompleted() {
095: return status == COMPLETED;
096: }
097:
098: public boolean isDone() {
099: return status == DONE;
100: }
101:
102: public boolean isError() {
103: return status == ERROR;
104: }
105:
106: public synchronized void setStatus(int status) {
107: if (status == REQUESTED || status == PENDING
108: || status == COMPLETED || status == DONE
109: || status == ERROR) {
110: this .status = status;
111: } else {
112: throw new IllegalArgumentException("Invalid status code "
113: + status + "\t Valid codes are 1 - 5");
114: }
115: }
116:
117: public int getStatus() {
118: return status;
119: }
120:
121: public void setTimeSpan(TimeSpan span) {
122: this .span = span;
123: }
124:
125: public TimeSpan getTimeSpan() {
126: return span;
127: }
128:
129: public void setAvailable(boolean available) {
130: this .available = available;
131: }
132:
133: public boolean isAvailable() {
134: return available;
135: }
136:
137: public String toString() {
138: return super .toString() + " role = " + role + ", status = "
139: + status + ", timespan = " + span + " , available = "
140: + available;
141: }
142:
143: }
|