org.vostok.management.mbean
Class MBeanFactory

java.lang.Object
  extended by org.vostok.management.mbean.MBeanFactory

public class MBeanFactory
extends java.lang.Object

An MBeanFactory is responsible to load and initialize identifed mbean TODO : gestion des erreurs, dep cycliques

Version:
0.3
Author:
levreau.jerome@vostoksystem.eu

Nested Class Summary
static class MBeanFactory.ERROR
          define what to do on error
 
Field Summary
protected  java.util.HashMap<java.lang.String,org.vostok.management.mbean.MBeanFactory.BeantItem> mbeanList
           
 
Constructor Summary
protected MBeanFactory()
           
protected MBeanFactory(java.lang.String name, java.lang.String[] source, MBeanFactory.ERROR errorLevel)
           
 
Method Summary
static MBeanFactory CreateFactory(java.lang.String source)
          return a new factory - with default name - but indicate a single top package to look for mbean at.
static MBeanFactory CreateFactory(java.lang.String[] source)
          return a new factory - with default name - but indicate a set of packages to look for mbean at.
static MBeanFactory CreateFactory(java.lang.String name, java.lang.String source)
          create a new factory with name "name", and scan for mbean into package "source"
static MBeanFactory CreateFactory(java.lang.String name, java.lang.String[] source)
          create a new factory with name "name", and scan for mbean into 'source' packages
static MBeanFactory CreateFactory(java.lang.String name, java.lang.String[] source, MBeanFactory.ERROR errorLevel)
          create an register a new factory. whnen using the default factory, just call MBeanFactory.getFactory().
protected  java.util.concurrent.FutureTask<java.lang.String> doStart()
          start the factory.
 MBeanFactory.ERROR getErrorLevel()
          get error level for this factory, default to warn
static MBeanFactory getFactory()
          will return the default factory.
static MBeanFactory getFactory(java.lang.String name)
          get factory with name "name" .
static java.lang.String getJndi(java.lang.Class c)
          return jndi for a class first look for mbean annoation, if not empty return mbean.jndi else build a jdni name using default format.
<T> T
getMbean(java.lang.Class<T> type)
          This method should be used for getting an mbean instance, this factory manage.
<T> T
getMbean(java.lang.Class<T> type, java.lang.String jndi)
          retrieve mbean from jndi
 javax.management.MBeanServer getMbeanServer()
          convenience method, will return mbean instance beans are registered into
 java.lang.String getName()
          return the name for this factory
 java.lang.String[] getPackage()
          return package jndi this factory locate annotation from
 boolean isStarted()
          return true if this factory is succesfully started, meaning all bean deployed on the mbeanserver
 void start()
          Start deploying mbean according to configuration.
 void startAndWait()
          Synchronious version of start
 void stop()
          stop this factory, and unload all mbean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mbeanList

protected java.util.HashMap<java.lang.String,org.vostok.management.mbean.MBeanFactory.BeantItem> mbeanList
Constructor Detail

MBeanFactory

protected MBeanFactory()

MBeanFactory

protected MBeanFactory(java.lang.String name,
                       java.lang.String[] source,
                       MBeanFactory.ERROR errorLevel)
Method Detail

getFactory

public static MBeanFactory getFactory()
will return the default factory. Will scan any packaged for mbean, and won't stop deploying on error If you need more control, use the CreateFactory method

Returns:

getFactory

public static MBeanFactory getFactory(java.lang.String name)
get factory with name "name" . If unknow, will create it with default parameters, ei, errorLevel = warm, scan depend all package For more control, use CreateFactory

Parameters:
name -
Returns:

CreateFactory

public static MBeanFactory CreateFactory(java.lang.String[] source)
                                  throws DuplicateNameException
return a new factory - with default name - but indicate a set of packages to look for mbean at. Packages will be scanned recursively.

Parameters:
source -
Returns:
Throws:
DuplicateNameException

CreateFactory

public static MBeanFactory CreateFactory(java.lang.String source)
                                  throws DuplicateNameException
return a new factory - with default name - but indicate a single top package to look for mbean at.

Parameters:
source -
Returns:
Throws:
DuplicateNameException

CreateFactory

public static MBeanFactory CreateFactory(java.lang.String name,
                                         java.lang.String[] source)
                                  throws DuplicateNameException
create a new factory with name "name", and scan for mbean into 'source' packages

Parameters:
name -
source -
Returns:
Throws:
DuplicateNameException

CreateFactory

public static MBeanFactory CreateFactory(java.lang.String name,
                                         java.lang.String source)
                                  throws DuplicateNameException
create a new factory with name "name", and scan for mbean into package "source"

Parameters:
name -
source -
Returns:
Throws:
DuplicateNameException

CreateFactory

public static MBeanFactory CreateFactory(java.lang.String name,
                                         java.lang.String[] source,
                                         MBeanFactory.ERROR errorLevel)
                                  throws DuplicateNameException
create an register a new factory. whnen using the default factory, just call MBeanFactory.getFactory(). If a factory for "name" already exist, abort

Parameters:
name - name for this factory. if null will use MBeanFactory.DEFAULT_FACTORY_NAME
source - top package name where to start scanning fr mbean declaration
errorLevel -
Returns:
Throws:
DuplicateNameException - if a forctory for "name" already exist

getPackage

public java.lang.String[] getPackage()
return package jndi this factory locate annotation from

Returns:
the package jndi
See Also:
MBean

getErrorLevel

public MBeanFactory.ERROR getErrorLevel()
get error level for this factory, default to warn

Returns:

getName

public java.lang.String getName()
return the name for this factory

Returns:

getMbeanServer

public javax.management.MBeanServer getMbeanServer()
convenience method, will return mbean instance beans are registered into

Returns:

start

public void start()
           throws javax.management.MBeanRegistrationException,
                  LocalDependencyException,
                  RunningException,
                  javax.management.MalformedObjectNameException
Start deploying mbean according to configuration. If the factory already started, do nothing. This call is asynchronious, if you need synchoniuous deployenement, used MBeanFactory.startAndWait instead

Throws:
javax.management.MBeanRegistrationException - if no mbean server found and cannot start none
LocalDependencyException - : thow when target bean for a localdependencies is not annoted with MBean
java.lang.RuntimeException - : deployement is already running
javax.management.MalformedObjectNameException - : a jndi name dependency is an invalid name
RunningException

startAndWait

public void startAndWait()
                  throws javax.management.MBeanRegistrationException,
                         LocalDependencyException,
                         RunningException,
                         javax.management.MalformedObjectNameException
Synchronious version of start

Throws:
javax.management.MBeanRegistrationException - if no mbean server found and cannot start none
LocalDependencyException - : thow when target bean for a localdependencies is not annoted with MBean
java.lang.RuntimeException - : deployement is already running
javax.management.MalformedObjectNameException - : a jndi name dependency is an invalid name
RunningException

doStart

protected java.util.concurrent.FutureTask<java.lang.String> doStart()
                                                             throws javax.management.MBeanRegistrationException,
                                                                    LocalDependencyException,
                                                                    RunningException,
                                                                    javax.management.MalformedObjectNameException
start the factory. Locate all bean annoted an load then as service. Depend on configuration, might stop before all bean as been loaded

Throws:
javax.management.MBeanRegistrationException - if no mbean server found and cannot start none
LocalDependencyException - : thow when target bean for a localdependencies is not annoted with MBean
java.lang.RuntimeException - : deployement is already running
javax.management.MalformedObjectNameException - : a jndi name dependency is an invalid name
RunningException

isStarted

public boolean isStarted()
return true if this factory is succesfully started, meaning all bean deployed on the mbeanserver

Returns:

stop

public void stop()
stop this factory, and unload all mbean


getMbean

public <T> T getMbean(java.lang.Class<T> type)
           throws javax.management.InstanceNotFoundException
This method should be used for getting an mbean instance, this factory manage. Return mbean object corresponding to this class, on class implementing an interface. For jmx, use of interface is mandatory note this method use a cache

Parameters:
type -
Returns:
instance for mbean service, never null
Throws:
javax.management.InstanceNotFoundException - if this factory doesn't manange this mbean

getMbean

public <T> T getMbean(java.lang.Class<T> type,
                      java.lang.String jndi)
           throws javax.management.InstanceNotFoundException
retrieve mbean from jndi

Parameters:
type - target type for the resource (interface)
jndi - jndi name under mbean (or resource) get registered
Returns:
a proxy instance for the resource associated with "jndi"
Throws:
javax.management.InstanceNotFoundException

getJndi

public static java.lang.String getJndi(java.lang.Class c)
return jndi for a class first look for mbean annoation, if not empty return mbean.jndi else build a jdni name using default format. Default format is bean:{package}={className}Service

Parameters:
c -
Returns:
a jndi jndi for this classn depend default format
Throws:
java.lang.NullPointerException - if c is null
See Also:
MBeanFactory.jndiPattern