Skip to content

Commit

Permalink
references #215 Implement an asynch processing API based on HornetQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Polevoy committed Apr 6, 2015
1 parent 8086a07 commit 6104022
Show file tree
Hide file tree
Showing 12 changed files with 605 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activeweb/pom.xml
Expand Up @@ -70,6 +70,6 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
</dependency>
</dependencies>
</project>
18 changes: 18 additions & 0 deletions activeweb/src/main/java/org/javalite/activeweb/async/Host.java
@@ -0,0 +1,18 @@
package org.javalite.activeweb.async;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* @author Igor Polevoy on 3/4/15.
*/
public class Host {

public static String get() {
String res = "127.0.0.1";
try {
res = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignored) {}
return res;
}
}
7 changes: 7 additions & 0 deletions javalite-hornet-nest/README.md
@@ -0,0 +1,7 @@
# Hornet Nest is an asynchronous processor for Java applications

This is a simple to use library for processing asynchronous jobs. It can be used in a web application to process
jobs in a thread separate from the one that renders HMTL. It is also a genera purpose library that can be used in any
non-web system.

Internal Implementation is based on [JBoss HornetQ](http://hornetq.jboss.org/).
53 changes: 53 additions & 0 deletions javalite-hornet-nest/pom.xml
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>javalite-hornet-nest</artifactId>
<version>1.12-SNAPSHOT</version>
<name>JavaLite - Hornet Nest</name>
<packaging>jar</packaging>

<parent>
<groupId>org.javalite</groupId>
<artifactId>activeweb-root</artifactId>
<version>1.12-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.javalite</groupId>
<artifactId>javalite-common</artifactId>
</dependency>

<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-server</artifactId>
</dependency>

<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-client</artifactId>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-server</artifactId>
</dependency>

</dependencies>

</project>
@@ -0,0 +1,37 @@
/*
Copyright 2009-2015 Igor Polevoy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/


package org.javalite.hornet_nest;

/**
* Implementations of this interface will have to know how to serialize themselves into
* a string using a <code>toString()</code> method and how to de-serialize from string using <code>fromString(String)</code>
* method.
*
* @author Igor Polevoy on 4/4/15.
*/
public interface Command {
/**
* Implementation will have to de-serialize from string.
*
* @param commandString String representation of a command. Can be XML, JSON or whatever you like,
* so long as <code>toString()</code> produces a string and this method initializes a new
* object with the same exact values.
*/
void fromString(String commandString);
void execute();
}
@@ -0,0 +1,45 @@
/*
Copyright 2009-2015 Igor Polevoy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.javalite.hornet_nest;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
* @author Igor Polevoy on 4/5/15.
*/
public class CommandListener implements MessageListener{

@Override
public void onMessage(Message message) {
TextMessage tm = (TextMessage) message;
try {
String className = tm.getStringProperty("command_class");
Command command = (Command) Class.forName(className).newInstance();
command.fromString(tm.getText());
onCommand(command);
} catch (Exception e) {
throw new HornetNestException("Failed to process command", e);
}
}

public <T extends Command> void onCommand(T command) {
command.execute();
}

}

0 comments on commit 6104022

Please sign in to comment.