com.sag.osami.contextstore
Class ContextStoreBuilder

java.lang.Object
  extended by com.sag.osami.contextstore.ContextStoreBuilder

public class ContextStoreBuilder
extends java.lang.Object

This builder class can be used in non-OSGi-evnironments to configure and create a ContextStore instance conveniently.

It is also used internally in the OsgiContextStoreActivator (using registered OSGi services as the respective implementations).

It provides methods (all of which return the builder itself, allowing to chain the configuration in one line) for configuring:

Additionally, it can be configured via a .properties configuration file in '/' on the CLASSPATH or any file defined via the builder constructor. Also, it can be configured via system properties (using the same configuration keys as in the .properties file, but with the prefix ).

Following properties can be configured:

The most simple, but working usage example for this class looks like this:
 ContextStore store = new ContextStoreBuilder().build();
 


Field Summary
static java.lang.String CONFIG_STORE_ID
           
 
Constructor Summary
ContextStoreBuilder()
          Creates a new ContextStore builder with defaults.
ContextStoreBuilder(java.io.File propsFile)
          Creates a new ContextStore builder, overriding defaults with the properties from the given file.
ContextStoreBuilder(java.util.Properties props)
          Creates a new ContextStore builder, overriding defaults with the given properties.
 
Method Summary
 ContextStore build()
          Builds the ContextStore according to the configuration.
 ContextStoreBuilder jdbcDialect(IJDBCDialect jdbcDialect)
          Sets the dialect to be used by the JDBCStorage.
 ContextStoreBuilder serializer(ISerializationHandler serializer)
          Sets the serialization handler implementation, which is used for serializing and deserializing context events (e.g. when persisting).
 ContextStoreBuilder storage(ISerializedContextStorage storage)
          Sets the storage implementation, which is responsible for persisting, loading and querying context events.
 ContextStoreBuilder storeID(java.lang.String storeID)
          Sets the context store ID as used in ContextEvent.getContextStoreOriginID().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_STORE_ID

public static final java.lang.String CONFIG_STORE_ID
See Also:
Constant Field Values
Constructor Detail

ContextStoreBuilder

public ContextStoreBuilder(java.util.Properties props)
Creates a new ContextStore builder, overriding defaults with the given properties.

Parameters:
props - configuration properties

ContextStoreBuilder

public ContextStoreBuilder(java.io.File propsFile)
Creates a new ContextStore builder, overriding defaults with the properties from the given file.

Parameters:
propsFile - '.properties' file

ContextStoreBuilder

public ContextStoreBuilder()
Creates a new ContextStore builder with defaults.

Method Detail

serializer

public ContextStoreBuilder serializer(ISerializationHandler serializer)
Sets the serialization handler implementation, which is used for serializing and deserializing context events (e.g. when persisting).

Default: JSONSerializer

Parameters:
serializer - the implementation of the serialization handler
Returns:
the builder itself

storage

public ContextStoreBuilder storage(ISerializedContextStorage storage)
Sets the storage implementation, which is responsible for persisting, loading and querying context events.

Default: JDBCStorage with DerbyDialect and DerbyDialect.DEFAULT_URL.

Parameters:
storage - the implementation of the storage
Returns:
the builder itself
See Also:
jdbcDialect(IJDBCDialect)

jdbcDialect

public ContextStoreBuilder jdbcDialect(IJDBCDialect jdbcDialect)
Sets the dialect to be used by the JDBCStorage.

Default: DerbyDialect

Parameters:
jdbcDialect - the implementation of the JDBC dialect
Returns:
the builder itself

storeID

public ContextStoreBuilder storeID(java.lang.String storeID)
Sets the context store ID as used in ContextEvent.getContextStoreOriginID().

Default: hostname of the executing machine

Parameters:
storeID - the context store ID
Returns:
the builder itself

build

public ContextStore build()
Builds the ContextStore according to the configuration.

Returns:
the context store instance