Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
[RELEASE]squashing 'release/1.3' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xERR0R committed Nov 3, 2017
2 parents d716b8a + 72ccf1b commit bba3784
Show file tree
Hide file tree
Showing 38 changed files with 1,016 additions and 331 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: java
sudo: false
install: true

jdk:
- oraclejdk8
script:
- mvn clean install sonar:sonar -Dsonar.organization=0xerr0r-github -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.sonar/cache'

after_success:
- bash <(curl -s https://codecov.io/bash)
10 changes: 0 additions & 10 deletions DEV.md

This file was deleted.

29 changes: 26 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

<parent>
<groupId>jmstool</groupId>
<artifactId>jmstool2</artifactId>
<version>1.2</version>
<artifactId>jmstool</artifactId>
<version>1.3</version>
</parent>
<properties>
<mockrunner-version>1.0.4</mockrunner-version>
<mockrunner-version>1.1.1</mockrunner-version>
</properties>

<dependencies>
Expand Down Expand Up @@ -62,6 +62,29 @@
<version>${mockrunner-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>2.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.machinezoo.noexception</groupId>
<artifactId>noexception</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>
<finalName>jmstool</finalName>
Expand Down
11 changes: 11 additions & 0 deletions backend/src/main/java/jmstool/BadRequestException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package jmstool;

public class BadRequestException extends IllegalStateException {

private static final long serialVersionUID = 1L;

public BadRequestException(String s) {
super(s);
}

}
24 changes: 6 additions & 18 deletions backend/src/main/java/jmstool/Jmstool2Application.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package jmstool;

import java.util.Properties;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.ConversionService;
Expand All @@ -25,8 +21,10 @@
@EnableJms
public class Jmstool2Application extends SpringBootServletInitializer {

public static void main(String[] args) {
SpringApplication.run(Jmstool2Application.class, args);
static {
// LocalDateTime should be serialized in a string, which can be read in
// javascript
System.setProperty("spring.jackson.serialization.write_dates_as_timestamps", "false");
}

@Bean
Expand All @@ -35,18 +33,8 @@ public TaskExecutor taskExecutor() {
}

@Bean
public CommandLineRunner schedulingRunner(TaskExecutor executor, AsyncMessageSender sender) {
return new CommandLineRunner() {
public void run(String... args) throws Exception {
executor.execute(sender);
}
};
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Jmstool2Application.class)
.properties("spring.jackson.serialization.write_dates_as_timestamps=false");
public CommandLineRunner asyncMessageSenderExecutorRunner(TaskExecutor executor, AsyncMessageSender sender) {
return (args) -> executor.execute(sender);
}

@Bean
Expand Down
68 changes: 55 additions & 13 deletions backend/src/main/java/jmstool/QueueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.listener.MessageListenerContainer;
import org.springframework.jms.support.destination.JndiDestinationResolver;
import org.springframework.jndi.JndiLocatorDelegate;
import org.springframework.stereotype.Component;

import com.machinezoo.noexception.Exceptions;

import jmstool.jms.JmsMessageListener;
import jmstool.storage.LocalMessageStorage;

Expand All @@ -28,7 +34,7 @@
*
*/
@Component
public class QueueManager implements CommandLineRunner, DisposableBean {
public class QueueManager implements CommandLineRunner {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Value("${jmstool.incomingQueues:}")
Expand All @@ -50,22 +56,35 @@ public class QueueManager implements CommandLineRunner, DisposableBean {

@Override
public void run(String... arg0) throws Exception {
for (final String queue : incomingQueues) {
logger.info("registering listener for incoming queue '{}'", queue);

// lookup to fail fast
new JndiLocatorDelegate().lookup(queue, Queue.class);
DefaultMessageListenerContainer c = createContainer(queue);
containers.add(c);
c.start();
for (final String queue : incomingQueues) {
registerIncomingQueue(queue);
}

for (final String queue : outgoingQueues) {
logger.info("lookup outgoing queue '{}'", queue);
new JndiLocatorDelegate().lookup(queue, Queue.class);
registerOutgoingQueue(queue);
}
}

private void registerOutgoingQueue(final String queue) {
logger.info("lookup outgoing queue '{}'", queue);
lookupQueue(queue);
}

private void registerIncomingQueue(final String queue) {
logger.info("registering listener for incoming queue '{}'", queue);

// lookup to fail fast
lookupQueue(queue);
DefaultMessageListenerContainer c = createContainer(queue);
containers.add(c);
c.start();
}

private void lookupQueue(String queue) {
Exceptions.sneak().get(() -> new JndiLocatorDelegate().lookup(queue, Queue.class));
}

private DefaultMessageListenerContainer createContainer(String queue) {
DefaultMessageListenerContainer c = new DefaultMessageListenerContainer();
c.setConnectionFactory(cf);
Expand All @@ -81,10 +100,33 @@ public List<String> getOutgoingQueues() {
return Collections.unmodifiableList(outgoingQueues);
}

@Override
public void destroy() throws Exception {
@PreDestroy
public void shutdown() {
logger.debug("destroying running containers on shutdown");
for (DefaultMessageListenerContainer c : containers) {
c.shutdown();
}
}

public Map<String, Boolean> getListenerStatus() {
return containers.stream().collect(Collectors.toMap(c -> c.getDestinationName(), c -> c.isRunning()));

}

private MessageListenerContainer findContainerForQueue(String queue) {
Optional<DefaultMessageListenerContainer> container = containers.stream()
.filter(c -> c.getDestinationName().equals(queue)).findFirst();
return container.orElseThrow(() -> new BadRequestException("Couldn't find a listener for queuev" + queue));

}

public void stopListener(String queue) {
logger.debug("stopping listener container for queue {}", queue);
findContainerForQueue(queue).stop();
}

public void startListener(String queue) {
logger.debug("starting listener container for queue {}", queue);
findContainerForQueue(queue).start();
}
}
Loading

0 comments on commit bba3784

Please sign in to comment.