0

私はJMXの世界に不慣れですが、これまでのところ、主にアプリケーションの監視と管理に使用されていることを調査しました.Spring JMXに非常に興味があるため、このインターフェースとクラスを開発しました。 spring を使用して特別に JMX に最適化するには、このために spring xml でどのような設定を行う必要があります...

package dustin.jmx.modelmbeans;

/**
 * Interface to expose Model MBean via Spring.
 */
public interface SimpleCalculatorIf
{
   public int add(final int augend, final int addend);

   public int subtract(final int minuend, final int subtrahend);

   public int multiply(final int factor1, final int factor2);

   public double divide(final int dividend, final int divisor);
} 

そして以下はクラスです..

package dustin.jmx.modelmbeans;


public class SimpleCalculator implements SimpleCalculatorIf
{
   /**
    * Calculate the sum of the augend and the addend.
    *
    * @param augend First integer to be added.
    * @param addend Second integer to be added.
    * @return Sum of augend and addend.
    */
   public int add(final int augend, final int addend)
   {
      return augend + addend;
   }

   /**
    * Calculate the difference between the minuend and subtrahend.
    * 
    * @param minuend Minuend in subtraction operation.
    * @param subtrahend Subtrahend in subtraction operation.
    * @return Difference of minuend and subtrahend.
    */
   public int subtract(final int minuend, final int subtrahend)
   {
      return minuend - subtrahend;
   }

   /**
    * Calculate the product of the two provided factors.
    *
    * @param factor1 First integer factor.
    * @param factor2 Second integer factor.
    * @return Product of provided factors.
    */
   public int multiply(final int factor1, final int factor2)
   {
      return factor1 * factor2;
   }

   /**
    * Calculate the quotient of the dividend divided by the divisor.
    *
    * @param dividend Integer dividend.
    * @param divisor Integer divisor.
    * @return Quotient of dividend divided by divisor.
    */
   public double divide(final int dividend, final int divisor)
   {
      return dividend / divisor;
   }
}
4

1 に答える 1

2

1) SimpleCalculatorIf の名前を SimpleCalculatorMBean に変更します。次に、context.xml のこれらの 2 行で、Spring が SimpleCalculator を検出して MBean http://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.htmlとして登録するのに十分です。

<context:mbean-export/>
<bean class="dustin.jmx.modelmbeans.SimpleCalculator"/>

2) しかし、最も効率的な方法は、Spring アノテーションを使用することです。そうすれば、インターフェースさえ必要ありません。

@ManagedResource(objectName="bean:name=SimpleCalculator", description="My Managed Calculator", log=true,
logFile="jmx.log", currencyTimeLimit=15, persistPolicy="OnUpdate", persistPeriod=200,
persistLocation="foo", persistName="bar")
public class SimpleCalculator implements SimpleCalculatorIf
{
   @ManagedOperation
   public int add(final int augend, final int addend)
   {
      return augend + addend;
   }
   ...

実際には、パラメーターのないデフォルトの @ManagedResource も機能します。注釈付きのオプションの数を示したかっただけです。Spring ドキュメントで詳細を読む

于 2013-05-04T07:45:13.300 に答える