As humans, we tend to think of the world in objects. For instance, my car has four tires and my body has a pair of arms and legs. Since everything around us is thought of as objects, then why would we want to write code that stores data relationally? The short answer is; we are forced to based on the way traditional databases store data.
Let’s say for instance we have a group of Students that wish to enroll in several University Courses. Storing the Students and Courses in a relational database is trivial, however, how do we express Students that are enrolled in Courses? This is a typical many-to-many relationship where any number of students can be enrolled in any number of courses.
In the world of databases, a single table is created for Students and another for Courses. Then, a third table is created that holds the students that are enrolled in each course. The Enrolled table is called a cross-reference table.
This poses a problem for object oriented languages such as Java, C#, and Ruby because, while we don’t mind creating separate Student and Course objects, creating a third Enrolled object is poor OO design and will… Read the rest
Algorithmic Art – also known as Computational Art – is a form of expression that uses various algorithms and processing techniques to create visually aesthetic digital artwork in the form of still images, animations, and music.
Processing is an open source programming language and environment invented by Ben Fry and Casey Reyes from the MIT Media Lab that provides a way for anyone to create algorithmic art. Even you! Simply download Processing and follow one of the introductory tutorials to get started.
Here is a piece of algorithmic art I created by extending one of the 2D Array Processing tutorial.
This is the code used to create the animation below. Just copy and paste into your Processing editor and run to get the same output.
Square[][] grid;
int numCols = 10;
int numRows = 10;
//Called at the initialization of the program.
void setup() {
size(300, 300);
grid = new Square[numCols][numRows];
for (int x = 0; x < numCols; x++) {
for (int y = 0; y < numRows; y++) {
grid[x][y] = new Square(x * 30, y * 30, 30, 30, (x + y) * cos(y));
}
}
}
//The draw method acts
Now that the hard parts are finished, all that’s left is to run our bundle in the Knopflerfish Desktop.
Click File -> Open Bundle File (Ctrl+O) and select the bundle we created in Part 2 (the default is:
/out). Note, the bundle .jar file gets built automatically through Eclipse.
Once the bundle has been loaded into the Knopflerfish OSGi Desktop simply hit the Start Bundle button and watch it go!
And that’s it! You have just created your very first OSGi bundle using Eclipse and Knopflerfish. The RandomRoll application is probably one of the lamest apps around, so go and make something awesome and send me a comment when you do.
This is Part 3 of a 3 part introduction to OSGi and Knopflerfish.
SOA OSGi Development with Knopflerfish – Part 1: The Setup
SOA OSGi Development with Knopflerfish – Part 2: The Code
SOA OSGi Development with Knopflerfish – Part 3: The Execution
Now that we have Eclipse and Knopflerfish installed let’s get into some code. This OSGi bundle will roll a random six-sided die every second and print the result to the Knopflerfish Desktop console.
Click File -> New Project and select OSGi Bundle
Fill in the project information, I am going to call this project RandomRoll.
This is the OSGi specific information, make sure you check the “Create Activator” class box (More on this later.)
The manifest file contains all of the OSGi required information for your bundle. The Eclipse OSGi plugin has a built-in editor for the bundle.manifest file to make editing it a little easier on you.
Your default bundle.manifest file should look like this.
Manifest-Version: 1.0 Bundle-Name: RandomRoll Bundle-Description: Roll a die every second Bundle-Activator: RandomRoll.Activator Import-Package: org.osgi.framework Bundle-Vendor: Tutorial Bundle-ManifestVersion: 2 Bundle-SymbolicName: RandomRoll Bundle-Version: 1.0.0
This is where the logic of our OSGi application lies. We’ll treat the RandomRoll class just like any other class. The only OSGi requirement is that RandomRoll must extend java.lang.Thread.
package RandomRoll;
import java.util.Random;
public class RandomRoll extends Thread {
private boolean running = true;
public RandomRoll() {
The OSGi framework allows Java developers to create a dynamic component model for their applications. Developers create “bundles” that can be deployed and executed remotely and provide distributed services. The OSGi Framework can act as a Install New Software
Next, click the “Add” button and add the Knopflerfish update site: http://www.knopflerfish.org/eclipse-update/
Once the update site has been added, you should automatically see an option for the Knopflerfish plugin. Check the box and hit “Next” to install. Read the license terms and complete the installation.
Now, we can create OSGi Projects (More on that later)
Download the latest stable release from the Knopflerfish website. I will be using the complete framework version 2.3.3 for this tutorial.
Now, we need to install the Knopflerfish framework:
java –jar knopflerfish_osgi_.jar
This will open up an installation wizard which will let you set an installation directory.
Finally, we need to run Knopflerfish:
java –jar framework.jar
You should now see the Knopflerfish OSGi Desktop. This is where we will register our bundles and execute them.
Now we’re finally ready to write our first bundle, time to move on to Part 2.
This is Part 3 of a… Read the rest