Class Daemon

    • Field Detail

      • logmon

        protected Logger logmon
      • running

        protected volatile boolean running
        Boolean variable used to stop the daemon properly. The daemon tests this variable between each request, and stops if it is false.
        See Also:
        start(), stop()
      • canStop

        protected volatile boolean canStop
        Boolean variable used to stop the daemon properly. If this variable is true then the daemon is waiting for a long time and it can be interrupted, else it handles a request and it will exit after (it tests the running variable between each reaction)
      • thread

        protected Thread thread
        The active component of this daemon.
      • name

        private String name
        The daemon's name.
      • daemon

        private boolean daemon
        The daemon's nature.
      • priority

        protected int priority
        The priority that is assigned to the daemon.
      • group

        protected ThreadGroup group
        The group of this thread. Note: The ThreadGroup is just used as information.
    • Constructor Detail

      • Daemon

        protected Daemon​(String name)
        Deprecated.
        Allocates a new Daemon object. Be careful, the use of this constructor is not recommended as it does not dissociate the corresponding logger.
        Parameters:
        name - the name of the new Daemon
      • Daemon

        protected Daemon​(String name,
                         Logger logmon)
        Allocates a new Daemon object.
        Parameters:
        name - the name of the new Daemon
        logmon - inherited logging monitor
    • Method Detail

      • isRunning

        public boolean isRunning()
        Tests if this daemon is alive.
        Returns:
        true if this daemon is alive; false otherwise.
      • getName

        public final String getName()
        Returns this daemon's name.
        Returns:
        this daemon's name.
      • toString

        public String toString()
        Returns a string representation of this daemon.
        Overrides:
        toString in class Object
        Returns:
        A string representation of this daemon.
      • setDaemon

        public void setDaemon​(boolean daemon)
        Marks the daemon's thread as either a daemon thread a user thread. This method must be called before the daemon is started.
        Parameters:
        daemon - if true marks the daemon's thread as either a daemon thread.
        Throws:
        IllegalThreadStateException - if this daemon was already active.
      • setPriority

        public void setPriority​(int newPriority)
        Changes the priority of this daemon. If the daemon is running calls the setPriority method on corresponding thread, else stores value for next start.
        Parameters:
        newPriority - the new priority.
      • setThreadGroup

        public void setThreadGroup​(ThreadGroup group)
        Set the thread group to which this daemon's thread belongs. This method must be called before the daemon is started.
        Parameters:
        group - the thread group.
        Throws:
        IllegalThreadStateException - if this daemon was already active.
      • start

        public void start()
        Causes this daemon to begin execution. A new thread is created to execute the run method.
        Throws:
        IllegalThreadStateException - If the daemon was already started.
      • close

        protected abstract void close()
        Releases any resources attached to this daemon. Be careful, its method should be called more than one time.
      • shutdown

        protected abstract void shutdown()
        Interrupts a thread that waits for long periods. In some cases, we must use application specific tricks. For example, if a thread is waiting on a known socket, we have to close the socket to cause the thread to return immediately. Unfortunately, there really isn't any technique that works in general.
      • interrupt

        public void interrupt()
        Interrupts this daemon.
      • finish

        protected final void finish()
      • stop

        public void stop()
        Forces the daemon to stop executing. This method notifies thread that it should stop running, if the thread is waiting it is first interrupted then the shutdown method is called to close all resources.
      • isCurrentThread

        public boolean isCurrentThread()
        Tests if the daemon's thread is the current one.
        Returns:
        true if the daemon's thread is the current one, false otherwise.
      • setName

        public void setName​(String name)
        Set the name of the daemon's thread.
        Parameters:
        name - the thread name.