tags:

views:

759

answers:

4

I have a Problem here using Java in Red5 0.9 Server here's the code

package com.hwakin.i5lc.manager;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;

import com.hwakin.i5l.vo.ExternalPoint;
import com.hwakin.i5l.vo.UserInfo;
import com.hwakin.i5lc.vo.ExternalDrawInfo;

public class I5lcDrawManager extends ApplicationAdapter {
    protected static Log log = LogFactory.getLog(I5lcDrawManager.class.getName());

public void startDrawingHandler(String type,ExternalPoint point, ExternalDrawInfo data){

   try{
   IConnection Lconn = Red5.getConnectionLocal();

   IScope scope = Lconn.getScope();

   Iterator<IConnection> it = scope.getConnections();

   while (it.hasNext()) {
    IConnection conn = it.next();

    if (Lconn.equals(conn)) {
     continue;
    }

    log.info("i5lvDrawManagerReceiver.startDrawingHandler invoked.");

    IClient client = conn.getClient();

    UserInfo userInfo =(UserInfo) client.getAttribute("userInfo");


    if (conn instanceof IServiceCapableConnection) {
     if(userInfo.lectureInfo.sync.equals("true")){

      ((IServiceCapableConnection) conn).invoke("invoke",new Object[]{"i5lvDrawManagerReceiver.startDrawingHandler",type,point,data});
     }  
    } 
   }

  }catch(Exception e){
    log.debug("Exception in noticeChattingTo Method:"+e);
  }
 }
 public void drawingHandler(String type,ExternalPoint point){

   try{
   IConnection Lconn = Red5.getConnectionLocal();
   IScope scope = Lconn.getScope();

   Iterator<IConnection> it = scope.getConnections();

   while (it.hasNext()) {
    IConnection conn = it.next();

    if (Lconn.equals(conn)) {
     continue;
    }

    log.info("i5lvDrawManagerReceiver.drawingHandler invoked.");

                IClient client = conn.getClient();

    UserInfo userInfo =(UserInfo) client.getAttribute("userInfo");


    if (conn instanceof IServiceCapableConnection) {
     if(userInfo.lectureInfo.sync.equals("true")){

      ((IServiceCapableConnection) conn).invoke("invoke",new Object[]{"i5lvDrawManagerReceiver.drawingHandler",type,point});

     }

    } 
   }

  }catch(Exception e){
    log.debug("Exception in noticeChattingTo Method:"+e);
  }
 }

 public void endDrawingHandler(String type,ExternalPoint point, ExternalDrawInfo data){

   try{
   IConnection Lconn = Red5.getConnectionLocal();
   IScope scope = Lconn.getScope();

   Iterator<IConnection> it = scope.getConnections();

   while (it.hasNext()) {
    IConnection conn = it.next();

    if (Lconn.equals(conn)) {
     continue;
    }

    log.info("i5lvDrawManagerReceiver.endDrawingHandler invoked.");

                IClient client = conn.getClient();

    UserInfo userInfo =(UserInfo) client.getAttribute("userInfo");


    if (conn instanceof IServiceCapableConnection) {
     if(userInfo.lectureInfo.sync.equals("true")){

      ((IServiceCapableConnection) conn).invoke("invoke",new Object[]{"i5lvDrawManagerReceiver.endDrawingHandler",type,point,data});
     }  
    } 
   }

  }catch(Exception e){
    log.debug("Exception in noticeChattingTo Method:"+e);
  }
 }
}

The Errors are:

  1. ERROR in /opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java (at line 29)

    Iterator <IConnection> it = scope.getConnections();
    

Type mismatch: cannot convert from Collection<Set<IConnection>> to Iterator

  1. ERROR in /opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java (at line 63)

    Iterator<IConnection> it = scope.getConnections();
    

Type mismatch: cannot convert from Collection<Set<IConnection>> to Iterator<IConnection>

  1. ERROR in /opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java (at line 100)

    Iterator<IConnection> it = scope.getConnections();
    

Type mismatch: cannot convert from Collection<Set<IConnection>> to Iterator<IConnection>

3 problems (3 errors)

+2  A: 

It sounds like your getConnections() method returns Collection<Set<IConnection>> while you seem to think that it should return Iterator<IConnection>.

Are you forgetting the call to .iterator()? Such as

Iterator<IConnection> it = scope.getConnections.iterator();

although from the compiler error it sounds as if you'll need

Iterator<Set<IConnection>> it = scope.getConnections.iterator();
matt b
there is no iterator() property for scope.getConnectionsgetConnections returns Iterator<IConnection> as shown herehttp://dl.fancycode.com/red5/api/org/red5/server/api/class-use/IConnection.html
Treby
The error message is clearly telling you that scope.getConnections() is returning a Collection<Set<IConnection>>.
Jim Garrison
+2  A: 

A Collection is an Iterable, not an Iterator. You don't need an Iterator for looping; the enhanced for loop works with any Iterable implementation.

Try this instead:

for (Set<IConnection>> connections : scope.getConnections()) {
  for (IConnection con : connections) {
    /* Use each 'conn' instance... */
  }
}
erickson
I didn't get your code. can you please state the whole code for me. thanks
Treby
+1  A: 

What you appear to have here is an unstable API.

Is it Iterator<IConnection> getConnections() or Collection<Set<IConnection>> getConnections() (nicely documents as "Get a connection iterator." - comments lie)? Google is your friend.

Tom Hawtin - tackline
Iterator<IConnection> getConnections()as the code states:Iterator<IConnection> it = scope.getConnections();
Treby
As your code states? But what about the code you are using? There are clearly at least two versions floating about. You can use `javap` to find out what really is in the class files/jars that you are using.
Tom Hawtin - tackline
+2  A: 

I Added (Iterator) to parse scope.getConnection();

Iterator<IConnection> it = (Iterator) scope.getConnections();

Then I added @SuppressWarnings("unchecked") in the beginning of the function

@SuppressWarnings("unchecked")
    public void startDrawingHandler(String type,ExternalPoint point, ExternalDrawInfo data){

   // Rest of the code

}
Treby