⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vijxtacallcontrol.java

📁 jxta官方例程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        this.callEndTime = System.currentTimeMillis ();    }        /**     *  Command HoldCall reveived from remote     */    private void localActionHoldCall (boolean myHold) {                getLocalMonitorControl ().pauseMonitor ();                getRemoteMonitorControl ().pauseMonitor ();            }                /**     *  Command ResumeCall received from remote     */    private void localActionResumeCall () {                getLocalMonitorControl ().resumeMonitor ();                getRemoteMonitorControl ().resumeMonitor ();    }        /**     *  Command EndSession received from remote     */    private void localActionEndSession () {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("localActionEndSession");        }                if(receiveTimeoutThread != null) {                        receiveTimeoutThread.stopThread ();                        receiveTimeoutThread = null;        }                this.stopTransmitReceive ();                this.stopMonitors ();            }            /**     * Called from UI signaling user accepts call invitation     */    public void viewActionAcceptCall () {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("viewActionAcceptCall");        }                sendCommand (this.COMMAND_VIJXTA_START_ACCEPT, null);                setProtocolState (this.SESSION_VIJXTA_START_ACCEPT_SENT);                setProtocolState (this.SESSION_VIJXTA_INCALL);    }        /**     * Called from IU signaling user wishes to place call on hold.     */    public void viewActionHoldCall () {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("viewActionHoldCall");        }                sendCommand (this.COMMAND_VIJXTA_HOLD_REQUEST, this.COMMAND_VIJXTA_HOLD_ACCEPT);                setProtocolState (this.SESSION_VIJXTA_HOLD_REQUEST_SENT);            }        /**     * Called from IU signaling user wishes to hangup call.     */    public void viewActionHangupCall () {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("viewActionHangupCall");        }                sendCommand (this.COMMAND_VIJXTA_HANGUP_REQUEST,this.COMMAND_VIJXTA_HANGUP_ACCEPT);                setProtocolState (this.SESSION_VIJXTA_HANGUP_REQUEST_SENT);                this.setCallEndTime ();                this.stopTransmitReceive ();                this.stopMonitors ();    }        /**     * Called from IU signaling user wishes to resume a call previsously placed     * on hold.     */    public void viewActionResumeCall () {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("viewActionResumeCall");        }                sendCommand (this.COMMAND_VIJXTA_RESUME_REQUEST,this.COMMAND_VIJXTA_RESUME_ACCEPT);                setProtocolState (this.SESSION_VIJXTA_RESUME_REQUEST_SENT);            }            private void sendCommand (String command) {                sendCommand (command,null, null);    }        private void sendCommand (String command,String ackCommand) {                sendCommand (command,ackCommand, null);    }        /**     *  Sends a command on the vijxta dialog pipe. This does not change the     *  Protocol state. We have to remember to do this ourselves.     *     */    private void sendCommand (String command,String ackCommand, HashMap elementMap ) {                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("sendCommand : "+ command);        }                                DialogMessage msg = (DialogMessage)templateMessage.clone ();                StringMessageElement commandElement = new StringMessageElement (                TAG_SESSION_COMMAND, command, null);                msg.addMessageElement (TAG_SESSION_COMMAND, commandElement);                if(elementMap != null) {                        Iterator keys = elementMap.keySet ().iterator ();                        while(keys.hasNext ()) {                                String elementName = (String)keys.next ();                                MessageElement element = (MessageElement)elementMap.get (elementName);                                msg.addMessageElement (elementName,  element);                            }        }                if(ackCommand != null) {                        this.messageAckThread = new MessageAckThread (ackCommand);                        this.messageAckThread.start ();                        this.messageAckThread.waitForStart ();        }                this.viJxtaDialog.dispatch (msg);            }            /**     *  This method updates the current protocol state. Also signals the UI     *  of a protocol state change.     */    private void setProtocolState (int protocolState) {                this.protocolState = protocolState;                if (LOG.isEnabledFor (Level.INFO)) {            LOG.info ("ProtocolStateChanged to "+ this.sessionStateTable.get (new Integer (protocolState)));        }                this.viJxtaView.protocolStateChanged (protocolState);    }        /**     *  Returns the protocol state     */    public int getProtocolState () {                return this.protocolState;    }        /**     *  Returns the current time in milliseconds to wait for a message respose     *  before session shutdown.     */    public long getMessageAckTimeout () {                return (messageAckTimeout  > this.MINIMUM_MESSAGE_ACK_TIMEOUT) ?            messageAckTimeout : DEFAULT_MESSAGE_ACK_TIMEOUT;    }        public void setMessageAckTimeout (long timeInMilliseconds) {                if (timeInMilliseconds > MINIMUM_MESSAGE_ACK_TIMEOUT) {                        this.messageAckTimeout = timeInMilliseconds;        }    }        /**     *  Message ack thread has timed out and no message ack has been received.     *  End session.     */    protected void localActionMessageGoneUnAcknowledged () {        if (LOG.isEnabledFor (Level.INFO)) {            LOG.info (" localActionMessageGoneUnAcknowledged ");        }                localActionEndSession ();                /** Normally we'd just call sendcommand(END_SESSION) and wait for a         *  end END_SEESION_ACCEPT then go down gracefully. Since we aren't         *  receiving command messages we choose to just exit hard. */                sendCommand (this.COMMAND_VIJXTA_DISCONNECT_REQUEST);                this.setProtocolState (this.SESSION_VIJXTA_DISCONNECTED);    }        /**     *     */    public RemoteMonitorControl getRemoteMonitorControl () {                return this.remoteMonitorControl;    }        /**     *     */    public DeviceMonitorControl getLocalMonitorControl () {                return this.localMonitorControl;    }            /**     *  A templete DialogMessage is already constructed. All we need do is call     *  this method and clone. This will cleanup the code for message production     *  as well offer the possibility of a speedup in message creation.     *     *@return templeted DialogMessage     */    public DialogMessage getNewTemplateMessage () {                return (DialogMessage) this.templateMessage.clone ();    }        public String getOriginator () {                if(this.getRemoteMonitorControl () == null) {            LOG.info ("remoteMonitorCOntrol is null");        }        if(getRemoteMonitorControl ().getOriginator () == null) {            LOG.info ("getOriginator is null");        }                return getRemoteMonitorControl ().getOriginator ();    }        /**     *  Returns the system time in ms this call was started. Only valid after     *  call ha started     */    public long getCallStartTime () {                return callStartTime;    }        /**     *  Returns a formated string of the call start time     */    public String getCallStartTimeString () {                return new Date (callStartTime).toString ();    }        /**     *  Returns the system time is ms this call ended. Is only valid after call     *  has ended.     */    public long getCallEndTime () {                return callEndTime;    }        /**     *  Returns a formated string of hte call end time.     */    public String getCallEndTimeString () {                return ((callEndTime != 0) ? new Date (callEndTime).toString () : "");    }        /**     *  Returns the time elapsed in ms from call start time. Only valid after     *  call has started     */    public long getCallElapsedTime () {                return callElapsedTime = System.currentTimeMillis () - getCallStartTime ();    }        /**     *  Returns formated string of the call elapsed time     */    public String getCallElapseTimeString () {                        return formatElapsedTime (getCallElapsedTime ());    }        /**     *  Returns a string formated to represent hours:minutes:seconds of the time     *  elapsed since call start.     */    protected String formatElapsedTime (long elapsedTime) {                long tmp = elapsedTime;                long hours = tmp / HOUR;                tmp = tmp - (hours * HOUR);                long minutes = tmp / MINUTE;                tmp = tmp - (minutes * MINUTE);                long seconds = tmp / SECOND;                String timeString = null;                if(hours < 10) {            timeString = "0";        }        timeString = String.valueOf (hours) + this.TIME_SEPARATOR;;                if(minutes < 10) {            timeString = timeString + "0";        }        timeString = timeString + String.valueOf (minutes) + this.TIME_SEPARATOR;                if(seconds < 10) {            timeString = timeString + "0";        }        timeString = timeString + String.valueOf (seconds);                return timeString;    }                                /**     *  After a message is sent this thread is instantiated, started and will     *  wait till it's lock is notified of an incoming message or till a timeout     *  is reached. The idea being each commmand message dispatched will return     *  an accept response. If that response is received then +1 if not this thread     *  will notify us and shutdown the session as gracefully as possible. A new     *  Thread is started for each command message sent.     *TODO     *  Better option then creating a new thread for each command. Reuse of a single     *  thread maybe.     */    cl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -