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

📄 dialog.java

📁 用jxse开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**  Copyright (c) 2001 Sun Microsystems, Inc.  All rights*  reserved.**  Redistribution and use in source and binary forms, with or without*  modification, are permitted provided that the following conditions*  are met:**  1. Redistributions of source code must retain the above copyright*  notice, this list of conditions and the following disclaimer.**  2. Redistributions in binary form must reproduce the above copyright*  notice, this list of conditions and the following discalimer in*  the documentation and/or other materials provided with the*  distribution.**  3. The end-user documentation included with the redistribution,*  if any, must include the following acknowledgment:*  "This product includes software developed by the*  Sun Microsystems, Inc. for Project JXTA."*  Alternately, this acknowledgment may appear in the software itself,*  if and wherever such third-party acknowledgments normally appear.**  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"*  must not be used to endorse or promote products derived from this*  software without prior written permission. For written*  permission, please contact Project JXTA at http://www.jxta.org.**  5. Products derived from this software may not be called "JXTA",*  nor may "JXTA" appear in their name, without prior written*  permission of Sun.**  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR*  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF*  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND*  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT*  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF*  SUCH DAMAGE.*  ====================================================================**  This software consists of voluntary contributions made by many*  individuals on behalf of Project JXTA.  For more*  information on Project JXTA, please see*  <http://www.jxta.org/>.**  This license is based on the BSD license adopted by the Apache Foundation.**  $Id: Dialog.java,v 1.25 2007/06/10 21:15:10 nano Exp $*/package net.jxta.myjxta.dialog;import net.jxta.document.Advertisement;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredTextDocument;import net.jxta.endpoint.Message;import net.jxta.logging.Logging;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.View;import net.jxta.myjxta.dialog.util.Text;import net.jxta.myjxta.misc.beam.BeamDialog;import net.jxta.myjxta.plugin.PluginView;import net.jxta.myjxta.util.Group;import net.jxta.peergroup.PeerGroup;import net.jxta.pipe.PipeService;import net.jxta.protocol.PipeAdvertisement;import java.io.IOException;import java.io.StringWriter;import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;/** * @author james todd [gonzo at jxta dot org] * @author mike mcangus [mcangus at jxta dot org] * @version $Id: Dialog.java,v 1.25 2007/06/10 21:15:10 nano Exp $ * @modified 2005-03-27 jamoore add vojxtaDialog to dialog types * @modified 2005-04-24 jamoore add vijxtaDialog to dialog types */public abstract class Dialog {    /**     * describes the number of retries a dispatch call is given after failure     */    private static final int DEFAULT_DISPATCH_RETRY_METRIC = 5;    private static final int MIN_DISPATCH_RETRY_METRIC = 1;    private static final int MAX_DISPATCH_RETRY_METRIC = 100;    private int dispatchRetryMetric = DEFAULT_DISPATCH_RETRY_METRIC;    protected FilterChain inbound = null;    protected FilterChain outbound = null;    /**     * The list of registered DialogListener objects     */    private List<DialogListener> listeners = null;    /**     * The DialogMesage used as the template for all DialogMessage object     * originated by this Dialog object     */    protected DialogMessage dialogMessage = null;    /**     * Are we currently connected to a pipe and can send messages     */    private boolean isConnected = false;//true if the GUI-Panel was already closed    protected boolean m_closed = false;    /**     * The tag prefix for all myxta2 Message tags     */    public static final String IMFREE = "Jxta:IMFree";    /**     * The Message tag that denotes the PeerGroup ID of the originator     * of a DialogMessage object     */    public static final String IMFREE_GROUP_ID = Dialog.IMFREE + "GroupId";    /**     * The Message tag that denotes the PeerGroup name of the originator     * of a DialogMessage object     */    public static final String IMFREE_GROUP_NAME = Dialog.IMFREE + "GrpName";    /**     * The Message tag that denotes the name of the originator     * of a DialogMessage object     */    public static final String IMFREE_ORIGINATOR_NAME = Dialog.IMFREE + "SenderName";    /**     * The Message tag that denotes the actual message part     * of a DialogMessage object     */    public static final String IMFREE_MESSAGE = Dialog.IMFREE + "Message";    /**     * The Message tag that denotes the legacy message part     * of a DialogMessage object     */    public static final String IMFREE_LEGACY_MESSAGE = Dialog.IMFREE + "SenderMessage";    /**     * The  String that is prefixed to the peer name to indicate a     * PipeAdvertisment specific to myjxta     */    public static final String IMFREE_USER_NAME = Dialog.IMFREE + "UserName";    /**     * The delimiter that indictates the end of a prefix specific to     * myjxta     */    public static final String IMFREE_DELIMITER = ".";    /**     * The Message tag that denotes the command part     * of a DialogMessage object     */    public static final String IMFREE_COMMAND = Dialog.IMFREE + "Command";    public static String DIALOG_NAME = Dialog.IMFREE_USER_NAME;    protected Group group = null;    protected PipeAdvertisement pipeAdvertisement = null;    protected MyJXTA myjxta = null;    protected static final Logger LOG = Logger.getLogger(Dialog.class.getName());    public static final String GOODBYE_CMD = "GOODBYE";    private static final HashMap<String, DialogNamer> dialogNamers = new HashMap<String, DialogNamer>();    public Dialog(MyJXTA myjxta, PipeAdvertisement pa, Group group) {        this.myjxta = myjxta;        pipeAdvertisement = pa;        this.group = group;        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin Dialog(Group, PipeAdvertisement, MyJXTA) Constructor");        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   Dialog(Group, PipeAdvertisement, MyJXTA) Constructor");        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin AbstractDialog(Group, MyJXTA) Constructor");        }        PeerGroup pg = getGroup().getPeerGroup();        // initialize the template DialogMessage object        this.dialogMessage = new DialogMessage(pg.getPeerName(), null,                pg.getPeerGroupID().toString(), pg.getPeerGroupName());        this.inbound = new FilterChain();        this.outbound = new FilterChain();        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   AbstractDialog(Group, MyJXTA) Constructor");        }    }    /**     * Returns the current peer group name.     *     * @return The current peer group name.     */    public String getName() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getName()");        }        return getGroup().getPeerGroup().getPeerGroupName();    }    /**     * Returns the current <code>FilterChain</code> that process all inbound <code>DialogMessage</code>s.     *     * @return The current <code>FilterChain</code> that process all inbound <code>DialogMessage</code>s.     */    public FilterChain getInboundFilters() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getInboundFilters()");        }        return this.inbound;    }    /**     * Adds a <code>DialogFilter</code> to the current <code>FilterChain</code> that process all inbound     * <code>DialogMessage</code>s.     *     * @param filter The filter to be added to the current chain.     */    public void addInboundFilter(DialogFilter filter) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In addInboundFilter(DialogFilter)");        }        this.inbound.addFilter(filter);    }    /**     * Removes a <code>DialogFilter</code> from the current <code>FilterChain</code> that process all inbound     * <code>DialogMessage</code>s.     *     * @param filterClass The <code>Class</code> of the filter to remove from the current chain.     */    public void removeInboundFilter(Class filterClass) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In removeInboundFilter(Class)");        }        this.inbound.removeFilter(filterClass);    }    /**     * Returns the current <code>FilterChain</code> that process all outbound <code>DialogMessage</code>s.     *     * @return The current <code>FilterChain</code> that process all outbound <code>DialogMessage</code>s.     */    public FilterChain getOutboundFilters() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getOutboundFilters()");        }        return this.outbound;    }    /**     * Adds a <code>DialogFilter</code> to the current <code>FilterChain</code> that process all outbound     * <code>DialogMessage</code>s.     *     * @param filter The filter to be added to the current chain.     */    public void addOutboundFilter(DialogFilter filter) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In addOutboundFilter(DialogFilter)");        }        this.outbound.addFilter(filter);    }    /**     * Removes a <code>DialogFilter</code> from the current <code>FilterChain</code> that process all outbound     * <code>DialogMessage</code>s.     *     * @param filterClass The <code>Class</code> of the filter to remove from the current chain.     */    public void removeOutboundFilter(Class filterClass) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In removeOutboundFilter(Class)");        }        this.outbound.removeFilter(filterClass);    }    /**     * Returns the current <code>List</code> of {@link net.jxta.myjxta.dialog.DialogListener}s that process all inbound and outbound     * <code>DialogMessage</code>s.     *     * @return The current list of listeners.     */    public List getListeners() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getListeners()");        }        return this.listeners != null ?                this.listeners : Collections.EMPTY_LIST;    }    /**     * Add a new <code>DialogListener</code> object to the {@link java.util.List} of listeners being maintained for this session.     *     * @param listener the new DialogListener object to add     */    public void addListener(DialogListener listener) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin addListener(DialogListener)");            LOG.fine("listener.getClass() = " + listener.getClass());        }        if (listener != null) {            // create the listeners array if necessary            if (this.listeners == null) {                this.listeners = new ArrayList<DialogListener>();            }            // add the listener            synchronized (listeners) {                this.listeners.add(listener);            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   addListener(DialogListener)");        }    }    /**     * Remove a previously registered {@link net.jxta.myjxta.dialog.DialogListener} object from the current <code>List</code>     * being maintained for this session.     *     * @param l the DialogListener object to remove     */    public void removeListener(DialogListener l) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin removeListener(DialogListener)");            LOG.fine("listener.getClass() = " + l.getClass());        }        if (this.listeners != null) {            synchronized (listeners) {                this.listeners.remove(l);                // if there are no more registered listeners                // allow the listeners array to be garbage collected                if (this.listeners.size() == 0) {                    this.listeners = null;                }            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   removeListener(DialogListener)");        }    }    /**     * Remove a <code>List</code> of {@link net.jxta.myjxta.dialog.DialogListener} objects to the current <code>List</code>     * being maintained for this session.     *     * @param listeners the List of DialogListener objects to remove     */    public void removeListeners(List listeners) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin removeListeners(List)");        }        this.listeners.removeAll(listeners);        // if there are no more registered listeners        // allow the listeners array to be garbage collected        if (this.listeners.size() == 0) {            this.listeners = null;        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   removeListeners(List)");        }    }    public void clear() {        clearListeners();        clearCache();    }    /**     * Remove all {@link net.jxta.myjxta.dialog.DialogListener} objects from the {@link java.util.List} being maintained for this session.     */    public void clearListeners() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin clearListeners()");        }        if (this.listeners != null) {            this.listeners.clear();            this.listeners = null;        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("End   clearListeners()");        }    }    public void clearCache() {        Cache.getCache(getGroup()).clear();    }    /**     * Dispatch a Message object to the intended receivers     *     * @param msg the Message object to send across an open pipe     * @return true if the message was successfully dispatched, and false otherwise.     */    public abstract boolean dispatch(Message msg);    /**     * { @inheritDoc }     */    public void close() {        m_closed = true;    }

⌨️ 快捷键说明

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