Search in sources :

Example 1 with AcsJIdentifierUnexpectedEx

use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx in project ACS by ACS-Community.

the class UIDLibrary method getNewRestrictedRange.

/**
	 * Fetches a new restricted range. 
	 * This will return a URI allowing access to the new Range. 
	 * The range is automatically stored in the archive. 
	 * This method should only be used in very special cases, 
	 * see <a href="http://almasw.hq.eso.org/almasw/bin/view/Archive/UidLibrary">Archive/UidLibrary wiki page</a>!
	 * @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>.
	 * @param printLogs Emit logs, iff set to true.
	 * @return the UID of the range, which can be used for example as an argument in {@link #assignUniqueEntityId(EntityT, URI)}.
	 * @throws UniqueIdException  if the range cannot be obtained from the archive. 
	 */
public URI getNewRestrictedRange(int size, String user, IdentifierJ identifier, boolean printLogs) throws AcsJRangeUnavailableEx, AcsJIdentifierUnexpectedEx {
    Range range = null;
    try {
        if (printLogs)
            logger.finest("UIDLibrary: Fetching a restricted range");
        IdentifierRange idRange = identifier.getNewRestrictedRange(size, user);
        range = new Range(idRange);
    } catch (NotAvailable e) {
        throw new AcsJRangeUnavailableEx(e);
    }
    URI uri = range.rangeId();
    if (idRanges.containsKey(uri)) {
        AcsJIdentifierUnexpectedEx ex = new AcsJIdentifierUnexpectedEx();
        ex.setContextInfo("Cannot store new range. URI occupied. This should never have happened by design!!");
        throw ex;
    }
    if (printLogs)
        logger.finest("UIDLibrary: Storing Range under: " + uri.toASCIIString());
    idRanges.put(uri, range);
    return uri;
}
Also used : NotAvailable(alma.xmlstore.IdentifierPackage.NotAvailable) AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) AcsJIdentifierUnexpectedEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx) IdentifierRange(alma.archive.range.IdentifierRange) IdentifierRange(alma.archive.range.IdentifierRange) URI(java.net.URI)

Example 2 with AcsJIdentifierUnexpectedEx

use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx 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);
    }
}
Also used : AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) AcsJIdentifierUnexpectedEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx) AcsJIdentifierUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx)

Example 3 with AcsJIdentifierUnexpectedEx

use of alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx 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);
    }
}
Also used : AcsJUidAlreadyExistsEx(alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx) AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) AcsJIdentifierUnexpectedEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx) AcsJIdentifierUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx)

Aggregations

AcsJIdentifierUnexpectedEx (alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnexpectedEx)3 AcsJRangeUnavailableEx (alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx)3 AcsJIdentifierUnavailableEx (alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx)2 AcsJUidAlreadyExistsEx (alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx)1 IdentifierRange (alma.archive.range.IdentifierRange)1 NotAvailable (alma.xmlstore.IdentifierPackage.NotAvailable)1 URI (java.net.URI)1