1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.kandula.context;
18
19 import java.util.HashMap;
20
21 import org.apache.axis2.addressing.EndpointReference;
22 import org.apache.kandula.Status;
23 import org.apache.kandula.utility.EndpointReferenceFactory;
24
25 /***
26 * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
27 */
28 public abstract class AbstractContext {
29
30 public static String ACTIVATION_EPR = "activationEPR";
31
32 public static String COORDINATION_EPR = "coordinationEPR";
33
34 public static String REQUESTER_ID = "requesterID";
35
36 protected String activityID;
37
38 protected CoordinationContext coordinationContext = null;
39
40 private boolean locked = false;
41
42 private final HashMap propertyBag;
43
44 private int status = Status.CoordinatorStatus.STATUS_NONE;
45
46 protected AbstractContext() {
47 propertyBag = new HashMap();
48 }
49
50 public AbstractContext(String coordinationType) {
51 propertyBag = new HashMap();
52 activityID = "urn:"
53 + EndpointReferenceFactory.getRandomStringOf18Characters();
54 EndpointReference registrationEpr = EndpointReferenceFactory
55 .getInstance().getRegistrationEndpoint(activityID);
56 coordinationContext = CoordinationContext.Factory.newContext(
57 activityID, coordinationType, registrationEpr);
58 }
59
60 public final CoordinationContext getCoordinationContext() {
61 return coordinationContext;
62 }
63
64 public abstract String getCoordinationType();
65
66 public abstract String getRegistrationProtocol();
67
68 public final Object getProperty(Object key) {
69 return propertyBag.get(key);
70 }
71
72 public final int getStatus() {
73 return status;
74 }
75
76 public final synchronized void lock() {
77 if (locked) {
78 while (locked) {
79 try {
80 wait();
81 } catch (InterruptedException ex) {
82
83 }
84 if (status == Status.CoordinatorStatus.STATUS_NONE)
85 throw new IllegalStateException();
86 }
87 }
88
89 locked = true;
90 }
91
92 public final void setCoordinationContext(CoordinationContext context) {
93 this.coordinationContext = context;
94 }
95
96 public final void setProperty(Object key, Object value) {
97 propertyBag.put(key, value);
98
99 }
100
101
102
103 public final void setStatus(int value) {
104 status = value;
105 }
106
107 public final synchronized void unlock() {
108 if (!locked)
109 throw new IllegalStateException();
110 locked = false;
111 notify();
112 }
113
114 }