edu.mit.jverbnet.util
Class AbstractHasLifecycle

java.lang.Object
  extended by edu.mit.jverbnet.util.AbstractHasLifecycle
All Implemented Interfaces:
IHasLifecycle
Direct Known Subclasses:
VerbIndex

public abstract class AbstractHasLifecycle
extends java.lang.Object
implements IHasLifecycle

Abstract implementation of an object that has a lifecycle. This class's methods are thread safe. Subclasses should put their actual lifecycle code in the doOpen(), doIsOpen(), and doClose() methods. Synchronization happens in the abstract class, so subclasses do not need to worry about that.

Since:
JVerbnet 1.0.0
Version:
1.2.0
Author:
Mark A. Finlayson

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.mit.jverbnet.util.IHasLifecycle
IHasLifecycle.ObjectClosedException
 
Constructor Summary
AbstractHasLifecycle()
           
 
Method Summary
protected  void checkOpen()
          Throws an exception if the object is closed
 void close()
          This closes the object by disposing of data backing objects or connections.
protected abstract  void doClose()
          Subclasses should put tear-down, closing code in this method.
protected abstract  boolean doIsOpen()
          Subclasses should put code that determines whether the object is open in here.
protected abstract  boolean doOpen()
          Subclasses should put initialization code in this method.
 boolean isOpen()
          Returns true if the object is open, that is, ready to be used; returns false otherwise
 boolean open()
          This opens the object by performing any required initialization steps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHasLifecycle

public AbstractHasLifecycle()
Method Detail

checkOpen

protected final void checkOpen()
Throws an exception if the object is closed

Since:
JVerbnet 1.0.0

open

public final boolean open()
                   throws java.io.IOException
Description copied from interface: IHasLifecycle
This opens the object by performing any required initialization steps. If this method returns false, then subsequent calls to IHasLifecycle.isOpen() will return false.

Specified by:
open in interface IHasLifecycle
Returns:
true if there were no errors in initialization; false otherwise.
Throws:
java.io.IOException - if there was IO error while performing initialization

isOpen

public final boolean isOpen()
Description copied from interface: IHasLifecycle
Returns true if the object is open, that is, ready to be used; returns false otherwise

Specified by:
isOpen in interface IHasLifecycle
Returns:
true if the object is open; false otherwise

close

public final void close()
Description copied from interface: IHasLifecycle
This closes the object by disposing of data backing objects or connections. If the object is already closed, or in the process of closing, this method does nothing (although, if the object is in the process of closing, it may block until closing is complete).

Specified by:
close in interface IHasLifecycle

doOpen

protected abstract boolean doOpen()
                           throws java.io.IOException
Subclasses should put initialization code in this method. If initialization fails, the method should not attempt to cleanup; it should just return false or throw an exception. The abstract lifecycle object takes care of calling the doClose() method if initialization fails.

Returns:
true if initialization succeeds; false otherwise
Throws:
java.io.IOException - if there is an IO error while initializing
Since:
JVerbnet 1.0.0

doIsOpen

protected abstract boolean doIsOpen()
Subclasses should put code that determines whether the object is open in here. Returns true if the object is open; false otherwise.

Returns:
true if the object is open; false otherwise.
Since:
JVerbnet 1.0.0

doClose

protected abstract void doClose()
Subclasses should put tear-down, closing code in this method. This method should be able to clean up after a failed attempt to open() the object.

Since:
JVerbnet 1.0.0


Copyright © 2012 ${project.organization.name}. All Rights Reserved.