Skip to content

Commit

Permalink
Triggering Travis CI build.
Browse files Browse the repository at this point in the history
  • Loading branch information
hekonsek committed Feb 19, 2014
1 parent b11ccce commit 1bf366b
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 171 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java

This file was deleted.

12 changes: 12 additions & 0 deletions fuse-pocs-springdm-springbatch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
JBoss Fuse proof of concept - Using OSGi Compendium Configuration Admin Service in Camel Spring module
=========

In this example I demonstrate how to use
[OSGi Compendium Configuration Admin
Service](http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html) in Camel Spring module. The example is verified by companion Pax Exam tests.

In order to execute this proof of concept just run the following command in `fuse-pocs-camel-spring-properties`
directory:

mvn install

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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>

<parent>
<groupId>fuse-pocs</groupId>
<artifactId>fuse-pocs-springdm-springbatch</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>fuse-pocs-springdm-springbatch-bundle</artifactId>
<packaging>bundle</packaging>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-batch</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package fuse.pocs.camel.spring.properties;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.repository.dao.JobExecutionDao;
import org.springframework.batch.support.SerializationUtils;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.io.OptionalDataException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

public class FixedMapJobExecutionDao implements JobExecutionDao {

// OSGi-friendly deserialization utility

public static Object deserialize(byte[] bytes) {
if (bytes == null) {
return null;
}

try {
return new ObjectInputStream(new ByteArrayInputStream(bytes)) {
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
String name = desc.getName();
return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
}
}.readObject();
} catch (OptionalDataException e) {
throw new IllegalArgumentException("Could not deserialize object: eof=" + e.eof + " at length=" + e.length, e);
} catch (IOException e) {
throw new IllegalArgumentException("Could not deserialize object", e);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Could not deserialize object type", e);
}

}

// The rest of the copied class starts here

// JDK6 Make this into a ConcurrentSkipListMap: adds and removes tend to be very near the front or back
private final ConcurrentMap<Long, JobExecution> executionsById = new ConcurrentHashMap<Long, JobExecution>();

private final AtomicLong currentId = new AtomicLong(0L);

public void clear() {
executionsById.clear();
}

private static JobExecution copy(JobExecution original) {
JobExecution copy = (JobExecution) deserialize(SerializationUtils.serialize(original));
return copy;
}

public void saveJobExecution(JobExecution jobExecution) {
Long newId = currentId.getAndIncrement();
jobExecution.setId(newId);
jobExecution.incrementVersion();
executionsById.put(newId, copy(jobExecution));
}

public List<JobExecution> findJobExecutions(JobInstance jobInstance) {
List<JobExecution> executions = new ArrayList<JobExecution>();
for (JobExecution exec : executionsById.values()) {
if (exec.getJobInstance().equals(jobInstance)) {
executions.add(copy(exec));
}
}
Collections.sort(executions, new Comparator<JobExecution>() {

public int compare(JobExecution e1, JobExecution e2) {
long result = (e1.getId() - e2.getId());
if (result > 0) {
return -1;
} else if (result < 0) {
return 1;
} else {
return 0;
}
}
});
return executions;
}

public void updateJobExecution(JobExecution jobExecution) {
Long id = jobExecution.getId();
JobExecution persistedExecution = executionsById.get(id);

synchronized (jobExecution) {
if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) {
throw new RuntimeException("Attempt to update step execution id=" + id
+ " with wrong version (" + jobExecution.getVersion() + "), where current version is "
+ persistedExecution.getVersion());
}
jobExecution.incrementVersion();
executionsById.put(id, copy(jobExecution));
}
}

public JobExecution getLastJobExecution(JobInstance jobInstance) {
JobExecution lastExec = null;
for (JobExecution exec : executionsById.values()) {
if (!exec.getJobInstance().equals(jobInstance)) {
continue;
}
if (lastExec == null) {
lastExec = exec;
}
if (lastExec.getCreateTime().before(exec.getCreateTime())) {
lastExec = exec;
}
}
return copy(lastExec);
}

/*
* (non-Javadoc)
*
* @seeorg.springframework.batch.core.repository.dao.JobExecutionDao#
* findRunningJobExecutions(java.lang.String)
*/
public Set<JobExecution> findRunningJobExecutions(String jobName) {
Set<JobExecution> result = new HashSet<JobExecution>();
for (JobExecution exec : executionsById.values()) {
if (!exec.getJobInstance().getJobName().equals(jobName) || !exec.isRunning()) {
continue;
}
result.add(copy(exec));
}
return result;
}

/*
* (non-Javadoc)
*
* @see
* org.springframework.batch.core.repository.dao.JobExecutionDao#getJobExecution
* (java.lang.Long)
*/
public JobExecution getJobExecution(Long executionId) {
return copy(executionsById.get(executionId));
}

public void synchronizeStatus(JobExecution jobExecution) {
JobExecution saved = getJobExecution(jobExecution.getId());
if (saved.getVersion().intValue() != jobExecution.getVersion().intValue()) {
jobExecution.upgradeStatus(saved.getStatus());
jobExecution.setVersion(saved.getVersion());
}
}
}
Loading

0 comments on commit 1bf366b

Please sign in to comment.