001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.mbeans;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.cache.FxBackingCache;
037: import com.flexive.shared.cache.FxCacheException;
038:
039: import javax.management.*;
040: import java.util.Set;
041:
042: import org.jboss.cache.Cache;
043:
044: /**
045: * Proxy for the FxCache MBean (only for internal used!)
046: * TODO: code error handling
047: *
048: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
049: */
050: public class FxCacheProxy implements FxCacheMBean {
051: private MBeanServer server;
052: private ObjectName name;
053:
054: public FxCacheProxy(MBeanServer server)
055: throws MalformedObjectNameException {
056: this .server = server;
057: this .name = new ObjectName(CacheAdmin.CACHE_SERVICE_NAME);
058: }
059:
060: public ObjectName getName() {
061: return name;
062: }
063:
064: /**
065: * {@inheritDoc}
066: */
067: public void create() throws Exception {
068: server.invoke(name, "create", new Object[0], new String[0]);
069: }
070:
071: /**
072: * {@inheritDoc}
073: */
074: public void destroy() throws Exception {
075: server.invoke(name, "destroy", new Object[0], new String[0]);
076: }
077:
078: /**
079: * {@inheritDoc}
080: */
081: public Cache<Object, Object> getCache() throws FxCacheException {
082: return getBackingCache().getCache();
083: }
084:
085: private FxBackingCache getBackingCache() {
086: try {
087: return (FxBackingCache) server
088: .getAttribute(name, "FxCache");
089: } catch (MBeanException e) {
090: e.printStackTrace();
091: } catch (AttributeNotFoundException e) {
092: e.printStackTrace();
093: } catch (InstanceNotFoundException e) {
094: e.printStackTrace();
095: } catch (ReflectionException e) {
096: e.printStackTrace();
097: }
098: System.out.println("Error - returning null!");
099: return null;
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public Object get(String path, Object key) throws FxCacheException {
106: try {
107: return server.invoke(name, "get",
108: new Object[] { path, key }, new String[] {
109: "java.lang.String", "java.lang.Object" });
110: } catch (InstanceNotFoundException e) {
111: e.printStackTrace();
112: } catch (MBeanException e) {
113: e.printStackTrace();
114: } catch (ReflectionException e) {
115: e.printStackTrace();
116: }
117: System.out.println("Error - returning null!");
118: return null;
119: }
120:
121: /**
122: * {@inheritDoc}
123: */
124: public void put(String path, Object key, Object value)
125: throws FxCacheException {
126: try {
127: server.invoke(name, "put",
128: new Object[] { path, key, value }, new String[] {
129: "java.lang.String", "java.lang.Object",
130: "java.lang.Object" });
131: } catch (InstanceNotFoundException e) {
132: e.printStackTrace();
133: } catch (MBeanException e) {
134: e.printStackTrace();
135: } catch (ReflectionException e) {
136: e.printStackTrace();
137: }
138: }
139:
140: /**
141: * {@inheritDoc}
142: */
143: public void remove(String path) throws FxCacheException {
144: try {
145: server.invoke(name, "remove", new Object[] { path },
146: new String[] { "java.lang.String" });
147: } catch (InstanceNotFoundException e) {
148: e.printStackTrace();
149: } catch (MBeanException e) {
150: e.printStackTrace();
151: } catch (ReflectionException e) {
152: e.printStackTrace();
153: }
154: }
155:
156: /**
157: * {@inheritDoc}
158: */
159: public void remove(String path, Object key) throws FxCacheException {
160: try {
161: server.invoke(name, "remove", new Object[] { path, key },
162: new String[] { "java.lang.String",
163: "java.lang.Object" });
164: } catch (InstanceNotFoundException e) {
165: e.printStackTrace();
166: } catch (MBeanException e) {
167: e.printStackTrace();
168: } catch (ReflectionException e) {
169: e.printStackTrace();
170: }
171: }
172:
173: /**
174: * {@inheritDoc}
175: */
176: public Set getKeys(String path) throws FxCacheException {
177: try {
178: return (Set) server.invoke(name, "getKeys",
179: new Object[] { path },
180: new String[] { "java.lang.String" });
181: } catch (InstanceNotFoundException e) {
182: e.printStackTrace();
183: } catch (MBeanException e) {
184: e.printStackTrace();
185: } catch (ReflectionException e) {
186: e.printStackTrace();
187: }
188: System.out.println("Error - returning null!");
189: return null;
190: }
191:
192: /**
193: * {@inheritDoc}
194: */
195: public Set globalGetKeys(String path) throws FxCacheException {
196: try {
197: return (Set) server.invoke(name, "globalGetKeys",
198: new Object[] { path },
199: new String[] { "java.lang.String" });
200: } catch (InstanceNotFoundException e) {
201: e.printStackTrace();
202: } catch (MBeanException e) {
203: e.printStackTrace();
204: } catch (ReflectionException e) {
205: e.printStackTrace();
206: }
207: System.out.println("Error - returning null!");
208: return null;
209: }
210:
211: /**
212: * {@inheritDoc}
213: */
214: public Object globalGet(String path, Object key)
215: throws FxCacheException {
216: try {
217: return server.invoke(name, "globalGet", new Object[] {
218: path, key }, new String[] { "java.lang.String",
219: "java.lang.Object" });
220: } catch (InstanceNotFoundException e) {
221: e.printStackTrace();
222: } catch (MBeanException e) {
223: e.printStackTrace();
224: } catch (ReflectionException e) {
225: e.printStackTrace();
226: }
227: System.out.println("Error - returning null!");
228: return null;
229: }
230:
231: /**
232: * {@inheritDoc}
233: */
234: public boolean globalExists(String path, Object key)
235: throws FxCacheException {
236: try {
237: return (Boolean) server.invoke(name, "globalExists",
238: new Object[] { path, key }, new String[] {
239: "java.lang.String", "java.lang.Object" });
240: } catch (InstanceNotFoundException e) {
241: e.printStackTrace();
242: } catch (MBeanException e) {
243: e.printStackTrace();
244: } catch (ReflectionException e) {
245: e.printStackTrace();
246: }
247: System.out.println("Error - returning null!");
248: return false;
249: }
250:
251: /**
252: * {@inheritDoc}
253: */
254: public boolean exists(String path, Object key)
255: throws FxCacheException {
256: try {
257: return (Boolean) server.invoke(name, "exists",
258: new Object[] { path, key }, new String[] {
259: "java.lang.String", "java.lang.Object" });
260: } catch (InstanceNotFoundException e) {
261: e.printStackTrace();
262: } catch (MBeanException e) {
263: e.printStackTrace();
264: } catch (ReflectionException e) {
265: e.printStackTrace();
266: }
267: System.out.println("Error - returning null!");
268: return false;
269: }
270:
271: /**
272: * {@inheritDoc}
273: */
274: public void globalPut(String path, Object key, Object value)
275: throws FxCacheException {
276: try {
277: server.invoke(name, "globalPut", new Object[] { path, key,
278: value }, new String[] { "java.lang.String",
279: "java.lang.Object", "java.lang.Object" });
280: } catch (InstanceNotFoundException e) {
281: e.printStackTrace();
282: } catch (MBeanException e) {
283: e.printStackTrace();
284: } catch (ReflectionException e) {
285: e.printStackTrace();
286: }
287: }
288:
289: /**
290: * {@inheritDoc}
291: */
292: public void globalRemove(String path) throws FxCacheException {
293: try {
294: server.invoke(name, "globalRemove", new Object[] { path },
295: new String[] { "java.lang.String" });
296: } catch (InstanceNotFoundException e) {
297: e.printStackTrace();
298: } catch (MBeanException e) {
299: e.printStackTrace();
300: } catch (ReflectionException e) {
301: e.printStackTrace();
302: }
303: }
304:
305: /**
306: * {@inheritDoc}
307: */
308: public void globalRemove(String path, Object key)
309: throws FxCacheException {
310: try {
311: server.invoke(name, "globalRemove", new Object[] { path,
312: key }, new String[] { "java.lang.String",
313: "java.lang.Object" });
314: } catch (InstanceNotFoundException e) {
315: e.printStackTrace();
316: } catch (MBeanException e) {
317: e.printStackTrace();
318: } catch (ReflectionException e) {
319: e.printStackTrace();
320: }
321: }
322:
323: /**
324: * {@inheritDoc}
325: */
326: public Set getChildrenNames(String path) throws FxCacheException {
327: try {
328: return (Set) server.invoke(name, "getChildrenNames",
329: new Object[] { path },
330: new String[] { "java.lang.String" });
331: } catch (InstanceNotFoundException e) {
332: e.printStackTrace();
333: } catch (MBeanException e) {
334: e.printStackTrace();
335: } catch (ReflectionException e) {
336: e.printStackTrace();
337: }
338: System.out.println("Error - returning null!");
339: return null;
340: }
341:
342: /**
343: * {@inheritDoc}
344: */
345: public String getDeploymentId() {
346: try {
347: return (String) server.getAttribute(name, "DeploymentId");
348: } catch (InstanceNotFoundException e) {
349: e.printStackTrace();
350: } catch (MBeanException e) {
351: e.printStackTrace();
352: } catch (ReflectionException e) {
353: e.printStackTrace();
354: } catch (AttributeNotFoundException e) {
355: e.printStackTrace();
356: }
357: System.out.println("Error - returning null!");
358: return null;
359: }
360:
361: /**
362: * {@inheritDoc}
363: */
364: public long getSystemStartTime() {
365: try {
366: return (Long) server.getAttribute(name, "SystemStartTime");
367: } catch (InstanceNotFoundException e) {
368: e.printStackTrace();
369: } catch (MBeanException e) {
370: e.printStackTrace();
371: } catch (ReflectionException e) {
372: e.printStackTrace();
373: } catch (AttributeNotFoundException e) {
374: e.printStackTrace();
375: }
376: System.out.println("Error - returning 0!");
377: return 0;
378: }
379:
380: /**
381: * {@inheritDoc}
382: */
383: public long getNodeStartTime() {
384: try {
385: return (Long) server.getAttribute(name, "NodeStartTime");
386: } catch (InstanceNotFoundException e) {
387: e.printStackTrace();
388: } catch (MBeanException e) {
389: e.printStackTrace();
390: } catch (ReflectionException e) {
391: e.printStackTrace();
392: } catch (AttributeNotFoundException e) {
393: e.printStackTrace();
394: }
395: System.out.println("Error - returning 0!");
396: return 0;
397: }
398:
399: /**
400: * {@inheritDoc}
401: */
402: public void reloadEnvironment(Integer divisionId) throws Exception {
403: try {
404: server.invoke(name, "reloadEnvironment",
405: new Object[] { divisionId },
406: new String[] { "java.lang.Integer" });
407: } catch (InstanceNotFoundException e) {
408: e.printStackTrace();
409: } catch (MBeanException e) {
410: e.printStackTrace();
411: } catch (ReflectionException e) {
412: e.printStackTrace();
413: }
414: }
415:
416: /**
417: * {@inheritDoc}
418: */
419: public void setEvictionStrategy(Integer divisionId, String path,
420: Integer maxContents, Integer timeToIdle, Integer timeToLive) {
421: try {
422: server.invoke(name, "setEvictionStrategy", new Object[] {
423: divisionId, path, maxContents, timeToIdle,
424: timeToLive }, new String[] { "java.lang.Integer",
425: "java.lang.String", "java.lang.Integer",
426: "java.lang.Integer", "java.lang.Integer" });
427: } catch (InstanceNotFoundException e) {
428: e.printStackTrace();
429: } catch (MBeanException e) {
430: e.printStackTrace();
431: } catch (ReflectionException e) {
432: e.printStackTrace();
433: }
434: }
435: }
|