Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The UnboundID LDAP SDK for Java is a fast, comprehensive, and easy-to-use
Java API for communicating with LDAP directory servers and performing
related tasks like reading and writing LDIF, encoding and decoding data
using base64 and ASN.1 BER, and performing secure communication. This
package contains the Commercial Edition of the LDAP SDK, which includes
all of the general-purpose functionality contained in the Standard
Edition, plus additional functionality specific to UnboundID server
products.
/*
* Copyright 2008-2017 UnboundID Corp.
* All Rights Reserved.
*/
/*
* Copyright (C) 2015-2017 UnboundID Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPLv2 only)
* or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
package com.unboundid.ldap.sdk.unboundidds.tasks;
import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.unboundid.ldap.sdk.Attribute;
import com.unboundid.ldap.sdk.Entry;
import com.unboundid.util.NotExtensible;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;
import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
import static com.unboundid.util.Debug.*;
import static com.unboundid.util.StaticUtils.*;
import static com.unboundid.util.Validator.*;
/**
* This class defines a data structure for holding information about scheduled
* tasks as used by the Ping Identity, UnboundID, or Alcatel-Lucent 8661
* Directory Server. Subclasses be used to provide additional functionality
* when dealing with certain types of tasks.
*
*
* NOTE: This class is part of the Commercial Edition of the UnboundID
* LDAP SDK for Java. It is not available for use in applications that
* include only the Standard Edition of the LDAP SDK, and is not supported for
* use in conjunction with non-UnboundID products.
*
*
* All types of tasks can include the following information:
*
*
Task ID -- Uniquely identifies the task in the server. It may be
* omitted when scheduling a new task in order to have a task ID generated
* for the task.
*
Task Class Name -- The fully-qualified name of the {@code Task}
* subclass that provides the logic for the task. This does not need to
* be provided when creating a new task from one of the task-specific
* subclasses.
*
Task State -- The current state of the task. See the {@link TaskState}
* enum for information about the possible states that a task may
* have.
*
Scheduled Start Time -- The earliest time that the task should be
* eligible to start. It may be omitted when scheduling a new task in
* order to use the current time.
*
Actual Start Time -- The time that server started processing the
* task.
*
Actual Start Time -- The time that server completed processing for the
* task.
*
Dependency IDs -- A list of task IDs for tasks that must complete
* before this task may be considered eligible to start.
*
Failed Dependency Action -- Specifies how the server should treat this
* task if any of the tasks on which it depends failed. See the
* {@link FailedDependencyAction} enum for the failed dependency action
* values that may be used.
*
Notify on Completion -- A list of e-mail addresses for users that
* should be notified when the task completes, regardless of whether it
* was successful.
*
Notify On Error -- A list of e-mail addresses for users that should be
* notified if the task fails.
*
Log Messages -- A list of the messages logged by the task while it was
* running.
*
* Each of these elements can be retrieving using specific methods within this
* class (e.g., the {@link Task#getTaskID} method can be used to retrieve the
* task ID), but task properties (including those specific to the particular
* type to task) may also be accessed using a generic API. For example, the
* {@link Task#getTaskPropertyValues} method retrieves a map that correlates the
* {@link TaskProperty} objects for the task with the values that have been set
* for those properties. See the documentation for the {@link TaskManager}
* class for an example that demonstrates accessing task information using the
* generic API.
*
* Also note that it is possible to create new tasks using information obtained
* from the generic API, but that is done on a per-class basis. For example, in
* order to create a new {@link BackupTask} instance using the generic API, you
* would use the {@link BackupTask#BackupTask(Map)} constructor, in which the
* provided map contains a mapping between the properties and their values for
* that task. The {@link Task#getTaskSpecificProperties} method may be used to
* retrieve a list of the task-specific properties that may be provided when
* scheduling a task, and the {@link Task#getCommonTaskProperties} method may be
* used to retrieve a list of properties that can be provided when scheduling
* any type of task.
*/
@NotExtensible()
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public class Task
implements Serializable
{
/**
* The name of the attribute used to hold the actual start time for scheduled
* tasks.
*/
static final String ATTR_ACTUAL_START_TIME = "ds-task-actual-start-time";
/**
* The name of the attribute used to hold the completion time for scheduled
* tasks.
*/
static final String ATTR_COMPLETION_TIME = "ds-task-completion-time";
/**
* The name of the attribute used to hold the task IDs for tasks on which a
* scheduled task is dependent.
*/
static final String ATTR_DEPENDENCY_ID = "ds-task-dependency-id";
/**
* The name of the attribute used to indicate what action to take if one of
* the dependencies for a task failed to complete successfully.
*/
static final String ATTR_FAILED_DEPENDENCY_ACTION =
"ds-task-failed-dependency-action";
/**
* The name of the attribute used to hold the log messages for scheduled
* tasks.
*/
static final String ATTR_LOG_MESSAGE = "ds-task-log-message";
/**
* The name of the attribute used to hold the e-mail addresses of the users
* that should be notified whenever a scheduled task completes, regardless of
* success or failure.
*/
static final String ATTR_NOTIFY_ON_COMPLETION =
"ds-task-notify-on-completion";
/**
* The name of the attribute used to hold the e-mail addresses of the users
* that should be notified if a scheduled task fails to complete successfully.
*/
static final String ATTR_NOTIFY_ON_ERROR = "ds-task-notify-on-error";
/**
* The name of the attribute used to hold the scheduled start time for
* scheduled tasks.
*/
static final String ATTR_SCHEDULED_START_TIME =
"ds-task-scheduled-start-time";
/**
* The name of the attribute used to hold the name of the class that provides
* the logic for scheduled tasks.
*/
static final String ATTR_TASK_CLASS = "ds-task-class-name";
/**
* The name of the attribute used to hold the task ID for scheduled tasks.
*/
static final String ATTR_TASK_ID = "ds-task-id";
/**
* The name of the attribute used to hold the current state for scheduled
* tasks.
*/
static final String ATTR_TASK_STATE = "ds-task-state";
/**
* The name of the base object class for scheduled tasks.
*/
static final String OC_TASK = "ds-task";
/**
* The DN of the entry below which scheduled tasks reside.
*/
static final String SCHEDULED_TASKS_BASE_DN =
"cn=Scheduled Tasks,cn=tasks";
/**
* The task property that will be used for the task ID.
*/
static final TaskProperty PROPERTY_TASK_ID =
new TaskProperty(ATTR_TASK_ID, INFO_DISPLAY_NAME_TASK_ID.get(),
INFO_DESCRIPTION_TASK_ID.get(), String.class, false,
false, true);
/**
* The task property that will be used for the scheduled start time.
*/
static final TaskProperty PROPERTY_SCHEDULED_START_TIME =
new TaskProperty(ATTR_SCHEDULED_START_TIME,
INFO_DISPLAY_NAME_SCHEDULED_START_TIME.get(),
INFO_DESCRIPTION_SCHEDULED_START_TIME.get(), Date.class,
false, false, true);
/**
* The task property that will be used for the set of dependency IDs.
*/
static final TaskProperty PROPERTY_DEPENDENCY_ID =
new TaskProperty(ATTR_DEPENDENCY_ID,
INFO_DISPLAY_NAME_DEPENDENCY_ID.get(),
INFO_DESCRIPTION_DEPENDENCY_ID.get(), String.class,
false, true, true);
/**
* The task property that will be used for the failed dependency action.
*/
static final TaskProperty PROPERTY_FAILED_DEPENDENCY_ACTION =
new TaskProperty(ATTR_FAILED_DEPENDENCY_ACTION,
INFO_DISPLAY_NAME_FAILED_DEPENDENCY_ACTION.get(),
INFO_DESCRIPTION_FAILED_DEPENDENCY_ACTION.get(),
String.class, false, false, true,
new String[]
{
FailedDependencyAction.CANCEL.getName(),
FailedDependencyAction.DISABLE.getName(),
FailedDependencyAction.PROCESS.getName()
});
/**
* The task property that will be used for the notify on completion addresses.
*/
static final TaskProperty PROPERTY_NOTIFY_ON_COMPLETION =
new TaskProperty(ATTR_NOTIFY_ON_COMPLETION,
INFO_DISPLAY_NAME_NOTIFY_ON_COMPLETION.get(),
INFO_DESCRIPTION_NOTIFY_ON_COMPLETION.get(),
String.class, false, true, true);
/**
* The task property that will be used for the notify on error addresses.
*/
static final TaskProperty PROPERTY_NOTIFY_ON_ERROR =
new TaskProperty(ATTR_NOTIFY_ON_ERROR,
INFO_DISPLAY_NAME_NOTIFY_ON_ERROR.get(),
INFO_DESCRIPTION_NOTIFY_ON_ERROR.get(),
String.class, false, true, true);
/**
* The serial version UID for this serializable class.
*/
private static final long serialVersionUID = -3521189553470479032L;
// The time that this task actually started.
private final Date actualStartTime;
// The time that this task completed.
private final Date completionTime;
// The time that this task was scheduled to start.
private final Date scheduledStartTime;
// The entry from which this task was decoded.
private final Entry taskEntry;
// The failed dependency action for this task.
private final FailedDependencyAction failedDependencyAction;
// The set of task IDs of the tasks on which this task is dependent.
private final List dependencyIDs;
// The set of log messages for this task.
private final List logMessages;
// The set of e-mail addresses of users that should be notified when the task
// processing is complete.
private final List notifyOnCompletion;
// The set of e-mail addresses of users that should be notified if task
// processing completes with an error.
private final List notifyOnError;
// The fully-qualified name of the task class.
private final String taskClassName;
// The DN of the entry for this task.
private final String taskEntryDN;
// The task ID for this task.
private final String taskID;
// The current state for this task.
private final TaskState taskState;
/**
* Creates a new uninitialized task instance which should only be used for
* obtaining general information about this task, including the task name,
* description, and supported properties. Attempts to use a task created with
* this constructor for any other reason will likely fail.
*/
protected Task()
{
actualStartTime = null;
completionTime = null;
scheduledStartTime = null;
taskEntry = null;
failedDependencyAction = null;
dependencyIDs = null;
logMessages = null;
notifyOnCompletion = null;
notifyOnError = null;
taskClassName = null;
taskEntryDN = null;
taskID = null;
taskState = null;
}
/**
* Creates a new unscheduled task with the specified task ID and class name.
*
* @param taskID The task ID to use for this task. If it is
* {@code null} then a UUID will be generated for use
* as the task ID.
* @param taskClassName The fully-qualified name of the Java class that
* provides the logic for the task. It must not be
* {@code null}.
*/
public Task(final String taskID, final String taskClassName)
{
this(taskID, taskClassName, null, null, null, null, null);
}
/**
* Creates a new unscheduled task with the provided information.
*
* @param taskID The task ID to use for this task.
* @param taskClassName The fully-qualified name of the Java class
* that provides the logic for the task. It
* must not be {@code null}.
* @param scheduledStartTime The time that this task should start
* running.
* @param dependencyIDs The list of task IDs that will be required
* to complete before this task will be
* eligible to start.
* @param failedDependencyAction Indicates what action should be taken if
* any of the dependencies for this task do
* not complete successfully.
* @param notifyOnCompletion The list of e-mail addresses of individuals
* that should be notified when this task
* completes.
* @param notifyOnError The list of e-mail addresses of individuals
* that should be notified if this task does
* not complete successfully.
*/
public Task(final String taskID, final String taskClassName,
final Date scheduledStartTime, final List dependencyIDs,
final FailedDependencyAction failedDependencyAction,
final List notifyOnCompletion,
final List notifyOnError)
{
ensureNotNull(taskClassName);
this.taskClassName = taskClassName;
this.scheduledStartTime = scheduledStartTime;
this.failedDependencyAction = failedDependencyAction;
if (taskID == null)
{
this.taskID = UUID.randomUUID().toString();
}
else
{
this.taskID = taskID;
}
if (dependencyIDs == null)
{
this.dependencyIDs = Collections.emptyList();
}
else
{
this.dependencyIDs = Collections.unmodifiableList(dependencyIDs);
}
if (notifyOnCompletion == null)
{
this.notifyOnCompletion = Collections.emptyList();
}
else
{
this.notifyOnCompletion =
Collections.unmodifiableList(notifyOnCompletion);
}
if (notifyOnError == null)
{
this.notifyOnError = Collections.emptyList();
}
else
{
this.notifyOnError = Collections.unmodifiableList(notifyOnError);
}
taskEntry = null;
taskEntryDN = ATTR_TASK_ID + '=' + this.taskID + ',' +
SCHEDULED_TASKS_BASE_DN;
actualStartTime = null;
completionTime = null;
logMessages = Collections.emptyList();
taskState = TaskState.UNSCHEDULED;
}
/**
* Creates a new task from the provided entry.
*
* @param entry The entry to use to create this task.
*
* @throws TaskException If the provided entry cannot be parsed as a
* scheduled task.
*/
public Task(final Entry entry)
throws TaskException
{
taskEntry = entry;
taskEntryDN = entry.getDN();
// Ensure that the task entry has the appropriate object class for a
// scheduled task.
if (! entry.hasObjectClass(OC_TASK))
{
throw new TaskException(ERR_TASK_MISSING_OC.get(taskEntryDN));
}
// Get the task ID. It must be present.
taskID = entry.getAttributeValue(ATTR_TASK_ID);
if (taskID == null)
{
throw new TaskException(ERR_TASK_NO_ID.get(taskEntryDN));
}
// Get the task class name. It must be present.
taskClassName = entry.getAttributeValue(ATTR_TASK_CLASS);
if (taskClassName == null)
{
throw new TaskException(ERR_TASK_NO_CLASS.get(taskEntryDN));
}
// Get the task state. If it is not present, then assume "unscheduled".
final String stateStr = entry.getAttributeValue(ATTR_TASK_STATE);
if (stateStr == null)
{
taskState = TaskState.UNSCHEDULED;
}
else
{
taskState = TaskState.forName(stateStr);
if (taskState == null)
{
throw new TaskException(ERR_TASK_INVALID_STATE.get(taskEntryDN,
stateStr));
}
}
// Get the scheduled start time. It may be absent.
String timestamp = entry.getAttributeValue(ATTR_SCHEDULED_START_TIME);
if (timestamp == null)
{
scheduledStartTime = null;
}
else
{
try
{
scheduledStartTime = decodeGeneralizedTime(timestamp);
}
catch (ParseException pe)
{
debugException(pe);
throw new TaskException(ERR_TASK_CANNOT_PARSE_SCHEDULED_START_TIME.get(
taskEntryDN, timestamp, pe.getMessage()),
pe);
}
}
// Get the actual start time. It may be absent.
timestamp = entry.getAttributeValue(ATTR_ACTUAL_START_TIME);
if (timestamp == null)
{
actualStartTime = null;
}
else
{
try
{
actualStartTime = decodeGeneralizedTime(timestamp);
}
catch (ParseException pe)
{
debugException(pe);
throw new TaskException(ERR_TASK_CANNOT_PARSE_ACTUAL_START_TIME.get(
taskEntryDN, timestamp, pe.getMessage()),
pe);
}
}
// Get the completion start time. It may be absent.
timestamp = entry.getAttributeValue(ATTR_COMPLETION_TIME);
if (timestamp == null)
{
completionTime = null;
}
else
{
try
{
completionTime = decodeGeneralizedTime(timestamp);
}
catch (ParseException pe)
{
debugException(pe);
throw new TaskException(ERR_TASK_CANNOT_PARSE_COMPLETION_TIME.get(
taskEntryDN, timestamp, pe.getMessage()),
pe);
}
}
// Get the failed dependency action for this task. It may be absent.
final String name = entry.getAttributeValue(ATTR_FAILED_DEPENDENCY_ACTION);
if (name == null)
{
failedDependencyAction = null;
}
else
{
failedDependencyAction = FailedDependencyAction.forName(name);
}
// Get the dependent task IDs for this task. It may be absent.
dependencyIDs = parseStringList(entry, ATTR_DEPENDENCY_ID);
// Get the log messages for this task. It may be absent.
logMessages = parseStringList(entry, ATTR_LOG_MESSAGE);
// Get the notify on completion addresses for this task. It may be absent.
notifyOnCompletion = parseStringList(entry, ATTR_NOTIFY_ON_COMPLETION);
// Get the notify on error addresses for this task. It may be absent.
notifyOnError = parseStringList(entry, ATTR_NOTIFY_ON_ERROR);
}
/**
* Creates a new task from the provided set of task properties.
*
* @param taskClassName The fully-qualified name of the Java class that
* provides the logic for the task. It must not be
* {@code null}.
* @param properties The set of task properties and their corresponding
* values to use for the task. It must not be
* {@code null}.
*
* @throws TaskException If the provided set of properties cannot be used to
* create a valid scheduled task.
*/
public Task(final String taskClassName,
final Map> properties)
throws TaskException
{
ensureNotNull(taskClassName, properties);
this.taskClassName = taskClassName;
String idStr = UUID.randomUUID().toString();
Date sst = null;
String[] depIDs = NO_STRINGS;
FailedDependencyAction fda = FailedDependencyAction.CANCEL;
String[] noc = NO_STRINGS;
String[] noe = NO_STRINGS;
for (final Map.Entry> entry :
properties.entrySet())
{
final TaskProperty p = entry.getKey();
final String attrName = p.getAttributeName();
final List