Class CompressedSchema

    • Constructor Detail

      • CompressedSchema

        public CompressedSchema​(ServerContext serverContext)
        Creates a new empty instance of this compressed schema.
        Parameters:
        serverContext - The server context.
    • Method Detail

      • decodeAttribute

        public final Attribute decodeAttribute​(ByteSequenceReader reader)
                                        throws DirectoryException
        Decodes the contents of the provided array as an attribute at the current position.
        Parameters:
        reader - The byte string reader containing the encoded entry.
        Returns:
        The decoded attribute.
        Throws:
        DirectoryException - If the attribute could not be decoded properly for some reason.
      • decodeObjectClasses

        public final Map<ObjectClass,​String> decodeObjectClasses​(ByteSequenceReader reader)
                                                                throws DirectoryException
        Decodes an object class set from the provided byte string.
        Parameters:
        reader - The byte string reader containing the object class set identifier.
        Returns:
        The decoded object class set.
        Throws:
        DirectoryException - If the provided byte string reader cannot be decoded as an object class set.
      • encodeAttribute

        public final void encodeAttribute​(ByteStringBuilder builder,
                                          Attribute attribute)
                                   throws DirectoryException
        Encodes the information in the provided attribute to a byte array.
        Parameters:
        builder - The buffer to encode the attribute to.
        attribute - The attribute to be encoded.
        Throws:
        DirectoryException - If a problem occurs while attempting to determine the appropriate identifier.
      • encodeObjectClasses

        public final void encodeObjectClasses​(ByteStringBuilder builder,
                                              Map<ObjectClass,​String> objectClasses)
                                       throws DirectoryException
        Encodes the provided set of object classes to a byte array. If the same set had been previously encoded, then the cached value will be used. Otherwise, a new value will be created.
        Parameters:
        builder - The buffer to encode the object classes to.
        objectClasses - The set of object classes for which to retrieve the corresponding byte array token.
        Throws:
        DirectoryException - If a problem occurs while attempting to determine the appropriate identifier.
      • getAllAttributes

        protected final Iterable<Map.Entry<byte[],​Map.Entry<String,​Iterable<String>>>> getAllAttributes()
        Returns a view of the encoded attributes in this compressed schema which can be used for saving the entire content to disk.

        The iterator returned by this method is not thread safe.

        Returns:
        A view of the encoded attributes in this compressed schema.
      • getAllObjectClasses

        protected final Iterable<Map.Entry<byte[],​Collection<String>>> getAllObjectClasses()
        Returns a view of the encoded object classes in this compressed schema which can be used for saving the entire content to disk.

        The iterator returned by this method is not thread safe.

        Returns:
        A view of the encoded object classes in this compressed schema.
      • loadAttribute

        protected final AttributeDescription loadAttribute​(byte[] encodedAttribute,
                                                           String attributeName,
                                                           Collection<String> attributeOptions)
        Loads an encoded attribute into this compressed schema. This method may called by implementations during initialization when loading content from disk.
        Parameters:
        encodedAttribute - The encoded attribute description.
        attributeName - The user provided attribute type name.
        attributeOptions - The non-null but possibly empty set of attribute options.
        Returns:
        The attribute type description, or null if the definition was skipped because the key it is stored under is not one a compressed schema hands out.
      • loadObjectClasses

        protected final Map<ObjectClass,​String> loadObjectClasses​(byte[] encodedObjectClasses,
                                                                        Collection<String> objectClassNames)
        Loads an encoded object class into this compressed schema. This method may called by implementations during initialization when loading content from disk.
        Parameters:
        encodedObjectClasses - The encoded object classes.
        objectClassNames - The user provided set of object class names.
        Returns:
        The object class set, or null if the definition was skipped because the key it is stored under is not one a compressed schema hands out.
      • storeAttribute

        protected void storeAttribute​(byte[] encodedAttribute,
                                      String attributeName,
                                      Iterable<String> attributeOptions)
                               throws DirectoryException
        Persists the provided encoded attribute. The default implementation is to do nothing. Calls to this method are synchronized, so implementations can assume that this method is not being called by other threads. Note that this method is not thread-safe with respect to storeObjectClasses(byte[], Collection).

        Called with the exclusive lock of this compressed schema held, and that lock is reentrant, so an implementation must re-enter neither the encode, the load nor the decode path of the compressed schema it belongs to. The registration being persisted has already been appended to the decode map - so that an implementation persisting the whole content rather than the element it is handed, as DefaultCompressedSchema does, has it - and is withdrawn from there if this method throws. Encoding or loading appends to the same decode map, and the withdrawal would take back whatever was appended last; decoding rebuilds the mappings when the schema has changed, and the withdrawal would then have to take the element out of a map that has already been replaced. Neither is withdrawn: the violation is reported and the registration is left behind, holding an id no definition was persisted under.

        Parameters:
        encodedAttribute - The encoded attribute description.
        attributeName - The user provided attribute type name.
        attributeOptions - The non-null but possibly empty set of attribute options.
        Throws:
        DirectoryException - If an error occurred while persisting the encoded attribute.
      • storeObjectClasses

        protected void storeObjectClasses​(byte[] encodedObjectClasses,
                                          Collection<String> objectClassNames)
                                   throws DirectoryException
        Persists the provided encoded object classes. The default implementation is to do nothing. Calls to this method are synchronized, so implementations can assume that this method is not being called by other threads. Note that this method is not thread-safe with respect to storeAttribute(byte[], String, Iterable).

        Called with the exclusive lock of this compressed schema held, and that lock is reentrant, so an implementation must re-enter neither the encode, the load nor the decode path of the compressed schema it belongs to. The registration being persisted has already been appended to the decode map - so that an implementation persisting the whole content rather than the element it is handed, as DefaultCompressedSchema does, has it - and is withdrawn from there if this method throws. Encoding or loading appends to the same decode map, and the withdrawal would take back whatever was appended last; decoding rebuilds the mappings when the schema has changed, and the withdrawal would then have to take the element out of a map that has already been replaced. Neither is withdrawn: the violation is reported and the registration is left behind, holding an id no definition was persisted under.

        Parameters:
        encodedObjectClasses - The encoded object classes.
        objectClassNames - The user provided set of object class names.
        Throws:
        DirectoryException - If an error occurred while persisting the encoded object classes.