## net.i2p
Class I2PAppContext

    java.lang.Object
      net.i2p.I2PAppContext

Direct Known Subclasses:
  RouterContext

    public class I2PAppContext

extends java.lang.Object

Provide a base scope for accessing singletons that I2P exposes. Rather than using the traditional singleton, where any component can access the component in question directly, all of those I2P related singletons are exposed through a particular I2PAppContext. This helps not only with understanding their use and the components I2P exposes, but it also allows multiple isolated environments to operate concurrently within the same JVM - particularly useful for stubbing out implementations of the rooted components and simulating the software's interaction between multiple instances.

As a simplification, there is also a global context - if some component needs access to one of the singletons but doesn't have its own context from which to root itself, it binds to the I2PAppContext's globalAppContext(), which is the first context that was created within the JVM, or a new one if no context existed already. This functionality is often used within the I2P core for logging - e.g.

         private static final Log _log = new Log(someClass.class);

It is for this reason that applications that care about working with multiple contexts should build their own context as soon as possible (within the main(..)) so that any referenced components will latch on to that context instead of instantiating a new one. However, there are situations in which both can be relevent.

Field Summary
`protected Clock` `_clock`
`protected boolean` `_clockInitialized`
`protected static I2PAppContext` `_globalAppContext` the context that components without explicit root are bound

Constructor Summary
`I2PAppContext()` Lets root a brand new context
`I2PAppContext(java.util.Properties envProps)` Lets root a brand new context

Method Summary
`AESEngine` `aes()` Ok, I'll admit it.
`Clock` `clock()` The context's synchronized clock, which is kept context specific only to enable simulators to play with clock skew among different instances.
`DSAEngine` `dsa()` Our DSA engine (see HMAC and SHA above)
`ElGamalAESEngine` `elGamalAESEngine()` Access the ElGamal/AES+SessionTag engine for this context.
`ElGamalEngine` `elGamalEngine()` This is the ElGamal engine used within this context.
`static I2PAppContext` `getGlobalContext()` Pull the default context, creating a new one if necessary, else using the first one created.
`java.lang.String` `getProperty(java.lang.String propName)` Access the configuration attributes of this context, using properties provided during the context construction, or falling back on System.getProperty if no properties were provided during construction (or the specified prop wasn't included).
`java.lang.String` `getProperty(java.lang.String propName, java.lang.String defaultValue)` Access the configuration attributes of this context, using properties provided during the context construction, or falling back on System.getProperty if no properties were provided during construction (or the specified prop wasn't included).
`java.util.Set` `getPropertyNames()` Access the configuration attributes of this context, listing the properties provided during the context construction, as well as the ones included in System.getProperties.
`HMACGenerator` `hmac()` There is absolutely no good reason to make this context specific, other than for consistency, and perhaps later we'll want to include some stats.
`HMAC256Generator` `hmac256()`
`protected void` `initializeClock()`
`KeyGenerator` `keyGenerator()` Component to generate ElGamal, DSA, and Session keys.
`LogManager` `logManager()` Query the log manager for this context, which may in turn have its own set of configuration settings (loaded from the context's properties).
`NamingService` `namingService()` Pull up the naming service used in this context.
`PetNameDB` `petnameDb()`
`RandomSource` `random()` [insert snarky comment here]
`RoutingKeyGenerator` `routingKeyGenerator()` Determine how much do we want to mess with the keys to turn them into something we can route.
`SessionKeyManager` `sessionKeyManager()` The session key manager which coordinates the sessionKey / sessionTag data.
`SHA256Generator` `sha()` Our SHA256 instance (see the hmac discussion for why its context specific)
`StatManager` `statManager()` The statistics component with which we can track various events over time.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### _globalAppContext

    protected static I2PAppContext _globalAppContext

  the context that components without explicit root are bound

### _clock

    protected Clock _clock

### _clockInitialized

    protected volatile boolean _clockInitialized

Constructor Detail

### I2PAppContext

    public I2PAppContext()

  Lets root a brand new context

### I2PAppContext

    public I2PAppContext(java.util.Properties envProps)

  Lets root a brand new context

Method Detail

### getGlobalContext

    public static I2PAppContext getGlobalContext()

  Pull the default context, creating a new one if necessary, else using the first one created.

### getProperty

    public java.lang.String getProperty(java.lang.String propName)

  Access the configuration attributes of this context, using properties provided during the context construction, or falling back on System.getProperty if no properties were provided during construction (or the specified prop wasn't included).

### getProperty

    public java.lang.String getProperty(java.lang.String propName,
                                        java.lang.String defaultValue)

  Access the configuration attributes of this context, using properties provided during the context construction, or falling back on System.getProperty if no properties were provided during construction (or the specified prop wasn't included).

### getPropertyNames

    public java.util.Set getPropertyNames()

  Access the configuration attributes of this context, listing the properties provided during the context construction, as well as the ones included in System.getProperties.

  Returns:
    set of Strings containing the names of defined system properties

### statManager

    public StatManager statManager()

  The statistics component with which we can track various events over time.

### sessionKeyManager

    public SessionKeyManager sessionKeyManager()

  The session key manager which coordinates the sessionKey / sessionTag data. This component allows transparent operation of the ElGamal/AES+SessionTag algorithm, and contains all of the session tags for one particular application. If you want to seperate multiple apps to have their own sessionTags and sessionKeys, they should use different I2PAppContexts, and hence, different sessionKeyManagers.

### namingService

    public NamingService namingService()

  Pull up the naming service used in this context. The naming service itself works by querying the context's properties, so those props should be specified to customize the naming service exposed.

### petnameDb

    public PetNameDB petnameDb()

### elGamalEngine

    public ElGamalEngine elGamalEngine()

  This is the ElGamal engine used within this context. While it doesn't really have anything substantial that is context specific (the algorithm just does the algorithm), it does transparently use the context for logging its performance and activity. In addition, the engine can be swapped with the context's properties (though only someone really crazy should mess with it ;)

### elGamalAESEngine

    public ElGamalAESEngine elGamalAESEngine()

  Access the ElGamal/AES+SessionTag engine for this context. The algorithm makes use of the context's sessionKeyManager to coordinate transparent access to the sessionKeys and sessionTags, as well as the context's elGamal engine (which in turn keeps stats, etc).

### aes

    public AESEngine aes()

  Ok, I'll admit it. there is no good reason for having a context specific AES engine. We dont really keep stats on it, since its just too fast to matter. Though for the crazy people out there, we do expose a way to disable it.

### logManager

    public LogManager logManager()

  Query the log manager for this context, which may in turn have its own set of configuration settings (loaded from the context's properties). Each context's logManager keeps its own isolated set of Log instances with their own log levels, output locations, and rotation configuration.

### hmac

    public HMACGenerator hmac()

  There is absolutely no good reason to make this context specific, other than for consistency, and perhaps later we'll want to include some stats.

### hmac256

    public HMAC256Generator hmac256()

### sha

    public SHA256Generator sha()

  Our SHA256 instance (see the hmac discussion for why its context specific)

### dsa

    public DSAEngine dsa()

  Our DSA engine (see HMAC and SHA above)

### keyGenerator

    public KeyGenerator keyGenerator()

  Component to generate ElGamal, DSA, and Session keys. For why it is in the appContext, see the DSA, HMAC, and SHA comments above.

### clock

    public Clock clock()

  The context's synchronized clock, which is kept context specific only to enable simulators to play with clock skew among different instances.

### initializeClock

    protected void initializeClock()

### routingKeyGenerator

    public RoutingKeyGenerator routingKeyGenerator()

  Determine how much do we want to mess with the keys to turn them into something we can route. This is context specific because we may want to test out how things react when peers don't agree on how to skew.

### random

    public RandomSource random()

  [insert snarky comment here]