/
AbstractCellComponent.java
200 lines (179 loc) · 5.4 KB
/
AbstractCellComponent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package dmg.cells.nucleus;
import java.io.PrintWriter;
import java.util.Map;
import dmg.util.Args;
public class AbstractCellComponent
implements CellInfoProvider,
CellSetupProvider,
CellMessageSender,
CellLifeCycleAware
{
private CellEndpoint _endpoint;
private CellAddressCore _cellAddress;
/**
* Implements CellInfoProvider interface.
*/
@Override
public void getInfo(PrintWriter pw) {}
/**
* Implements CellInfoProvider interface.
*/
@Override
public CellInfo getCellInfo(CellInfo info)
{
return info;
}
/**
* Implements CellSetupProvider interface.
*/
@Override
public void printSetup(PrintWriter pw) {}
/**
* Implements CellSetupProvider interface.
*/
@Override
public void beforeSetup() {}
/**
* Implements CellSetupProvider interface.
*/
@Override
public void afterSetup() {}
/**
* Implements CellLifeCycleAware interface.
*/
@Override
public void afterStart() {}
/**
* Implements CellLifeCycleAware interface.
*/
@Override
public void beforeStop() {}
/**
* Implements CellMessageSender interface.
*/
@Override
public void setCellEndpoint(CellEndpoint endpoint)
{
_endpoint = endpoint;
CellInfo cellInfo = _endpoint.getCellInfo();
_cellAddress = new CellAddressCore(cellInfo.getCellName(), cellInfo.getDomainName());
}
/**
* Implements CellMessageSender interface.
*/
protected CellEndpoint getCellEndpoint()
{
return _endpoint;
}
/**
* Sends <code>envelope</code>.
*
* @param envelope the cell message to be sent.
* @throws SerializationException if the payload object of this
* message is not serializable.
* @throws NoRouteToCellException if the destination could not be
* reached.
*/
protected void sendMessage(CellMessage envelope)
throws SerializationException,
NoRouteToCellException
{
_endpoint.sendMessage(envelope);
}
/**
* Sends <code>envelope</code>. The <code>callback</code> argument
* (which has to be non-null) allows to specify an object which is
* informed as soon as an has answer arrived or if the timeout has
* expired.
*
* @param envelope the cell message to be sent.
* @param callback specifies an object class which will be informed
* as soon as the message arrives.
* @param timeout is the timeout in msec.
* @exception SerializationException if the payload object of this
* message is not serializable.
*/
protected void sendMessage(CellMessage envelope,
CellMessageAnswerable callback,
long timeout)
throws SerializationException
{
_endpoint.sendMessage(envelope, callback, timeout);
}
/**
* Sends <code>envelope</code> and waits <code>timeout</code>
* milliseconds for an answer to arrive. The answer will bypass
* the ordinary queuing mechanism and will be delivered before any
* other asynchronous message. The answer need to have the
* getLastUOID set to the UOID of the message send with
* sendAndWait. If the answer does not arrive withing the specified
* time interval, the method returns <code>null</code> and the
* answer will be handled as if it was an ordinary asynchronous
* message.
*
* @param envelope the cell message to be sent.
* @param timeout milliseconds to wait for an answer.
* @return the answer or null if the timeout was reached.
* @throws SerializationException if the payload object of this
* message is not serializable.
* @throws NoRouteToCellException if the destination
* couldnot be reached.
*/
protected CellMessage sendAndWait(CellMessage envelope, long timeout)
throws SerializationException,
NoRouteToCellException,
InterruptedException
{
return _endpoint.sendAndWait(envelope, timeout);
}
/**
* Provides information about the host cell.
*
* Depending on the cell, a subclass of CellInfo with additional
* information may be returned instead.
*
* @return The cell information encapsulated in a CellInfo object.
*/
protected CellInfo getCellInfo()
{
return _endpoint.getCellInfo();
}
/**
* Returns the address of the cell hosting this component.
*/
protected CellAddressCore getCellAddress()
{
return _cellAddress;
}
/**
* Returns the name of the cell hosting this component.
*/
protected String getCellName()
{
return getCellAddress().getCellName();
}
/**
* Returns the name of the domain hosting the cell hosting this
* component.
*/
protected String getCellDomainName()
{
return getCellAddress().getCellDomainName();
}
/**
* Returns the domain context. The domain context is shared by all
* cells in a domain.
*/
protected Map<String,Object> getDomainContext()
{
return _endpoint.getDomainContext();
}
/**
* Returns the cell command line arguments provided when the cell
* was created.
*/
protected Args getArgs()
{
return _endpoint.getArgs();
}
}