traceable.java

来自「The Java Network Simulator is a Java imp」· Java 代码 · 共 59 行

JAVA
59
字号
package jns.trace;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;


public abstract class Traceable
{

    /**
     List of Trace objects that are listening to us.
     */
    Vector m_traces = null;

    public Traceable()
    {
        m_traces = new Vector();
    }

    public void attach(Trace trace)
    {
        m_traces.addElement(trace);
    }

    public void detach(Trace trace)
    {
    }


    /**
     Used by subclasses to send events to a Trace object. This gets rid of
     lots of if/else code by making the decision if anyone is listening
     in here.
     */
    protected void sendEvent(Event event)
    {
        Enumeration e = m_traces.elements();
        while(e.hasMoreElements())
        {
            Trace trace = (Trace) e.nextElement();

            try
            {
                trace.handleEvent(event);
            }
            catch(IOException xept)
            {
                System.out.println("ERROR: An I/O exception occured while writing" +
                                   " an event!");
            }
        }


    }


}

⌨️ 快捷键说明

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