[jboss-user] [Management, JMX/JBoss] - Custom MBean on JBoss 5.0.0 GA

mayankmit2002 do-not-reply at jboss.com
Mon Mar 2 22:42:47 EST 2009


Hello,
   I'm trying to migrate my application from Jboss 4.2.2 to Jboss 5.0.0 GA. My Application is like that, it has a MBean which initiates some threads that keeps listing to some socket, along with that, it also has a MDB, which needs to perform some task on receiving some messages from my another application.

Now the problem is that, when I try to deploy the existing application on this new AS ( 5.0.0 GA), MBean is not getting deployed, along with that, MDB gets deployed, but still it is not visible in JMX console.
  But, the same application is working fine on Jboss AS 4.2.2.

Following is the code:
package com.barco.cms.tcpip;
  | 
  | 
  | /**
  |  * TODO: Documentation to be done for type 'TelNetMBean'..
  |  * 
  |  */
  | 
  | public interface TelNetMBean
  | {
  | 
  |     /**
  |      * This method is one of the life cycle method of MBean, will be invoked automatically while starting this service.
  |      * 
  |      * @throws Exception
  |      */
  |     public void start ()
  |         throws Exception;
  | 
  | 
  |     /**
  |      * This method is one of the life cycle method of MBean, will be invoked automatically while stoping this service.
  |      * 
  |      * @throws Exception
  |      */
  |     public void stop ()
  |         throws Exception;
  | 
  | 
  |     /**
  |      * This method is used to set the port of the TCP\IP server by JMX console.
  |      * 
  |      * @param aPort
  |      * @throws Exception
  |      */
  |     public void setPort (String aPort)
  |         throws Exception;;
  | 
  | 
  | }
  | 

  | package com.barco.cms.tcpip;
  | 
  | 
  | import java.io.IOException;
  | import java.net.InetSocketAddress;
  | import java.nio.charset.Charset;
  | 
  | import javax.jms.Session;
  | import javax.jms.Topic;
  | import javax.jms.TopicConnection;
  | import javax.jms.TopicConnectionFactory;
  | import javax.jms.TopicPublisher;
  | import javax.jms.TopicSession;
  | import javax.naming.InitialContext;
  | 
  | import org.apache.mina.common.ByteBuffer;
  | import org.apache.mina.common.IoAcceptor;
  | import org.apache.mina.common.SimpleByteBufferAllocator;
  | import org.apache.mina.filter.LoggingFilter;
  | import org.apache.mina.filter.codec.ProtocolCodecFilter;
  | import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
  | import org.apache.mina.transport.socket.nio.SocketAcceptor;
  | import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
  | import org.jboss.annotation.ejb.Management;
  | import org.jboss.annotation.ejb.Service;
  | 
  | import com.barco.cms.foundation.logging.Logger;
  | 
  | 
  | /**
  |  * This is main class which acts as a TCP/IP Server for the clients.
  |  * 
  |  * @author srgk
  |  */
  | @Service(objectName = "com.barco.cms.tcpip:service=TelnetService", name = "com.barco.cms.tcpip:service=TelnetService")
  | @Management(TelNetMBean.class)
  | public class TelNetServer
  |     implements TelNetMBean
  | {
  | 
  |     // Member Variables
  |     // ============================================================================================
  | 
  |     private static int PORT = 4585; // Default Port 4585
  |     private static Logger mLogger = null;
  |     private IoAcceptor mAcceptor = null;
  |     private InetSocketAddress mInetAddress = null;
  |     private SocketAcceptorConfig mSktActConf = null;
  | 
  |     static
  |     {
  |         mLogger = Logger.getLogger(TelNetServer.class);
  |     }
  | 
  | 
  |     /**
  |      * Main Method for starting the TCP/IP Server.
  |      * 
  |      * @param args
  |      * @throws IOException
  |      */
  | 
  | 
  |     public static void main (final String[] args)
  |     {
  |         try
  |         {
  |             new TelNetServer().start();
  |         }
  |         catch (final Exception anException)
  |         {
  | 
  |         }
  |     }
  | 
  | 
  |     // /**
  |     // * @see org.jboss.system.ServiceMBeanSupport#startService()
  |     // */
  |     // @Override
  |     // protected void startService ()
  |     // throws Exception
  |     // {
  |     // // TODO Auto-generated method stub
  |     // super.startService();
  |     // }
  |     /**
  |      * @see com.barco.cms.tcpip.TelNetMBean#start()
  |      */
  |     @Override
  |     public void start ()
  |         throws Exception
  |     {
  |         System.out.println("Hello");;
  |         // Just to initiate the session threads for first time
  |         ServerRequestHandler lServerRequestHandler = new ServerRequestHandler();
  |         mInetAddress = new InetSocketAddress(System.getenv("COMPUTERNAME"), PORT);
  | 
  |         ByteBuffer.setUseDirectBuffers(false);
  |         ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
  | 
  |         mAcceptor = new SocketAcceptor();
  | 
  |         mSktActConf = new SocketAcceptorConfig();
  |         mSktActConf.getFilterChain().addLast("logger", new LoggingFilter());
  |         mSktActConf.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
  | 
  |         mAcceptor.bind(mInetAddress, lServerRequestHandler, mSktActConf);
  |         send("com.barco.cms.tcpip.telnetServer.started");
  |         // System.out.println("TCP/IP server started.");
  | 
  |     }
  | 
  | 
  |     /**
  |      * @throws Exception
  |      * @see com.barco.cms.tcpip.TelNetMBean#setPort()
  |      */
  |     @Override
  |     public void setPort (final String aPort)
  |         throws Exception
  |     {
  | 
  | 
  |         ServerRequestHandler.sendMessageToAllClients("Telnet Server Port has been changed to " + aPort);
  |         // This provides some time to the client before resetting the port.
  |         Thread.sleep(1000);
  |         stop();
  |         PORT = Integer.parseInt(aPort.trim());
  | 
  |         mLogger.info("Port Changed to " + aPort + "!! ");
  |         start();
  |     }
  | 
  | 
  |     /**
  |      * @see com.barco.cms.tcpip.TelNetMBean#stop()
  |      */
  |     @Override
  |     public void stop ()
  |     {
  |         mAcceptor.unbind(mInetAddress);
  |         mSktActConf = null;
  |     }
  | 
  | 
  |     // Helper Methods
  | 
  |     /**
  |      * This method publishes the message to the message Queue
  |      */
  |     private static void send (String aMessage)
  |     {
  |         try
  |         {
  |             InitialContext ctx = new InitialContext();
  |             TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
  |             TopicConnection connection = factory.createTopicConnection();
  |             Topic topic = (Topic) ctx.lookup("topic/events");
  |             TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
  |             connection.start();
  | 
  |             TopicPublisher sender = session.createPublisher(topic);
  |             sender.publish(session.createObjectMessage(aMessage));
  |             connection.stop();
  |             session.close();
  |             connection.close();
  |         }
  |         catch (Throwable t)
  |         {
  |         }
  |     }
  | 
  | }

Code for MDB is 

  | package com.barco.cms.tcpip;
  | 
  | 
  | import javax.annotation.PreDestroy;
  | import javax.ejb.ActivationConfigProperty;
  | import javax.ejb.MessageDriven;
  | import javax.jms.JMSException;
  | import javax.jms.Message;
  | import javax.jms.MessageListener;
  | import javax.jms.TextMessage;
  | 
  | import com.barco.cms.tcpip.TelNetUtil.APIServer_Status;
  | 
  | 
  | /**
  |  * Act as a broadcast client for Telnet module. This class recieves the broadcasted packet from the API server and send
  |  * 
  |  * @author maym
  |  */
  | @MessageDriven(activationConfig = {
  |         @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
  |         @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/events")}
  | )
  | public class TelnetBroadcastClientMDB
  |     implements MessageListener
  | 
  | {
  |     /**
  |      * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
  |      */
  |     @Override
  |     public void onMessage (Message anMessage)
  |     {
  |         TextMessage textMessage = null;
  |         String lMessage = null;
  |         textMessage = (TextMessage) anMessage;
  | 
  | 
  |         try
  |         {
  | 
  |             System.out.println(textMessage.getText());
  |             lMessage = (String) textMessage.getText();
  |             {
  |                 if (lMessage.contains("org.jboss.system.server.started"))
  |                 {
  |                     CommandExecutor.mAPIServerStatus = APIServer_Status.Ready;
  |                 }
  |                 else if (lMessage.contains("stopped"))
  |                 {
  |                     CommandExecutor.mAPIServerStatus = APIServer_Status.Offline;
  |                 }
  |                 else if (lMessage.contains("EventEmitter.restore_started"))
  |                 {
  |                     CommandExecutor.mAPIServerStatus = APIServer_Status.Busy;
  |                 }
  |                 else if (lMessage.contains("EventEmitter.restore_completed"))
  |                 {
  |                     CommandExecutor.mAPIServerStatus = APIServer_Status.Ready;
  |                 }
  |                 else if (lMessage.contains("com.barco.cms.tcpip.telnetServer.started"))
  |                 {
  |                     CommandExecutor.mAPIServerStatus = APIServer_Status.Ready;
  |                 }
  |             }
  |         }
  |         catch (JMSException exception)
  |         {
  |             exception.printStackTrace();
  |         }
  | 
  |     }
  |                          
  | 
  |     // Lifecycle Methods
  | 
  |     /**
  |      * This method stops all running threads which are renewing session. This method is executed specially in case of hot undeplyment.
  |      */
  |     @PreDestroy
  |     public void stopThreads ()
  |     {
  |         CommandExecutor.stopThreads();
  |     }
  | 
  | 
  | }

Is there any backward compatibility issue with AS 5.0.0 GA, or I'm doing some thing wrong.


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4214346#4214346

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4214346



More information about the jboss-user mailing list