001 package com.hammurapi.flow.runtime;
002
003 import java.util.Set;
004 import java.util.concurrent.Callable;
005 import java.util.concurrent.Future;
006 import java.util.concurrent.TimeUnit;
007
008 /**
009 * Set of properties.
010 * @author Pavel
011 */
012 public interface PropertySet {
013
014 /**
015 * @return Names of properties in the set
016 */
017 Set<String> getPropertyNames();
018
019 /**
020 * @param prefix
021 * @return Property set which operates on properties starting with given prefix.
022 */
023 PropertySet getSubset(String prefix);
024
025 /**
026 * Removes property from the set. Chained properties are shadowed (appear to be
027 * removed).
028 * @param name
029 */
030 void remove(String name);
031
032 /**
033 * Removes all entries from the property set
034 */
035 void clear();
036
037 /**
038 * Mounts source property set at specified prefix. E.g. if source property set has entry 'a' and prefix is 'b/' then that entry will be
039 * available as 'b/a'. Mounted entries shadow own entries.
040 * @param prefix
041 * @param source
042 */
043 void mount(String prefix, PropertySet source);
044
045 /**
046 * Copies all entries from the source property set to self.
047 * @param source
048 */
049 void setAll(PropertySet source);
050
051 /**
052 * @param subSet
053 * @return true if all properties of subset are present in this set with
054 * same values.
055 */
056 boolean containsAll(PropertySet subSet);
057
058 /**
059 * @param otherSet
060 * @return true if all properties in this set are equal to properties
061 * in the other set.
062 */
063 boolean compareProperties(PropertySet otherSet);
064
065 /**
066 * Retrieves property.
067 */
068 Object get(String name);
069
070 /**
071 * @param name Property name.
072 * @param defaultValue Default value.
073 * @return Property value or default value if property doesn't exist in the
074 * property set.
075 */
076 Object get(String name, Object defaultValue);
077
078 /**
079 * Sets property.
080 * @param name
081 * @param value
082 */
083 void set(String name, Object value);
084
085 /**
086 * Puts callable to the property set for asynchronous invocation to retrieve
087 * value at some point in the future.
088 * @param name
089 * @param callable
090 */
091 void cook(String name, Callable<?> callable);
092
093 /**
094 * Puts callable to the property set for asynchronous invocation to retrieve
095 * value at some point in the future after specified delay.
096 * @param name
097 * @param callable
098 * @param delay
099 */
100 void cook(String name, Callable<?> callable, long delay, TimeUnit timeUnit);
101
102 /**
103 * Puts value which is not ready yet but "is being cooked by another thread"
104 * to the property set to be used at some point of time in the future.
105 * @param name
106 * @param future Value being cooked.
107 */
108 void cooking(String name, Future<?> future);
109
110
111 /**
112 * Puts callable to the property set. Value from callable is retrieved when
113 * <code>get()</code> method for the given name is invoked.
114 * @param name
115 * @param callable
116 */
117 void lazy(String name, Callable<?> callable);
118
119 /**
120 * Removes callable to be cooked from the cooking queue, converting it to lazy,
121 * if it is not already cooked.
122 * @param name
123 */
124 void cancel(String name);
125 }