use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx in project ACS by ACS-Community.
the class UIDLibraryTest method testAllocateDefaultID.
public void testAllocateDefaultID() throws Exception {
UIDLibrary lib = new UIDLibrary(logger);
EntityT e = new EntityT();
// assign and check a UID
lib.assignUniqueEntityId(e, ident);
String uid = e.getEntityId();
logger.info("Got a new UID for an entity object: " + uid);
assertEquals("uid://X01/Xaabb/X1", uid);
// try to reassign a UID
try {
lib.assignUniqueEntityId(e, ident);
fail("expected AcsJUidAlreadyExistsEx");
} catch (AcsJUidAlreadyExistsEx ex) {
// fine
}
// verify that the exception did not change the old ID
assertEquals(uid, e.getEntityId());
// try a null identifier archive
try {
lib.assignUniqueEntityId(e, (IdentifierJ) null);
fail("Expected AcsJIdentifierUnavailableEx when using a null Identifier archive.");
} catch (AcsJIdentifierUnavailableEx ex) {
// fine
}
}
use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx in project ACS by ACS-Community.
the class UIDLibrary method checkDefaultRange.
/**
* Creates a default range on demand, or sets a new default range if the old range has no more UID
* (which happens after pulling Long.MAX UIDs, or sooner if a limit was set).
* @param identifier the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
* <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
* to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object
* (<code>identRaw</code>) that is obtained, for example, by <br>
* <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
*/
protected synchronized void checkDefaultRange(IdentifierJ identifier) throws AcsJRangeUnavailableEx, AcsJIdentifierUnavailableEx {
if (identifier == null) {
AcsJIdentifierUnavailableEx ex = new AcsJIdentifierUnavailableEx();
ex.setContextInfo("Provided identifier reference is null.");
throw ex;
}
try {
if (defaultRange == null || !defaultRange.hasNextID()) {
defaultRange = new Range(identifier.getNewRange());
}
} catch (NotAvailable e) {
AcsJRangeUnavailableEx ex = new AcsJRangeUnavailableEx();
ex.setRange("default");
throw ex;
}
}
use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx in project ACS by ACS-Community.
the class UIDLibrary method replaceUniqueEntityId.
/**
* Similar to {@link #assignUniqueEntityId(EntityT, IdentifierJ)}, but allows replacing an existing ID.
* Only in very special cases such as ObsPrep replacing locally-generated IDs with archive-generated UIDs
* should this method be used. Replacing UIDs can easily corrupt the archive because existing links would no longer hold!
* @param identifier the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
* <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
* to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object
* (<code>identRaw</code>) that is obtained, for example, by <br>
* <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
* @see #assignUniqueEntityId(EntityT, IdentifierJ)
*/
public synchronized void replaceUniqueEntityId(EntityT entity, IdentifierJ identifier) throws AcsJRangeUnavailableEx, AcsJIdentifierUnavailableEx, AcsJIdentifierUnexpectedEx {
if (entity == null) {
throw new NullPointerException("argument 'entity' must not be null.");
}
try {
String oldUid = entity.getEntityId();
checkDefaultRange(identifier);
defaultRange.replaceUniqueEntityId(entity);
logger.info("Replaced old UID '" + oldUid + "' with new UID '" + entity.getEntityId() + "' on an entity of type " + entity.getEntityTypeName());
} catch (AcsJRangeUnavailableEx e) {
throw e;
} catch (AcsJIdentifierUnavailableEx e) {
throw e;
} catch (Throwable e) {
// AcsJRangeLockedEx and AcsJRangeExhaustedEx should not occur for default range, thanks to method checkDefaultRange
throw new AcsJIdentifierUnexpectedEx(e);
}
}
use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx in project ACS by ACS-Community.
the class UIDLibrary method assignUniqueEntityId.
/**
* Assigns a UID from the default range to the <code>EntityT</code> castor class
* of an XML-based entity such as a SchedBlock.
* <p>
* Implementation note: the default range of UIDs is retrieved from the archive at the first call and is then shared among instances
* in order to be frugal on UIDs and to minimize archive access.
* This means that often the passed in <code>identifier</code> will not be used at all but still must be provided,
* because the calling component can not know whether another component or the container has
* called this method before.
* This method is synchronized to avoid the very unlikely situation that <code>defaultRange.hasNextId</code> succeeds for one thread but then later
* assigning the UID still fails because of another thread having stolen the last free UID in the meantime.
*
* @param identifier the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
* <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
* to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object
* (<code>identRaw</code>) that is obtained, for example, by <br>
* <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
* @see ContainerServices#assignUniqueEntityId(EntityT)
*/
public synchronized void assignUniqueEntityId(EntityT entity, IdentifierJ identifier) throws AcsJUidAlreadyExistsEx, AcsJIdentifierUnavailableEx, AcsJRangeUnavailableEx, AcsJIdentifierUnexpectedEx {
try {
checkDefaultRange(identifier);
defaultRange.assignUniqueEntityId(entity);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Assigned UID '" + entity.getEntityId() + "' to entity of type " + entity.getEntityTypeName());
}
} catch (AcsJUidAlreadyExistsEx e) {
throw e;
} catch (AcsJRangeUnavailableEx e) {
throw e;
} catch (AcsJIdentifierUnavailableEx e) {
throw e;
} catch (Throwable e) {
// AcsJRangeLockedEx and AcsJRangeExhaustedEx should not occur for default range, thanks to method checkDefaultRange
throw new AcsJIdentifierUnexpectedEx(e);
}
}
Aggregations