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

📄 dialog.java

📁 用jxse开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public abstract PluginView getDialogPanel(View p_myJXTAView);//quick hack --> this DialogClass is "hot" (not a template)    public void activate() {    }    /**     * @return The number of retrys the dialog will attempt when dispatching on     *         it's pipe.     */    public int getDispatchRetryMetric() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getDispatchRetryMetric()");        }        return dispatchRetryMetric;    }    /**     * Sets the number of retrys attempted to dispatch on the current pipe.     * Normally the only reason a dispatch would return false is due to a     * null time. Usually after a timeout on connection or remote peer has     * gone down. We need a way of notifying the local peer of such a case.     * As is, dispatch simply will not send a message after a number of retrys.     * This megates the purpose of reliable pipes. Notification of servere errors     * to child classes would be enough...     *     * @param dispatchRetryMetric TODO describe this param     */    public void setDispatchRetryMetric(int dispatchRetryMetric) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin setDispatchRetryMetric(int)");        }        if (dispatchRetryMetric < MIN_DISPATCH_RETRY_METRIC) {            this.dispatchRetryMetric = MIN_DISPATCH_RETRY_METRIC;        } else if (dispatchRetryMetric > MAX_DISPATCH_RETRY_METRIC) {            this.dispatchRetryMetric = MAX_DISPATCH_RETRY_METRIC;        } else {            this.dispatchRetryMetric = dispatchRetryMetric;        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   setDispatchRetryMetric(int)");        }    }    /**     * Send the indicated message to the intended receivers     *     * @param htmlMessage the message to send     */    public boolean dispatch(String htmlMessage) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin dispatch(String)");        }        DialogMessage dm = (DialogMessage) this.dialogMessage.clone();        dm.setHtmlMessage(htmlMessage);        boolean result=dispatch(dm);        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   dispatch(String)");        }        return result;    }    /**     * Send a DialogMessage object to its intended receivers.     * DialogMessage object with an empty message will not be send     *     * @param msg the DialogMessage object to send     */    public boolean dispatch(DialogMessage msg) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin dispatch(DialogMessage)");            LOG.fine("msg = " + msg);        }        if (msg != null) {            DialogMessageWrapper w = new DialogMessageWrapper(this, msg);            DialogFilter df;            for (Iterator f = this.outbound != null ?                    this.outbound.getFilters().iterator() :                    Collections.EMPTY_LIST.iterator();                 f.hasNext();) {                df = (DialogFilter) f.next();                try {                    w = (DialogMessageWrapper) df.filter(w);                } catch (Exception e) {                    e.printStackTrace();                }            }            if (w != null &&                    w.isValid()) {                Message m = w.toMessage(this.dialogMessage);                /** this avoids an infinite loop on dispatch if the pipe is null */            boolean isDispatched=false;                int i=0;                int maxRetry=getDispatchRetryMetric();                do {                    i++;                    if (dispatch(m)) {                        isDispatched=true;                        break;                    } else {                        try {                            Thread.sleep(200);                        } catch (InterruptedException e) {                            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.                        }                    }                } while (i<maxRetry);                // do any task necessary to do after the message was send                postDispatch(m);                if (!isDispatched){                    LOG.severe("unable to send message: "+this.getName());                }                return isDispatched;            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   dispatch(DialogMessage)");        }        return false;    }    /**     * Called if a new DialogMessage object was received.     * This method informs all registered DialogListener objects     * that a new DialogMessage object was received.     *     * @param msg the DialogMessage object that was received     */    public void receive(DialogMessage msg) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin receive(DialogMessage)");            LOG.fine("msg = " + msg);        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            String msgText = Text.deleteBlankLines(Text.replace(msg.getHtmlMessage(), Text.MARKUP, Text.EMPTY));            if (msgText == null || msgText.trim().length() > 0) {                LOG.info(msg.getOriginator() + ": " + msgText);            }        }        if (msg != null) {            DialogMessageWrapper w = new DialogMessageWrapper(this, msg);            DialogFilter df;            // Apply each inbound filter to the message.            for (Iterator f = this.inbound != null ?                    this.inbound.getFilters().iterator() :                    Collections.EMPTY_LIST.iterator();                 f.hasNext();) {                df = (DialogFilter) f.next();                w = (DialogMessageWrapper) df.filter(w);            }            // Apply each Listener to the message.            // xxx: consider threading each invocation            if (w != null && w.isValid() && this.listeners != null) {                synchronized (listeners) {                    for (DialogListener listener : this.listeners) {                        try {                            listener.receive(w);                        } catch (Exception e) {                            e.printStackTrace();                        }                    }                }            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   receive(DialogMessage)");        }    }    /**     * Return whether this  Dialog object is connected to a pipe     *     * @return true if we are connected to a pipe, false otherwise     */    public boolean isConnected() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In isConnected()");        }        return this.isConnected;    }    /**     * Get the DialogMessage object that is used as a template     * for all DialogMessage objects send via this Dialog object     *     * @return the DialogMessage object that is used as a template     */    public DialogMessage getDialogMessage() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getDialogMessage()");        }        return this.dialogMessage;    }    /**     * Perform any task  that need to be performed after the     * Message object was send     *     * @param msg the Message object that was send     */    protected abstract void postDispatch(Message msg);    /**     * Perform any tasks that need to be performed before all     * registered DialogListeners are informed that a new DialogMessage     * object was received     *     * @param dm the DialogMessage object that was received     * @return the changed DialogMessage image is any     */    protected abstract DialogMessage preReceive(DialogMessage dm);    /**     * Change the connection status of this Dialog object     *     * @param isConnected to new connection status     */    protected void setIsConnected(boolean isConnected) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In isConnected(boolean)");        }        this.isConnected = isConnected;    }    /**     * Called if a new Message object was received.     * The Message object is first converted to a DialogMessage     * object. Then we call {@link #preReceive(net.jxta.myjxta.dialog.DialogMessage) preReceive}     * to perform any necessary pre-processing. After that all registered     * DialogListener objects are informed that a new message was received     *     * @param msg the newly received Message object     */    protected void receive(Message msg) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin receive(Message)");            LOG.fine("msg = " + msg);        }        DialogMessage dm = new DialogMessage(msg, this.dialogMessage.getKeys());        receive(preReceive(dm));        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   receive(Message)");        }    }    /**     * Get a string representation of the indicated Advertisment object     *     * @param adv the Advertisment object for which to build the     *            string representation     * @return a string representation of the indicated Advertisment object     */    protected String advertisementToString(Advertisement adv) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin advertisementToString(Advertisement)");        }        StringWriter sw = new StringWriter();        try {            StructuredTextDocument d =                    (StructuredTextDocument) adv.getDocument(MimeMediaType.XMLUTF8);            d.sendToWriter(sw);        } catch (IOException ioe) {            if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                LOG.log(Level.SEVERE, "Caught unexpected Exception", ioe);            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   advertisementToString(Advertisement)");        }        return (sw.toString());    }    /**     * Set the template from which all DialogMessage objects     * created by this Dialog object are build     *     * @param dm the new template     */    protected void setDialogMessage(DialogMessage dm) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In setDialogMessage(DialogMessage)");        }        this.dialogMessage = dm;    }    public static String getDialogName() {        return null;    }    /**     * Normalize the name under which to search for a PipeAdvertisement     * for which to search for  if establishing a group chat     *     * @param c the Class to which to add the chat specific parameters to mark the     *          PipeAdvertisment we are looking for as belonging to myjxta     * @return the full name of the PipeAdvertisment label     * @modified 2005-04-24 jamoore added vijxta dialog support     */    // xxx: hackary    public static DialogNamer getDialogNamer(Class c) {        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("Begin getDialogNamer(Class)");        }        DialogNamer dn = null;        if (c == OneToOneCommandDialog.class) {            dn = new DialogNamer() {                public String getDialogName(String s) {                    return OneToOneCommandDialog.DIALOG_NAME +                            IMFREE_DELIMITER + s;                }            };        } else if (c == BeamDialog.class) {            dn = new DialogNamer() {                public String getDialogName(String s) {                    return BeamDialog.DIALOG_NAME +                            IMFREE_DELIMITER + s;                }            };        } else {            DialogNamer dialogNamer = dialogNamers.get(c.getName());            if (dialogNamer != null) {                return dialogNamer;            }        }        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("End   getDialogNamer(Class)");        }        return dn;    }    public Group getGroup() {        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("In getGroup()");        }        return this.group;    }    public PipeAdvertisement getPipeAdvertisement() {        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("In getPipeAdvertisement()");        }        return this.pipeAdvertisement;    }    public MyJXTA getMyJXTA() {        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("In getMyJXTA()");        }        return this.myjxta;    }    public boolean isSecure() {        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("In isSecure()");        }        return getPipeAdvertisement().getType().equals(PipeService.UnicastSecureType);    }    public boolean equals(Object o) {        if (o == null) {            return false;        }        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("Begin equals(Object)");        }        PipeAdvertisement pa = Dialog.class.isAssignableFrom(o.getClass()) ?                ((Dialog) o).getPipeAdvertisement() : null;        if (Logging.SHOW_FINE && Dialog.LOG.isLoggable(Level.FINE)) {            Dialog.LOG.fine("End   equals(Object)");            Dialog.LOG.fine("returning " +                    (pa != null &&                            pa.getID().equals(getPipeAdvertisement().getID()) &&                            pa.getType().equals(getPipeAdvertisement().getType())));        }        return pa != null &&                pa.getID().equals(getPipeAdvertisement().getID()) &&                pa.getType().equals(getPipeAdvertisement().getType());    }    public int hashCode() {        return (pipeAdvertisement != null ? pipeAdvertisement.hashCode() : 0);    }    public static void registerDialogNamer(Class dialogClass, DialogNamer namer) {        dialogNamers.put(dialogClass.getName(), namer);    }    public static void removeDialogNamer(Class dialogClass) {        dialogNamers.remove(dialogClass.getName());    }}

⌨️ 快捷键说明

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