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

« back to all changes in this revision

Viewing changes to source/libs/jdrmaa/src/com/sun/grid/drmaa/JobInfoImpl.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.drmaa;
 
33
 
 
34
import java.util.HashMap;
 
35
import java.util.Map;
 
36
 
 
37
import org.ggf.drmaa.*;
 
38
 
 
39
/**
 
40
 * This class provides information about a completed Grid Engine job.
 
41
 * @see org.ggf.drmaa.JobInfo
 
42
 * @author  dan.templeton@sun.com
 
43
 * @since 0.5
 
44
 * version 1.0
 
45
 */
 
46
public class JobInfoImpl implements JobInfo {
 
47
    private static final int EXITED_BIT = 0x00000001;
 
48
    private static final int SIGNALED_BIT = 0x00000002;
 
49
    private static final int COREDUMP_BIT = 0x00000004;
 
50
    private static final int NEVERRAN_BIT = 0x00000008;
 
51
    /* POSIX exit status has only 8 bit */
 
52
    private static final int EXIT_STATUS_BITS = 0x00000FF0;
 
53
    private static final int EXIT_STATUS_OFFSET = 4;
 
54
    private final String signal;
 
55
    private final int status;
 
56
    private final String jobId;
 
57
    private final Map resources;
 
58
    
 
59
    /**
 
60
     * Creates a new instance of JobInfoImpl
 
61
     * @param jobId the job id string
 
62
     * @param status an opaque status code
 
63
     * @param resourceUsage an array of name=value resource usage pairs
 
64
     * @param signal the string description of the terminating signal
 
65
     */
 
66
    JobInfoImpl(String jobId, int status, String[] resourceUsage, String signal) {
 
67
        this.jobId = jobId;
 
68
        this.status = status;
 
69
        this.resources = nameValuesToMap(resourceUsage);
 
70
        this.signal = signal;
 
71
    }
 
72
    
 
73
    public int getExitStatus() {
 
74
        if (!hasExited()) {
 
75
            throw new IllegalStateException();
 
76
        }
 
77
 
 
78
        return ((status & EXIT_STATUS_BITS) >> EXIT_STATUS_OFFSET);
 
79
    }
 
80
    
 
81
    /**
 
82
     * If hasSignaled() returns true, this method returns a representation of
 
83
     * the signal that caused the termination of the job. For signals declared
 
84
     * by POSIX or otherwise known to Grid Engine, the symbolic names are
 
85
     * returned (e.g., SIGABRT, SIGALRM).<BR>
 
86
     * For signals not known by Grid Engine, the string &quot;unknown
 
87
     * signal&quot; is returned.
 
88
     * @return the name of the terminating signal
 
89
     */
 
90
    public String getTerminatingSignal() {
 
91
        if (!hasSignaled()) {
 
92
            throw new IllegalStateException();
 
93
        }
 
94
 
 
95
        return signal;
 
96
    }
 
97
    
 
98
    public boolean hasCoreDump() {
 
99
        return ((status & COREDUMP_BIT) != 0);
 
100
    }
 
101
    
 
102
    public boolean hasExited() {
 
103
        return ((status & EXITED_BIT) != 0);
 
104
    }
 
105
    
 
106
    public boolean hasSignaled() {
 
107
        return ((status & SIGNALED_BIT) != 0);
 
108
    }
 
109
    
 
110
    public boolean wasAborted() {
 
111
        return ((status & NEVERRAN_BIT) != 0);
 
112
    }
 
113
 
 
114
    public String getJobId() {
 
115
        return jobId;
 
116
    }
 
117
 
 
118
    public Map getResourceUsage() {
 
119
        return resources;
 
120
    }
 
121
    
 
122
    private static Map nameValuesToMap(String[] nameValuePairs) {
 
123
        Map map = null;
 
124
 
 
125
        if (nameValuePairs != null) {
 
126
            map = new HashMap();
 
127
 
 
128
            for (int count = 0; count < nameValuePairs.length; count++) {
 
129
                int equals = nameValuePairs[count].indexOf('=');
 
130
                map.put(nameValuePairs[count].substring(0, equals), nameValuePairs[count].substring(equals + 1));
 
131
            }
 
132
        }
 
133
 
 
134
        return map;
 
135
    }
 
136
}