Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
references #215 Implement an asynch processing API based on HornetQ
- Loading branch information
Igor Polevoy
committed
Apr 6, 2015
1 parent
8086a07
commit 6104022
Showing
12 changed files
with
605 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
activeweb/src/main/java/org/javalite/activeweb/async/Host.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
37 changes: 37 additions & 0 deletions
37
javalite-hornet-nest/src/main/java/org/javalite/hornet_nest/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
45 changes: 45 additions & 0 deletions
45
javalite-hornet-nest/src/main/java/org/javalite/hornet_nest/CommandListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
Oops, something went wrong.