To create a context from an XML context description, use the class ContextParser
Code Block |
---|
import org.tupeloproject.kernel.Context;
import edu.uiuc.ncsa.datastream.util.ContextParser;
import java.io.File;
Context context = ContextParser.parseContext(new File("contextDescription.xml")); |
The general structure of a context description file is as follows:
Code Block |
---|
<context class="java class name">
<propertyA>value1</propertyA>
<propertyB>value2</propertyB>
...
<context ....>
child context
</context>
</context> |
The properties like 'propertyA' will be considered as properties of the context and initialized by calling 'setPropertyA(value1)'. Notice this will only work when the value of the property, as expected by the respective set method in the context takes as argument a java primitive value, or a File object. This makes contexts that require more complex initializations not available through the ContextParser class.
If the property should be initialized by a method other than 'setProperty', you can specify the name of the method:
Code Block |
---|
<propertyA property="myMethod">value</propertyA> |
Finally, a CompositeContext, the main wrapper class to introduce time-annotating capabilities to a regular tupelo context, requires a DataSource object to connect to a relational database where to store the time indexes and other information. This can be specified in the XML context description file:
Code Block |
---|
<context class="edu.uiuc.ncsa.context.impl.CompositeContext">
<context ...>
child context
</context>
<dataSource>
<type>mysql</type> <!-- mysql,h2,derby,postgre -->
<url>jdbc:mysql://localhost/database>
<username>user</username>
<password>user_password</password>
</dataSource>
</context> |
Examples
A streaming context in memory
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?>
<context class="edu.uiuc.ncsa.datastream.context.impl.StreamMemoryContext">
</context> |
A streaming context in mysql
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?>
<context class="edu.uiuc.ncsa.datastream.context.impl.MysqlContext">
<url>jdbc:mysql://localhost</url>
<schema>database</schema>
<adminPassword>adminPassoword</adminPassword>
<adminUser>admin</adminUser>
<user>user</user>
<password>password</password>
</context> |
A streaming context formed of the union of other contexts
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?>
<context class="edu.uiuc.ncsa.datastream.context.impl.CompositeContext">
<context class="org.tupeloproject.kernel.UnionContext" property="setCompositedContext"/>
<context class="org.tupeloproject.kernel.impl.HashFileContext">
<depth>5</depth>
<directory>/home/user/data</directory>
</context>
<context class="org.tupeloproject.mysql.MysqlContext" >
<AdminJdbcUrl>jdbc:mysql://localhost</AdminJdbcUrl>
<Schema>database</Schema>
<JdbcUrl>jdbc:mysql://localhost</JdbcUrl>
<AdminUser>admin</AdminUser>
<AdminPassword>admin_password</AdminPassword>
<User>user</User>
<Password>user_Password</Password>
</context>
</context>
<dataSource>
<type>mysql</type>
<url>jdbc:mysql://localhost/database</url>
<username>user</username>
<password>user_password</password>
</dataSource>
</context> |
A regular mysql context (with no time-annotation capabilities)
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?>
<context class="org.tupeloproject.mysql.MysqlContext" >
<AdminJdbcUrl>jdbc:mysql://localhost</AdminJdbcUrl>
<Schema>database</Schema>
<JdbcUrl>jdbc:mysql://localhost</JdbcUrl>
<AdminUser>admin</AdminUser>
<AdminPassword>admin_password</AdminPassword>
<User>user</User>
<Password>user_Password</Password>
</context> |
A context serialized in n3 format
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?>
<context n3="/home/user/contex.n3">
</context> |