You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by 凌晨 <cl...@netspeed-tech.com> on 2007/02/08 06:31:11 UTC

答复: Asking

Iterator iter = sessions.iterator();
            while( iter.hasNext() )
            {
                IoSession s = ( IoSession ) iter.next();
					

                if( s.isConnected() )
                {
					//here would be like this
					s.write( wb.slice());	
					
                }
          
			}
By the way,when the collections of sessions(here sessions) changed there
would be ConcurrentModification Exception threw so you'd better change it to
for()loop
-----邮件原件-----
发件人: ramesh murugaswamy [mailto:ramesh.murugaswamy@rediffmail.com] 
发送时间: 2007年2月8日 13:19
收件人: dev@mina.apache.org
主题: Asking

  
 Hai All,
            
         I have been doing some performance testing with MINA for our stock
info application. I slightly modified echo server , i had wrote two handler,
one is for FeedHandler(Message receiver this bind the port 8081) and Another
one is  EchoHandler(that bind the port 9401 ).All the client is connectd
throws this port(9401).When the message received from feed handler , the
message is put into message queue.
   
       When the client is connected to the port 9401 , the MessageThreade r
will start and get the message from message queue and sent this message to
all the connected clients.

     What is my problem is , when iterate the session and sent each message
to everyone i got the exception.'Already releaed the buufer. You have
released the buffer too many times'

    I want to know is this right way,i also need to know the is there
available to sent message to everyone.Please help me i am new to Apache and
Java N/W also.



My ThreadCode is shown

       public class StartThread implements Runnable
{	
	public static Set sessions = Collections.synchronizedSet( new
HashSet() );
	
	private Queue que = null;
	public StartThread(Queue que,Set sessions) {
		this.sessions = sessions;
		this.que = que;
		System.out.println("Constructer");
		
	}

	public void run() {
		int count  = 0;
		while(true) {
		
		try{



			System.out.println("getQueue");
			ByteBuffer rb = null;
			//synchronized( sessions) {
			try{
				rb = (ByteBuffer)que.deQueue();		
				//System.out.println("rb is ------->"+rb);
			}catch(Exception ee) {
				System.out.println("Error While getting Msg
from Queue ---->"+ee);
			}

			System.out.println("No of Session
--------->"+sessions.size());
			

			// Write the received data back to remote peer
			//ByteBuffer wb = ByteBuffer.allocate(
rb.remaining() );
			String str ="Hai Ramesh"+count;

			ByteBuffer wb = ByteBuffer.allocate( str.length() +
2 );	
			rb.release();
			wb.put( str.getBytes() );
			wb.flip();
			System.out.println("Hai ");		
				
			

            Iterator iter = sessions.iterator();
            while( iter.hasNext() )
            {
                IoSession s = ( IoSession ) iter.next();
					

                if( s.isConnected() )
                {
					
					s.write( wb);	
					
                }
          
			}
			 wb.release();	
			
       	}catch(Exception e) {

		}
		}
		
	}

regds
Ramesh.M