MentaContainer

Compare Revisions

Ignore whitespace Rev 87 → Rev 88

/trunk/src/main/java/org/mentacontainer/Interceptable.java
1,46 → 1,27
package org.mentacontainer;
 
public interface Interceptable {
/**
* Some components can also implement this interface to perform some cleanup
* when the instance is cleared. For example, a connection pool will want
* to know when the connection instance is cleared so it can return it to
* the pool.
*
* It makes more sense to use this interface for components that will be placed
* in the THREAD scope, but you can also use it with components in the SINGLETON
* scope.
*
* This is particular useful for the THREAD scope for dealing with thread pools, so
* when the thread is returned to the thread pool you will want to clear the THREAD
* scope. That's pretty much how web containers work: one thread per request coming from
* a thread pool.
*
* @author sergio.oliveira.jr@gmail.com
*
* @param <E>
*/
public interface Interceptable<E> {
public static String DEFAULT_PRE_DESTROY_METHOD = "preDestroy";
public void onCreated(E createdObject);
public static String DEFAULT_POST_CREATE_METHOD = "postCreate";
/**
* Configure the name of the method that will be used as a
* post create interceptor. You may want to use this method to check
* and validate the required dependencies of this component class.
*
* @param methodName The name of the method that will be called just after creation
* @return The component itself. (Fluent API)
*/
public Interceptable setPostCreate(String methodName);
/**
* Configure the name of the method that will be used as a
* pre destroy interceptor. You may want to use this method to release
* resources for example to return a database connection to a pool or to close it.
*
* @param methodName The name of the method that will be called just before destruction
* @return The component itself. (Fluent API)
*/
public Interceptable setPreDestroy(String methodName);
/**
* Return the post create method used for interception.
* By default it should return DEFAULT_POST_CREATE_METHOD.
* It can also return null to indicate no interception should take place.
*
* @return The method used to perform the interception or null if no interception should take place
*/
public String getPostCreate();
/**
* Return the pre destroy method used for interception.
* By default it should return DEFAULT_PRE_DESTROY_METHOD.
* It can also return null to indicate no interception should take place.
*
* @return The method used to perform the interception or null if no interception should take place
*/
public String getPreDestroy();
public void onCleared(E clearedObject);
}