initial
This commit is contained in:
commit
03e403d717
26
.classpath
Normal file
26
.classpath
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target
|
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>HottisLibJava</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
37
pom.xml
Normal file
37
pom.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<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>
|
||||
<groupId>de.hottis.common</groupId>
|
||||
<artifactId>HottisLibJava</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>HottisLibJava</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
<version>5.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
14
src/main/java/de/hottis/common/HottisCommonException.java
Normal file
14
src/main/java/de/hottis/common/HottisCommonException.java
Normal file
@ -0,0 +1,14 @@
|
||||
package de.hottis.common;
|
||||
|
||||
public class HottisCommonException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public HottisCommonException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public HottisCommonException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
5
src/main/java/de/hottis/common/ITriggerable.java
Normal file
5
src/main/java/de/hottis/common/ITriggerable.java
Normal file
@ -0,0 +1,5 @@
|
||||
package de.hottis.common;
|
||||
|
||||
public interface ITriggerable {
|
||||
public void trigger();
|
||||
}
|
124
src/main/java/de/hottis/common/JmsTopic.java
Normal file
124
src/main/java/de/hottis/common/JmsTopic.java
Normal file
@ -0,0 +1,124 @@
|
||||
package de.hottis.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.ObjectMessage;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class JmsTopic<T extends Serializable> implements MyQueue<T> {
|
||||
static final String JMS_PARSED_DATA_TOPIC = "jms.parseddata.topic";
|
||||
static final String JMS_CLIENTID_PROP = "jms.clientid";
|
||||
static final String JMS_BROKER ="jms.broker";
|
||||
|
||||
static public enum Mode { CONSUMER, PRODUCER, CONSUMER_PRODUCER };
|
||||
|
||||
final protected Logger logger = LogManager.getRootLogger();
|
||||
|
||||
private String clientId;
|
||||
private Properties config;
|
||||
private Connection connection;
|
||||
private Session session;
|
||||
private Topic topic;
|
||||
private MessageProducer producer;
|
||||
private MessageConsumer consumer;
|
||||
private String topicTxt;
|
||||
private String broker;
|
||||
private Mode mode;
|
||||
|
||||
public JmsTopic(Properties config, Mode mode) {
|
||||
this.config = config;
|
||||
clientId = this.config.getProperty(JMS_CLIENTID_PROP);
|
||||
topicTxt = this.config.getProperty(JMS_PARSED_DATA_TOPIC);
|
||||
broker = this.config.getProperty(JMS_BROKER);
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
|
||||
public void init() throws HottisCommonException {
|
||||
try {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker);
|
||||
connectionFactory.setTrustAllPackages(true);
|
||||
logger.debug("connectionFactory: " + connectionFactory);
|
||||
connection = connectionFactory.createConnection();
|
||||
connection.setClientID(clientId);
|
||||
connection.start();
|
||||
logger.debug("connection: " + connection);
|
||||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
logger.debug("session: " + session);
|
||||
topic = session.createTopic(topicTxt);
|
||||
logger.debug("topic: " + topic);
|
||||
|
||||
if ((mode == Mode.PRODUCER) || (mode == Mode.CONSUMER_PRODUCER)) {
|
||||
producer = session.createProducer(topic);
|
||||
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
logger.debug("producer: " + producer);
|
||||
} else {
|
||||
producer = null;
|
||||
}
|
||||
|
||||
if ((mode == Mode.CONSUMER) || (mode == Mode.CONSUMER_PRODUCER)) {
|
||||
consumer = session.createDurableSubscriber(topic, "DatabaseEngine");
|
||||
logger.debug("consumer: " + consumer);
|
||||
} else {
|
||||
consumer = null;
|
||||
}
|
||||
|
||||
} catch (JMSException e) {
|
||||
logger.error("JMSException in AJmsQueue.init", e);
|
||||
throw new HottisCommonException("JMSException in AJmsTopic.init", e);
|
||||
}
|
||||
}
|
||||
|
||||
public T dequeue() throws HottisCommonException {
|
||||
if (consumer == null) {
|
||||
throw new HottisCommonException("This is no consumer");
|
||||
}
|
||||
try {
|
||||
ObjectMessage message = (ObjectMessage) consumer.receiveNoWait();
|
||||
T item;
|
||||
if (message != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T t = (T) message.getObject();
|
||||
item = t;
|
||||
logger.debug("message dequeued");
|
||||
} else {
|
||||
item = null;
|
||||
}
|
||||
return item;
|
||||
} catch (JMSException e) {
|
||||
logger.error("JMSException in JmsTopic.dequeue", e);
|
||||
logger.error("Calling init");
|
||||
init();
|
||||
throw new HottisCommonException("JMSException in JmsTopic.dequeue", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void enqueue(T item) throws HottisCommonException {
|
||||
if (producer == null) {
|
||||
throw new HottisCommonException("This is no producer");
|
||||
}
|
||||
try {
|
||||
ObjectMessage message = session.createObjectMessage();
|
||||
message.setObject(item);
|
||||
producer.send(message);
|
||||
logger.debug("message enqueued");
|
||||
} catch (JMSException e) {
|
||||
logger.error("JMSException in JmsTopic.enqueue", e);
|
||||
logger.error("Calling init");
|
||||
init();
|
||||
throw new HottisCommonException("JMSException in JmsTopic.enqueue", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
src/main/java/de/hottis/common/MyQueue.java
Normal file
8
src/main/java/de/hottis/common/MyQueue.java
Normal file
@ -0,0 +1,8 @@
|
||||
package de.hottis.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface MyQueue<T extends Serializable> {
|
||||
public T dequeue() throws HottisCommonException;
|
||||
public void enqueue(T item) throws HottisCommonException;
|
||||
}
|
15
src/main/java/de/hottis/common/TriggerTimer.java
Normal file
15
src/main/java/de/hottis/common/TriggerTimer.java
Normal file
@ -0,0 +1,15 @@
|
||||
package de.hottis.common;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class TriggerTimer extends TimerTask {
|
||||
private ITriggerable triggerable;
|
||||
|
||||
public TriggerTimer(ITriggerable triggerable) {
|
||||
this.triggerable = triggerable;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
triggerable.trigger();
|
||||
}
|
||||
}
|
38
src/test/java/de/hottis/common/AppTest.java
Normal file
38
src/test/java/de/hottis/common/AppTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
package de.hottis.common;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user