Search in sources :

Example 1 with NotAvailable

use of alma.xmlstore.IdentifierPackage.NotAvailable 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 NotAvailable

use of alma.xmlstore.IdentifierPackage.NotAvailable 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;
    }
}
Also used : NotAvailable(alma.xmlstore.IdentifierPackage.NotAvailable) AcsJRangeUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJRangeUnavailableEx) IdentifierRange(alma.archive.range.IdentifierRange) AcsJIdentifierUnavailableEx(alma.ArchiveIdentifierError.wrappers.AcsJIdentifierUnavailableEx)

Aggregations

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