/********************************************************* * Store caller's information and session *********************************************************/ package myServlet; import java.util.HashSet; import java.util.Iterator; import javax.servlet.sip.SipSession; public class Call { private String from; private String to; private String status; private HashSet<SipSession> sessions = new HashSet<SipSession>(); public Call(String from, String to) { this.from = from; this.to = to; } public String getFrom() { return from; } public String getTo() { return to; } public boolean equals(Object a) { Call other = (Call) a; if(other.from.equals(from) && other.to.equals(to)) return true; return false; } public int hashCode() { return from.hashCode()^to.hashCode(); } public void addSession(SipSession session) { this.sessions.add(session); } @SuppressWarnings("unchecked") public void end() { Iterator it = this.sessions.iterator(); while(it.hasNext()) { SipSession session = (SipSession) it.next(); try { session.createRequest("BYE").send(); } catch (Exception ex) { ex.printStackTrace(); } } } public String getStatus() { return this.status; } public void setStatus(String status) { this.status = status; } } /******************************************************** * Collect calls *******************************************************/ package myServlet; import java.util.HashSet; import java.util.Iterator; public class CallStatusContainer{ private HashSet<Call> activeCalls = new HashSet<Call> (); public Call addCall(String from, String to, String status) { Call call = new Call(from, to); call.setStatus(status); activeCalls.add(call); return call; } public void updateCall(Call call,String status) { call.setStatus(status); activeCalls.remove(call); activeCalls.add(call); } public void removeCall(String from, String to) { activeCalls.remove(new Call(from, to)); } public void removeCall(Call call) { activeCalls.remove(call); } public Call getCall(String from, String to) { Iterator<Call> it = activeCalls.iterator(); while(it.hasNext()) { Call call = it.next(); if(call.getFrom().equals(from) && call.getTo().equals(to)) return call; } return null; } public String getStatus(String from, String to) { Call call = getCall(from,to); if(call != null) { return call.getStatus(); } else { return null; } } } 1.不熟悉JAVA语言 2.总爱用C++的思维去思考JAVA 3.不熟悉IDE,不熟悉API 4.缺乏经验 5.浮躁,自负