Logo
Distributed Genetic Programming Framework
print print

File org.sfc.events.EventPropagator.java

Here you can find all the information about the file org.sfc.events.EventPropagator.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2005 Thomas Weise
 *
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2005-07-12 18:07:04
 * Original Filename: org.sfc.events.EventPropagator.java
 * Version          : 3.0.1
 * Last modification: 2006-07-24
 *                by: Thomas Weise
 *
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */


package org.sfc.events;

import java.io.Serializable;

import org.sfc.collections.Arrays;
import org.sfc.io.IO;


/**
 * A <code>EventPropagator</code> is an object able to multiplex events
 * to multiple <code>IEventListener</code>s. Note that the multiplexer is
 * an <code>IEventListener</code> itself.<br/>
 * The listeners subscribed to this propagator are not notified in the
 * order of their subscription.
 *
 * @author Thomas Weise
 */

public  class EventPropagator implements  IEventSource, Serializable,
                                          IEventListener
  {
/**
 * The serial version uid.
 */

  private static  final long  serialVersionUID  = 1;

/**
 * The internal list with the event sinks.
 */

  IEventListener[]  m_sinks     ;
/**
 * The count of listeners stored.
 */

  int               m_count     ;

/**
 * Create a new <code>EventPropagator</code>.
 */

  public EventPropagator()
    {
    super();
    this.m_sinks = new IEventListener[8];
    }

/**
 * Returns <code>true</code> if and only if no event sinks are attached to
 * propagate to.
 * @return  <code>true</code> if and only if no event sinks are attached to
 *          propagate to.
 */

  public  final boolean is_empty  ()
    {
    return (this.m_count <= 0);
    }


/**
 * This method delivers an event to a list of listeners.
 * @param p_event     The event to be delivered.
 */

  public synchronized   void  receive(final SfcEvent p_event)
    {
    int               l_i;
    IEventListener[]  l_l;

    l_l = this.m_sinks;

    for(l_i = (this.m_count-1); l_i >= 0; l_i--)
      {
      l_l[l_i].receive(p_event);
      }
    }

/**
 * Attaches a new event sink to this event multiplexer. The events received
 * by this event multiplexer will be propagated to the sink from
 * now on.
 * @param p_sink  The sink to be attached.
 */

  public synchronized final void add_listener(final IEventListener p_sink)
    {
    IEventListener[]  l_e;
    int               l_c;

    l_e = this.m_sinks;
    l_c = this.m_count;

    l_e      = Arrays.insert_space( l_e, l_c, l_c, 1);
    l_e[l_c] = p_sink;

    this.m_count = (l_c+1);
    this.m_sinks = l_e;
    }

/**
 * Removes a event sink from this event multiplexer. The events
 * received by this event multiplexer will no longer be propagated to the
 * sink from now on.
 * @param p_sink  The sink to be removed.
 */

  public synchronized final void remove_listener(final IEventListener p_sink)
    {
    IEventListener[]  l_e;
    int               l_c, l_i;

    l_e = this.m_sinks;
    l_c = this.m_count;

    for(l_i = (l_c - 1); l_i >= 0; l_i--)
      {
      if(l_e[l_i] == p_sink)
        {
        this.m_sinks = Arrays.delete_fast(l_e, l_c, l_i, 1);
        this.m_count = (l_c-1);
        return;
        }
      }
    }

/**
 * Close all event listeners of this event propagator.
 */

  public  synchronized  final void  close_all_listeners()
    {
    final IEventListener[]  l_e;
          int               l_c;

    l_e = this.m_sinks;
    for(l_c = (this.m_count-1); l_c >= 0; l_c--)
      {
      try
        {
        IO.close(l_e[l_c]);
        }
      catch(Throwable l_t)
        {
        //
        }
      }

    Arrays.fill(l_e, null);
    this.m_count = 0;
    }
  }

File Information:

file name:EventPropagator.java
package:org.sfc.events
qualified name:org.sfc.events.EventPropagator.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/events/EventPropagator.java
size:4.369 KB (4474 B)
uploaded: 2018-01-07 12:03:36 GMT+0000
last update: 2006-07-24 06:11:12 GMT+0000
last access: 2018-04-21 09:46:47 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2018-01-07 12:03:34 GMT+0000 served at 2018-04-21 09:46:47 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo