You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/01/30 00:53:14 UTC
svn commit: r739085 - in
/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog:
ChangeLog.java ChangeLogInterceptor.java ChangeLogStore.java
DefaultChangeLog.java MemoryChangeLogStore.java
Author: elecharny
Date: Thu Jan 29 23:53:13 2009
New Revision: 739085
URL: http://svn.apache.org/viewvc?rev=739085&view=rev
Log:
o Added Javadoc
o Added a flag to forbid the store from being changed when it's in use
o Some minor code cleanup
Modified:
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLog.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogStore.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/DefaultChangeLog.java
directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLog.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLog.java?rev=739085&r1=739084&r2=739085&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLog.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLog.java Thu Jan 29 23:53:13 2009
@@ -45,12 +45,23 @@
boolean isEnabled();
+ /**
+ * Enable or disable the ChangeLog service
+ * @param enabled true to enable the service, flase to disable it
+ */
void setEnabled( boolean enabled );
+ /**
+ * @return The underlying storage
+ */
ChangeLogStore getChangeLogStore();
+ /**
+ * Set the underlying storage
+ * @param store The storage
+ */
void setChangeLogStore( ChangeLogStore store );
@@ -185,12 +196,30 @@
*/
Tag tag() throws Exception;
+ /**
+ * @return The latest tag
+ * @throws Exception if there is a problem taking the latest tag
+ */
Tag getLatest() throws Exception;
+ /**
+ * Initialize the ChangeLog system.
+ *
+ * @param service The associated DirectoryService
+ * @throws Exception
+ */
void init( DirectoryService service ) throws Exception;
+ /**
+ * Flush the changes to disk
+ * @throws Exception If the flush failed
+ */
void sync() throws Exception;
+ /**
+ * Destroy the changeLog
+ * @throws Exception
+ */
void destroy() throws Exception;
/**
@@ -200,6 +229,10 @@
*/
void setExposeChangeLog( boolean exposeChangeLog );
+ /**
+ * DODO: Add Javadoc
+ * @return
+ */
boolean isExposeChangeLog();
/**
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java?rev=739085&r1=739084&r2=739085&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java Thu Jan 29 23:53:13 2009
@@ -84,6 +84,10 @@
// -----------------------------------------------------------------------
+ /**
+ * The init method will initialize the local variables and load the
+ * entryDeleted AttributeType.
+ */
public void init( DirectoryService directoryService ) throws Exception
{
super.init( directoryService );
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogStore.java?rev=739085&r1=739084&r2=739085&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogStore.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogStore.java Thu Jan 29 23:53:13 2009
@@ -33,17 +33,35 @@
* A store for change events on the directory which exposes methods for
* managing, querying and in general performing legal operations on the log.
*
+ * @org.apache.xbean.XBean
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
public interface ChangeLogStore
{
+ /**
+ * Initialize the store.
+ *
+ * @param service The associated DirectoryService
+ * @throws Exception If the initialization failed
+ */
void init( DirectoryService service ) throws Exception;
+ /**
+ * Write the changes on disk
+ *
+ * @throws Exception If the write failed
+ */
void sync() throws Exception;
+ /**
+ * Destroy the logs.
+ *
+ * @throws Exception If we can't destroy the logs
+ */
void destroy() throws Exception;
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/DefaultChangeLog.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/DefaultChangeLog.java?rev=739085&r1=739084&r2=739085&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/DefaultChangeLog.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/DefaultChangeLog.java Thu Jan 29 23:53:13 2009
@@ -25,21 +25,44 @@
import org.apache.directory.server.core.authn.LdapPrincipal;
import org.apache.directory.server.core.partition.Partition;
import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * The default ChangeLog service implementation.
- *
- * @org.apache.xbean.XBean
+ * The default ChangeLog service implementation. It stores operations
+ * in memory.
+ *
+ * Entries are stored into a dedicated partition, named ou=changelog, under which
+ * we have two other sub-entries : ou=tags and ou= revisions :
+ *
+ * ou=changelog
+ * |
+ * +-- ou=revisions
+ * |
+ * +-- ou=tags
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
public class DefaultChangeLog implements ChangeLog
{
+ /** The class logger */
+ private static final Logger LOG = LoggerFactory.getLogger( DefaultChangeLog.class );
+
+ /** Tells if the service is activated or not */
private boolean enabled;
+
+ /** The latest tag set */
private Tag latest;
- private ChangeLogStore store = new MemoryChangeLogStore();
+
+ /**
+ * The default store is a InMemory store.
+ **/
+ private ChangeLogStore store;
+
+ /** A volatile flag used to avoid store switching when in use */
+ private volatile boolean storeInitialized = false;
private boolean exposeChangeLog;
@@ -49,21 +72,42 @@
private String tagContainerName = "ou=tags";
+ /**
+ * {@inheritDoc}
+ */
public ChangeLogStore getChangeLogStore()
{
return store;
}
+ /**
+ * {@inheritDoc}
+ *
+ * If there is an existing changeLog store, we don't switch it
+ */
public void setChangeLogStore( ChangeLogStore store )
{
- this.store = store;
+ if ( storeInitialized )
+ {
+ LOG.error( "Cannot set a changeLog store when one is already active" );
+ }
+ else
+ {
+ this.store = store;
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public long getCurrentRevision() throws Exception
{
- return store.getCurrentRevision();
+ synchronized( store )
+ {
+ return store.getCurrentRevision();
+ }
}
@@ -95,24 +139,36 @@
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isLogSearchSupported()
{
return store instanceof SearchableChangeLogStore;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isTagSearchSupported()
{
return store instanceof TaggableSearchableChangeLogStore;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isTagStorageSupported()
{
return store instanceof TaggableChangeLogStore;
}
+ /**
+ * {@inheritDoc}
+ */
public ChangeLogSearchEngine getChangeLogSearchEngine()
{
if ( isLogSearchSupported() )
@@ -125,6 +181,9 @@
}
+ /**
+ * {@inheritDoc}
+ */
public TagSearchEngine getTagSearchEngine()
{
if ( isTagSearchSupported() )
@@ -137,6 +196,9 @@
}
+ /**
+ * {@inheritDoc}
+ */
public Tag tag( long revision, String description ) throws Exception
{
if ( revision < 0 )
@@ -158,36 +220,54 @@
}
+ /**
+ * {@inheritDoc}
+ */
public Tag tag( long revision ) throws Exception
{
return tag( revision, null );
}
+ /**
+ * {@inheritDoc}
+ */
public Tag tag( String description ) throws Exception
{
return tag( store.getCurrentRevision(), description );
}
+ /**
+ * {@inheritDoc}
+ */
public Tag tag() throws Exception
{
return tag( store.getCurrentRevision(), null );
}
+ /**
+ * {@inheritDoc}
+ */
public void setEnabled( boolean enabled )
{
this.enabled = enabled;
}
+ /**
+ * {@inheritDoc}
+ */
public boolean isEnabled()
{
return enabled;
}
+ /**
+ * {@inheritDoc}
+ */
public Tag getLatest() throws Exception
{
if ( latest != null )
@@ -204,10 +284,19 @@
}
+ /**
+ * Initialize the ChangeLog system. We will initialize the associated store.
+ */
public void init( DirectoryService service ) throws Exception
{
if ( enabled )
{
+ if ( store == null )
+ {
+ // If no store has been defined, create an In Memory store
+ store = new MemoryChangeLogStore();
+ }
+
store.init( service );
if ( exposeChangeLog && isTagSearchSupported() )
@@ -222,9 +311,15 @@
service.addPartition( partition );
}
}
+
+ // Flip the protection flag
+ storeInitialized = true;
}
+ /**
+ * {@inheritDoc}
+ */
public void sync() throws Exception
{
if ( enabled )
@@ -234,12 +329,17 @@
}
+ /**
+ * {@inheritDoc}
+ */
public void destroy() throws Exception
{
if ( enabled )
{
store.destroy();
}
+
+ storeInitialized = false;
}
Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java?rev=739085&r1=739084&r2=739085&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java (original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java Thu Jan 29 23:53:13 2009
@@ -54,17 +54,27 @@
*/
public class MemoryChangeLogStore implements TaggableChangeLogStore
{
+
private static final String REV_FILE = "revision";
private static final String TAG_FILE = "tags";
private static final String CHANGELOG_FILE = "changelog.dat";
+ /** An incremental number giving the current revision */
private long currentRevision;
+
+ /** The latest tag */
private Tag latest;
+
+ /** A Map of tags and revisions */
private final Map<Long,Tag> tags = new HashMap<Long,Tag>( 100 );
+
private final List<ChangeLogEvent> events = new ArrayList<ChangeLogEvent>();
private File workingDirectory;
+ /**
+ * {@inheritDoc}
+ */
public Tag tag( long revision ) throws Exception
{
if ( tags.containsKey( revision ) )
@@ -78,9 +88,12 @@
}
+ /**
+ * {@inheritDoc}
+ */
public Tag tag() throws Exception
{
- if ( latest != null && latest.getRevision() == currentRevision )
+ if ( ( latest != null) && ( latest.getRevision() == currentRevision ) )
{
return latest;
}
@@ -93,7 +106,7 @@
public Tag tag( String description ) throws Exception
{
- if ( latest != null && latest.getRevision() == currentRevision )
+ if ( ( latest != null ) && ( latest.getRevision() == currentRevision ) )
{
return latest;
}
@@ -116,9 +129,11 @@
private void loadRevision() throws Exception
{
File revFile = new File( workingDirectory, REV_FILE );
+
if ( revFile.exists() )
{
BufferedReader reader = null;
+
try
{
reader = new BufferedReader( new FileReader( revFile ) );
@@ -150,12 +165,14 @@
private void saveRevision() throws Exception
{
File revFile = new File( workingDirectory, REV_FILE );
+
if ( revFile.exists() )
{
revFile.delete();
}
PrintWriter out = null;
+
try
{
out = new PrintWriter( new FileWriter( revFile ) );
@@ -179,20 +196,24 @@
private void saveTags() throws Exception
{
File tagFile = new File( workingDirectory, TAG_FILE );
+
if ( tagFile.exists() )
{
tagFile.delete();
}
FileOutputStream out = null;
+
try
{
out = new FileOutputStream( tagFile );
Properties props = new Properties();
+
for ( Tag tag : tags.values() )
{
String key = String.valueOf( tag.getRevision() );
+
if ( tag.getDescription() == null )
{
props.setProperty( key, "null" );
@@ -230,15 +251,18 @@
private void loadTags() throws Exception
{
File revFile = new File( workingDirectory, REV_FILE );
+
if ( revFile.exists() )
{
Properties props = new Properties();
FileInputStream in = null;
+
try
{
in = new FileInputStream( revFile );
props.load( in );
ArrayList<Long> revList = new ArrayList<Long>();
+
for ( Object key : props.keySet() )
{
revList.add( Long.valueOf( ( String ) key ) );
@@ -249,6 +273,7 @@
// @todo need some serious syncrhoization here on tags
tags.clear();
+
for ( Long lkey : revList )
{
String rev = String.valueOf( lkey );
@@ -340,6 +365,7 @@
private void saveChangeLog() throws Exception
{
File file = new File( workingDirectory, CHANGELOG_FILE );
+
if ( file.exists() )
{
file.delete();
@@ -398,6 +424,9 @@
}
+ /**
+ * Save logs, tags and revision on disk, and clean everything in memory
+ */
public void destroy() throws Exception
{
saveRevision();