sk.baka.webvm.misc
Class BackgroundService

java.lang.Object
  extended by sk.baka.webvm.misc.BackgroundService
Direct Known Subclasses:
HistorySampler, NotificationDelivery

public abstract class BackgroundService
extends Object

Executes various tasks in background thread.

Author:
Martin Vysny

Field Summary
protected  int maxThreads
          Maximum thread pool size.
protected  String name
          A short name of the service - used in thread names.
 
Constructor Summary
protected BackgroundService(String name, int maxThreads)
          Creates new service instance.
 
Method Summary
protected  ScheduledExecutorService getExecutor()
          Returns the executor.
static ThreadFactory newDaemonFactory(String name)
          Creates a new factory which creates daemon threads using the Executors.defaultThreadFactory().
 void start()
          Starts the sampling process in a background thread.
protected abstract  void started(ScheduledExecutorService executor)
          Invoked when the service is started.
 void stop()
          Disposes of this sampler.
protected abstract  void stopped()
          Invoked after the service has been stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected final String name
A short name of the service - used in thread names.


maxThreads

protected final int maxThreads
Maximum thread pool size.

Constructor Detail

BackgroundService

protected BackgroundService(String name,
                            int maxThreads)
Creates new service instance.

Parameters:
name - A short name of the service - used in thread names.
maxThreads - Maximum thread pool size.
Method Detail

start

public void start()
Starts the sampling process in a background thread.


started

protected abstract void started(ScheduledExecutorService executor)
Invoked when the service is started.

Parameters:
executor - executes tasks.

getExecutor

protected final ScheduledExecutorService getExecutor()
Returns the executor.

Returns:
the executor. null if not started.

stop

public final void stop()
Disposes of this sampler. This instance is no longer usable and cannot be started again.


stopped

protected abstract void stopped()
Invoked after the service has been stopped.


newDaemonFactory

public static ThreadFactory newDaemonFactory(String name)
Creates a new factory which creates daemon threads using the Executors.defaultThreadFactory().

Parameters:
name - create threads marked with this name.
Returns:
a daemon thread factory.


Copyright © 2010 Baka. All Rights Reserved.