org.apache.jetspeed.services.registry
Class CastorRegistryService

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitable
      extended byorg.apache.turbine.services.BaseService
          extended byorg.apache.turbine.services.TurbineBaseService
              extended byorg.apache.jetspeed.services.registry.CastorRegistryService
All Implemented Interfaces:
FileRegistry, org.apache.turbine.services.Initable, javax.jms.MessageListener, RegistryService, org.apache.turbine.services.Service
Direct Known Subclasses:
HybridRegistryService

public class CastorRegistryService
extends org.apache.turbine.services.TurbineBaseService
implements RegistryService, FileRegistry, javax.jms.MessageListener

This is an implementation of the RegistryService based on the Castor XML serialization mechanisms

This registry aggregates multiple RegistryFragment to store the regsistry entries

This service expects the following properties to be set for correct operation:

directory
The directory where the Registry will look for fragment files
extension
The extension used for identifying the registry fragment files. Default .xreg
mapping
the Castor object mapping file path
registries
a comma separated list of registry names to load from this file
refreshRate
Optional. The manager will check every refreshRate seconds if the config has changed and if true will refresh all the registries. A value of 0 or negative will disable the automatic refresh operation. Default: 300 (5 minutes)

Version:
$Id: CastorRegistryService.java,v 1.47 2005/04/27 14:08:24 raphael Exp $
Author:
Raphaël Luta, Santiago Gala

Field Summary
static java.lang.String DEFAULT_EXTENSION
           
static java.lang.String DEFAULT_MAPPING
           
static int DEFAULT_REFRESH
           
protected  java.util.Hashtable defaults
          The list of default fragments stores for newly created objects
protected  java.lang.String directory
          the base regsitry directory
protected  boolean enableMessaging
          enable messaging
protected  java.util.Hashtable entryIndex
          Associates entries with their fragments name for quick lookup
protected  java.lang.String extension
          the extension for registry files
protected  org.apache.xml.serialize.OutputFormat format
          the output format for pretty printing when saving registries
protected  java.util.Hashtable fragments
          The Castor generated RegsitryFragment objects
protected static JetspeedLogger logger
          Static initialization of the logger for this class
protected  org.exolab.castor.mapping.Mapping mapping
          the Castor mapping file name
protected  java.util.Hashtable registries
          regsitry type keyed list of entries
protected  RegistryWatcher watcher
          the Watcher object which monitors the regsitry directory
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.jetspeed.services.registry.RegistryService
SERVICE_NAME
 
Constructor Summary
CastorRegistryService()
           
 
Method Summary
 void addEntry(java.lang.String regName, RegistryEntry entry)
          Add a new RegistryEntry in the named Registry.
 RegistryEntry createEntry(java.lang.String regName)
          Creates a new RegistryEntry instance compatible with the current Registry instance implementation
 void createFragment(java.lang.String name, java.io.Reader reader, boolean persistent)
          Read and unmarshal a fragment in memory
protected  javax.jms.Message createMessage(java.lang.String registry, java.lang.String entryName)
           
protected  Registry createRegistry(java.lang.String name)
           
 Registry get(java.lang.String regName)
          Returns a Registry object for further manipulation
 RegistryEntry getEntry(java.lang.String regName, java.lang.String entryName)
          Returns a RegistryEntry from the named Registry.
 java.util.Map getFragmentMap()
           
 java.util.Enumeration getNames()
          List all the registry currently available to this service
 void init()
          Late init method from Turbine Service model
 void init(javax.servlet.ServletConfig conf)
          This is the early initialization method called by the Turbine Service framework
protected  java.util.Map loadDatabaseManagedRegistries(org.apache.turbine.services.resources.ResourceService serviceConf)
           
 void loadFragment(java.lang.String file)
          Load and unmarshal a RegistryFragment from the file
 void onMessage(javax.jms.Message message)
           
 void refresh()
          Refresh the state of the registry implementation.
protected  void refresh(java.lang.String regName)
          Scan all the registry fragments for new entries relevant to this registry and update its definition.
 void removeEntry(java.lang.String regName, java.lang.String entryName)
          Deletes a RegistryEntry from the named Registry This is a convenience wrapper around Registry.removeEntry(org.apache.jetspeed.om.registry.RegistryEntry)
 void removeFragment(java.lang.String file)
          Remove a fragment from storage
 void saveEntry(java.lang.String regName, RegistryEntry entry)
          Saves a RegistryEntry to the named Registry.
 void saveFragment(java.lang.String file)
          Marshal and save a RegistryFragment to disk
 void shutdown()
          This is the shutdown method called by the Turbine Service framework
protected  void updateFragment(java.lang.String name, RegistryFragment fragment)
          Updates a fragment in storage and the associated entryIndex
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker
 

Field Detail

logger

protected static final JetspeedLogger logger
Static initialization of the logger for this class


DEFAULT_REFRESH

public static final int DEFAULT_REFRESH
See Also:
Constant Field Values

DEFAULT_EXTENSION

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

DEFAULT_MAPPING

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

registries

protected java.util.Hashtable registries
regsitry type keyed list of entries


fragments

protected java.util.Hashtable fragments
The Castor generated RegsitryFragment objects


defaults

protected java.util.Hashtable defaults
The list of default fragments stores for newly created objects


entryIndex

protected java.util.Hashtable entryIndex
Associates entries with their fragments name for quick lookup


watcher

protected RegistryWatcher watcher
the Watcher object which monitors the regsitry directory


mapping

protected org.exolab.castor.mapping.Mapping mapping
the Castor mapping file name


format

protected org.apache.xml.serialize.OutputFormat format
the output format for pretty printing when saving registries


directory

protected java.lang.String directory
the base regsitry directory


extension

protected java.lang.String extension
the extension for registry files


enableMessaging

protected boolean enableMessaging
enable messaging

Constructor Detail

CastorRegistryService

public CastorRegistryService()
Method Detail

get

public Registry get(java.lang.String regName)
Returns a Registry object for further manipulation

Specified by:
get in interface RegistryService
Parameters:
regName - the name of the registry to fetch
Returns:
a Registry object if found by the manager or null

getNames

public java.util.Enumeration getNames()
List all the registry currently available to this service

Specified by:
getNames in interface RegistryService
Returns:
an Enumeration of registry names.

createEntry

public RegistryEntry createEntry(java.lang.String regName)
Creates a new RegistryEntry instance compatible with the current Registry instance implementation

Specified by:
createEntry in interface RegistryService
Parameters:
regName - the name of the registry to use
Returns:
the newly created RegistryEntry

getEntry

public RegistryEntry getEntry(java.lang.String regName,
                              java.lang.String entryName)
Returns a RegistryEntry from the named Registry. This is a convenience wrapper around Registry.getEntry(java.lang.String)

Specified by:
getEntry in interface RegistryService
Parameters:
regName - the name of the registry
entryName - the name of the entry to retrieve from the registry
Returns:
a RegistryEntry object if the key is found or null

addEntry

public void addEntry(java.lang.String regName,
                     RegistryEntry entry)
              throws RegistryException
Add a new RegistryEntry in the named Registry. This is a convenience wrapper around Registry.addEntry(org.apache.jetspeed.om.registry.RegistryEntry)

Specified by:
addEntry in interface RegistryService
Parameters:
regName - the name of the registry
entry - the Registry entry to add
Throws:
Sends - a RegistryException if the manager can't add the provided entry
RegistryException

removeEntry

public void removeEntry(java.lang.String regName,
                        java.lang.String entryName)
Deletes a RegistryEntry from the named Registry This is a convenience wrapper around Registry.removeEntry(org.apache.jetspeed.om.registry.RegistryEntry)

Specified by:
removeEntry in interface RegistryService
Parameters:
regName - the name of the registry
entryName - the name of the entry to remove

init

public void init(javax.servlet.ServletConfig conf)
          throws org.apache.turbine.services.InitializationException
This is the early initialization method called by the Turbine Service framework

Throws:
org.apache.turbine.services.InitializationException

loadDatabaseManagedRegistries

protected java.util.Map loadDatabaseManagedRegistries(org.apache.turbine.services.resources.ResourceService serviceConf)

createRegistry

protected Registry createRegistry(java.lang.String name)

init

public void init()
          throws org.apache.turbine.services.InitializationException
Late init method from Turbine Service model

Specified by:
init in interface org.apache.turbine.services.Initable
Throws:
org.apache.turbine.services.InitializationException

shutdown

public void shutdown()
This is the shutdown method called by the Turbine Service framework

Specified by:
shutdown in interface org.apache.turbine.services.Initable

refresh

public void refresh()
Refresh the state of the registry implementation. Should be called whenever the underlying fragments are modified

Specified by:
refresh in interface FileRegistry

getFragmentMap

public java.util.Map getFragmentMap()
Specified by:
getFragmentMap in interface FileRegistry
Returns:
a Map of all fragments keyed by file names

loadFragment

public void loadFragment(java.lang.String file)
Load and unmarshal a RegistryFragment from the file

Specified by:
loadFragment in interface FileRegistry
Parameters:
file - the absolute file path storing this fragment

createFragment

public void createFragment(java.lang.String name,
                           java.io.Reader reader,
                           boolean persistent)
Read and unmarshal a fragment in memory

Specified by:
createFragment in interface FileRegistry
Parameters:
name - the name of this fragment
reader - the reader to use for creating this fragment
persistent - whether this fragment should be persisted on disk in the registry

saveFragment

public void saveFragment(java.lang.String file)
Marshal and save a RegistryFragment to disk

Specified by:
saveFragment in interface FileRegistry
Parameters:
file - the absolute file path storing this fragment

removeFragment

public void removeFragment(java.lang.String file)
Remove a fragment from storage

Specified by:
removeFragment in interface FileRegistry
Parameters:
file - the absolute file path storing this fragment

updateFragment

protected void updateFragment(java.lang.String name,
                              RegistryFragment fragment)
Updates a fragment in storage and the associated entryIndex


refresh

protected void refresh(java.lang.String regName)
Scan all the registry fragments for new entries relevant to this registry and update its definition.

Parameters:
regName - the name of the Registry to refresh

saveEntry

public void saveEntry(java.lang.String regName,
                      RegistryEntry entry)
               throws RegistryException
Description copied from interface: RegistryService
Saves a RegistryEntry to the named Registry. This should save the entry immediately to the underlying storage mechanism. This is a convenience wrapper around Registry.removeEntry(org.apache.jetspeed.om.registry.RegistryEntry)

Specified by:
saveEntry in interface RegistryService
Parameters:
regName - the name of the registry
entry - the name of the entry to remove
Throws:
RegistryException
See Also:
org.apache.jetspeed.services.registry.RegistryService#saveEntry(java.lang.String, java.lang.String)

createMessage

protected javax.jms.Message createMessage(java.lang.String registry,
                                          java.lang.String entryName)

onMessage

public void onMessage(javax.jms.Message message)
Specified by:
onMessage in interface javax.jms.MessageListener
See Also:
MessageListener.onMessage(javax.jms.Message)


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.