
java.fedora.server.Module Maven / Gradle / Ivy
Show all versions of fcrepo-client Show documentation
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to the
* Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
* http://www.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server;
import java.util.Map;
import fedora.server.errors.ModuleInitializationException;
import fedora.server.errors.ModuleShutdownException;
/**
* Base class for Fedora server modules.
*
* A Module
is a singleton object of a Fedora Server
* instance with a simple lifecycle, supported by the initModule()
* and shutdownModule()
methods, which are automatically called
* during server startup and shutdown, respectively.
*
* Modules are configured via "param" elements inside module elements
* in the configuration file. An instance of each module specified in the
* configuration file is automatically created at startup and is available
* via the getModule(String)
instance method of the
* Server
class.
*
* @author [email protected]
* @version $Id: Module.java 5220 2006-11-20 13:52:20Z cwilper $
*/
public abstract class Module
extends Pluggable {
private String m_role;
private Server m_server;
/**
* Creates and initializes the Module.
*
* When the server is starting up, this is invoked as part of the
* initialization process.
*
* @param moduleParameters A pre-loaded Map of name-value pairs comprising
* the intended configuration of this Module.
* @param server The Server
instance.
* @param role The role this module fulfills, a java class name.
* @throws ModuleInitializationException If initilization values are
* invalid or initialization fails for some other reason.
*/
public Module(Map moduleParameters, Server server, String role)
throws ModuleInitializationException {
super(moduleParameters);
m_role=role;
m_server=server;
initModule();
}
/**
* Gets the Server
instance to which this Module
* belongs.
*
* @return The Server
instance.
*/
public Server getServer() {
return m_server;
}
/**
* Gets the role this module fulfills, as given in the constructor.
*
* Role is the name of the class or interface that this
* concrete Module
extends or implements.
*
* @return String The role.
*/
public final String getRole() {
return m_role;
}
/**
* Initializes the Module based on configuration parameters.
*
* @throws ModuleInitializationException If initialization values are
* invalid or initialization fails for some other reason.
*/
public void initModule()
throws ModuleInitializationException {
if (1==2) throw new ModuleInitializationException(null, null);
}
/**
* Second stage of Module initialization.
*
* This is guaranteed to run after all Module's initModule() methods
* have run.
*
* @throws ModuleInitializationException If initialization values are
* invalid or initialization fails for some other reason.
*/
public void postInitModule()
throws ModuleInitializationException {
if (1==2) throw new ModuleInitializationException(null, null);
}
/**
* Frees system resources allocated by this Module.
*
* @throws ModuleShutdownException If there is a problem freeing
* system resources. Note that if there is a problem, it won't end
* up aborting the shutdown process. Therefore, this method should
* do everything possible to recover from exceptional situations
* before throwing an exception.
*/
public void shutdownModule()
throws ModuleShutdownException {
if (1==2) throw new ModuleShutdownException(null, null);
}
}