KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > scheduler > AbstractSchedulerControl


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Jeff Mesnil.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.controller.scheduler;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.management.NotCompliantMBeanException JavaDoc;
30
31 import org.continuent.sequoia.common.i18n.Translate;
32 import org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean;
33 import org.continuent.sequoia.controller.jmx.AbstractStandardMBean;
34 import org.continuent.sequoia.controller.requestmanager.TransactionMetaData;
35 import org.continuent.sequoia.controller.requests.AbstractRequest;
36
37 /**
38  * AbstractSchedulerControlMBean implemementation. Used to manage Schedulers
39  *
40  * @see org.continuent.sequoia.controller.scheduler.AbstractScheduler
41  * @see org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean
42  */

43 public class AbstractSchedulerControl extends AbstractStandardMBean
44     implements
45       AbstractSchedulerControlMBean
46 {
47
48   private AbstractScheduler managedScheduler;
49
50   /**
51    * Creates a new <code>AbstractSchedulerControl</code> object
52    *
53    * @param scheduler the managed AbstractScheduler
54    * @throws NotCompliantMBeanException if this mbean is not compliant
55    */

56   public AbstractSchedulerControl(AbstractScheduler scheduler)
57       throws NotCompliantMBeanException JavaDoc
58   {
59     super(AbstractSchedulerControlMBean.class);
60     this.managedScheduler = scheduler;
61   }
62
63   /**
64    * @see org.continuent.sequoia.controller.jmx.AbstractStandardMBean#getAssociatedString()
65    */

66   public String JavaDoc getAssociatedString()
67   {
68     return "abstractscheduler"; //$NON-NLS-1$
69
}
70
71   /**
72    * @see org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean#listActiveTransactionIds()
73    */

74   public long[] listActiveTransactionIds()
75   {
76     List JavaDoc transactions = managedScheduler.getActiveTransactions();
77     int sz = transactions.size();
78     long[] res = new long[sz];
79     for (int i = 0; i < sz; i++)
80     {
81       TransactionMetaData tmd = (TransactionMetaData) transactions.get(i);
82       res[i] = tmd.getTransactionId();
83     }
84     return res;
85   }
86
87   private long[] listPendingRequestIds(HashMap JavaDoc requests)
88   {
89     Set JavaDoc reqIds = requests.keySet();
90     long[] res = new long[reqIds.size()];
91     int i = 0;
92     for (Iterator JavaDoc iter = reqIds.iterator(); iter.hasNext(); i++)
93     {
94       Long JavaDoc l = (Long JavaDoc) iter.next();
95       res[i] = l.longValue();
96     }
97     return res;
98   }
99
100   /**
101    * @see org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean#listPendingWriteRequestIds()
102    */

103   public long[] listPendingWriteRequestIds()
104   {
105     return listPendingRequestIds(managedScheduler.getActiveWriteRequests());
106   }
107
108   /**
109    * @see org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean#listPendingReadRequestIds()
110    */

111   public long[] listPendingReadRequestIds()
112   {
113     return listPendingRequestIds(managedScheduler.getActiveReadRequests());
114   }
115
116   /**
117    * @see org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean#dumpRequest(long)
118    */

119   public String JavaDoc dumpRequest(long requestId)
120   {
121     AbstractRequest request = null;
122     HashMap JavaDoc writeRequests = managedScheduler.getActiveWriteRequests();
123     synchronized (writeRequests)
124     {
125       request = (AbstractRequest) writeRequests.get(new Long JavaDoc(requestId));
126     }
127     if (request == null)
128     {
129       HashMap JavaDoc readRequests = managedScheduler.getActiveReadRequests();
130       synchronized (readRequests)
131       {
132         request = (AbstractRequest) readRequests.get(new Long JavaDoc(requestId));
133       }
134     }
135     if (request == null)
136     {
137       return Translate.get("scheduler.request.notActive", requestId);
138     }
139     return request.toDebugString();
140   }
141 }
142
Popular Tags