在Red5中创建线程时出错

时间:2011-06-20 13:57:45

标签: java multithreading red5

首先,我在java应用程序中成功创建了线程。然后,我尝试将它带入Red5应用程序,但它显示错误,我无法解决。

我的代码,像这样:

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.so.ISharedObject;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;
import net.sf.asterisk.manager.TimeoutException;
import net.sf.asterisk.manager.action.CommandAction;
import net.sf.asterisk.manager.response.CommandResponse;

class UserOnline extends Thread{
    private ManagerConnection c;
     public LinkedList<String> listtUser;
     private LinkedList<String> sendList = new LinkedList<String>();
        public UserOnline()
        {
            start();
        }
        public void run()
        {
            try {
                c = new ManagerConnectionFactory().getManagerConnection("localhost", 
                        "admin", "secret5");
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                c.login();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (AuthenticationFailedException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            }
            CommandResponse response =  new CommandResponse();
            listtUser = new LinkedList<String>();
            CommandAction action;
            Iterator lineIterator;
            while (true){
                action = new CommandAction();
                action.setCommand("sip show peers");
                try {
                    response = (CommandResponse) c.sendAction(action);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (TimeoutException e) {
                    e.printStackTrace();
                }
                lineIterator = response.getResult().iterator();
                //int i=0;
                while (lineIterator.hasNext())
                {
                    listtUser.add(lineIterator.next().toString());          
                    //System.out.println(listtUser.get(i));
                    //i++;
                }
                parseList(listtUser);
                listtUser.clear();
                //c.logoff();
                try {
                    Thread.currentThread().sleep(5000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }

    public void parseList(LinkedList<String> llUser){
        llUser.removeFirst();
        llUser.removeLast();
        String[] node;
        for(String s : llUser) {
            //System.out.println(s);
            node = s.split(" ");
            if(!s.contains("Unspecified")){
                //System.out.println(node[0]+" online");
                sendList.add(node[0]+"-online");
            }
            else if(s.contains("Unspecified")){
                //System.out.println(node[0]+" offline");
                sendList.add(node[0]+"-offline");
            }
        }
        for(String t : sendList){
            System.out.println(t);
        }
        this.getListUser();
        sendList.clear();
        //index=0;          
    }
    public List<String> getListUser(){
        return sendList;
    }
}

    public class Application extends ApplicationAdapter {
        /** {@inheritDoc} */
        private IScope apScope;
        @Override
        public boolean connect(IConnection conn, IScope scope, Object[] params) {
            apScope = scope;
            createSharedObject(apScope, "user", false);
            //sendUserOnline();
            return true;
        }

    /** {@inheritDoc} */
    @Override
    public void disconnect(IConnection conn, IScope scope) {
        super.disconnect(conn, scope);
    }

    public void sendUserOnline(){
        UserOnline uso = new UserOnline();
        uso.start();
        List<String> listUserStatus = new LinkedList<String>();
        ISharedObject so = getSharedObject(apScope, "user");
        try {
            uso = new UserOnline();
            listUserStatus = uso.getListUser();
            so.sendMessage("receiveUserStatus", listUserStatus);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

它显示如下错误:

[INFO] [NioProcessor-1] org.red5.server.adapter.MultiThreadedApplicationAdapter
- W3C x-category:session x-event:disconnect c-ip:127.0.0.1 c-client-id:0

请提前帮助,请提供帮助

0 个答案:

没有答案