CallSessionFactory callSessionFactory = getCallSessionFactory();
    protected void handleHangupEvent(HangupEvent event) {        //everything after the hyphen should be skipped        String device = getDevice(event.getChannel());        try {            PhoneUser phoneUser = phoneManager.getActivePhoneUserByDevice(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            phoneManager.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) {                	plugin.restorePresence(phoneUser.getUsername());                }                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 (Throwable e) {            Log.error(e.getMessage(), e);        }    }