我有一个问题,这里使用Red5 0.9 Server中的Java,这里是代码
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);
}
}
}
错误是:
/opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java中的错误(第29行)
Iterator <IConnection> it = scope.getConnections();
/opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java中的错误(第63行)
Iterator<IConnection> it = scope.getConnections();
/opt/red5/dist/webapps/i5lecture/WEB-INF/src/com/hwakin/i5lc/manager/I5lcDrawManager.java中的错误(第100行)
Iterator<IConnection> it = scope.getConnections();
3个问题(3个错误)
答案 0 :(得分:2)
听起来您的getConnections()
方法会返回Collection<Set<IConnection>>
,而您似乎认为它应该返回Iterator<IConnection>
。
您是否忘记了对.iterator()
的通话?如
Iterator<IConnection> it = scope.getConnections.iterator();
虽然从编译器错误中听起来好像你需要
Iterator<Set<IConnection>> it = scope.getConnections.iterator();
答案 1 :(得分:2)
Collection
是Iterable
,而非Iterator
。您不需要Iterator
进行循环;增强的for循环适用于任何Iterable
实现。
请改为尝试:
for (Set<IConnection>> connections : scope.getConnections()) {
for (IConnection con : connections) {
/* Use each 'conn' instance... */
}
}
答案 2 :(得分:2)
我添加了(Iterator)来解析scope.getConnection();
Iterator<IConnection> it = (Iterator) scope.getConnections();
然后我在函数的开头添加了@SuppressWarnings(“unchecked”)
@SuppressWarnings("unchecked")
public void startDrawingHandler(String type,ExternalPoint point, ExternalDrawInfo data){
// Rest of the code
}
答案 3 :(得分:1)
您在这里看到的是一个不稳定的API。
是Iterator<IConnection> getConnections()
还是Collection<Set<IConnection>> getConnections()
(很好地将文档称为“获取连接迭代器。” - 评论谎言)?谷歌是你的朋友。