de.nava.informa.utils
Class PersistChanGrpMgr

java.lang.Object
  extended by de.nava.informa.utils.PersistChanGrpMgr

public class PersistChanGrpMgr
extends Object

PersistChanGrpMgr - Controls and Manages a single Hibernate based Informa ChannelGroup. Provides for threaded Updating of the Channel Group, persistence management, session management etc. N O T T H R E A D S A F E


Field Summary
(package private)  int acceptNrErrors
           
(package private)  int taskPeriod
           
(package private)  int taskStartDelay
           
 
Constructor Summary
PersistChanGrpMgr(SessionHandler handler, boolean debug)
          Constructor.
 
Method Summary
 void activate()
          activate - -
 Channel addChannel(String url)
          Add a channel to this Persisten Channel Group.
 Iterator channelIterator()
          Create an iterator to iterate across all the channels in this group.
 ChannelGroup createGroup(String name)
          Called to create a Group.
 void deActivate()
          Interrupts the update task and return immediately.
 void deActivate(boolean waitForFinish)
          Interrupts the update task and return immediately.
 boolean deleteChannel(Channel channel)
          Delete specified channel from this PersistChanGrpMgr.
 void deleteGroup()
          Deletes persistent group.
 int deleteItemFromChannel(Channel channel, Item item)
          Delete specified item from specified Channel
 int getAcceptNrErrors()
           
 ChannelBuilder getBuilder()
          Get currently associated ChannelBuilder
 ChannelGroup getChannelGroup()
          Get currently assocaited ChannelGrouo
 SessionHandler getHandler()
          Get currently assocaited SessionHandler
 int getItemCount(Channel channel)
          Return number of Items currently in specified Channel
 int getPollingCounter()
          Return how many times the task has polled the feed since this PersistChanGrp was built
 boolean hasChannel(Channel achannel)
          Check if this PersistChanGrp has specified CHannel as a member already
 void incrPollingCounter()
          Bump up polling counter by one.
 boolean isActivated()
          Simply return whether we are currently activated (that is, running the tasks that download and process RSS.
 void moveChannelTo(Channel channel, PersistChanGrpMgr destGrp)
          Move a Channel from this PersistentChannelGroup to a different one
 void notifyChannelRetrieved(Channel chan)
          Send notification that specified channel was retrieved.
 void notifyChannels()
          Send notifications about all Channels in this group (but not their items) -
 void notifyChannelsAndItems()
          notifyChannelsAndItems - Call notifyChannelAndItems(channels) across all channels in this PersistentChanGrpMgr.
 void notifyChannelsAndItems(Channel channel)
          notifyChannelsAndItems - Notify both item and channel listeners for a channel and all its items.
 void notifyItemAdded(Item newItem)
          Send notification that specified item was retrieved.
 void notifyItems(Channel channelHandle)
          Send notifications for all the items of this channel that they have been added.
 void notifyPolling(boolean isPolling)
          Notify that the PersistChanGrpMgrTask is currently in the middle of its 'run()' method.
 void setGlobalObserver(PersistChanGrpMgrObserverIF obser)
          Setup the one and only Global observer.
 void setParams(int startDel, int period, int acceptErr)
          Change parameters of how this PersistChanGrpMgr works.
 String toString()
          Return nicely formatted string for this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

taskStartDelay

int taskStartDelay

taskPeriod

int taskPeriod

acceptNrErrors

int acceptNrErrors
Constructor Detail

PersistChanGrpMgr

public PersistChanGrpMgr(SessionHandler handler,
                         boolean debug)
Constructor.

Parameters:
handler - - SessionHandler to use. This needs to have been built by caller.
debug - - - true will run this in debug mode, which basically means that threads are run with no delays thereby revealing threading bugs.
Method Detail

createGroup

public ChannelGroup createGroup(String name)
Called to create a Group.

Parameters:
name - - Text name of the group
Returns:
- Channel Group being managed by this PersistChanGrpMgr

deleteGroup

public void deleteGroup()
Deletes persistent group.


hasChannel

public boolean hasChannel(Channel achannel)
Check if this PersistChanGrp has specified CHannel as a member already

Parameters:
achannel - - candidate channel to check
Returns:
TRUE = yes

addChannel

public Channel addChannel(String url)
Add a channel to this Persisten Channel Group. If Channel already exists then just add it, if it doesn't then create it and add it.

Parameters:
url - the url of the rss feed
Returns:
Channel so created or located

moveChannelTo

public void moveChannelTo(Channel channel,
                          PersistChanGrpMgr destGrp)
Move a Channel from this PersistentChannelGroup to a different one

Parameters:
channel - channel in this PersistentChannelGroup that is being moved.
destGrp - destination where the Channel is going to

deleteChannel

public boolean deleteChannel(Channel channel)
Delete specified channel from this PersistChanGrpMgr. Status indicates whether Channel was previously part of this group.

Parameters:
channel - - Channel being removed from the Group.
Returns:
true if channel was deleted, false if channel was not a member to begin with

deleteItemFromChannel

public int deleteItemFromChannel(Channel channel,
                                 Item item)
Delete specified item from specified Channel

Parameters:
channel - - Channel to delete from
item - - Item to delete from that channel
Returns:
number of items left in the channel AFTER the deletion.

getItemCount

public int getItemCount(Channel channel)
Return number of Items currently in specified Channel

Parameters:
channel - Channel to query
Returns:
number of Items

notifyChannelsAndItems

public void notifyChannelsAndItems(Channel channel)
notifyChannelsAndItems - Notify both item and channel listeners for a channel and all its items. This is useful if the client wants to treat a Channel that was recently read in by hibernate in a consistent way with listeners.

Parameters:
channel - - Relevant channel.

notifyItems

public void notifyItems(Channel channelHandle)
Send notifications for all the items of this channel that they have been added.

Parameters:
channelHandle - -

notifyChannelsAndItems

public void notifyChannelsAndItems()
notifyChannelsAndItems - Call notifyChannelAndItems(channels) across all channels in this PersistentChanGrpMgr.


notifyChannels

public void notifyChannels()
Send notifications about all Channels in this group (but not their items) -


notifyChannelRetrieved

public void notifyChannelRetrieved(Channel chan)
Send notification that specified channel was retrieved.

Parameters:
chan - -

notifyItemAdded

public void notifyItemAdded(Item newItem)
Send notification that specified item was retrieved.

Parameters:
newItem - -

notifyPolling

public void notifyPolling(boolean isPolling)
Notify that the PersistChanGrpMgrTask is currently in the middle of its 'run()' method.

Parameters:
isPolling - true - start polling, false- end

setGlobalObserver

public void setGlobalObserver(PersistChanGrpMgrObserverIF obser)
Setup the one and only Global observer. Note this is not an observer chain, but just a single one.

Parameters:
obser - Observer to register

activate

public void activate()
activate - -


isActivated

public boolean isActivated()
Simply return whether we are currently activated (that is, running the tasks that download and process RSS. Will also return true if the PersistChanGrpMgrTask is still in the middle of finishing.

Returns:
true = activated

incrPollingCounter

public void incrPollingCounter()
Bump up polling counter by one.


getPollingCounter

public int getPollingCounter()
Return how many times the task has polled the feed since this PersistChanGrp was built

Returns:
polling count so far

deActivate

public void deActivate()
Interrupts the update task and return immediately. Do not waits for task to stop.


deActivate

public void deActivate(boolean waitForFinish)
Interrupts the update task and return immediately. Waits for task to finish if waitForFinish argument set.

Parameters:
waitForFinish - TRUE to wait until task actually finishes.

setParams

public void setParams(int startDel,
                      int period,
                      int acceptErr)
Change parameters of how this PersistChanGrpMgr works. Only allowed when this PersistChanGrp is inactive.

Parameters:
startDel - ms before starting (-1 means don't change.)
period - ms between iterations (-1 means don't change.)
acceptErr - number of errors before putting a channel offline (-1 means don't change)

channelIterator

public Iterator channelIterator()
Create an iterator to iterate across all the channels in this group.

Returns:
the iterator

getBuilder

public ChannelBuilder getBuilder()
Get currently associated ChannelBuilder

Returns:
the current cb

getChannelGroup

public ChannelGroup getChannelGroup()
Get currently assocaited ChannelGrouo

Returns:
the cg

getHandler

public SessionHandler getHandler()
Get currently assocaited SessionHandler

Returns:
the sh

getAcceptNrErrors

public int getAcceptNrErrors()
Returns:
acceptable number of errors

toString

public String toString()
Return nicely formatted string for this object

Overrides:
toString in class Object
Returns:
- the string


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