Class StorageContext<Value>

java.lang.Object
com.codingchili.core.context.SystemContext
com.codingchili.core.context.StorageContext<Value>
All Implemented Interfaces:
CoreContext

public class StorageContext<Value> extends SystemContext
context used by storage plugins.
  • Constructor Details

    • StorageContext

      public StorageContext()
    • StorageContext

      public StorageContext(CoreContext context)
  • Method Details

    • logger

      public Logger logger(Class aClass)
      Specified by:
      logger in interface CoreContext
      Overrides:
      logger in class SystemContext
      Parameters:
      aClass - added as metadata to all logged events.
      Returns:
      get a new instance of a logger.
    • settings

      protected StorageSettings settings()
      Returns:
      get the storage settings.
    • storage

      public RemoteStorage storage()
      Returns:
      get the storage settings for the current plugin.
    • properties

      public io.vertx.core.json.JsonObject properties()
    • valueClass

      public Class<Value> valueClass()
      Returns:
      the class to be stored in the storage.
    • plugin

      public Class<? extends AsyncStorage> plugin()
      Returns:
      the plugin identifier to us as storage.
    • toValue

      public Value toValue(io.vertx.core.json.JsonObject json)
      converts a json object into the generic template used by a storage
      Parameters:
      json - the json object to convert
      Returns:
      json mapped to an object of generic type
    • toValue

      public Value toValue(String string)
      converts a byte array to a value using the deserialization template class
      Parameters:
      string - a json-formatted string
      Returns:
      generic Value inflated using the bytes and template class.
    • toJson

      public io.vertx.core.json.JsonObject toJson(Value object)
      converts the given object of generic type into a json object.
      Parameters:
      object - the object to be converted to json
      Returns:
      the serialized form of the given object
    • toPacked

      public byte[] toPacked(Value value)
      converts the given object of generic type into a byte array
      Parameters:
      value - the object to be converted
      Returns:
      a byte array created from the serialized objects json text
    • handle

      public void handle(io.vertx.core.Handler<io.vertx.core.AsyncResult<Value>> handler, Value value)
      handles a handler successfully with the given value.
      Parameters:
      handler - the handler to be handled
      value - the value to send the handler.
    • database

      public String database()
      get the name of the database used by the context.
      Returns:
      the name of the database as a string
    • collection

      public String collection()
      get the name of the collection within the database used by the context.
      Returns:
      the name of the collection as a string.
    • port

      public Integer port()
      Returns:
      the port of a remote database if configured.
    • host

      public String host()
      Returns:
      the hostname of a remote database if configured.
    • validate

      public boolean validate(Comparable comparable)
      Validates that the given string consists only of plaintext and is at least as long as the specified number of feedback-characters.
      Parameters:
      comparable - the text to check if plaintext
      Returns:
      true if the given comparable contains only plaintext
    • minFeedbackChars

      public Integer minFeedbackChars()
    • maxResults

      public Integer maxResults()
      Returns:
      the number of results all queries are limited to.
    • onWatcherFailed

      public void onWatcherFailed(String name, String cause)
      Called when a value has been expired by ttl.
      Parameters:
      name - the id of the object that was expired.
      cause - the reason why invocation failed.
    • onWatcherCompleted

      public void onWatcherCompleted(String name, int affected)
      Called when a value failed to expire as it was not found.
      Parameters:
      name - the id of the object that was expired.
      affected - the number of items affected by the query.
    • onWatcherPaused

      public void onWatcherPaused(String name)
    • onWatcherResumed

      public void onWatcherResumed(String name)
    • onCollectionDropped

      public void onCollectionDropped()
      Called when the collection has been dropped/cleared.
    • setClass

      public StorageContext<Value> setClass(Class<Value> aClass)
      sets the class that is used for deserialization. This should be the same or a supertype of the object type in the storage.
      Parameters:
      aClass - the class template to inflate
      Returns:
      fluent
    • setCollection

      public StorageContext<Value> setCollection(String collection)
      sets the collection context of the storage engine.
      Parameters:
      collection - name of the collection
      Returns:
      fluent
    • setDatabase

      public StorageContext<Value> setDatabase(String database)
      sets the database name to be used
      Parameters:
      database - name as string
      Returns:
      fluent
    • setProperties

      public StorageContext<Value> setProperties(io.vertx.core.json.JsonObject properties)
      Parameters:
      properties - implementation specific configuration options.
      Returns:
      fluent
    • setPlugin

      public StorageContext<Value> setPlugin(Class<? extends AsyncStorage> plugin)
      sets the storage plugin name the context is bound to so that configuration for it may be retrieved.
      Parameters:
      plugin - fully qualified class name as String.
      Returns:
      fluent
    • identifier

      public String identifier()
      Returns:
      storage identifier.