package org.jboss.media.engine;
import java.util.Iterator;
import java.util.Vector;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.MBeanProxyCreationException;
import org.jboss.system.ServiceMBeanSupport;
public class MediaPublisherFactory
extends ServiceMBeanSupport
implements MediaPublisherFactoryMBean
{
Vector m_publishers = new Vector();
public ObjectName createPublisher(
String publisherClassName,
String context,
String host,
int port,
String arguments,
String fileName)
{
System.out.println("IIIIIIIIIIII" + arguments + "IIIIIIIIIIII");
ObjectName publisherName;
publisherName = getObjectName(publisherClassName, context);
try
{
Class publisher = Class.forName(publisherClassName);
Class publisherMBean = Class.forName(publisherClassName + "MBean");
MediaPublisherMBean pBean =
(MediaPublisherMBean) MBeanProxy.create(
publisher,
publisherMBean,
publisherName,
getServer());
m_publishers.add(pBean);
pBean.setName(publisherName);
pBean.setHost(host);
pBean.setPort(port);
pBean.setContext(context);
pBean.setFileName(fileName);
}
catch (MBeanProxyCreationException e)
{
log.error("Big Nasty error. Get out o' here ", e);
}
catch (ClassNotFoundException e)
{
log.error("Publisher class " + publisherClassName + " notFound",e);
}
return publisherName;
}
public void destroyPublisher(ObjectName name)
{
try
{
for (Iterator iter = m_publishers.iterator(); iter.hasNext();)
{
MediaPublisherMBean element = (MediaPublisherMBean) iter.next();
if (element.getName().equals(name))
{
element.stop();
server.unregisterMBean(element.getName());
break;
}
}
}
catch (InstanceNotFoundException e)
{
e.printStackTrace();
}
catch (MBeanRegistrationException e)
{
e.printStackTrace();
}
}
public ObjectName getObjectName(String publisherClassName, String context)
{
try
{
return new ObjectName(
"jboss.media.engine:service=Media,Type="
+ publisherClassName
+ ",Context="
+ context);
}
catch (MalformedObjectNameException e)
{
log.error(e);
}
catch (NullPointerException e)
{
log.error(e);
}
return null;
}
protected void createService() throws Exception
{
}
protected void destroyService() throws Exception
{
for (Iterator iter = m_publishers.iterator(); iter.hasNext();)
{
MediaPublisherMBean element = (MediaPublisherMBean) iter.next();
element.stop();
server.unregisterMBean(element.getName());
}
}
protected void startService() throws Exception
{
}
protected void stopService() throws Exception
{
}
}