1 7 8 package org.jboss.media.engine; 9 10 import java.util.Iterator ; 11 import java.util.Vector ; 12 13 import javax.management.InstanceNotFoundException ; 14 import javax.management.MBeanRegistrationException ; 15 import javax.management.MalformedObjectNameException ; 16 import javax.management.ObjectName ; 17 18 import org.jboss.mx.util.MBeanProxy; 19 import org.jboss.mx.util.MBeanProxyCreationException; 20 import org.jboss.system.ServiceMBeanSupport; 21 22 23 30 public class MediaPublisherFactory 31 extends ServiceMBeanSupport 32 implements MediaPublisherFactoryMBean 33 { 34 35 Vector m_publishers = new Vector (); 36 37 41 public ObjectName createPublisher( 42 String publisherClassName, 43 String context, 44 String host, 45 int port, 46 String arguments, 47 String fileName) 48 { 49 50 System.out.println("IIIIIIIIIIII" + arguments + "IIIIIIIIIIII"); 51 52 ObjectName publisherName; 53 54 publisherName = getObjectName(publisherClassName, context); 55 56 try 58 { 59 60 Class publisher = Class.forName(publisherClassName); 61 Class publisherMBean = Class.forName(publisherClassName + "MBean"); 62 MediaPublisherMBean pBean = 63 (MediaPublisherMBean) MBeanProxy.create( 64 publisher, 65 publisherMBean, 66 publisherName, 67 getServer()); 68 69 m_publishers.add(pBean); 70 pBean.setName(publisherName); 73 pBean.setHost(host); 74 pBean.setPort(port); 76 pBean.setContext(context); 77 pBean.setFileName(fileName); 78 79 } 80 81 catch (MBeanProxyCreationException e) 82 { 83 log.error("Big Nasty error. Get out o' here ", e); 84 } 85 catch (ClassNotFoundException e) 86 { 87 log.error("Publisher class " + publisherClassName + " notFound",e); 88 } 89 return publisherName; 91 } 92 93 97 public void destroyPublisher(ObjectName name) 98 { 99 try 100 { 101 for (Iterator iter = m_publishers.iterator(); iter.hasNext();) 102 { 103 MediaPublisherMBean element = (MediaPublisherMBean) iter.next(); 104 if (element.getName().equals(name)) 105 { 106 element.stop(); 107 server.unregisterMBean(element.getName()); 108 break; 109 } 110 111 } 112 } 113 114 catch (InstanceNotFoundException e) 115 { 116 e.printStackTrace(); 118 } 119 catch (MBeanRegistrationException e) 120 { 121 e.printStackTrace(); 123 } 124 } 125 126 130 public ObjectName getObjectName(String publisherClassName, String context) 131 { 132 try 133 { 134 return new ObjectName ( 135 "jboss.media.engine:service=Media,Type=" 136 + publisherClassName 137 + ",Context=" 138 + context); 139 } 140 catch (MalformedObjectNameException e) 141 { 142 log.error(e); 143 } 144 catch (NullPointerException e) 145 { 146 log.error(e); 148 } 149 150 return null; 151 } 152 153 154 157 protected void createService() throws Exception 158 { 159 } 160 161 164 protected void destroyService() throws Exception 165 { 166 for (Iterator iter = m_publishers.iterator(); iter.hasNext();) 168 { 169 MediaPublisherMBean element = (MediaPublisherMBean) iter.next(); 170 element.stop(); 171 server.unregisterMBean(element.getName()); 172 } 173 174 } 175 176 179 protected void startService() throws Exception 180 { 181 } 182 183 186 protected void stopService() throws Exception 187 { 188 } 189 190 } 191 | Popular Tags |