diff --git a/li.strolch.website/www.strolch.li/blog.html b/li.strolch.website/www.strolch.li/blog.html index 6123ad003..021c56f79 100644 --- a/li.strolch.website/www.strolch.li/blog.html +++ b/li.strolch.website/www.strolch.li/blog.html @@ -36,6 +36,7 @@
Setting up Strolch is just a few lines:
-+mkdir strolch cd strolch git clone https://github.com/eitchnet/li.strolch.dev.git cd li.strolch.dev ./bootstrap_https.sh -mvn clean package -DskipTests=true+mvn clean install -DskipTests
Note: If you want to run the tests, then either install a PostgreSQL DB and configure the users as is required by the project, or remove the project from the li.strolch.dev module build, otherwise the build will fail =))
After running the Maven build, you will have a full build of all Strolch projects. Now you can start modifying the projects, and add your own features, or, far more interesting, start developing your projects using the Strolch agent.
+To use Strolch in your own projects, look at the two tutorial apps on how they are configured. You can also simply copy the projects, modify the Maven POMs and remove what ever you do not need.
+The following sections describe the Strolch configuration files and folder structure.
+ +Strolch requires two main directories under the Strolch root:
+Strolch is built using Maven, so here we show the minimum Maven POM.
+ +This POM creates a compressed file which contains a runnable Strolch instance. Just unpack and run the startup.sh script.
++<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <properties> + <strolch.version>1.0.0-SNAPSHOT</strolch.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <finalName>strolch_app</finalName> + <m2eclipse.wtp.contextRoot>${finalName}</m2eclipse.wtp.contextRoot> + <buildTimestamp>${maven.build.timestamp}</buildTimestamp> + </properties> + + <groupId>org.example</groupId> + <artifactId>org.example.strolch.app</artifactId> + <version>1.0.0-SNAPSHOT</version> + <name>org.example.strolch.app</name> + + <scm> + <developerConnection>scm:git:https://git.example.org/strolch_app.git</developerConnection> + </scm> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.bom</artifactId> + <type>pom</type> + <version>${strolch.version}</version> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <!-- main --> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.model</artifactId> + <version>${strolch.version}</version> + </dependency> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.agent</artifactId> + <version>${strolch.version}</version> + </dependency> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.service</artifactId> + <version>${strolch.version}</version> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>runtime</scope> + <version>1.7.2</version> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + <version>4.11</version> + </dependency> + </dependencies> + + <build> + <finalName>${finalName}</finalName> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>**/componentVersion.properties</include> + </includes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + <excludes> + <exclude>**/componentVersion.properties</exclude> + </excludes> + </resource> + </resources> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.0</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + <showDeprecation>true</showDeprecation> + <showWarnings>true</showWarnings> + <compilerArgument>-Xlint:all</compilerArgument> + </configuration> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>buildnumber-maven-plugin</artifactId> + <version>1.2</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>create</goal> + </goals> + </execution> + </executions> + <configuration> + <doCheck>false</doCheck> + <doUpdate>false</doUpdate> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + + <!-- When creating an executable jar, use copy-dependencies plugin with libs in lib/ dir: --> + <mainClass>li.strolch.tutorialapp.main.Main</mainClass> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + </manifest> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptor>src/assembly/bin.xml</descriptor> + <finalName>tutorial-app-${project.version}</finalName> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project>+ +
This creates a simple WAR which starts Strolch after deployed to a servlet container.
++<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <properties> + <strolch.version>1.0.0-SNAPSHOT</strolch.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <warFinalName>strolch_webapp</warFinalName> + <m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot> + <buildTimestamp>${maven.build.timestamp}</buildTimestamp> + </properties> + + <groupId>org.example</groupId> + <artifactId>org.example.strolch.webapp</artifactId> + <version>1.0.0-SNAPSHOT</version> + <name>org.example.strolch.webapp</name> + <packaging>war</packaging> + + <scm> + <developerConnection>scm:git:https://git.example.org/strolch_webapp.git</developerConnection> + </scm> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.bom</artifactId> + <type>pom</type> + <version>${strolch.version}</version> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <!-- main --> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.model</artifactId> + <version>${strolch.version}</version> + </dependency> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.agent</artifactId> + <version>${strolch.version}</version> + </dependency> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.service</artifactId> + <version>${strolch.version}</version> + </dependency> + <dependency> + <groupId>li.strolch</groupId> + <artifactId>li.strolch.rest</artifactId> + <version>${strolch.version}</version> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>runtime</scope> + <version>1.7.2</version> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.0.1</version> + <scope>provided</scope> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + <version>4.11</version> + </dependency> + + </dependencies> + + <build> + <finalName>${warFinalName}</finalName> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>**/componentVersion.properties</include> + </includes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + <excludes> + <exclude>**/componentVersion.properties</exclude> + </excludes> + </resource> + </resources> + + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.0</version> + <configuration> + <source>1.7</source> + <target>1.7</target> + <showDeprecation>true</showDeprecation> + <showWarnings>true</showWarnings> + <compilerArgument>-Xlint:all</compilerArgument> + </configuration> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>buildnumber-maven-plugin</artifactId> + <version>1.2</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>create</goal> + </goals> + </execution> + </executions> + <configuration> + <doCheck>false</doCheck> + <doUpdate>false</doUpdate> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <failOnMissingWebXml>false</failOnMissingWebXml> + <warName>${warFinalName}</warName> + <webResources> + <resource> + <directory>src/main/non-packaged-resources</directory> + <targetPath>WEB-INF</targetPath> + <filtering>true</filtering> + <includes> + <include>**/ENV.properties</include> + </includes> + </resource> + </webResources> + </configuration> + </plugin> + + </plugins> + </build> + + <profiles> + <profile> + <id>m2e</id> + <!-- This profile is only activated when building in Eclipse with m2e --> + <activation> + <property> + <name>m2e.version</name> + </property> + </activation> + <properties> + <strolch.env>dev</strolch.env> + </properties> + </profile> + </profiles> +</project>+ + +
Happy coding =))
diff --git a/li.strolch.website/www.strolch.li/downloads.html b/li.strolch.website/www.strolch.li/downloads.html index d180f7034..819ac5f1d 100644 --- a/li.strolch.website/www.strolch.li/downloads.html +++ b/li.strolch.website/www.strolch.li/downloads.html @@ -36,6 +36,7 @@Strolch is written in Java and is programmed against the JDK 7. Strolch runs on any JRE 7 compliant environment. Strolch is tested on the Oracle JRE 7.
Strolch strives to use as few external dependencies as possible, so that the Strolch runtime is not bloated unnecessarily. The following list of Strolch dependencies is a summary and was created using mvn dependency:tree on the li.strolch.dev project on the 2014-03-08.
+Strolch strives to use as few external dependencies as possible, so that the Strolch runtime is not bloated unnecessarily. The following list of Strolch dependencies is a summary and was created using mvn dependency:tree on the li.strolch.dev project on the 2014-09-18.
implements the authorization and authentication in Strolch
Consists of utility classes for recurring problems
Implements the XML Persistence layer used by li.strolch.persistence.xml
Implements the PostgreSQL Persistence layer used by li.strolch.persistence.postgresql
Testing facilities
Logging facilities
Logging facilities API
+Logging facilities Implementation
If you want to access Strolch using the RESTful API, then we got you covered - but sadly RESTful service development requires quite a few extra dependencies:
The Strolch model is implemented in the project li.strolch.model.
- - The Strolch model consists of two root level elements: Resource and Order. Each element has at least the following attributes: -Each root element can have any number of ParameterBag instances on it, which in turn can have any number of Parameters on it. Accessing these objects is always done by their IDs. Strolch root elements are always stored in the respective ElementMaps in their Strolch realm. Thus accessing a certain parameter from a Resource would look like this:
--try (StrolchTransaction tx = realm.openTx()) { - Resource resource = tx.getResourceMap().getBy(tx, "TestType", "MyTestResource"); - DateParameter dateP = resource.getParameter("@bag01", "@param6"); - Date date = dateP.getValue(); - logger.info("@param6 date is " + date); -}- - XML Presentation of Strolch's top level elements: -
-<!-- Resource instance --> -<Resource Id="MyTestResource" Name="Test Name" Type="TestType"> - <ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag"> - <Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" /> - <Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" /> - <Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" /> - </ParameterBag> - <ParameterBag Id="@bag02" Name="Test Bag" Type="TestBag"> - <Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" /> - <Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" /> - <Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" /> - <Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" /> - </ParameterBag> -</Resource> - -<!-- Order instance --> -<Order Id="MyTestOrder" Name="Test Name" Type="TestType" Date="2013-11-20T07:42:57.699+01:00" State="CREATED"> - <ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag"> - <Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" /> - <Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" /> - <Parameter Id="@param5" Name="String Param" Type="String" Value="Strolch" /> - </ParameterBag> - <ParameterBag Id="@bag02" Name="Test Bag" Type="TestBag"> - <Parameter Id="@param4" Name="Long Param" Type="Long" Value="4453234566" /> - <Parameter Id="@param3" Name="Integer Param" Type="Integer" Value="77" /> - <Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" /> - <Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" /> - </ParameterBag> -</Order>- - -
This is a transient data store mode, where no model changes are persisted, but they are only kept in memory. When the Strolch agent is started, this realm stays empty as no data is loaded.
This is the same as EMPTY, but with the difference that when the Strolch agent is started, an XML file is parsed and the in memory realm is populated with the elements parsed from that XML file.
In this mode, all data is stored in memory, and any changes made are written back to the persistence layer. This allows for fast in-memory quries, but makes sure no data is lost when the agent is restarted.
In this mode no data is kept in memory and every query, and root element retrieval is passed to the persistence layer to be retrieved from the underlying database. This is what comes closest to a typical Java+Hibernate implementation.
Strolch Realms are also responsible for opening Transactions, as these are bound to the persistence layer configured for this realm. At runtime, a realm is then accessed from the ComponentContainer:
--ComponentContainer container = getAgent().getContainer(); -StrolchRealm realm = container.getRealm(StrolchConstants.DEFAULT_REALM); -try(StrolchTransaction tx = realm.openTx()) { - Resource resource = tx.getResourceMap().getBy(tx, "TestType", "MyTestResource"); - ... -}- In a Service implementation there is a convenience method, so that this is as simple as calling openTx(String). - -
In the motivation section, it was discusses that writing business logic is what developing is about and a reason why Strolch is a different approach to the Java EE ecosystem. So this is where Services and Commands come into play, and tries to make writing business logic a first class citizen.
- -Services are to be used once for each use case. Services are not re-used or called by other services. Services open transactions are implement the calling of the re-usable commands. Thus when writing projects using Strolch, the first thing to do after configuring the runtime environmet for your situation, Services will be implemented.
- -Commands on the other hand are re-usable and should be implemented in such a way, that the encapsulate the use case's different actions. Commands are then passed to a transaction for execution and, when the transaction is comitted, will be executed. Commands also implement undoing its operation in the case of exceptions. Strolch transactions handle the life-cycle of a command. A further function of Commands is to lock the relevant Strolch elements before execution.
- -A typical Service and Command implementation would look as follows:
--public class SetParameterService extends AbstractService<SetParameterArg, ServiceResult> { - - public static final long serialVersionUID = 1L; - - @Override - protected ServiceResult internalDoService(SetParameterArg arg) { - - // open a new transaction - try (StrolchTransaction tx = openTx(arg.realm)) { - - // find parameter to modify - Parameter<?> parameter = tx.findElement(arg.locator); - - // instantiate the command - SetParameterCommand command = new SetParameterCommand(getContainer(), tx); - - // set the arguments - command.setParameter(parameter); - command.setName(arg.name); - command.setInterpretation(arg.interpretation); - command.setUom(arg.uom); - command.setHidden(arg.hidden); - command.setIndex(arg.index); - command.setValueAsString(arg.valueAsString); - - // add the command to the transaction - tx.addCommand(command); - } - - // return the execution result of the service - return ServiceResult.success(); - } - - /** - * The argument class for this service - */ - public static class SetParameterArg extends ServiceArgument { - public static final long serialVersionUID = 1L; - public Locator locator; - - public String name; - public String interpretation; - public String uom; - public Boolean hidden; - public Integer index; - - public String valueAsString; - } - - @Override - protected ServiceResult getResultInstance() { - return new ServiceResult(); - } -} -- -
-public class SetParameterCommand extends Command { - - // input fields - private Parameter<?> parameter; - private String valueAsString; - - // undo fields - private String oldValueAsString; - - private StrolchRootElement replacedElement; - - /** - * @param container - * @param tx - */ - public SetParameterCommand(ComponentContainer container, StrolchTransaction tx) { - super(container, tx); - } - - // setters for input ... - // getters for output ... - - @Override - public void validate() { - DBC.PRE.assertNotNull("Parameter may not be null!", this.parameter); - } - - @Override - public void doCommand() { - - // lock the element to be modified - StrolchRootElement rootElement = this.parameter.getRootElement(); - tx().lock(rootElement); - - // perform changes - if (this.valueAsString != null) { - this.oldValueAsString = this.parameter.getValueAsString(); - SetParameterValueVisitor visitor = new SetParameterValueVisitor(); - visitor.setValue(this.parameter, this.valueAsString); - } - - // update root element - if (hasChanges()) { - replacedElement = new UpdateElementVisitor(tx()).update(rootElement); - } - } - - private boolean hasChanges() { - return this.oldValueAsString != null || this.oldName != null || this.oldInterpretation != null - || this.oldUom != null || this.oldHidden != null || this.oldIndex != null; - } - - @Override - public void undo() { - - // undo changes - if (this.oldValueAsString != null) { - SetParameterValueVisitor visitor = new SetParameterValueVisitor(); - visitor.setValue(this.parameter, this.oldValueAsString); - } - - // update root element - if (hasChanges() && this.replacedElement != null && this.replacedElement != this.parameter.getRootElement()) { - new UpdateElementVisitor(tx()).update(replacedElement); - } - } - } -}- -
The Strolch code can be retrieved from GitHub, where the code is hosted. Each commit triggers a continuous integration build, so that SNAPSHOT builds can be quickly integrated in projects if needed.
- -Strolch is divided up into different projects on GitHub so that these projects can be developed, or bugfixed independently and not all parts are required in every context.
- -All Strolch projects on GitHub
- -This project implements the Strolch model. This is where you will find the different elements that can store data at runtime. Currently there are two root elements: Resource and Order
The agent is the Strolch runtime and is the component which implements the core Agent functionality. That is:
-Implements the basic Services and the re-usable Commands:
-Implements a PostgreSQL persistence layer so that the Strolch model can be persisted to a PostgreSQL RDBMS when the realm is configured to have a data store mode of either CACHED or TRANSACTIONAL
-Implements an XML persistence layer so that the Strolch model can be persisted to XML files when the realm is configured to have a data store mode of either CACHED or TRANSACTIONAL. This implementation uses the xmlpers project.
-Implements a Restful API to communicate with the Strolch runtime from clients and external systems.
-To quickly get started developing Strolch, this projects provides scripts to checkout all the relevant projects and implements a Maven module so that building this projects builds all Strolch projects.
-A Maven parent project for the Strolch projects to synchronize the maven project structure
-This bill of material is a Maven project which, when imported in one's own Strolch project, pulls in all required dependencies needed to set up a minimal working Strolch environment.
-Implements a test base so that writing tests for Strolch is easy. It provides a RuntimeMock, which handles setting up and tearing down Strolch runtimes during tests.
-A tutorial application which showcases how to setup Strolch as a standalone Java SE project and starts the Strolch runtime by means of a main-class.
-A tutorial application which showcases how to setup Strolch as a standalone Java Webapp which can be deployed to a servlet container e.g. Apache Tomcat 7.
-To start getting involved with Strolch Development, or create your own applications using Strolch, then see the development page
+Check out the API page to see how to use Strolch.