Jacson

de.spieleck.app.jacson.source
Class TailSource

java.lang.Object
  extended byde.spieleck.app.jacson.PluginBase
      extended byde.spieleck.app.jacson.source.ChunkSourceBase
          extended byde.spieleck.app.jacson.source.TailSource
All Implemented Interfaces:
JacsonChunkSource, JacsonReporting, JacsonStately

public class TailSource
extends ChunkSourceBase

Implement a JacsonChunkSource which is continuously running and monitoring files for changes.
Note1: This works under the char = byte assumption, i.e. does not treat unicode right!
Note2: This is Java and their might be problems which are so plattform dependand, that there is no Java solutions (e.g. I do not expect this to help with lock rollovers and inodes...)

Author:
fsn

Nested Class Summary
 class TailSource.MetaThread
          The MetaThread enqueues the changing files
protected  class TailSource.WatchedFile
          Encapsulate a file with the ability to check for new bytes and a Runnable to fetch new bytes.
 
Field Summary
protected  java.util.LinkedList chunkQueue
          The queue of Chunks to be returned
protected  int deltaTime
          Delay between inspections of queue
static java.lang.String JACSON_STATE_CHUNK_TYPE
           
protected  java.lang.Thread metaThread
          The thread watching ALL files for change
protected  ThreadPool threads
          A ThreadPool of assignments to read files.
protected  TaskQueue tQueue
          The threads are queued into above pool by the ThreadQueue.
protected  java.util.List watched
          The watched Resources
protected  int workers
          The number of worker Threads
 
Constructor Summary
TailSource()
           
 
Method Summary
 void addWatch(java.lang.String label, java.lang.String fName)
          Add file to be watched.
 void join()
          Wait for finish.
 java.lang.String message()
           
 java.lang.String nextChunk()
          Deliver a sequence of chunks (that is Strings).
 void setDeltaTime(int deltaTime)
          Set the delay between file checks
 void setWorkers(int workers)
          Set the number of workers
 void startWatching()
          Start watching on the files.
 
Methods inherited from class de.spieleck.app.jacson.PluginBase
getRegReport, getRegState, registerReport, registerState, summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.spieleck.app.jacson.JacsonStately
registerState
 
Methods inherited from interface de.spieleck.app.jacson.JacsonReporting
registerReport, summary
 

Field Detail

JACSON_STATE_CHUNK_TYPE

public static final java.lang.String JACSON_STATE_CHUNK_TYPE
See Also:
Constant Field Values

metaThread

protected java.lang.Thread metaThread
The thread watching ALL files for change


threads

protected ThreadPool threads
A ThreadPool of assignments to read files.


tQueue

protected TaskQueue tQueue
The threads are queued into above pool by the ThreadQueue.


deltaTime

protected int deltaTime
Delay between inspections of queue


workers

protected int workers
The number of worker Threads


watched

protected java.util.List watched
The watched Resources


chunkQueue

protected java.util.LinkedList chunkQueue
The queue of Chunks to be returned

Constructor Detail

TailSource

public TailSource()
Method Detail

setWorkers

public void setWorkers(int workers)
Set the number of workers


setDeltaTime

public void setDeltaTime(int deltaTime)
Set the delay between file checks


addWatch

public void addWatch(java.lang.String label,
                     java.lang.String fName)
              throws java.io.IOException
Add file to be watched.

Throws:
java.io.IOException

startWatching

public void startWatching()
Start watching on the files. Calling this more than once will create strange results.


nextChunk

public java.lang.String nextChunk()
                           throws JacsonException
Description copied from interface: JacsonChunkSource
Deliver a sequence of chunks (that is Strings).

Returns:
The next String if available, null if sequence is finished.
Throws:
JacsonException

join

public void join()
Wait for finish. Note this is not a well defined notion, since logfiles may every grow. Therefore this method can exhibt both failes: "never return" or "return prematurely" depending on application. It was good though for the JUnit test.


message

public java.lang.String message()

Spieleck

Copyleft 2002 spieleck.de.