Class OutputWorker

java.lang.Object
java.lang.Thread
de.calamanari.pk.observer.OutputWorker
All Implemented Interfaces:
OutputObservable, java.lang.Runnable

public class OutputWorker
extends java.lang.Thread
implements OutputObservable
Output Worker is a concrete observable in this OBSERVER example.
Author:
Karl Eilebrecht
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields inherited from class java.lang.Thread

    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
  • Constructor Summary

    Constructors
    Constructor Description
    OutputWorker​(int workerNumber, long bytesToWrite)
    Creates new worker with the given "work" to do.
  • Method Summary

    Modifier and Type Method Description
    void addOutputObserver​(OutputObserver outputObserver)
    This implementation supports exactly one observer, calling this method twice replaces an oberserver registered before.
    int getWorkerNumber()
    Returns the number (id) of this worker
    void removeOutputObserver​(OutputObserver outputObserver)
    This de-registers the observer from the observable.
    A call with an instance that was not observing (not in list) behaves like a no-op.
    void run()  

    Methods inherited from class java.lang.Thread

    activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • OutputWorker

      public OutputWorker​(int workerNumber, long bytesToWrite)
      Creates new worker with the given "work" to do.
      Parameters:
      workerNumber - identifier of the worker
      bytesToWrite - number of bytes to be written by the worker
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable
      Overrides:
      run in class java.lang.Thread
    • getWorkerNumber

      public int getWorkerNumber()
      Returns the number (id) of this worker
      Returns:
      workerNumber
    • addOutputObserver

      public void addOutputObserver​(OutputObserver outputObserver)
      This implementation supports exactly one observer, calling this method twice replaces an oberserver registered before.
      Specified by:
      addOutputObserver in interface OutputObservable
      Parameters:
      outputObserver - the instance that wants to listen
    • removeOutputObserver

      public void removeOutputObserver​(OutputObserver outputObserver)
      Description copied from interface: OutputObservable
      This de-registers the observer from the observable.
      A call with an instance that was not observing (not in list) behaves like a no-op.
      Specified by:
      removeOutputObserver in interface OutputObservable
      Parameters:
      outputObserver - instance which shall no longer be informed about events.