LDIFConnectionHandler.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines an LDIF connection handler, which can be used to watch for
* new LDIF files to be placed in a specified directory. If a new LDIF file is
* detected, the connection handler will process any changes contained in that
* file as internal operations.
*/
public final class LDIFConnectionHandler
implements ConfigurationChangeListener<LDIFConnectionHandlerCfg>,
{
/** The debug log tracer for this class. */
// Indicates whether this connection handler is currently stopped.
private volatile boolean isStopped;
// Indicates whether we should stop this connection handler.
private volatile boolean stopRequested;
// The path to the directory to watch for new LDIF files.
private File ldifDirectory;
// The internal client connection that will be used for all processing.
private InternalClientConnection conn;
// The current configuration for this LDIF connection handler.
private LDIFConnectionHandlerCfg currentConfig;
// The thread used to run the connection handler.
private Thread connectionHandlerThread;
// Help to not warn permanently and fullfill the log file
// in debug mode.
private boolean alreadyWarn = false;
/**
* Creates a new instance of this connection handler. All initialization
* should be performed in the {@code initializeConnectionHandler} method.
*/
public LDIFConnectionHandler()
{
super("LDIFConnectionHandler");
isStopped = true;
stopRequested = false;
alreadyWarn = false;
}
/**
* {@inheritDoc}
*/
public void initializeConnectionHandler(LDIFConnectionHandlerCfg
{
// If we have a relative path to the instance, get the absolute one.
if ( ! ldifDirectory.isAbsolute() ) {
}
if (ldifDirectory.exists())
{
if (! ldifDirectory.isDirectory())
{
// The path specified as the LDIF directory exists, but isn't a
// directory. This is probably a mistake, and we should at least log
// a warning message.
}
}
else
{
// The path specified as the LDIF directory doesn't exist. We should log
// a warning message saying that we won't do anything until it's created.
}
this.currentConfig = configuration;
}
/**
* {@inheritDoc}
*/
{
stopRequested = true;
for (int i=0; i < 5; i++)
{
if (isStopped)
{
return;
}
else
{
try
{
if ((connectionHandlerThread != null) &&
{
}
else
{
return;
}
} catch (Exception e) {}
}
}
}
/**
* {@inheritDoc}
*/
public String getConnectionHandlerName()
{
return "LDIF Connection Handler";
}
/**
* {@inheritDoc}
*/
public String getProtocol()
{
return "LDIF";
}
/**
* {@inheritDoc}
*/
{
// There are no listeners for this connection handler.
}
/**
* {@inheritDoc}
*/
{
// There are no client connections for this connection handler.
}
/**
* {@inheritDoc}
*/
public void run()
{
isStopped = false;
try
{
while (! stopRequested)
{
try
{
{
{
{
{
processLDIFFile(f);
}
}
}
}
else
{
{
dir.getAbsolutePath() +
" doesn't exist or isn't a directory");
alreadyWarn = true;
}
}
if (! stopRequested)
{
if (sleepTime > 0)
{
try
{
}
catch (InterruptedException ie)
{
}
}
}
}
catch (Exception e)
{
logger.traceException(e);
}
}
}
finally
{
isStopped = true;
}
}
/**
* Processes the contents of the provided LDIF file.
*
* @param ldifFile The LDIF file to be processed.
*/
{
if (logger.isTraceEnabled())
{
}
boolean fullyProcessed = false;
boolean errorEncountered = false;
new LDIFImportConfig(inputPath);
importConfig.setInvokeImportPlugins(false);
importConfig.setValidateSchema(true);
{
int i=2;
while (true)
{
{
break;
}
i++;
}
}
if (logger.isTraceEnabled())
{
}
try
{
while (true)
{
try
{
if (logger.isTraceEnabled())
{
}
}
catch (LDIFException le)
{
errorEncountered = true;
if (le.canContinueReading())
{
le.getMessageObject());
continue;
}
else
{
le.getMessageObject());
break;
}
}
if (changeRecord == null)
{
fullyProcessed = true;
break;
}
if (changeRecord instanceof AddChangeRecordEntry)
{
}
else if (changeRecord instanceof DeleteChangeRecordEntry)
{
}
else if (changeRecord instanceof ModifyChangeRecordEntry)
{
}
else if (changeRecord instanceof ModifyDNChangeRecordEntry)
{
}
{
}
else
{
if (logger.isTraceEnabled())
{
}
{
}
{
}
{
{
}
}
}
}
}
catch (IOException ioe)
{
fullyProcessed = false;
}
finally
{
}
if (errorEncountered || (! fullyProcessed))
{
{
int i=2;
while (true)
{
{
}
i++;
}
}
try
{
if (logger.isTraceEnabled())
{
}
}
catch (Exception e)
{
logger.traceException(e);
}
}
else
{
try
{
if (logger.isTraceEnabled())
{
}
}
catch (Exception e)
{
logger.traceException(e);
getExceptionMessage(e));
}
}
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
{
// The configuration should always be acceptable.
return true;
}
/**
* {@inheritDoc}
*/
{
// The only processing we need to do here is to get the LDIF directory and
// create a File object from it.
this.ldifDirectory = newLDIFDirectory;
return new ConfigChangeResult();
}
/**
* {@inheritDoc}
*/
public DN getComponentEntryDN()
{
return currentConfig.dn();
}
/**
* {@inheritDoc}
*/
public String getClassName()
{
return LDIFConnectionHandler.class.getName();
}
/**
* {@inheritDoc}
*/
{
return alerts;
}
}