package org.jboss.test.jmx.invoker;
import java.util.Timer;
import java.util.TimerTask;
import javax.management.ListenerNotFoundException;
import javax.management.NotificationListener;
import javax.management.NotificationFilter;
import javax.management.Notification;
import org.jboss.logging.Logger;
import org.jboss.mx.notification.AsynchNotificationBroadcasterSupport;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.w3c.dom.Element;
public class InvokerTest
extends AsynchNotificationBroadcasterSupport
implements InvokerTestMBean
{
static Logger log = Logger.getLogger(InvokerTest.class);
private CustomClass custom = new CustomClass("InitialValue");
private NonserializableClass custom2 = new NonserializableClass();
private Element xml;
public InvokerTest()
{
BasicThreadPool pool = new BasicThreadPool();
pool.setBlockingMode(BlockingMode.RUN);
pool.setMaximumQueueSize(20);
pool.setMaximumPoolSize(1);
super.setThreadPool(pool);
super.setNotificationTimeout(1000);
}
public String getSomething()
{
return "something";
}
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter, Object handback)
{
log.info("addNotificationListener, listener: "+listener+", handback: "+handback);
super.addNotificationListener(listener, filter, handback);
if( "runTimer".equals(handback) )
{
Timer t = new Timer();
Send10Notifies task = new Send10Notifies();
t.scheduleAtFixedRate(task, 0, 1000);
}
}
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException
{
log.info("removeNotificationListener, listener: "+listener);
super.removeNotificationListener(listener);
}
public CustomClass getCustom()
{
return custom;
}
public void setCustom(CustomClass custom)
{
this.custom = custom;
}
public NonserializableClass getNonserializableClass()
{
return custom2;
}
public void setNonserializableClass(NonserializableClass custom)
{
this.custom2 = custom;
}
public Element getXml()
{
return xml;
}
public void setXml(Element xml)
{
this.xml = xml;
}
public CustomClass doSomething(CustomClass custom)
{
return new CustomClass(custom.getValue());
}
public CustomClass doSomething()
{
return new CustomClass(custom.getValue());
}
public void stop()
{
stopThreadPool(true);
}
private class Send10Notifies extends TimerTask
{
int count;
public void run()
{
log.info("Sending notification on timer, count="+count);
Notification notify = new Notification("InvokerTest.timer",
InvokerTest.this, count);
InvokerTest.super.sendNotification(notify);
count ++;
if( count == 10 )
{
super.cancel();
log.info("Cancelled timer");
}
}
}
}