Hi all,
I have written a chat server with java.nio classes and I'd like to launch 
it with JBoss as a service.

So I created a wrapper on it with a ServiceMBean which simply instantiates the 
chat server.

public class ChatService extends ServiceMBeanSupport implements ChatServiceMBean
  | {
  | 
  |    
  |    // The lifecycle
  |    protected void startService() throws Exception
  |    {
  |       new NbChatServer(9999);
  |       
  |    }
  |   .......
  |  }


The NbChatServer is a standard java.nio Server which listens for incoming 
messages:

public NbChatServer( int port ) {
  |     
  |     this.port = port;
  | 
  |     new Thread( this ).start();
  |   
  |   }
  | 
  |   public void run() {
  |     try {
  | 
  |       ServerSocketChannel ssc = ServerSocketChannel.open();
  | 
  |       // Set it to non-blocking, so we can use select
  |       ssc.configureBlocking( false );
  | 
  |       // Get the Socket connected to this channel, and bind it
  |       // to the listening port
  |       ServerSocket ss = ssc.socket();
  |       InetSocketAddress isa = new InetSocketAddress( port );
  |       ss.bind( isa );
  | 
  |       // Create a new Selector for selecting
  |       Selector selector = Selector.open();
  | 
  |       // Register the ServerSocketChannel, so we can
  |       // listen for incoming connections
  |       ssc.register( selector, SelectionKey.OP_ACCEPT );
  | 
  |       System.out.println( "Server started on port "+port );
  | 
  |       while (true) {
  |         // See if we've had any activity -- either
  |         // an incoming connection, or incoming data on an
  |         // existing connection
  |       
  |       
  |         int num = selector.select();
  |      // EXECUTION HANGS HERE!!!    
  | 
  |         // If we don't have any activity, loop around and wait
  |         // again
  |         if (num == 0) {
  |           continue;
  |         }
  | 
  |             
  |         Set keys = selector.selectedKeys();
  |         Iterator it = keys.iterator();
  | 
  |         .......

As you can see from the comments executions hangs after

       int num = selector.select();

but launched as a plain Java applications it doesn't stops there........
why is it such when it's launched from a ServiceMBean ? 
Anyway I can see that the port stays busy as if the server is up but it doesn't 
receive any messages.......

is it forbidden to use java.nio api from a ServiceMBean ?

Hope I can get help........

Thanks & regards
Francesco

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

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


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to