KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > engine > MediaPublisherFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.engine;
9
10 import java.util.Iterator JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import javax.management.InstanceNotFoundException JavaDoc;
14 import javax.management.MBeanRegistrationException JavaDoc;
15 import javax.management.MalformedObjectNameException JavaDoc;
16 import javax.management.ObjectName JavaDoc;
17
18 import org.jboss.mx.util.MBeanProxy;
19 import org.jboss.mx.util.MBeanProxyCreationException;
20 import org.jboss.system.ServiceMBeanSupport;
21
22
23 /**
24  * @version <tt>$Revision: 1.9 $</tt>
25  * @author <a HREF="mailto:spyridon_samothrakis@yahoo.com">Spyridon Samothrakis</a>
26  *
27  * @jmx.mbean extends="org.jboss.system.ServiceMBean"
28  * @jmx.mbean description="Creates MediaPublisher"
29  */

30 public class MediaPublisherFactory
31    extends ServiceMBeanSupport
32    implements MediaPublisherFactoryMBean
33 {
34
35    Vector JavaDoc m_publishers = new Vector JavaDoc();
36
37    /**
38     * Creates a media publisher according to the parameters passed
39     * @jmx.managed-operation description="Creates a MediaPublisher"
40     */

41    public ObjectName JavaDoc createPublisher(
42       String JavaDoc publisherClassName,
43       String JavaDoc context,
44       String JavaDoc host,
45       int port,
46       String JavaDoc arguments,
47       String JavaDoc fileName)
48    {
49
50       System.out.println("IIIIIIIIIIII" + arguments + "IIIIIIIIIIII");
51
52       ObjectName JavaDoc publisherName;
53
54       publisherName = getObjectName(publisherClassName, context);
55
56       // add the bean to the server
57
try
58       {
59
60          Class JavaDoc publisher = Class.forName(publisherClassName);
61          Class JavaDoc 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          // set initial parameters
71
// To be changed in the near future
72
pBean.setName(publisherName);
73          pBean.setHost(host);
74          // mambo number 22224
75
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 JavaDoc e)
86       {
87          log.error("Publisher class " + publisherClassName + " notFound",e);
88       }
89       // Should we return a string here ?
90
return publisherName;
91    }
92
93    /**
94     * Creates a media publisher according to the parameters passed
95     * @jmx.managed-operation description="Creates a MediaPublisher"
96     */

97    public void destroyPublisher(ObjectName JavaDoc name)
98    {
99       try
100       {
101          for (Iterator JavaDoc 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 JavaDoc e)
115       {
116          // TODO Auto-generated catch block
117
e.printStackTrace();
118       }
119       catch (MBeanRegistrationException JavaDoc e)
120       {
121          // TODO Auto-generated catch block
122
e.printStackTrace();
123       }
124    }
125
126    /**
127     * return the objectname that we are goint to use
128     * @jmx.managed-operation description="Creates a MediaPublisher"
129     */

130    public ObjectName JavaDoc getObjectName(String JavaDoc publisherClassName, String JavaDoc context)
131    {
132       try
133       {
134          return new ObjectName JavaDoc(
135             "jboss.media.engine:service=Media,Type="
136                + publisherClassName
137                + ",Context="
138                + context);
139       }
140       catch (MalformedObjectNameException JavaDoc e)
141       {
142          log.error(e);
143       }
144       catch (NullPointerException JavaDoc e)
145       {
146          // TODO Auto-generated catch block
147
log.error(e);
148       }
149
150       return null;
151    }
152    
153
154    /**
155     * @see org.jboss.system.ServiceMBeanSupport#createService()
156     */

157    protected void createService() throws Exception JavaDoc
158    {
159    }
160
161    /**
162     * @see org.jboss.system.ServiceMBeanSupport#destroyService()
163     */

164    protected void destroyService() throws Exception JavaDoc
165    {
166       // if I go down all of what I have deployed goes down!!!
167
for (Iterator JavaDoc 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    /**
177     * @see org.jboss.system.ServiceMBeanSupport#startService()
178     */

179    protected void startService() throws Exception JavaDoc
180    {
181    }
182
183    /**
184     * @see org.jboss.system.ServiceMBeanSupport#stopService()
185     */

186    protected void stopService() throws Exception JavaDoc
187    {
188    }
189
190 }
191
Popular Tags