View Javadoc

1   /***
2    * 
3    */
4   package org.xvsm.interfaces.container;
5   
6   import java.net.URI;
7   import java.util.List;
8   import java.util.Properties;
9   
10  import org.xvsm.core.ContainerRef;
11  import org.xvsm.core.aspect.IAspect;
12  import org.xvsm.core.aspect.IPoint;
13  import org.xvsm.interfaces.ICoordinator;
14  import org.xvsm.internal.exceptions.AspectNotOkException;
15  import org.xvsm.internal.exceptions.AspectRescheduleException;
16  import org.xvsm.internal.exceptions.ContainerFullException;
17  import org.xvsm.internal.exceptions.CountNotMetException;
18  import org.xvsm.internal.exceptions.InvalidTransactionException;
19  import org.xvsm.internal.exceptions.TransactionLockException;
20  import org.xvsm.internal.tasks.OperationTask;
21  import org.xvsm.selectors.Selector;
22  import org.xvsm.transactions.Transaction;
23  
24  /***
25   * @author Christian Schreiber, Michael Proestler
26   * 
27   */
28  public interface IContainer {
29  
30  	/***
31  	 * Constant representing infinite Container size.
32  	 */
33  	int INFINITE_SIZE = -1;
34  
35  	/***
36  	 * Executes the task.
37  	 * 
38  	 * @param task
39  	 *            the task to execute.
40  	 * @throws ContainerFullException
41  	 *             thrown if the there is no place left for the new entry.
42  	 * @throws CountNotMetException
43  	 *             thrown if there are not enough entries to read.
44  	 * @throws TransactionLockException
45  	 *             thrown if the container is used by annother tx.
46  	 * @return the result.
47  	 */
48  	Object execute(OperationTask task) throws ContainerFullException,
49  			CountNotMetException, TransactionLockException,
50  			AspectRescheduleException, AspectNotOkException;
51  
52  	/***
53  	 * Commits an existing {@link Transaction} for this container.
54  	 * 
55  	 * @param txn
56  	 *            The {@link Transaction} that should be commited.
57  	 * @throws TransactionLockException
58  	 *             thrown if the container is locked by another transaction.
59  	 * @throws InvalidTransactionException
60  	 *             thrown if tx is not valid.
61  	 * @throws AspectRescheduleException
62  	 *             thrown if an aspect answered with
63  	 *             {@link AspectResult#RESCHEDULE}.
64  	 * @throws AspectNotOkException
65  	 *             thrown if an aspect answered with {@link AspectResult#NOTOK}.
66  	 */
67  	void commit(Transaction txn) throws TransactionLockException,
68  			InvalidTransactionException, AspectRescheduleException,
69  			AspectNotOkException;
70  
71  	/***
72  	 * Does a rollback on this {@link Transaction}.
73  	 * 
74  	 * @param txn
75  	 *            The {@link Transaction} that should be rollbacked.
76  	 * @throws TransactionLockException
77  	 *             thrown if the container is locked by another transaction.
78  	 * @throws InvalidTransactionException
79  	 *             thrown if tx is not valid.
80  	 * @throws AspectRescheduleException
81  	 *             thrown if an aspect answered with
82  	 *             {@link AspectResult#RESCHEDULE}.
83  	 * @throws AspectNotOkException
84  	 *             thrown if an aspect answered with {@link AspectResult#NOTOK}.
85  	 */
86  	void rollback(Transaction txn) throws InvalidTransactionException,
87  			TransactionLockException, AspectRescheduleException,
88  			AspectNotOkException;
89  
90  	/***
91  	 * Get the {@link ContainerRef} of the container.
92  	 * 
93  	 * @return the {@link ContainerRef}
94  	 */
95  	ContainerRef getCref();
96  
97  	/***
98  	 * Set the {@link ContainerRef} of the container.
99  	 * 
100 	 * @param cref
101 	 *            the new {@link ContainerRef}
102 	 */
103 	void setCref(ContainerRef cref);
104 
105 	/***
106 	 * Updates the timeout information of each blocking event.
107 	 */
108 	void updateTimeouts();
109 
110 	/***
111 	 * Adds an Aspect to the Container.
112 	 * 
113 	 * @param p
114 	 *            the IPoint were the Aspect should be called.
115 	 * @param aspect
116 	 *            the Aspect that should be called.
117 	 * @param aspectProperties
118 	 *            possible properties that the aspect retreives, when it is
119 	 *            called.
120 	 * 
121 	 */
122 	String addAspects(List<IPoint> p, IAspect aspect,
123 			Properties aspectProperties);
124 
125 	/***
126 	 * Removes an Aspect from the Container.
127 	 * 
128 	 * @param p
129 	 *            the IPoint were the Aspect should be removed.
130 	 * @param uri
131 	 *            the URI of the aspect which shall be removed.
132 	 * @param aspectContext
133 	 *            possible properties that the aspect retrieves, when it is
134 	 *            called.
135 	 */
136 	void removeAspect(IPoint p, URI uri, Properties aspectContext);
137 
138 	/***
139 	 * Adds a coordinator to the engine. If a coordinator has been added with
140 	 * the same selector class the old coordinator will be replaced by the new
141 	 * one.
142 	 * 
143 	 * @param s
144 	 *            the class of the selector to register the coordinator with.
145 	 * @param c
146 	 *            the new coordinator.
147 	 */
148 	void addCoordinator(Class<? extends Selector> s, ICoordinator c);
149 
150 	/***
151 	 * Get a List of all Coordinators supported by this Container.
152 	 * 
153 	 * @return a List of all Coordinators supported by this Container.
154 	 */
155 	List<ICoordinator> getCoordinators();
156 
157 	/***
158 	 * Called if the container is destroyed.
159 	 * 
160 	 */
161 	void destroy();
162 
163 	/***
164 	 * Returns the current size of the container.
165 	 * 
166 	 * @return the number of entries currently in the container.
167 	 */
168 	int currentSize();
169 }