TaskProcessor.java revision 13588d95d6459633b746c603dbadd0e58fdc741d
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014 ForgeRock AS.
*/
/**
* Responsible for processing CTS Tasks asynchronously.
*
* This implementation will draw a task from an allocated BlockingQueue and
* makes no assumptions about the nature of the task, or the queue from which
* it is drawing tasks.
*
* This decoupled design is intended to ensure that each TaskProcessor can be
* run as part of a thread pool, and process tasks in a continuous fashion.
*
* Thread Policy: This runnable will respond to Thread interrupts and will
* exit cleanly in the event of an interrupt.
*
* @see org.forgerock.openam.cts.impl.task.Task
* @see org.forgerock.openam.cts.impl.task.TaskFactory
*/
public class TaskProcessor implements Runnable {
private final ConnectionFactory connectionFactory;
private final LDAPAdapter adapter;
/**
* Generate a default instance of the Task Processor.
*
* @param connectionFactory Required for initialising connections.
* @param adapter Required for LDAP operations.
* @param debug Required for debugging.
*/
public TaskProcessor(@Named(DataLayerConstants.DATA_LAYER_CTS_ASYNC_BINDING) ConnectionFactory connectionFactory,
this.connectionFactory = connectionFactory;
}
/**
* Assign a BlockingQueue to this processor.
*
* Note: This must be set before execution is started.
*
* @param queue Non null BlockingQueue implementation to use for asynchronous processing.
*/
}
/**
* Starts processing of the Queue Tasks.
*
* @throws java.lang.IllegalStateException If the queue has not been assigned.
*/
public void run() {
// Iterate until shutdown
try {
debug("acquired connection");
}
} catch (CoreTokenException e) {
error("processing task", e);
} catch (ErrorResultException e) {
error("acquiring connection", e);
} catch (InterruptedException e) {
error("interrupt detected", e);
}
}
debug("Processor thread shutdown.");
}
/**
* Close the connection if it was not null.
*
* @param connection The possibly null connection to close.
*/
if (connection != null) {
debug("Closing connection");
}
}
if (debug.messageEnabled()) {
}
}
}
}