summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java
blob: 862ddaa684d550fc655887fb074d7c5275c11681 (plain)
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
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.request;

import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.base.IConfigStore;
import com.netscape.certsrv.base.ISubsystem;
import com.netscape.certsrv.dbs.IDBSSession;
import com.netscape.certsrv.dbs.IDBSubsystem;
import com.netscape.certsrv.logging.ILogger;
import com.netscape.certsrv.request.INotify;
import com.netscape.certsrv.request.IPolicy;
import com.netscape.certsrv.request.IRequestQueue;
import com.netscape.certsrv.request.IRequestSubsystem;
import com.netscape.certsrv.request.IService;
import com.netscape.cmscore.dbs.DBSubsystem;

/**
 * RequestSubsystem
 * <p>
 * This class is reponsible for managing storage of request objects in the local database.
 * <p>
 * TODO: review this It provides: + registration of LDAP/JAVA mapping classes with the DBSubsystem + creation of
 * RequestQueue storage in the database + retrieval of existing RequestQueue objects from the database
 * <p>
 * 
 * @author thayes
 * @version $Revision$, $Date$
 */
public class RequestSubsystem
        implements IRequestSubsystem, ISubsystem {

    public final static String ID = IRequestSubsystem.SUB_ID;

    // singleton enforcement

    private static RequestSubsystem mInstance = new RequestSubsystem();

    public static RequestSubsystem getInstance() {
        return mInstance;
    }

    private RequestSubsystem() {
    }

    // end singleton enforcement.

    //
    // Create a new request queue.  The LDAP DN for the entry
    // in the database is supplied by the caller.
    //
    public void createRequestQueue(String name)
            throws EBaseException {

        /*
         String dbName = makeQueueName(name);
         IDBSSession dbs = createDBSSession();

         // Create Repository record here

        dbs.add(dbName, r);
        */
    }

    public IRequestQueue
            getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n)
                    throws EBaseException {
        return getRequestQueue(name, increment, p, s, n, null);
    }

    public IRequestQueue
            getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n,
                    INotify pendingNotifier)
                    throws EBaseException {
        RequestQueue rq = new RequestQueue(name, increment, p, s, n, pendingNotifier);

        // can't do this here because the service depends on getting rq
        // (to get request) and since this method hasn't returned it's rq is null. 
        //rq.recover();

        return rq;
    }

    //
    // ISubsystem methods:
    //   getId, setId, init, startup, shutdown, getConfigStore
    //

    /**
     * Implements ISubsystem.getId
     * <p>
     * 
     * @see ISubsystem#getId
     */
    public String getId() {
        return mId;
    }

    // ISubsystem.setId
    public void setId(String id)
            throws EBaseException {
        mId = id;
    }

    // ISubsystem.init
    public void init(ISubsystem parent, IConfigStore config) {
        mParent = parent;
        mConfig = config;
    }

    /**
     * Implements ISubsystem.startup
     * <p>
     * 
     * @see ISubsystem#startup
     */
    public void startup()
            throws EBaseException {
        mLogger = CMS.getLogger();

        mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO,
                "Request subsystem started");
    }

    public void shutdown() {
        mRequestQueue = null;

        if (mLogger != null) {
            mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO,
                    "Request subsystem stopped");
        }
    }

    public IConfigStore getConfigStore() {
        return mConfig;
    }

    //
    // Access to the DBSubsystem environment value
    //
    protected IDBSubsystem getDBSubsystem() {
        return DBSubsystem.getInstance();
    }

    //
    // Create a database session in the default database
    // system.
    //
    protected IDBSSession createDBSSession()
            throws EBaseException {
        return getDBSubsystem().createSession();
    }

    //
    // Make a queue name
    //
    protected String makeQueueName(String name) {
        IDBSubsystem db = getDBSubsystem();

        return "cn=" + name + "," + db.getBaseDN();
    }

    // Instance variables

    private IConfigStore mConfig;
    private ISubsystem mParent;
    private String mId = IRequestSubsystem.SUB_ID;
    private IRequestQueue mRequestQueue;

    protected ILogger mLogger;
}