/*********************************************************************
* EJServerConfig.java
* created on 25.03.2006 by netseeker
* $Source$
* $Date$
* $Revision$
*
* ====================================================================
*
* Copyright 2006 netseeker aka Michael Manske
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.jmx;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.AttributeChangeNotification;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import de.netseeker.ejoe.EJServer;
import de.netseeker.ejoe.handler.ServerHandler;
/**
* Simlpe MBean interface implementation to support runtime configuration via JMX
*
* @author netseeker
* @since 0.3.9.1
*/
public final class EJServerConfig extends NotificationBroadcasterSupport implements EJServerConfigMBean
{
private static final Logger logger = Logger.getLogger( EJServerConfig.class.getName() );
private EJServer _ejServer;
private long _sequenceNumber = 1;
/**
*
*/
public EJServerConfig()
{
super();
ServerHandler handler = null;
this._ejServer = new EJServer( handler );
this._ejServer.setMaxReadProcessors( 1 );
this._ejServer.setMaxWriteProcessors( 1 );
startEJServer();
}
/**
* @param ejServer
*/
public EJServerConfig(EJServer ejServer)
{
super();
this._ejServer = ejServer;
}
/*
* (non-Javadoc)
*
* @see javax.management.NotificationBroadcaster#getNotificationInfo()
*/
public MBeanNotificationInfo[] getNotificationInfo()
{
String[] types = new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE };
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of the monitored EJServer has changed";
MBeanNotificationInfo info = new MBeanNotificationInfo( types, name, description );
return new MBeanNotificationInfo[] { info };
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#isNonBlockingIO()
*/
public boolean isNonBlockingIO()
{
return this._ejServer.hasNonBlockingIO();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setNonBlockingIO(boolean)
*/
public void setNonBlockingIO( boolean isNonBlockingIO )
{
this._ejServer.enableNonBlockingIO( isNonBlockingIO );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#isPersistentConnections()
*/
public boolean isPersistentConnections()
{
return this._ejServer.hasPersistentConnections();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setIsPersistentConnections(boolean)
*/
public void setPersistentConnections( boolean isPersistentConnections )
{
this._ejServer.enablePersistentConnections( isPersistentConnections );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#isHttpPackaging()
*/
public boolean isHttpPackaging()
{
return this._ejServer.hasHttPackaging();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setHttpPackaging(boolean)
*/
public void setHttpPackaging( boolean enable )
{
this._ejServer.enableHttpPackaging( enable );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#isCompression()
*/
public boolean isCompression()
{
return this._ejServer.hasCommpression();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setCompression(boolean)
*/
public void setCompression( boolean compression )
{
this._ejServer.enableCompression( compression );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#isRunning()
*/
public boolean isRunning()
{
return this._ejServer.isRunning();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#getMaxReadProcessors()
*/
public int getMaxReadProcessors()
{
return this._ejServer.getMaxReadProcessors();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setMaxReadProcessors(int)
*/
public void setMaxReadProcessors( int maxReadProcessors )
{
this._ejServer.stop();
this._ejServer.setMaxReadProcessors( maxReadProcessors );
startEJServer();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#getMaxWriteProcessors()
*/
public int getMaxWriteProcessors()
{
return this._ejServer.getMaxWriteProcessors();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#setMaxWriteProcessors(int)
*/
public void setMaxWriteProcessors( int maxWriteProcessors )
{
this._ejServer.stop();
this._ejServer.setMaxWriteProcessors( maxWriteProcessors );
startEJServer();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#stopEJServer()
*/
public void stopEJServer()
{
this._ejServer.stop();
Notification n = new AttributeChangeNotification( this, _sequenceNumber++, System.currentTimeMillis(),
"Running state changed", "Running", "boolean", Boolean.TRUE,
Boolean.FALSE );
sendNotification( n );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#startEJServer()
*/
public void startEJServer()
{
try
{
this._ejServer.start();
Notification n = new AttributeChangeNotification( this, _sequenceNumber++, System.currentTimeMillis(),
"Running state changed", "Running", "boolean",
Boolean.FALSE, Boolean.TRUE );
sendNotification( n );
}
catch ( IOException e )
{
logger.log( Level.SEVERE, e.getMessage(), e );
}
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.jmx.EJServerConfigMBean#restartEJServer()
*/
public void restartEJServer()
{
stopEJServer();
startEJServer();
}
}