Coverage Report - nextgrid.api.pom.Reference
 
Classes in this File Line Coverage Branch Coverage Complexity
Reference
N/A
N/A
0
 
 1  
 /*
 2  
  Copyright (C) 2006 Grid Systems, S.A.
 3  
 
 4  
  This library is free software; you can redistribute it and/or
 5  
  modify it under the terms of the GNU Lesser General Public
 6  
  License as published by the Free Software Foundation; either
 7  
  version 2.1 of the License, or (at your option) any later version.
 8  
 
 9  
  This library is distributed in the hope that it will be useful,
 10  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  
  Lesser General Public License for more details.
 13  
 
 14  
  You should have received a copy of the GNU Lesser General Public
 15  
  License along with this library; if not, write to the Free Software
 16  
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 17  
 */
 18  
 package nextgrid.api.pom;
 19  
 
 20  
 import java.util.Set;
 21  
 import java.util.concurrent.locks.Lock;
 22  
 
 23  
 
 24  
 /**
 25  
  * Models an EndPointReference, that is, a reference to a remote process.
 26  
  * <p>
 27  
  * This reference must be filled in during workflow enaction.
 28  
  *
 29  
  * @param <T> The type of the referenced value
 30  
  * @author Rodrigo Ruiz
 31  
  */
 32  
 public interface Reference<T> extends java.io.Serializable, Cloneable {
 33  
 
 34  
   /**
 35  
    * Depending on the reference nature, it may be necessary to free resources,
 36  
    * or perform some kind of finalisation.
 37  
    */
 38  
   void dispose();
 39  
 
 40  
   /**
 41  
    * makes a deep copy of this instance.
 42  
    *
 43  
    * @return A deep copy
 44  
    */
 45  
   Reference<T> copy();
 46  
 
 47  
   /**
 48  
    * Clears the reader and writer lists.
 49  
    */
 50  
   void clearLinks();
 51  
 
 52  
   /**
 53  
    * Clears the value and marks the reference as not available.
 54  
    */
 55  
   void reset();
 56  
 
 57  
   /**
 58  
    * Adds a process to the readers list.
 59  
    *
 60  
    * @param reader The process to add
 61  
    */
 62  
   void addReader(Process reader);
 63  
 
 64  
   /**
 65  
    * Adds a process to the writers list.
 66  
    *
 67  
    * @param writer The process to add
 68  
    */
 69  
   void addWriter(Process writer);
 70  
 
 71  
   /**
 72  
    * Removes a process from the readers list.
 73  
    *
 74  
    * @param reader The process to remove
 75  
    */
 76  
   void removeReader(Process reader);
 77  
 
 78  
   /**
 79  
    * Removes a process from the writers list.
 80  
    *
 81  
    * @param writer The process to remove
 82  
    */
 83  
   void removeWriter(Process writer);
 84  
 
 85  
   /**
 86  
    * Gets the writer processes attached to this reference.
 87  
    *
 88  
    * @return  Returns the writers.
 89  
    */
 90  
   Set<Process> getWriters();
 91  
 
 92  
   /**
 93  
    * Gets the reader processes attached to this reference.
 94  
    *
 95  
    * @return  Returns the readers.
 96  
    */
 97  
   Set<Process> getReaders();
 98  
 
 99  
   /**
 100  
    * Gets the referenced value.
 101  
    *
 102  
    * @return The value
 103  
    */
 104  
   T getValue();
 105  
 
 106  
   /**
 107  
    * Sets the referenced value.
 108  
    *
 109  
    * @param value The value
 110  
    */
 111  
   void setValue(Object value);
 112  
 
 113  
   /**
 114  
    * Gets the value after casting it to the specified type.
 115  
    *
 116  
    * @param type The target type
 117  
    * @return An object instance of the specified type
 118  
    * @throws ClassCastException If the value cannot be correctly casted
 119  
    */
 120  
   Object castTo(Class<?> type);
 121  
 
 122  
   /**
 123  
    * Gets a class instance representing the type of referenced values.
 124  
    *
 125  
    * @return A class instance
 126  
    */
 127  
   Class<T> getValueType();
 128  
 
 129  
   /**
 130  
    * Gets if the value can be casted to the specified type.
 131  
    * <p>
 132  
    * This method is used by processes to validate input references.
 133  
    *
 134  
    * @param type The type to cast to
 135  
    * @return true if it can
 136  
    */
 137  
   boolean canCastTo(Class<?> type);
 138  
 
 139  
   /**
 140  
    * Gets if the value can be converted from the specified type.
 141  
    * <p>
 142  
    * This method is used by processes to validate output references.
 143  
    *
 144  
    * @param type The type to cast from
 145  
    * @return true if it can
 146  
    */
 147  
   boolean canCastFrom(Class<?> type);
 148  
 
 149  
   /**
 150  
    * Gets if the reference is available for reading.
 151  
    *
 152  
    * @return true if it can be read
 153  
    */
 154  
   boolean isAvailable();
 155  
 
 156  
   /**
 157  
    * Sets the available flag.
 158  
    *
 159  
    * @param available The new flag value
 160  
    */
 161  
   void setAvailable(boolean available);
 162  
 
 163  
   /**
 164  
    * Gets a lock for reading.
 165  
    *
 166  
    * @return A lock instance
 167  
    */
 168  
   Lock readLock();
 169  
 
 170  
   /**
 171  
    * Gets a lock for writing.
 172  
    *
 173  
    * @return A lock instance
 174  
    */
 175  
   Lock writeLock();
 176  
 
 177  
   /**
 178  
    * Waits until the reference is made available in another thread.
 179  
    *
 180  
    * @throws InterruptedException If the thread is interrupted while waiting
 181  
    */
 182  
   void waitAvailable() throws InterruptedException;
 183  
 }