KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > cache > parsing > ParsingCacheControl


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.cache.parsing;
23
24 import javax.management.NotCompliantMBeanException JavaDoc;
25
26 import org.continuent.sequoia.common.i18n.Translate;
27 import org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean;
28 import org.continuent.sequoia.controller.jmx.AbstractStandardMBean;
29
30 /**
31  * RequestFactoryControlMBean implemementation. Used to manage RequestFactory
32  *
33  * @see org.continuent.sequoia.controller.requests.RequestFactory
34  * @see org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean
35  */

36 public class ParsingCacheControl extends AbstractStandardMBean
37     implements
38       ParsingCacheMBean
39 {
40   private ParsingCache managedCache;
41   private static final int ENTRIES_PER_DUMP = 100;
42   private int numberOfCacheEntries = 0;
43   private int currentDumpIndex = 0;
44
45   /**
46    * Creates a new <code>ParsingCacheControl</code> object
47    *
48    * @param cache the managed cache
49    * @throws NotCompliantMBeanException if this mbean is not compliant
50    */

51   public ParsingCacheControl(ParsingCache cache)
52       throws NotCompliantMBeanException JavaDoc
53   {
54     super(ParsingCacheMBean.class);
55     this.managedCache = cache;
56   }
57
58   /**
59    * @see org.continuent.sequoia.controller.jmx.AbstractStandardMBean#getAssociatedString()
60    */

61   public String JavaDoc getAssociatedString()
62   {
63     return "requestfactory"; //$NON-NLS-1$
64
}
65
66   /**
67    * @see ParsingCacheMBean#dumpCacheConfig()
68    */

69   public String JavaDoc dumpCacheConfig()
70   {
71     return managedCache.dumpCacheConfig();
72   }
73
74   /**
75    * @see org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean#dumpNextCacheEntries()
76    */

77   public String JavaDoc dumpNextCacheEntries()
78   {
79     StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
80     if (currentDumpIndex > numberOfCacheEntries)
81     {
82       // last dump reached the end of the list, return null and reset counters
83
currentDumpIndex = 0;
84       return null;
85     }
86     if (currentDumpIndex == 0)
87     {
88       // This is a new dump => get the cache size and print a description
89
numberOfCacheEntries = managedCache.getNumberOfCacheEntries();
90       ret.append(Translate.get("cache.entries")); //$NON-NLS-1$
91
}
92     if (numberOfCacheEntries == 0) // no entry, stop dump
93
{
94       currentDumpIndex = 0;
95       return null;
96     }
97     try
98     {
99       ret.append(managedCache.dumpCacheEntries(currentDumpIndex,
100           ENTRIES_PER_DUMP));
101       currentDumpIndex += ENTRIES_PER_DUMP;
102     }
103     catch (OutOfMemoryError JavaDoc e)
104     {
105       // stop dump
106
currentDumpIndex = 0;
107       return null;
108     }
109     return ret.toString();
110   }
111
112   /**
113    * @see ParsingCacheMBean#resetDump()
114    */

115   public void resetDump()
116   {
117     currentDumpIndex = 0;
118     numberOfCacheEntries = 0;
119   }
120
121   /**
122    * @see ParsingCacheMBean#dumpCurrentlyParsedEntries()
123    */

124   public String JavaDoc dumpCurrentlyParsedEntries()
125   {
126     // Assume that the number of currently parsed entries is small enough to fit
127
// into a string (this is actually realistic...)
128
return managedCache.dumpCurrentlyParsedEntries();
129   }
130 }
131
Popular Tags