-
Notifications
You must be signed in to change notification settings - Fork 33
/
IMQService.java
317 lines (258 loc) · 8.48 KB
/
IMQService.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* @(#)IMQService.java 1.56 06/29/07
*/
package com.sun.messaging.jmq.jmsserver.service.imq;
import java.io.*;
import com.sun.messaging.jmq.jmsserver.service.*;
import com.sun.messaging.jmq.jmsserver.util.*;
import com.sun.messaging.jmq.jmsserver.auth.AuthCacheData;
import com.sun.messaging.jmq.jmsserver.net.*;
import com.sun.messaging.jmq.util.log.Logger;
import com.sun.messaging.jmq.util.ServiceState;
import com.sun.messaging.jmq.util.ServiceType;
import com.sun.messaging.jmq.jmsserver.resources.*;
import com.sun.messaging.jmq.jmsserver.config.*;
import com.sun.messaging.jmq.jmsserver.Globals;
import java.util.*;
public abstract class IMQService implements Service {
protected static boolean DEBUG = false;
/**
* the list of connections which this service knows about
*/
protected ConnectionManager connectionList = Globals.getConnectionManager();
private boolean serviceRunning = false;
private boolean shuttingDown = false;
private int state = ServiceState.UNINITIALIZED;
private int type = ServiceType.NORMAL;
protected Logger logger = Globals.getLogger();
protected String name = null;
private AuthCacheData authCacheData = new AuthCacheData();
protected static final long DESTROY_WAIT_DEFAULT = 30000;
private long serviceDestroyWait = DESTROY_WAIT_DEFAULT;
HashMap serviceprops = null;
private HashSet serviceress = new HashSet();
private ArrayList serviceressListeners = new ArrayList();
public IMQService(String name, int type) {
this.name = name;
this.type = type;
}
protected boolean getDEBUG() {
return DEBUG;
}
protected void addServiceProp(String name, String value) {
if (serviceprops == null) {
serviceprops = new HashMap();
}
serviceprops.put(name, value);
}
public void resetCounters() {
List cons = connectionList.getConnectionList(this);
Iterator itr = cons.iterator();
while (itr.hasNext()) {
((IMQConnection) itr.next()).resetCounters();
}
}
@Override
public Hashtable getDebugState() {
Hashtable ht = new Hashtable();
ht.put("name", name);
ht.put("state", ServiceState.getString(state));
ht.put("shuttingDown", String.valueOf(isShuttingDown()));
if (serviceprops != null) {
ht.put("props", new Hashtable(serviceprops));
}
ht.put("connections", connectionList.getDebugState(this));
return ht;
}
public Hashtable getPoolDebugState() {
return (new Hashtable());
}
/*
* public void dumpPool() { pool.debug(); }
*/
@Override
public int size() {
List list = connectionList.getConnectionList(this);
return list.size();
}
@Override
public List getConsumers() {
ArrayList list = new ArrayList();
List cons = connectionList.getConnectionList(this);
Iterator itr = cons.iterator();
while (itr.hasNext()) {
List newList = ((IMQConnection) itr.next()).getConsumers();
list.addAll(newList);
}
return list;
}
@Override
public List getProducers() {
ArrayList list = new ArrayList();
List cons = connectionList.getConnectionList(this);
Iterator itr = cons.iterator();
while (itr.hasNext()) {
List newList = ((IMQConnection) itr.next()).getProducers();
list.addAll(newList);
}
return list;
}
public Protocol getProtocol() {
return (null);
}
@Override
public String getName() {
return name;
}
@Override
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
@Override
public int getServiceType() {
return type;
}
public synchronized int getMinThreadpool() {
return (0);
}
public synchronized int getMaxThreadpool() {
return (0);
}
public synchronized int getActiveThreadpool() {
return (0);
}
public void setPriority(int priority) {
}
/**
* @return int[0] min; int[1] max; -1 or null no change
*/
public synchronized int[] setMinMaxThreadpool(int min, int max) {
return null;
}
public void setDestroyWaitTime(long value) {
serviceDestroyWait = value;
}
public long getDestroyWaitTime() {
return (serviceDestroyWait);
}
public void setServiceRunning(boolean value) {
serviceRunning = value;
}
public boolean isServiceRunning() {
return (serviceRunning);
}
public void setShuttingDown(boolean value) {
shuttingDown = value;
}
public boolean isShuttingDown() {
return (shuttingDown);
}
/** @throws IllegalStateException */
@Override
public void stopNewConnections() throws IOException {
if (state != ServiceState.RUNNING) {
throw new IllegalStateException(Globals.getBrokerResources().getKString(BrokerResources.X_CANT_STOP_SERVICE));
}
state = ServiceState.QUIESCED;
}
@Override
public void startNewConnections() throws IOException {
if (state != ServiceState.QUIESCED && state != ServiceState.PAUSED) {
throw new IllegalStateException(Globals.getBrokerResources().getKString(BrokerResources.X_CANT_START_SERVICE));
}
synchronized (this) {
setState(ServiceState.RUNNING);
this.notifyAll();
}
}
@Override
public void destroyService() {
if (getState() < ServiceState.STOPPED) {
stopService(true);
}
synchronized (this) {
setState(ServiceState.DESTROYED);
this.notifyAll();
}
}
public void updateService(int port, int min, int max) throws IOException, PropertyUpdateException, BrokerException {
}
public AuthCacheData getAuthCacheData() {
return authCacheData;
}
@Override
public void removeConnection(ConnectionUID uid, int reason, String str) {
connectionList.removeConnection(uid, true, reason, str);
}
public HashMap getServiceProperties() {
return serviceprops;
}
public boolean isDirect() {
return (false);
}
@Override
public String toString() {
return getName();
}
@Override
public void addServiceRestriction(ServiceRestriction sr) {
synchronized (serviceress) {
serviceress.add(sr);
notifyServiceRestrictionChanged();
}
}
@Override
public void removeServiceRestriction(ServiceRestriction sr) {
synchronized (serviceress) {
serviceress.remove(sr);
notifyServiceRestrictionChanged();
}
}
@Override
public ServiceRestriction[] getServiceRestrictions() {
synchronized (serviceress) {
return (ServiceRestriction[]) serviceress.toArray(new ServiceRestriction[serviceress.size()]);
}
}
@Override
public void addServiceRestrictionListener(ServiceRestrictionListener l) {
synchronized (serviceress) {
serviceressListeners.add(l);
}
}
@Override
public void removeServiceRestrictionListener(ServiceRestrictionListener l) {
synchronized (serviceress) {
serviceressListeners.remove(l);
}
}
private void notifyServiceRestrictionChanged() {
synchronized (serviceress) {
Iterator itr = serviceressListeners.iterator();
ServiceRestrictionListener l = null;
while (itr.hasNext()) {
l = (ServiceRestrictionListener) itr.next();
l.serviceRestrictionChanged(this);
}
}
}
}