org.norther.tammi.core.base
Class MBeanHandle<R>

java.lang.Object
  extended by org.norther.tammi.core.base.MBeanHandle<R>
Type Parameters:
R - the referent type.
All Implemented Interfaces:
Serializable, EventListener, NotificationBroadcaster, NotificationEmitter, NotificationListener, MBeanReference<R>
Direct Known Subclasses:
FilterHandle

public class MBeanHandle<R>
extends Object
implements MBeanReference<R>, NotificationEmitter, NotificationListener, Serializable

A reference handle to an MBean keeping itself up-to-date automatically during referent registrations and unregistrations. After use, the handle should be freed to release its resources. The handle is activated after the first call to the getMBean method or after addition of a listener. The renew method tries to restore a lost or released referent.

Version:
$Id: MBeanHandle.java,v 1.22 2010-06-22 17:50:22 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
static class MBeanHandle.ClassQueryExp
          An inner class for queries of a specific class.
protected static class MBeanHandle.RegistrationFilter
          An inner class for registration notifications of a named MBean.
 
Constructor Summary
MBeanHandle(MBeanServer server)
          Constructs a new handle.
MBeanHandle(MBeanServer server, MBeanReference<R> ref)
          Constructs a new handle for an explicit referent.
MBeanHandle(MBeanServer server, ObjectName name)
          Constructs a new handle with an initial value.
MBeanHandle(MBeanServer server, String ifname, boolean... exact)
          Constructs a new handle for a named interface and an optional default domain query.
MBeanHandle(MBeanServer server, String ifname, ObjectName name, boolean... exact)
          Constructs a new handle for a named interface with an initial value and an optional default domain query.
 
Method Summary
 void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
           
protected  void finalize()
           
 R get()
          Gets the referent.
 String getClassName()
          Gets the class name.
 String getInterface()
          Gets the MBean interface.
 MBeanReference<R> getMBean()
          Gets a reference to the referent.
 MBeanServer getMBeanServer()
          Gets the MBean server.
 MBeanNotificationInfo[] getNotificationInfo()
           
 ObjectName getObjectName()
          Gets the object name.
 ObjectName getQueryPattern()
          Gets the object name or a query pattern of the reference.
 void handleNotification(Notification notif, Object handback)
           
 void invalidate()
          Releases the referent and invalidates this handle.
 boolean isRegistered()
          Checks whether registered, already unregistered or unregistration is just going on.
 boolean isValid()
          Checks whether this handle is still valid.
 Set<ObjectName> queryObjectNames()
          Queries for a set of object names matching the query pattern.
 void release()
          Releases the current referent.
 void removeNotificationListener(NotificationListener listener)
           
 void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
           
 void renew()
          Renews the reference to the referent.
 void setInterface(String ifname, boolean... exact)
          Sets the MBean interface with an optional default query.
 void setMBeanServer(MBeanServer server)
          Sets the MBean server.
 void setQueryPattern(ObjectName name)
          Sets the object name or a query pattern of the reference.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MBeanHandle

public MBeanHandle(MBeanServer server)
Constructs a new handle.

Parameters:
server - the MBean server.

MBeanHandle

public MBeanHandle(MBeanServer server,
                   String ifname,
                   boolean... exact)
Constructs a new handle for a named interface and an optional default domain query.

Parameters:
server - the MBean server.
ifname - the class or interface name.
exact - no default query if true but an explicit one.

MBeanHandle

public MBeanHandle(MBeanServer server,
                   ObjectName name)
Constructs a new handle with an initial value.

Parameters:
server - the MBean server.
name - the object name or query pattern of the referent.

MBeanHandle

public MBeanHandle(MBeanServer server,
                   String ifname,
                   ObjectName name,
                   boolean... exact)
Constructs a new handle for a named interface with an initial value and an optional default domain query.

Parameters:
server - the MBean server.
ifname - the class or interface name.
name - the object name or query pattern of the referent.
exact - no default query if true but an explicit one.

MBeanHandle

public MBeanHandle(MBeanServer server,
                   MBeanReference<R> ref)
Constructs a new handle for an explicit referent. The referent is usually an unregistered one and the referrer has the responsibility on how to maintain and use such a handle.

Parameters:
server - the MBean server.
ref - the referent of this handle.
Method Detail

get

public R get()
Description copied from interface: MBeanReference
Gets the referent.

Specified by:
get in interface MBeanReference<R>
Returns:
the referent or null if not available.

getObjectName

public ObjectName getObjectName()
Description copied from interface: MBeanReference
Gets the object name.

Specified by:
getObjectName in interface MBeanReference<R>
Returns:
the object name or null if not available.

getClassName

public String getClassName()
Description copied from interface: MBeanReference
Gets the class name.

Specified by:
getClassName in interface MBeanReference<R>
Returns:
the class name or null if not available.

isRegistered

public boolean isRegistered()
Description copied from interface: MBeanReference
Checks whether registered, already unregistered or unregistration is just going on.

Specified by:
isRegistered in interface MBeanReference<R>
Returns:
true if still registered, otherwise false.

getMBeanServer

public MBeanServer getMBeanServer()
Description copied from interface: MBeanReference
Gets the MBean server.

Specified by:
getMBeanServer in interface MBeanReference<R>
Returns:
the MBean server or null if never registered.

setMBeanServer

public void setMBeanServer(MBeanServer server)
Sets the MBean server.

Parameters:
server - the MBean server.

addNotificationListener

public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
Specified by:
addNotificationListener in interface NotificationBroadcaster

removeNotificationListener

public void removeNotificationListener(NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
                                throws ListenerNotFoundException
Specified by:
removeNotificationListener in interface NotificationEmitter
Throws:
ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
                                throws ListenerNotFoundException
Specified by:
removeNotificationListener in interface NotificationBroadcaster
Throws:
ListenerNotFoundException

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface NotificationBroadcaster

getMBean

public MBeanReference<R> getMBean()
Gets a reference to the referent.

Returns:
the reference or null.

getQueryPattern

public ObjectName getQueryPattern()
Gets the object name or a query pattern of the reference.

Returns:
the object name or a query pattern.

setQueryPattern

public void setQueryPattern(ObjectName name)
Sets the object name or a query pattern of the reference.

Parameters:
name - the object name or a query pattern.

getInterface

public String getInterface()
Gets the MBean interface.

Returns:
the MBean interface.

setInterface

public void setInterface(String ifname,
                         boolean... exact)
Sets the MBean interface with an optional default query.

Parameters:
ifname - the MBean interface name.
exact - no default query if true but an explicit one.

queryObjectNames

public Set<ObjectName> queryObjectNames()
Queries for a set of object names matching the query pattern.

Returns:
a set of object names or an empty set.

renew

public void renew()
Renews the reference to the referent.


release

public void release()
Releases the current referent.

Throws:
IllegalStateException - for an invalid handle.

invalidate

public void invalidate()
Releases the referent and invalidates this handle.


isValid

public boolean isValid()
Checks whether this handle is still valid.

Returns:
true if valid, false otherwise.

handleNotification

public void handleNotification(Notification notif,
                               Object handback)
Specified by:
handleNotification in interface NotificationListener

finalize

protected void finalize()
Overrides:
finalize in class Object


Copyright © 2004 The Norther Organization. All rights reserved.