KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > console > jmx > RmiJmxClient


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

22
23 package org.continuent.sequoia.console.jmx;
24
25 import java.io.IOException JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Set JavaDoc;
30
31 import javax.management.Attribute JavaDoc;
32 import javax.management.InstanceNotFoundException JavaDoc;
33 import javax.management.MBeanInfo JavaDoc;
34 import javax.management.MBeanServerConnection JavaDoc;
35 import javax.management.MBeanServerInvocationHandler JavaDoc;
36 import javax.management.MalformedObjectNameException JavaDoc;
37 import javax.management.NotificationListener JavaDoc;
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.monitor.StringMonitor JavaDoc;
40 import javax.management.remote.JMXConnector JavaDoc;
41 import javax.management.remote.JMXConnectorFactory JavaDoc;
42 import javax.management.remote.JMXServiceURL JavaDoc;
43 import javax.naming.Context JavaDoc;
44 import javax.security.auth.Subject JavaDoc;
45
46 import org.continuent.sequoia.common.authentication.PasswordAuthenticator;
47 import org.continuent.sequoia.common.exceptions.VirtualDatabaseException;
48 import org.continuent.sequoia.common.i18n.ConsoleTranslate;
49 import org.continuent.sequoia.common.jmx.JMXPrincipalWithPassword;
50 import org.continuent.sequoia.common.jmx.JmxConstants;
51 import org.continuent.sequoia.common.jmx.mbeans.AbstractSchedulerControlMBean;
52 import org.continuent.sequoia.common.jmx.mbeans.BackendTaskQueuesControlMBean;
53 import org.continuent.sequoia.common.jmx.mbeans.ControllerMBean;
54 import org.continuent.sequoia.common.jmx.mbeans.DataCollectorMBean;
55 import org.continuent.sequoia.common.jmx.mbeans.DatabaseBackendMBean;
56 import org.continuent.sequoia.common.jmx.mbeans.ParsingCacheMBean;
57 import org.continuent.sequoia.common.jmx.mbeans.RecoveryLogControlMBean;
58 import org.continuent.sequoia.common.jmx.mbeans.RequestManagerMBean;
59 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
60 import org.continuent.sequoia.common.log.Trace;
61
62 /**
63  * This class defines a RmiJmxClient that uses Jmx 2.0 specifications to connect
64  * to the RmiSever
65  *
66  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
67  * @version 1.0
68  */

69 public class RmiJmxClient
70 {
71   private JMXConnector JavaDoc connector;
72   private Object JavaDoc credentials;
73   private String JavaDoc remoteHostAddress;
74   private String JavaDoc remoteHostPort;
75
76   private NotificationListener JavaDoc notificationListener;
77
78   // List of last used MBeans
79
private ControllerMBean controllerMBean;
80   private DatabaseBackendMBean backendMBean;
81   private DataCollectorMBean dataMBean;
82
83   private Trace logger = Trace
84                                           .getLogger("org.continuent.sequoia.console.jmx");
85
86   /**
87    * Returns the notificationListener value.
88    *
89    * @return Returns the notificationListener.
90    */

91   public NotificationListener JavaDoc getNotificationListener()
92   {
93     return notificationListener;
94   }
95
96   /**
97    * Sets the notificationListener value.
98    *
99    * @param notificationListener The notificationListener to set.
100    */

101   public void setNotificationListener(NotificationListener JavaDoc notificationListener)
102   {
103     this.notificationListener = notificationListener;
104   }
105
106   /**
107    * Returns the credentials value.
108    *
109    * @return Returns the credentials.
110    */

111   public Object JavaDoc getCredentials()
112   {
113     return credentials;
114   }
115
116   /**
117    * Creates a new <code>RmiJmxClient.java</code> object
118    *
119    * @param port the port of the host to connect to
120    * @param host the host name to connect to
121    * @param jmxUser the jmxUser if one, to be authenticated with
122    * @param jmxPassword the jmxPassword if one, to be authenticated with
123    * @throws IOException if cannot connect
124    */

125   public RmiJmxClient(String JavaDoc port, String JavaDoc host, String JavaDoc jmxUser,
126       String JavaDoc jmxPassword) throws IOException JavaDoc
127   {
128     this(port, host, PasswordAuthenticator.createCredentials(jmxUser,
129         jmxPassword));
130   }
131
132   /**
133    * Creates a new <code>RmiJmxClient</code> object
134    *
135    * @param url the jmx connector url
136    * @param credentials to use for the connection
137    * @throws IOException if connect fails
138    */

139   public RmiJmxClient(String JavaDoc url, Object JavaDoc credentials) throws IOException JavaDoc
140   {
141     int index = url.indexOf(":");
142     String JavaDoc ip = url.substring(0, index);
143     String JavaDoc port = url.substring(index + 1);
144     connect(port, ip, credentials);
145   }
146
147   /**
148    * Creates a new <code>RmiJmxClient.java</code> object
149    *
150    * @param port the port of the host to connect to
151    * @param host the host name to connect to
152    * @param credentials to use for the connection
153    * @throws IOException if connect fails
154    */

155   public RmiJmxClient(String JavaDoc port, String JavaDoc host, Object JavaDoc credentials)
156       throws IOException JavaDoc
157   {
158     connect(port, host, credentials);
159   }
160
161   /**
162    * Connect to the MBean server
163    *
164    * @param port the port of the host to connect to
165    * @param host the host name to connect to
166    * @param credentials to use for the connection
167    * @throws IOException if connect fails
168    */

169   public void connect(String JavaDoc port, String JavaDoc host, Object JavaDoc credentials)
170       throws IOException JavaDoc
171   {
172     JMXServiceURL JavaDoc address = new JMXServiceURL JavaDoc("rmi", host, 0, "/jndi/jrmp");
173
174     Map JavaDoc environment = new HashMap JavaDoc();
175     environment.put(Context.INITIAL_CONTEXT_FACTORY,
176         "com.sun.jndi.rmi.registry.RegistryContextFactory");
177     environment.put(Context.PROVIDER_URL, "rmi://" + host + ":" + port);
178
179     // use username and password for authentication of connections
180
// with the controller, the values are compared to the ones
181
// specified in the controller.xml config file.
182
if (credentials != null)
183     {
184       // this line is not required if no username/password has been configered
185
environment.put(JMXConnector.CREDENTIALS, credentials);
186     }
187
188     this.credentials = credentials;
189
190     connector = JMXConnectorFactory.connect(address, environment);
191     remoteHostAddress = host;
192     remoteHostPort = port;
193     invalidateMBeans();
194   }
195
196   /**
197    * Invalidate all MBeans. When connecting to a new Controller, all the local
198    * MBean instances must be invalidated (since they refered to the previous
199    * Controller and its associated MBean server).
200    */

201   private void invalidateMBeans()
202   {
203     controllerMBean = null;
204     dataMBean = null;
205     backendMBean = null;
206   }
207
208   /**
209    * List of all the mbean on the current server
210    *
211    * @return a set of <tt>ObjectInstance</tt>
212    * @throws Exception if fails
213    */

214   public Set JavaDoc listSequoiaMBeans() throws Exception JavaDoc
215   {
216     Set JavaDoc set = connector.getMBeanServerConnection().queryMBeans(
217         new ObjectName JavaDoc("sequoia:*"), null);
218     return set;
219   }
220
221   /**
222    * Get the mbean information
223    *
224    * @param mbean the <tt>ObjectName</tt> of the mbean to access
225    * @return <tt>MBeanInfo</tt> object
226    * @throws Exception if fails
227    */

228   public MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc mbean) throws Exception JavaDoc
229   {
230     return connector.getMBeanServerConnection().getMBeanInfo(mbean);
231   }
232
233   /**
234    * Get the value of an attribute on the given mbean
235    *
236    * @param mbean the <tt>ObjectName</tt> of the mbean to access
237    * @param attribute the attribute name
238    * @return <tt>Object</tt> being the value returned by the get <Attribute>
239    * method
240    * @throws Exception if fails
241    */

242   public Object JavaDoc getAttributeValue(ObjectName JavaDoc mbean, String JavaDoc attribute)
243       throws Exception JavaDoc
244   {
245     return connector.getMBeanServerConnection().getAttribute(mbean, attribute);
246   }
247
248   /**
249    * Change an attribute value
250    *
251    * @param mbean the <tt>ObjectName</tt> of the mbean to access
252    * @param attribute the attribute name
253    * @param value the attribute new value
254    * @throws Exception if fails
255    */

256   public void setAttributeValue(ObjectName JavaDoc mbean, String JavaDoc attribute, Object JavaDoc value)
257       throws Exception JavaDoc
258   {
259     Attribute JavaDoc att = new Attribute JavaDoc(attribute, value);
260     connector.getMBeanServerConnection().setAttribute(mbean, att);
261   }
262
263   /**
264    * Set the current subject for authentication
265    *
266    * @param user the user login
267    * @param password the user password
268    */

269   private Subject JavaDoc getSubject(String JavaDoc user, String JavaDoc password)
270   {
271     Set JavaDoc principals = new HashSet JavaDoc();
272     principals.add(new JMXPrincipalWithPassword(user, password));
273     return new Subject JavaDoc(true, principals, new HashSet JavaDoc(), new HashSet JavaDoc());
274   }
275
276   /**
277    * Get a reference to the virtualdatabaseMbean with the given authentication
278    *
279    * @param database the virtual database name
280    * @param user the user recognized as the <code>VirtualDatabaseUser</code>
281    * @param password the password for the <code>VirtualDatabaseUser</code>
282    * @return <code>VirtualDatabaseMBean</code> instance
283    * @throws IOException if cannot connect to MBean
284    * @throws InstanceNotFoundException if cannot locate MBean
285    * @throws VirtualDatabaseException if virtual database fails
286    */

287   public VirtualDatabaseMBean getVirtualDatabaseProxy(String JavaDoc database,
288       String JavaDoc user, String JavaDoc password) throws InstanceNotFoundException JavaDoc,
289       IOException JavaDoc, VirtualDatabaseException
290   {
291     if (!isValidConnection())
292     {
293       try
294       {
295         reconnect();
296       }
297       catch (Exception JavaDoc e)
298       {
299         throw new IOException JavaDoc(ConsoleTranslate
300             .get("jmx.server.connection.lost")); //$NON-NLS-1$
301
}
302     }
303     ObjectName JavaDoc db;
304     try
305     {
306       db = JmxConstants.getVirtualDataBaseObjectName(database);
307     }
308     catch (MalformedObjectNameException JavaDoc e)
309     {
310       throw new VirtualDatabaseException(e);
311     }
312     // we open a connection for this subject, all subsequent calls with this
313
// connection will be executed on the behalf of our subject.
314
MBeanServerConnection JavaDoc delegateConnection = connector
315         .getMBeanServerConnection(getSubject(user, password));
316
317     if (!delegateConnection.isRegistered(db))
318     {
319       throw new VirtualDatabaseException(ConsoleTranslate
320           .get("virtualdatabase.mbean.not.accessible")); //$NON-NLS-1$
321
}
322
323     // we create a proxy to the virtual database
324
VirtualDatabaseMBean local = (VirtualDatabaseMBean) MBeanServerInvocationHandler
325         .newProxyInstance(delegateConnection, db, VirtualDatabaseMBean.class,
326             false);
327     checkAccessible(local);
328     // Check authentication
329
boolean authenticated = false;
330     try
331     {
332       authenticated = local.checkAdminAuthentication(user, password);
333     }
334     catch (Exception JavaDoc e)
335     {
336       logger.warn(
337           "Exception while checking virtual database admin authentication", e);
338       throw new VirtualDatabaseException(
339           "Could not check authentication. MBean is not accessible.");
340     }
341     if (!authenticated)
342       throw new VirtualDatabaseException("Authentication Failed");
343
344     // Add notification listener
345
if (notificationListener != null)
346     {
347       delegateConnection.addNotificationListener(db, notificationListener,
348           null, null);
349
350       // CounterMonitor cm = new CounterMonitor();
351
// cm.setNotify(true);
352
// cm.setGranularityPeriod(100);
353
// cm.setObservedObject(db);
354
// cm.setObservedAttribute("currentNbOfThreads");
355
// cm.setThreshold(new Integer(6));
356
// cm.start();
357
}
358
359     return local;
360   }
361
362   /**
363    * Check that the VirtualDatabaseMBean is accessible. if
364    * <code>virtualDbMBean</code> is <code>null</code>, do nothing
365    *
366    * @param virtualDbMBean the VirtualDatabaseMBean to check
367    * @throws VirtualDatabaseException if the VirtualDatabaseMBean is not
368    * accessible
369    */

370   private void checkAccessible(VirtualDatabaseMBean virtualDbMBean)
371       throws VirtualDatabaseException
372   {
373     if (virtualDbMBean == null)
374     {
375       return;
376     }
377     // we try to get the name of the virtual database from the mbean to
378
// check if it is accessible
379
try
380     {
381       virtualDbMBean.getVirtualDatabaseName();
382     }
383     catch (Exception JavaDoc e)
384     {
385       throw new VirtualDatabaseException(ConsoleTranslate
386           .get("virtualdatabase.mbean.not.accessible")); //$NON-NLS-1$
387
}
388   }
389
390   /**
391    * Get a proxy to the ControllerMBean
392    *
393    * @return <code>ControllerMBean</code> instance
394    * @throws IOException if cannot connect to MBean
395    */

396   public ControllerMBean getControllerProxy() throws IOException JavaDoc
397   {
398
399     if (controllerMBean != null && isValidConnection())
400     {
401       return controllerMBean;
402     }
403     else
404     {
405       if (!isValidConnection())
406       {
407         try
408         {
409           reconnect();
410         }
411         catch (Exception JavaDoc e)
412         {
413           throw new IOException JavaDoc(ConsoleTranslate
414               .get("jmx.server.connection.lost")); //$NON-NLS-1$
415
}
416       }
417       ObjectName JavaDoc db;
418       try
419       {
420         db = JmxConstants.getControllerObjectName();
421       }
422       catch (MalformedObjectNameException JavaDoc e)
423       {
424         throw new IOException JavaDoc(e.getMessage());
425       }
426
427       // we create a new proxy to the controller
428
controllerMBean = (ControllerMBean) MBeanServerInvocationHandler
429           .newProxyInstance(connector.getMBeanServerConnection(), db,
430               ControllerMBean.class, false);
431
432       // Add notification listener
433
if (notificationListener != null)
434       {
435         try
436         {
437           connector.getMBeanServerConnection().addNotificationListener(db,
438               notificationListener, null, null);
439         }
440         catch (Exception JavaDoc e)
441         {
442           throw new IOException JavaDoc("Could not register listener on the mbean");
443         }
444       }
445
446       return controllerMBean;
447     }
448   }
449
450   /**
451    * Get a proxy to the DataCollectorMBean
452    *
453    * @return <code>DataCollectorMBean</code> instance
454    * @throws IOException if fails
455    */

456   public DataCollectorMBean getDataCollectorProxy() throws IOException JavaDoc
457   {
458
459     if (dataMBean != null && isValidConnection())
460     {
461       return dataMBean;
462     }
463     else
464     {
465       if (!isValidConnection())
466         reconnect();
467       ObjectName JavaDoc db = JmxConstants.getDataCollectorObjectName();
468
469       // we create a new proxy to the data collector
470
dataMBean = (DataCollectorMBean) MBeanServerInvocationHandler
471           .newProxyInstance(connector.getMBeanServerConnection(), db,
472               DataCollectorMBean.class, false);
473       return dataMBean;
474     }
475   }
476
477   /**
478    * Get a proxy to the DatabaseBackendMBean
479    *
480    * @return <code>DatabaseBackendMBean</code> instance
481    * @param vdb virtual database name
482    * @param backend backend name
483    * @param user user name
484    * @param password password name
485    * @throws IOException if cannot connect to MBean
486    * @throws InstanceNotFoundException if cannot locate MBean
487    */

488   public DatabaseBackendMBean getDatabaseBackendProxy(String JavaDoc vdb,
489       String JavaDoc backend, String JavaDoc user, String JavaDoc password)
490       throws InstanceNotFoundException JavaDoc, IOException JavaDoc
491   {
492     if (backendMBean != null && isValidConnection())
493     {
494       try
495       {
496         if (backendMBean.getName().equals(backend))
497           return backendMBean;
498       }
499       catch (Exception JavaDoc e)
500       {
501         // backend is no more there
502
}
503     }
504
505     if (!isValidConnection())
506       reconnect();
507
508     ObjectName JavaDoc backendObjectName;
509     try
510     {
511       backendObjectName = JmxConstants.getDatabaseBackendObjectName(vdb,
512           backend);
513     }
514     catch (MalformedObjectNameException JavaDoc e)
515     {
516       throw new IOException JavaDoc(e.getMessage());
517     }
518
519     MBeanServerConnection JavaDoc delegateConnection = connector
520         .getMBeanServerConnection(getSubject(user, password));
521
522     if (notificationListener != null)
523     {
524       delegateConnection.addNotificationListener(backendObjectName,
525           notificationListener, null, null);
526       StringMonitor JavaDoc sm = new StringMonitor JavaDoc();
527       sm.setObservedObject(backendObjectName);
528       sm.setObservedAttribute("LastKnownCheckpoint");
529       sm.setStringToCompare("hello");
530       sm.setGranularityPeriod(100);
531       sm.setNotifyDiffer(true);
532       sm.addNotificationListener(notificationListener, null, null);
533       sm.start();
534     }
535
536     // we create a proxy to the database backend
537
backendMBean = (DatabaseBackendMBean) MBeanServerInvocationHandler
538         .newProxyInstance(delegateConnection, backendObjectName,
539             DatabaseBackendMBean.class, false);
540     return backendMBean;
541   }
542
543   /**
544    * Returns a proxy on a BackendTaskQueuesControlMBean.
545    *
546    * @param vdb name of the virtual database
547    * @param backend name of the backend
548    * @param user user login for the virtual database
549    * @param password user password fort the virtual database
550    * @return a proxy on a BackendTaskQueuesControlMBean
551    * @throws IOException if an I/O exception occured
552    */

553   public BackendTaskQueuesControlMBean getBackendTaskQueues(String JavaDoc vdb,
554       String JavaDoc backend, String JavaDoc user, String JavaDoc password) throws IOException JavaDoc
555   {
556     if (!isValidConnection())
557       reconnect();
558
559     ObjectName JavaDoc taskQueuesObjectName;
560     try
561     {
562       taskQueuesObjectName = JmxConstants.getBackendTaskQueuesObjectName(vdb,
563           backend);
564     }
565     catch (MalformedObjectNameException JavaDoc e)
566     {
567       throw new IOException JavaDoc(e.getMessage());
568     }
569
570     MBeanServerConnection JavaDoc delegateConnection = connector
571         .getMBeanServerConnection(getSubject(user, password));
572
573     // we create a proxy to the database backend
574
return (BackendTaskQueuesControlMBean) MBeanServerInvocationHandler
575         .newProxyInstance(delegateConnection, taskQueuesObjectName,
576             BackendTaskQueuesControlMBean.class, false);
577   }
578
579   /**
580    * Returns a proxy on a RecoveryLogControlMBean.
581    *
582    * @param vdb name of the virtual databaseTODO: getRecoveryLog definition.
583    * @param user user login for the virtual database
584    * @param password user password fort the virtual database
585    * @return a proxy on a RecoveryLogControlMBean
586    * @throws IOException if an I/O exception occured
587    */

588   public RecoveryLogControlMBean getRecoveryLog(String JavaDoc vdb, String JavaDoc user,
589       String JavaDoc password) throws IOException JavaDoc
590   {
591     if (!isValidConnection())
592       reconnect();
593
594     ObjectName JavaDoc recoveryLogObjectName;
595     try
596     {
597       recoveryLogObjectName = JmxConstants.getRecoveryLogObjectName(vdb);
598     }
599     catch (MalformedObjectNameException JavaDoc e)
600     {
601       throw new IOException JavaDoc(e.getMessage());
602     }
603
604     MBeanServerConnection JavaDoc delegateConnection = connector
605         .getMBeanServerConnection(getSubject(user, password));
606
607     // we create a proxy to the database backend
608
return (RecoveryLogControlMBean) MBeanServerInvocationHandler
609         .newProxyInstance(delegateConnection, recoveryLogObjectName,
610             RecoveryLogControlMBean.class, false);
611   }
612
613   /**
614    * Returns a proxy on the given vdb Scheduler.
615    *
616    * @param vdb name of the virtual database
617    * @param user user login for the virtual database
618    * @param password user password fort the virtual database
619    * @return a proxy on an AbstractScheduler
620    * @throws IOException if an I/O exception occured
621    */

622   public AbstractSchedulerControlMBean getAbstractScheduler(String JavaDoc vdb,
623       String JavaDoc user, String JavaDoc password) throws IOException JavaDoc
624   {
625     if (!isValidConnection())
626       reconnect();
627
628     ObjectName JavaDoc recoveryLogObjectName;
629     try
630     {
631       recoveryLogObjectName = JmxConstants.getAbstractSchedulerObjectName(vdb);
632     }
633     catch (MalformedObjectNameException JavaDoc e)
634     {
635       throw new IOException JavaDoc(e.getMessage());
636     }
637
638     MBeanServerConnection JavaDoc delegateConnection = connector
639         .getMBeanServerConnection(getSubject(user, password));
640
641     // we create a proxy to the database backend
642
return (AbstractSchedulerControlMBean) MBeanServerInvocationHandler
643         .newProxyInstance(delegateConnection, recoveryLogObjectName,
644             AbstractSchedulerControlMBean.class, false);
645   }
646
647   /**
648    * Returns a proxy on the given vdb Scheduler parsing cache
649    *
650    * @param vdb name of the virtual database
651    * @param user user login for the virtual database
652    * @param password user password fort the virtual database
653    * @return a proxy on a ParsingCache
654    * @throws IOException if an I/O exception occured
655    */

656   public ParsingCacheMBean getParsingCache(String JavaDoc vdb, String JavaDoc user,
657       String JavaDoc password) throws IOException JavaDoc
658   {
659     if (!isValidConnection())
660       reconnect();
661
662     ObjectName JavaDoc parsingCacheObjectName;
663     try
664     {
665       parsingCacheObjectName = JmxConstants.getParsingCacheObjectName(vdb);
666     }
667     catch (MalformedObjectNameException JavaDoc e)
668     {
669       throw new IOException JavaDoc(e.getMessage());
670     }
671
672     MBeanServerConnection JavaDoc delegateConnection = connector
673         .getMBeanServerConnection(getSubject(user, password));
674
675     // we create a proxy to the database backend
676
return (ParsingCacheMBean) MBeanServerInvocationHandler.newProxyInstance(
677         delegateConnection, parsingCacheObjectName, ParsingCacheMBean.class,
678         false);
679   }
680
681   /**
682    * Returns a proxy on the RequestManager of the given virtual database.
683    *
684    * @param vdb name of the virtual database
685    * @param user user login for the virtual database
686    * @param password user password fort the virtual database
687    * @return a proxy on a RequestManager
688    * @throws IOException if an I/O exception occured
689    */

690   public RequestManagerMBean getRequestManager(String JavaDoc vdb, String JavaDoc user,
691       String JavaDoc password) throws IOException JavaDoc
692   {
693     if (!isValidConnection())
694       reconnect();
695
696     ObjectName JavaDoc requestManagerObjectName;
697     try
698     {
699       requestManagerObjectName = JmxConstants.getRequestManagerObjectName(vdb);
700     }
701     catch (MalformedObjectNameException JavaDoc e)
702     {
703       throw new IOException JavaDoc(e.getMessage());
704     }
705
706     MBeanServerConnection JavaDoc delegateConnection = connector
707         .getMBeanServerConnection(getSubject(user, password));
708
709     // we create a proxy to the database backend
710
return (RequestManagerMBean) MBeanServerInvocationHandler.newProxyInstance(
711         delegateConnection, requestManagerObjectName,
712         RequestManagerMBean.class, false);
713   }
714
715   /**
716    * Get the controller name used for jmx connection This is
717    * [hostname]:[jmxServerPort]
718    *
719    * @return <code>remoteHostName+":"+remoteHostPort</code>
720    */

721   public String JavaDoc getRemoteName()
722   {
723     return remoteHostAddress + ":" + remoteHostPort;
724   }
725
726   /**
727    * Returns the remoteHostAddress value.
728    *
729    * @return Returns the remoteHostAddress.
730    */

731   public String JavaDoc getRemoteHostAddress()
732   {
733     return remoteHostAddress;
734   }
735
736   /**
737    * Returns the remoteHostPort value.
738    *
739    * @return Returns the remoteHostPort.
740    */

741   public String JavaDoc getRemoteHostPort()
742   {
743     return remoteHostPort;
744   }
745
746   /**
747    * Reconnect to the same mbean server
748    *
749    * @throws IOException if reconnection failed
750    */

751   public void reconnect() throws IOException JavaDoc
752   {
753     connect(remoteHostPort, remoteHostAddress, credentials);
754   }
755
756   /**
757    * Test if the connection with the mbean server is still valid
758    *
759    * @return true if it is
760    */

761   public boolean isValidConnection()
762   {
763     try
764     {
765       connector.getMBeanServerConnection().getMBeanCount();
766       return true;
767     }
768     catch (Exception JavaDoc e)
769     {
770       controllerMBean = null;
771       backendMBean = null;
772       dataMBean = null;
773       return false;
774     }
775   }
776 }
Popular Tags