PhoneUser phoneUser = phoneManager.getByDevice(device);
PhoneUser phoneUser = phoneManager.getPhoneUserByDevice(device);
        public void run() {            //everything after the hyphen should be skipped            String device = getDevice(event.getChannel());            PhoneManager phoneManager = null;            try {                phoneManager = getPhoneManager();                PhoneUser phoneUser = phoneManager.getByDevice(device);                //If there is no jid for this device don't do anything else                if (phoneUser == null) {                    return;                }                Log.debug("Asterisk-IM HangupTask called for user " + phoneUser);                // Send hang up message to user                sendHangupMessage(event.getUniqueId(), device, phoneUser.getUsername());                CallSessionFactory callSessionFactory = getCallSessionFactory();                // If the user does not have any more call sessions, set back                // the presence to what it was before they received any calls                synchronized (phoneUser.getUsername().intern()) {                    int callSessionCount = callSessionFactory.getUserCallSessions(phoneUser.getUsername()).size();                    if (callSessionCount <= 1) {                        // Set the user's presence back to what it was before the phone call. The                        // presence will be broadcasted to corresponding users                        if (!restoreUserPresence(phoneUser.getUsername())) {                            // TODO Remove this code when the "always on-the-phone problem is fixed"                            // Check if the user is available and his presence is still                            // on-the-phone (and no there are no more calls)                            SessionManager sessionManager = XMPPServer.getInstance().getSessionManager();                            Collection<ClientSession> sessions = sessionManager.getSessions(phoneUser.getUsername());                            for (ClientSession session : sessions) {                                Presence presence = session.getPresence();                                Element phoneStatusElement = presence.getElement().element("phone-status");                                // If the phone-status attribute exists check to see if the status is avaialbable                                if (phoneStatusElement != null && PhoneStatus.Status.ON_PHONE.name().equals(phoneStatusElement.attributeValue("status"))) {                                    Log.debug("Asterisk-IM HangupTask: User " + phoneUser.getUsername() +                                            " has no more call sessions, but his presence is " +                                            "still ON_PHONE. Changing to AVAILABLE");                                    // Change presence to available since there are no more active calls                                    phoneStatusElement.addAttribute("status", PhoneStatus.Status.AVAILABLE.name());                                    getInstance().getPresenceRouter().route(presence);                                }                            }                        }                    }                    else {                        if (Log.isDebugEnabled()) {                            Log.debug("Asterisk-IM HangupTask: User " + phoneUser.getUsername() +                                    " has " + callSessionCount +                                    " call sessions,  not restoring presence. Destroying CallSession{id=" +                                    event.getUniqueId() + ", channel=" + event.getChannel() + "}");                        }                    }                    // finally destroy the session.                    if (callSessionFactory.destroyPhoneSession(event.getUniqueId()) == null) {                        // Events of ZOMBIE channels may have a different ID so try to locate                        // the CallSession to destroy based on the channel                        if (event.getChannel().contains("<ZOMBIE>")) {                            CallSession destroyedSession = callSessionFactory.destroyPhoneSession(                                    event.getChannel().replace("<ZOMBIE>", ""),                                    phoneUser.getUsername());                            if (Log.isDebugEnabled()) {                                Log.debug("Asterisk-IM HangupTask: Found ZOMBIE channel so " +                                        "trying to destroy CallSession based on channel " +                                        "instead of id. User: " + phoneUser.getUsername() +                                        " channel to destroy" + event.getChannel() +                                        " . Destruction status: " + destroyedSession == null ? "FAILED" : "SUCCEEDED");                            }                        }                    }                    if (callSessionCount > 1) {                        for (CallSession session : callSessionFactory.getUserCallSessions(phoneUser.getUsername())) {                            Log.debug("Asterisk-IM HangupTask: Remaining CallSession " + session);                        }                    }                    // just in case this was a fake session, kill the fake session.                    // This should be ok to do, since noone should be orginating a call and hanging up at the same time                    // for a device                    callSessionFactory.destroyPhoneSession(device);                }            }            catch (Exception e) {                Log.error(e.getMessage(), e);            }            finally {                close(phoneManager);            }        }