~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/src/com/sun/grid/jgdi/jni/JGDIBaseImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.jgdi.jni;
 
33
 
 
34
import com.sun.grid.jgdi.JGDIException;
 
35
import com.sun.grid.jgdi.configuration.JGDIAnswer;
 
36
import com.sun.grid.jgdi.monitoring.*;
 
37
import java.io.File;
 
38
import java.util.ArrayList;
 
39
import java.util.LinkedList;
 
40
import java.util.List;
 
41
import java.util.logging.Level;
 
42
import java.util.logging.LogRecord;
 
43
import java.util.logging.Logger;
 
44
 
 
45
/**
 
46
 *
 
47
 */
 
48
public abstract class JGDIBaseImpl implements com.sun.grid.jgdi.JGDIBase {
 
49
 
 
50
    private final static Logger log = Logger.getLogger(JGDIBaseImpl.class.getName());
 
51
    private int ctxIndex = -1;
 
52
    private File sgeRoot;
 
53
    private final static List<JGDIBaseImpl> instances = new LinkedList<JGDIBaseImpl>();
 
54
    private static boolean shutdown = false;
 
55
 
 
56
    public void init(String url) throws JGDIException {
 
57
        synchronized (instances) {
 
58
            if (shutdown) {
 
59
                throw new JGDIException("shutdown in progress");
 
60
            }
 
61
            instances.add(this);
 
62
        }
 
63
        ctxIndex = nativeInit(url);
 
64
        if (log.isLoggable(Level.FINE)) {
 
65
            log.log(Level.FINE, "native connection with id {1} established (url={0})", new Object[]{url, ctxIndex});
 
66
        }
 
67
    }
 
68
 
 
69
    int getCtxIndex() {
 
70
        return ctxIndex;
 
71
    }
 
72
 
 
73
    public static void resetShutdown() {
 
74
        synchronized (instances) {
 
75
            shutdown = false;
 
76
        }
 
77
    }
 
78
 
 
79
    public static void closeAllConnections() {
 
80
        List<JGDIBaseImpl> currentInstances = null;
 
81
        synchronized (instances) {
 
82
            shutdown = true;
 
83
            currentInstances = new ArrayList<JGDIBaseImpl>(instances);
 
84
        }
 
85
        for (JGDIBaseImpl jgdi : currentInstances) {
 
86
            try {
 
87
                jgdi.close();
 
88
            } catch (JGDIException ex) {
 
89
                LogRecord lr = new LogRecord(Level.FINE, "close of connection {0} failed");
 
90
                lr.setParameters(new Object[]{jgdi.ctxIndex});
 
91
                lr.setThrown(ex);
 
92
                log.log(lr);
 
93
            }
 
94
        }
 
95
    }
 
96
 
 
97
    public void close() throws com.sun.grid.jgdi.JGDIException {
 
98
        int tmpCtxIndex = -1;
 
99
        synchronized (this) {
 
100
            tmpCtxIndex = ctxIndex;
 
101
            ctxIndex = -1;
 
102
        }
 
103
        if (tmpCtxIndex >= 0) {
 
104
            log.log(Level.FINE, "Closing connection with id {0}", tmpCtxIndex);
 
105
            synchronized (instances) {
 
106
                instances.remove(this);
 
107
            }
 
108
            nativeClose(tmpCtxIndex);
 
109
            if (log.isLoggable(Level.FINE)) {
 
110
                log.log(Level.FINE, "Connection with id {0} closed", tmpCtxIndex);
 
111
            }
 
112
        }
 
113
    }
 
114
 
 
115
    public File getSGERoot() throws JGDIException {
 
116
        if (sgeRoot == null) {
 
117
            sgeRoot = new File(nativeGetSGERoot());
 
118
        }
 
119
        return sgeRoot;
 
120
    }
 
121
 
 
122
    public String getSGECell() throws JGDIException {
 
123
        return nativeGetSGECell();
 
124
    }
 
125
 
 
126
    public String getAdminUser() throws JGDIException {
 
127
        return nativeGetAdminUser();
 
128
    }
 
129
 
 
130
    public String getActQMaster() throws JGDIException {
 
131
        return nativeGetActQMaster();
 
132
    }
 
133
 
 
134
    public String getSchedulerHost() throws JGDIException {
 
135
        return nativeGetSchedulerHost();
 
136
    }
 
137
 
 
138
    public QHostResult execQHost(QHostOptions options) throws JGDIException {
 
139
        QHostResultImpl ret = new QHostResultImpl();
 
140
        nativeExecQHost(options, ret);
 
141
        return ret;
 
142
    }
 
143
 
 
144
    public List<ClusterQueueSummary> getClusterQueueSummary(ClusterQueueSummaryOptions options) throws JGDIException {
 
145
        List<ClusterQueueSummary> ret = new LinkedList<ClusterQueueSummary>();
 
146
        nativeFillClusterQueueSummary(options, ret);
 
147
        return ret;
 
148
    }
 
149
 
 
150
    public QueueInstanceSummaryResult getQueueInstanceSummary(QueueInstanceSummaryOptions options) throws JGDIException {
 
151
        QueueInstanceSummaryResultImpl ret = new QueueInstanceSummaryResultImpl();
 
152
        nativeFillQueueInstanceSummary(options, ret);
 
153
        return ret;
 
154
    }
 
155
 
 
156
    public QQuotaResult getQQuota(QQuotaOptions options) throws JGDIException {
 
157
        QQuotaResultImpl ret = new QQuotaResultImpl();
 
158
        nativeGetQQuota(options, ret);
 
159
        return ret;
 
160
    }
 
161
 
 
162
    public void cleanQueuesWithAnswer(String[] queues, List<JGDIAnswer> answers) throws JGDIException {
 
163
        nativeCleanQueuesWithAnswer(queues, answers);
 
164
    }
 
165
 
 
166
    public void cleanQueues(String[] queues) throws JGDIException {
 
167
        cleanQueuesWithAnswer(queues, null);
 
168
    }
 
169
 
 
170
    public void unsuspendWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
171
        nativeUnsuspendWithAnswer(queues, force, answers);
 
172
    }
 
173
 
 
174
    public void unsuspend(String[] queues, boolean force) throws JGDIException {
 
175
        unsuspendWithAnswer(queues, force, null);
 
176
    }
 
177
 
 
178
    public void unsuspendQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
179
        nativeUnsuspendQueuesWithAnswer(queues, force, answers);
 
180
    }
 
181
 
 
182
    public void unsuspendQueues(String[] queues, boolean force) throws JGDIException {
 
183
        unsuspendQueuesWithAnswer(queues, force, null);
 
184
    }
 
185
 
 
186
    public void unsuspendJobsWithAnswer(String[] jobs, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
187
        nativeUnsuspendJobsWithAnswer(jobs, force, answers);
 
188
    }
 
189
 
 
190
    public void unsuspendJobs(String[] jobs, boolean force) throws JGDIException {
 
191
        unsuspendJobsWithAnswer(jobs, force, null);
 
192
    }
 
193
 
 
194
    public void suspendWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
195
        nativeSuspendWithAnswer(queues, force, answers);
 
196
    }
 
197
 
 
198
    public void suspend(String[] queues, boolean force) throws JGDIException {
 
199
        suspendWithAnswer(queues, force, null);
 
200
    }
 
201
 
 
202
    public void suspendQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
203
        nativeSuspendQueuesWithAnswer(queues, force, answers);
 
204
    }
 
205
 
 
206
    public void suspendQueues(String[] queues, boolean force) throws JGDIException {
 
207
        suspendQueuesWithAnswer(queues, force, null);
 
208
    }
 
209
 
 
210
    public void suspendJobsWithAnswer(String[] jobs, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
211
        nativeSuspendJobsWithAnswer(jobs, force, answers);
 
212
    }
 
213
 
 
214
    public void suspendJobs(String[] jobs, boolean force) throws JGDIException {
 
215
        suspendJobsWithAnswer(jobs, force, null);
 
216
    }
 
217
 
 
218
    public void rescheduleJobsWithAnswer(String[] jobs, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
219
        nativeRescheduleJobsWithAnswer(jobs, force, answers);
 
220
    }
 
221
 
 
222
    public void rescheduleJobs(String[] jobs, boolean force) throws JGDIException {
 
223
        rescheduleJobsWithAnswer(jobs, force, null);
 
224
    }
 
225
 
 
226
    public void rescheduleQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
227
        nativeRescheduleQueuesWithAnswer(queues, force, answers);
 
228
    }
 
229
 
 
230
    public void rescheduleQueues(String[] queues, boolean force) throws JGDIException {
 
231
        rescheduleQueuesWithAnswer(queues, force, null);
 
232
    }
 
233
 
 
234
    public void rescheduleWithAnswer(String[] queue_or_job, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
235
        nativeRescheduleWithAnswer(queue_or_job, force, answers);
 
236
    }
 
237
 
 
238
    public void reschedule(String[] queue_or_job, boolean force) throws JGDIException {
 
239
        rescheduleWithAnswer(queue_or_job, force, null);
 
240
    }
 
241
 
 
242
    public void clearJobsWithAnswer(String[] jobs, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
243
        nativeClearJobsWithAnswer(jobs, force, answers);
 
244
    }
 
245
 
 
246
    public void clearJobs(String[] jobs, boolean force) throws JGDIException {
 
247
        clearJobsWithAnswer(jobs, force, null);
 
248
    }
 
249
 
 
250
    public void clearQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
251
        nativeClearQueuesWithAnswer(queues, force, answers);
 
252
    }
 
253
 
 
254
    public void clearQueues(String[] queues, boolean force) throws JGDIException {
 
255
        clearQueuesWithAnswer(queues, force, null);
 
256
    }
 
257
 
 
258
    public void disableQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
259
        nativeDisableQueuesWithAnswer(queues, force, answers);
 
260
    }
 
261
 
 
262
    public void disableQueues(String[] queues, boolean force) throws JGDIException {
 
263
        disableQueuesWithAnswer(queues, force, null);
 
264
    }
 
265
 
 
266
    public void enableQueuesWithAnswer(String[] queues, boolean force, List<JGDIAnswer> answers) throws JGDIException {
 
267
        nativeEnableQueuesWithAnswer(queues, force, answers);
 
268
    }
 
269
 
 
270
    public void enableQueues(String[] queues, boolean force) throws JGDIException {
 
271
        enableQueuesWithAnswer(queues, force, null);
 
272
    }
 
273
 
 
274
    public void killAllExecdsWithAnswer(boolean terminateJobs, List<JGDIAnswer> answers) throws JGDIException {
 
275
        nativeKillAllExecdsWithAnswer(terminateJobs, answers);
 
276
    }
 
277
 
 
278
    public void killAllExecds(boolean terminateJobs) throws JGDIException {
 
279
        killAllExecdsWithAnswer(terminateJobs, null);
 
280
    }
 
281
 
 
282
    public void killExecdWithAnswer(String[] hosts, boolean terminateJobs, List<JGDIAnswer> answers) throws JGDIException {
 
283
        nativeKillExecdWithAnswer(hosts, terminateJobs, answers);
 
284
    }
 
285
 
 
286
    public void killExecd(String[] hosts, boolean terminateJobs) throws JGDIException {
 
287
        killExecdWithAnswer(hosts, terminateJobs, null);
 
288
    }
 
289
 
 
290
    public void killEventClientsWithAnswer(int[] ids, List<JGDIAnswer> answers) throws JGDIException {
 
291
        nativeKillEventClientsWithAnswer(ids, answers);
 
292
    }
 
293
 
 
294
    public void killEventClients(int[] ids) throws JGDIException {
 
295
        killEventClientsWithAnswer(ids, null);
 
296
    }
 
297
 
 
298
    public void triggerSchedulerMonitoringWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
299
        nativeTriggerSchedulerMonitoringWithAnswer(answers);
 
300
    }
 
301
 
 
302
    public void triggerSchedulerMonitoring() throws JGDIException {
 
303
        triggerSchedulerMonitoringWithAnswer(null);
 
304
    }
 
305
 
 
306
    public void clearShareTreeUsageWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
307
        nativeClearShareTreeUsageWithAnswer(answers);
 
308
    }
 
309
 
 
310
    public void clearShareTreeUsage() throws JGDIException {
 
311
        clearShareTreeUsageWithAnswer(null);
 
312
    }
 
313
 
 
314
    public void killAllEventClientsWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
315
        nativeKillAllEventClientsWithAnswer(answers);
 
316
    }
 
317
 
 
318
    public void killAllEventClients() throws JGDIException {
 
319
        killAllEventClientsWithAnswer(null);
 
320
    }
 
321
 
 
322
    public void killMasterWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
323
        nativeKillMasterWithAnswer(answers);
 
324
    }
 
325
 
 
326
    public void killMaster() throws JGDIException {
 
327
        killMasterWithAnswer(null);
 
328
    }
 
329
 
 
330
    public void killSchedulerWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
331
        nativeKillSchedulerWithAnswer(answers);
 
332
    }
 
333
 
 
334
    public void killScheduler() throws JGDIException {
 
335
        killSchedulerWithAnswer(null);
 
336
    }
 
337
 
 
338
    public void startSchedulerWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
339
        nativeStartSchedulerWithAnswer(answers);
 
340
    }
 
341
 
 
342
    public void startScheduler() throws JGDIException {
 
343
        startSchedulerWithAnswer(null);
 
344
    }
 
345
 
 
346
    public String showDetachedSettingsWithAnswer(String[] queues, List<JGDIAnswer> answers) throws JGDIException {
 
347
        return nativeShowDetachedSettingsWithAnswer(queues, answers);
 
348
    }
 
349
 
 
350
    public String showDetachedSettings(String[] queues) throws JGDIException {
 
351
        return showDetachedSettingsWithAnswer(queues, null);
 
352
    }
 
353
 
 
354
    public String showDetachedSettingsAllWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
355
        return nativeShowDetachedSettingsAllWithAnswer(answers);
 
356
    }
 
357
 
 
358
    public String showDetachedSettingsAll() throws JGDIException {
 
359
        return showDetachedSettingsAllWithAnswer(null);
 
360
    }
 
361
 
 
362
    public void deleteShareTree() throws JGDIException {
 
363
        deleteShareTreeWithAnswer(null);
 
364
    }
 
365
 
 
366
    public void deleteShareTreeWithAnswer(List<JGDIAnswer> answers) throws JGDIException {
 
367
        nativeDeleteShareTreeWithAnswer(answers);
 
368
    }
 
369
 
 
370
    private native int nativeInit(String url) throws JGDIException;
 
371
 
 
372
    private native void nativeClose(int ctxIndex) throws JGDIException;
 
373
 
 
374
    private native String nativeGetSGERoot() throws JGDIException;
 
375
 
 
376
    private native String nativeGetSGECell() throws JGDIException;
 
377
 
 
378
    private native String nativeGetAdminUser() throws JGDIException;
 
379
 
 
380
    private native String nativeGetActQMaster() throws JGDIException;
 
381
 
 
382
    private native void nativeExecQHost(QHostOptions options, QHostResultImpl result);
 
383
 
 
384
    private native void nativeFillClusterQueueSummary(ClusterQueueSummaryOptions options, List<ClusterQueueSummary> list) throws JGDIException;
 
385
 
 
386
    private native void nativeFillQueueInstanceSummary(QueueInstanceSummaryOptions options, QueueInstanceSummaryResultImpl result) throws JGDIException;
 
387
 
 
388
    private native String nativeGetSchedulerHost() throws JGDIException;
 
389
 
 
390
    private native void nativeGetQQuota(QQuotaOptions options, QQuotaResultImpl ret) throws JGDIException;
 
391
 
 
392
    private native void nativeCleanQueuesWithAnswer(String[] queues, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
393
 
 
394
    private native void nativeUnsuspendWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
395
 
 
396
    private native void nativeKillSchedulerWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
397
 
 
398
    private native void nativeStartSchedulerWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
399
 
 
400
    private native void nativeUnsuspendQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
401
 
 
402
    private native void nativeUnsuspendJobsWithAnswer(String[] jobs, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
403
 
 
404
    private native void nativeSuspendWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
405
 
 
406
    private native void nativeSuspendQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
407
 
 
408
    private native void nativeSuspendJobsWithAnswer(String[] jobs, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
409
 
 
410
    private native void nativeRescheduleJobsWithAnswer(String[] jobs, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
411
 
 
412
    private native void nativeRescheduleQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
413
 
 
414
    private native void nativeRescheduleWithAnswer(String[] queue_or_job, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
415
 
 
416
    private native void nativeClearJobsWithAnswer(String[] jobs, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
417
 
 
418
    private native void nativeClearQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
419
 
 
420
    private native void nativeDisableQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
421
 
 
422
    private native void nativeEnableQueuesWithAnswer(String[] queues, boolean force, java.util.List<JGDIAnswer> answers) throws JGDIException;
 
423
 
 
424
    private native void nativeKillAllExecdsWithAnswer(boolean terminateJobs, List<JGDIAnswer> answers) throws JGDIException;
 
425
 
 
426
    private native void nativeKillExecdWithAnswer(String[] hosts, boolean terminateJobs, List<JGDIAnswer> answers) throws JGDIException;
 
427
 
 
428
    private native void nativeKillEventClientsWithAnswer(int[] ids, List<JGDIAnswer> answers) throws JGDIException;
 
429
 
 
430
    private native void nativeTriggerSchedulerMonitoringWithAnswer(java.util.List<JGDIAnswer> answer) throws JGDIException;
 
431
 
 
432
    private native void nativeClearShareTreeUsageWithAnswer(java.util.List<JGDIAnswer> answers) throws JGDIException;
 
433
 
 
434
    private native void nativeKillAllEventClientsWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
435
 
 
436
    private native void nativeKillMasterWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
437
 
 
438
    private native String nativeShowDetachedSettingsWithAnswer(String[] queues, List<JGDIAnswer> answers) throws JGDIException;
 
439
 
 
440
    private native String nativeShowDetachedSettingsAllWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
441
 
 
442
    private native void nativeDeleteShareTreeWithAnswer(List<JGDIAnswer> answers) throws JGDIException;
 
443
}