de.nava.informa.utils.cleaner
Class Cleaner

java.lang.Object
  extended by de.nava.informa.utils.cleaner.Cleaner

public class Cleaner
extends Object

Cleaner is an utility class, which is intended to help applications with detection of unwanted (old, corrupted and etc) items.

Cleaner works in background. It accepts unlimited number of observers, objects of CleanerObserverIF type, that are notified each time main engine finds unwanted items. In order to decide which item is unwanted engine uses matchers, objects of CleanerMatcherIF type. Each matcher is a rule. You can create unlimited number of rules to match items and tell that they are unwanted in some way.

Engine accepts individual channels for registration. You can register channel either with global or custom periods. Global period defaults to DEFAULT_CLEANING_PERIOD right after creation and can be changed with call to setPeriod(long) method.

At any time you can ask cleaner to unregister channel. After that it will never be cleaned by engine again and it's promised that all references to the object will be removed.

Cleaner uses WorkersManager to maintain asynchronous processing. This means that there will be several working threads in memory, which will be processing scheduled requests for channel cleaning. At any time you can change number of running worker threads starting from 1. If number of threads you require is less than current number of threads extra threads will be marked for termination and will quit right after finishing their current jobs.

Author:
Aleksey Gureev (spyromus@noizeramp.com)

Constructor Summary
Cleaner()
          Creates cleaner with default number of worker threads.
Cleaner(int workerThreads)
          Creates cleaner with specified number of worker threads.
 
Method Summary
 void addMatcher(CleanerMatcherIF matcher)
          Adds matcher to the list.
 void addObserver(CleanerObserverIF observer)
          Adds observer to the list of interested parties.
 void cleanChannel(ChannelIF channel)
          Performs immediate cleaning of the channel and reworks the schedule starting from current time.
 void registerChannel(ChannelIF channel)
          Registers channel for scheduled cleaning with default period (1 hour).
 void registerChannel(ChannelIF channel, long period)
          Registers channel for scheduled cleaning with given period.
 void removeMatcher(CleanerMatcherIF matcher)
          Removes matcher from the list.
 void removeObserver(CleanerObserverIF observer)
          Removes observer from the list.
 void setPeriod(long period)
          Sets global cleaning period to the specified value.
 void setWorkerThreads(int count)
          Changes the number of worker threads.
 void unregisterChannel(ChannelIF channel)
          Unregisters channel from cleaning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cleaner

public Cleaner()
Creates cleaner with default number of worker threads. It's possible to change number of worker threads later using setWorkerThreads(int) method.


Cleaner

public Cleaner(int workerThreads)
Creates cleaner with specified number of worker threads. It's possible to change number of worker threads later using setWorkerThreads(int) method.

Parameters:
workerThreads - number of worker threads.
Method Detail

addObserver

public final void addObserver(CleanerObserverIF observer)
Adds observer to the list of interested parties.

Parameters:
observer - new observer.

addMatcher

public final void addMatcher(CleanerMatcherIF matcher)
Adds matcher to the list.

Parameters:
matcher - new matcher.

removeObserver

public final void removeObserver(CleanerObserverIF observer)
Removes observer from the list.

Parameters:
observer - observer to remove.

removeMatcher

public final void removeMatcher(CleanerMatcherIF matcher)
Removes matcher from the list.

Parameters:
matcher - matcher to remove.

registerChannel

public final void registerChannel(ChannelIF channel)
Registers channel for scheduled cleaning with default period (1 hour).

Parameters:
channel - channel to schedule.

registerChannel

public final void registerChannel(ChannelIF channel,
                                  long period)
Registers channel for scheduled cleaning with given period.

Parameters:
channel - channel to schedule.
period - period to use.

unregisterChannel

public final void unregisterChannel(ChannelIF channel)
Unregisters channel from cleaning.

Parameters:
channel - channel to unregister.

cleanChannel

public final void cleanChannel(ChannelIF channel)
Performs immediate cleaning of the channel and reworks the schedule starting from current time. If channel isn't registered yet it will be registered with normal priority.

Parameters:
channel - channel to update.

setWorkerThreads

public final void setWorkerThreads(int count)
Changes the number of worker threads. In case when new number of threads is less than current extra threads will not be terminated right away while they are doing their jobs. Instead of this they will be marked for termination and finish their existence after job is complete.

Parameters:
count - new number of worker threads.

setPeriod

public final void setPeriod(long period)
Sets global cleaning period to the specified value. All tasks will be rescheduled.

Parameters:
period - period in millis.


Copyright © 2002-2007 Niko Schmuck. All Rights Reserved.