|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectconsciouscode.seedling.tree.GenericNode
consciouscode.seedling.tree.GenericBranch
public class GenericBranch
Provides a basic implementation of BranchNode
, suitable for
extension.
This class cannot provision new nodes on request, and is thus
decoupled from any particular provisioning mechanism.
See StandardBranch
for an implementation that provisions children
via a NodeProvider
.
Constructor Summary | |
---|---|
GenericBranch()
|
Method Summary | |
---|---|
void |
addBranchChangeListener(BranchChangeListener listener)
Registers the specified listener to receive branch change events for this branch. |
Object |
availableChild(String nodeName)
Gets a child node, provisioning and installing it if possible. |
Collection<String> |
availableChildNames()
Extracts a collection of the names of child nodes that are available on request from this branch. |
protected GenericBranch |
constructChildBranch()
Strategy method called by provisionChildBranch() to do
initial construction of child branches. |
protected Object |
createChild(String nodeName)
Deprecated. Renamed to provisionChild(String) .
Subclasses should override that method instead of this one. |
protected void |
fireChildInstalled(String nodeName,
Object node)
|
protected void |
fireChildUninstalled(String nodeName,
Object node)
|
Object |
getChild(String nodeName)
Deprecated. |
Object |
getInstalledNode(String path)
Deprecated. |
String |
getLocalPathForChild(String nodeName)
Deprecated. |
RootNode |
getLocalRoot()
Get the root of this node's local scope. |
Object |
getNode(String path)
Deprecated. |
void |
installChild(String nodeName,
Object node)
Installs an object as a child of this branch. |
Object |
installedChild(String nodeName)
Gets a child node, but doesn't provision it if it's not already installed. |
Collection<String> |
installedChildNames()
Extracts a collection of the names of this branch's current child nodes. |
void |
nodeInstalled(NodeLocation location)
Register the Seedling address at which this node has been installed. |
protected Object |
provisionChild(String nodeName)
Attempts to provision a child node, where one doesn't currently exist. |
BranchNode |
provisionChildBranch()
Provisions a child branch intended for installation as a child of this one. |
void |
startService()
Starts a Seedling service. |
void |
stopService()
Stops a Seedling service. |
Object |
uninstallChild(String nodeName)
Removes a child node from this branch. |
Methods inherited from class consciouscode.seedling.tree.GenericNode |
---|
getLog, getNodeLocation, getNodeName, getParentBranch, isLoggingDebug, setLog, setLoggingDebug |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface consciouscode.seedling.BranchNode |
---|
getLog |
Methods inherited from interface consciouscode.seedling.LocatableNode |
---|
getNodeLocation |
Constructor Detail |
---|
public GenericBranch()
Method Detail |
---|
public void nodeInstalled(NodeLocation location)
Note: This is not called setNodeLocation
because
the location is not intended as a writable property.
This implementation calls super
and then caches the location's
local root
.
nodeInstalled
in interface LocatableNode
nodeInstalled
in class GenericNode
location
- is this node's new location. It must not be null.getLocalRoot()
public void addBranchChangeListener(BranchChangeListener listener)
EventfulBranch
addBranchChangeListener
in interface EventfulBranch
listener
- the BranchChangeListener
to add.protected void fireChildInstalled(String nodeName, Object node)
protected void fireChildUninstalled(String nodeName, Object node)
public RootNode getLocalRoot()
This implementation returns a cached pointer, initialized by
nodeInstalled(NodeLocation)
.
getLocalRoot
in interface BranchNode
getLocalRoot
in class GenericNode
LocatableNode.nodeInstalled(NodeLocation)
is invoked.BranchNode.getLocalRoot()
public Collection<String> installedChildNames()
BranchNode
The result is a snapshot of the current state: subsequent changes to the branch are not reflected in the result. Thus the actual children may have changed by the time the collection is inspected; in particular, another thread may uninstall a node named in this collection before the name is even read from this list.
Implementations must ensure that the result stays usable even when the
branch changes in another thread. For example, iterating the result
must not throw ConcurrentModificationException
if the branch
changes during iteration.
installedChildNames
in interface BranchNode
public Collection<String> availableChildNames()
BranchNode
The result is a snapshot of the current state: subsequent changes to the branch are not reflected in the result. Thus the actual children may have changed by the time the collection is inspected; in particular, another thread may uninstall a node named in this collection (thereby making it unavailable) before the name is even read from this collection.
Implementations must ensure that the result stays usable even when the
branch changes in another thread. For example, iterating the result
must not throw ConcurrentModificationException
if the branch
changes during iteration.
availableChildNames
in interface BranchNode
@Deprecated public Object getNode(String path) throws NodeProvisioningException
BranchNode
getNode
in interface BranchNode
path
- is interpreted relative to this branch. It may also be a
(local or global) full path. It must not be null or empty.
NodeProvisioningException
- if no such node exists, or if there
was an error instantiating it.@Deprecated public Object getInstalledNode(String path)
BranchNode
getInstalledNode
in interface BranchNode
path
- is interpreted relative to this branch. It may also be a
(local or global) full path. It must not be null or empty.
null
if no node exists at
the given path.@Deprecated public String getLocalPathForChild(String nodeName)
@Deprecated public Object getChild(String nodeName) throws NoSuchNodeException, NodeProvisioningException
BranchNode
Provisioning of uninstalled nodes is defined by the implementation class, which may not do any dynamic provisioning at all.
This method will not return null
; see
BranchNode.availableChild(String)
and
BranchNode.installedChild(String)
for alternatives.
getChild
in interface BranchNode
nodeName
- must not be null or empty.
NoSuchNodeException
- if the node isn't installed and if the
branch cannot provision it on demand. This usually means that there's
no applicable configuration for the node
NodeProvisioningException
- if there
was an error provisioning the node.public Object availableChild(String nodeName) throws NodeProvisioningException
BranchNode
A node is available if its already installed, or if it can be
provided for installation, usually by being created from configuration.
Provisioning of uninstalled nodes is defined by the implementation
class, which may not do any dynamic provisioning at all, in which case
this method behaves identically to BranchNode.installedChild(String)
.
If the requested node is not available then null
is returned.
This is in contrast to BranchNode.getChild(String)
, which throws
NoSuchNodeException
in that case.
availableChild
in interface BranchNode
nodeName
- must not be null or empty.
null
if it's not available.
NodeProvisioningException
- if there was an error provisioning
the node.public Object installedChild(String nodeName)
BranchNode
installedChild
in interface BranchNode
nodeName
- must not be null or empty.
public void installChild(String nodeName, Object node) throws ChildExistsException, ServiceException
GrowingBranch
ServiceNode
then
ServiceNode.startService()
will be called.
installChild
in interface GrowingBranch
nodeName
- must not be null or empty.
It must not match the name of an existing child node.node
- must not be null.
ChildExistsException
- if a node is already installed at the given
nodeName
. (The node will not have
been installed in this case.)
ServiceException
- if node
implements
ServiceNode
and could not be started. (The node will not have
been installed in this case.)public Object uninstallChild(String nodeName)
This implementation invokes ServiceNode.stopService()
on nodes
that implement it.
uninstallChild
in interface GrowingBranch
nodeName
- must not be null, but it does not need to match an
actual child of this branch.
public void startService() throws Exception
RuntimeException
are propagated
to the application, but any other kind of exception is wrapped in a
ServiceException
and rethrown.
This implementation currently does nothing.
startService
in interface ServiceNode
Exception
public void stopService()
Implementations of this method must not do anything that may change
the state of the parent Seedling. In particular, it cannot call
any overload of the following methods:
BranchNode.getNode(java.lang.String)
,
BranchNode.getChild(java.lang.String)
, GrowingBranch.installChild(java.lang.String, java.lang.Object)
,
GrowingBranch.uninstallChild(java.lang.String)
.
Furthermore, this method may be called from within a JVM shutdown hook, which implies that it must work promptly and carefully.
This implementation loops through all child nodes and uninstall them.
stopService
in interface ServiceNode
Runtime.addShutdownHook(java.lang.Thread)
protected Object provisionChild(String nodeName) throws NodeProvisioningException
This implementation always returns null
.
null
if the node is
not available.
NodeProvisioningException
- if there's a problem provisioning the
node.@Deprecated protected Object createChild(String nodeName) throws NodeInstantiationException
provisionChild(String)
.
Subclasses should override that method instead of this one.
NodeInstantiationException
public BranchNode provisionChildBranch() throws NodeProvisioningException
This method doesn't take a node name because we don't want provisioning
to vary by name here. If that's desired then provisioning should happen
in the normal way via BranchNode.availableChild(String)
.
This implementation calls constructChildBranch()
to
construct a new GenericBranch
, and then configures it similarly
to this instance. Subclasses will probably want to override that method
rather than this one.
provisionChildBranch
in interface BranchingBranch
NodeProvisioningException
- if there's a problem providing an
appropriate child branch.constructChildBranch()
protected GenericBranch constructChildBranch() throws NodeProvisioningException
provisionChildBranch()
to do
initial construction of child branches.
Subclasses will generally override this to construct a new instance of
their own class.
GenericBranch
.
NodeProvisioningException
provisionChildBranch()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |