Package org.apache.cayenne.configuration

# Class CayenneRuntime

java.lang.Object
org.apache.cayenne.configuration.CayenneRuntime

Direct Known Subclasses:
  `ClientRuntime`, `ServerRuntime`

public abstract class CayenneRuntime extends Object
A superclass of various Cayenne runtime stacks. A Runtime is the main access point to Cayenne for a user application. It provides a default Cayenne configuration as well as a way to customize this configuration via a built-in dependency injection (DI) container. In fact implementation-wise, Runtime object is just a convenience thin wrapper around a DI `Injector`.

Since:
  3.1

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Injector`
  `injector`
  `protected Collection<Module>`
  `modules`
  `protected static final ThreadLocal<Injector>`
  `threadInjector`
  A holder of an Injector bound to the current thread.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `CayenneRuntime(Collection<Module> modules)`
  Creates a CayenneRuntime with configuration based on the supplied collection of DI modules.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `bindThreadInjector(Injector injector)`
  Binds a DI `Injector` bound to the current thread.
  `DataChannel`
  `getChannel()`
  Returns the runtime `DataChannel`.
  `Injector`
  `getInjector()`
  Returns DI injector used by this runtime.
  `Collection<Module>`
  `getModules()`
  Returns the collection of modules used to initialize this runtime.
  `static Injector`
  `getThreadInjector()`
  Returns the `Injector` bound to the current thread.
  `ObjectContext`
  `newContext()`
  Returns a new ObjectContext instance based on the runtime's main DataChannel.
  `ObjectContext`
  `newContext(DataChannel parentChannel)`
  Returns a new ObjectContext which is a child of the specified DataChannel.
  `void`
  `shutdown()`
  Shuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### threadInjector

    protected static final ThreadLocal<Injector> threadInjector
    A holder of an Injector bound to the current thread. Used mainly to allow serializable contexts to attach to correct Cayenne stack on deserialization.
    Since:
      3.1

  - ### injector

    protected Injector injector

  - ### modules

    protected Collection<Module> modules

- ## Constructor Details

  - ### CayenneRuntime

    protected CayenneRuntime(Collection<Module> modules)
    Creates a CayenneRuntime with configuration based on the supplied collection of DI modules.

- ## Method Details

  - ### bindThreadInjector

    public static void bindThreadInjector(Injector injector)
    Binds a DI `Injector` bound to the current thread. It is primarily intended for deserialization of ObjectContexts.
    Since:
      3.1

  - ### getThreadInjector

    public static Injector getThreadInjector()
    Returns the `Injector` bound to the current thread. Will return null if none is bound.
    Since:
      3.1

  - ### getModules

    public Collection<Module> getModules()
    Returns the collection of modules used to initialize this runtime.
    Since:
      4.0

  - ### getInjector

    public Injector getInjector()
    Returns DI injector used by this runtime.

  - ### shutdown

    @BeforeScopeEnd public void shutdown()
    Shuts down the DI injector of this runtime, giving all services that need to release some resources a chance to do that.

  - ### getChannel

    public DataChannel getChannel()
    Returns the runtime `DataChannel`.

  - ### newContext

    public ObjectContext newContext()
    Returns a new ObjectContext instance based on the runtime's main DataChannel.
    Since:
      4.0

  - ### newContext

    public ObjectContext newContext(DataChannel parentChannel)
    Returns a new ObjectContext which is a child of the specified DataChannel. This method is used for creation of nested ObjectContexts, with parent ObjectContext passed as an argument.
    Since:
      4.0