Class NamespacedKeyValueStore

  • All Implemented Interfaces:
    com.blueriq.component.api.store.keyvalue.IKeyValueStore

    public class NamespacedKeyValueStore
    extends Object
    implements com.blueriq.component.api.store.keyvalue.IKeyValueStore
    An IKeyValueStore wrapper which causes all keys to be namespaced by prefixing them with an specified namespace string followed by the the colon character.

    For example, if the namespace is "example", then calling set("test", "value") will set the "example:test" key in the key-value store.

    Since:
    11.0
    Author:
    Petru Galanton
    • Constructor Detail

      • NamespacedKeyValueStore

        public NamespacedKeyValueStore​(com.blueriq.component.api.store.keyvalue.IKeyValueStore delegate,
                                       String namespace)
        Creates a new instance.
        Parameters:
        delegate - - the delegate IKeyValueStore implementation
        namespace - - the key namespace, must not be null
        Throws:
        IllegalArgumentException - if namespace is null
    • Method Detail

      • set

        public void set​(String key,
                        Serializable value)
        Specified by:
        set in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • set

        public void set​(String key,
                        Serializable value,
                        long timeout,
                        TimeUnit unit)
        Specified by:
        set in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • setRaw

        public void setRaw​(String key,
                           byte[] value)
        Specified by:
        setRaw in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • setRaw

        public void setRaw​(String key,
                           byte[] value,
                           long timeout,
                           TimeUnit unit)
        Specified by:
        setRaw in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • get

        public <T extends Serializable> T get​(String key,
                                              Class<T> valueType)
        Specified by:
        get in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • getRaw

        public byte[] getRaw​(String key)
        Specified by:
        getRaw in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • delete

        public void delete​(String key)
        Specified by:
        delete in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • hasKey

        public boolean hasKey​(String key)
        Specified by:
        hasKey in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • expire

        public boolean expire​(String key,
                              long timeout,
                              TimeUnit unit)
        Specified by:
        expire in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • keyIterator

        public com.blueriq.component.api.store.keyvalue.IKeyValueStore.IKeyIterator keyIterator​(com.blueriq.component.api.store.keyvalue.IKeyPattern pattern)
        Specified by:
        keyIterator in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • getNamespaceSeparator

        public String getNamespaceSeparator()
        Specified by:
        getNamespaceSeparator in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • getKeyPatternBuilder

        public com.blueriq.component.api.store.keyvalue.IKeyPatternBuilder getKeyPatternBuilder()
        Specified by:
        getKeyPatternBuilder in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • serialize

        public byte[] serialize​(Serializable value)
        Specified by:
        serialize in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • deserialize

        public <T> T deserialize​(byte[] bytes,
                                 Class<T> valueType)
        Specified by:
        deserialize in interface com.blueriq.component.api.store.keyvalue.IKeyValueStore
      • getNamespacedKey

        public String getNamespacedKey​(String key)
        Applies the namespace to the given key and returns the result.
        Parameters:
        key - the key that shold be namespaced
        Returns:
        the namespaced key