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

📄 abstractdialog.java

📁 jxta官方例程
💻 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 ackndiowledgment:*  "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: AbstractDialog.java,v 1.14 2006/10/03 18:27:33 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.myjxta.MyJXTA;import net.jxta.myjxta.View;import net.jxta.myjxta.dialog.util.Text;import net.jxta.myjxta.plugin.PluginPanel;import net.jxta.myjxta.util.Group;import net.jxta.peergroup.PeerGroup;import net.jxta.protocol.PipeAdvertisement;import org.apache.log4j.Level;import org.apache.log4j.Logger;import java.io.IOException;import java.io.StringWriter;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;/** * Implements common dialog functionality. * * @author james todd [gonzo at jxta dot org] * @author mike mcangus [mcangus at jxta dot org] * @version $Id: AbstractDialog.java,v 1.14 2006/10/03 18:27:33 nano Exp $ * @modified 2005-04-02 jamoore add retry metric to dispatch, avoids pegg'd cpu * on a null pipe. issue#249 */public abstract class AbstractDialog        extends Dialog {    private static final Logger LOG = Logger.getLogger(AbstractDialog.class);    /**     * 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;    private FilterChain inbound = null;    private 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     */    private 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;    /**     * Create a new Dialog object for the indicated Group.     *     * @param group  the Group for this Dialog object     * @param pa     TODO document what this PipeAdvertisement is.     * @param myjxta the MyJXTA instance to use     */    public AbstractDialog(Group group, PipeAdvertisement pa, MyJXTA myjxta) {        super(group, pa, myjxta);        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   AbstractDialog(Group, MyJXTA) Constructor");        }    }    /**     * Returns the current peer group name.     *     * @return The current peer group name.     */    public String getName() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In removeOutboundFilter(Class)");        }        this.outbound.removeFilter(filterClass);    }    /**     * Returns the current <code>List</code> of {@link DialogListener}s that process all inbound and outbound     * <code>DialogMessage</code>s.     *     * @return The current list of listeners.     */    public List getListeners() {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("In getListeners()");        }        return this.listeners != null ?                this.listeners : Collections.EMPTY_LIST;    }    /**     * Add a new <code>DialogListener</code> object to the {@link List} of listeners being maintained for this session.     *     * @param listener the new DialogListener object to add     */    public void addListener(DialogListener listener) {        if (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Begin addListener(DialogListener)");            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   addListener(DialogListener)");        }    }    /**     * Remove a previously registered {@link 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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("Begin removeListener(DialogListener)");            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   removeListener(DialogListener)");        }    }    /**     * Remove a <code>List</code> of {@link 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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("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 (LOG.isEnabledFor(Level.DEBUG)) {            LOG.debug("End   removeListeners(List)");        }    }

⌨️ 快捷键说明

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