TransactionId.java revision 7436da7252e66e7a698239a5c6b9ca04df24179a
/*
* 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 2015 ForgeRock AS.
*/
/**
* Value logged with every Commons Audit event.
*
* TransactionId value should be unique per request coming from an external agent so that all events occurring in
* response to the same external stimulus can be tied together.
*
* Calls to external systems should propagate the value returned by {@link #createSubTransactionId()} so that Audit
* events reported by the external system can also be tied back to the original stimulus.
*
* Due to the fact that each TransactionId instance creates a sequence of sub-transaction IDs, the same TransactionId
* object should be used while fulfilling a given request; it is not appropriate to create multiple instances of
* TransactionId with the same value as this would lead to duplicate sub-transaction ID values. As such, two instances
* of TransactionId with the same value are not considered equal.
*
* @since 13.0.0
*/
public final class TransactionId {
/**
* Clients can set this HTTP header in order to specify the transactionId value that will be
* assigned to every Audit Event.
*
* If this HTTP header is not set, then a unique random transactionId value will be automatically generated.
*/
private final AtomicInteger subTransactionIdCounter;
/**
* Construct a <code>TransactionId</code> with a random value.
*/
public TransactionId() {
}
/**
* Construct a <code>TransactionId</code> with the specified value.
*
* @param value The transaction id.
*/
}
/**
* Gets the transaction id value.
*
* @return Non-null, <code>TransactionId</code>.
*/
return value;
}
/**
* Creates a sub transaction id that can be passed to an external system.
*
* @return Non-null, <code>TransactionId</code>.
*/
public TransactionId createSubTransactionId() {
return new TransactionId(subTransactionId);
}
}