Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/camel-disruptor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
/.classpath
/.project
81 changes: 81 additions & 0 deletions components/camel-disruptor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.camel</groupId>
<artifactId>camel-parent</artifactId>
<version>2.12-SNAPSHOT</version>
</parent>


<name>Camel :: Disruptor</name>
<artifactId>camel-disruptor</artifactId>
<description>Camel :: Disruptor component</description>
<packaging>bundle</packaging>

<properties>
<camel.osgi.export.pkg>org.apache.camel.component.disruptor.*</camel.osgi.export.pkg>
<camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=disruptor
</camel.osgi.export.service>
<camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=disruptor-vm
</camel.osgi.export.service>
</properties>

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>

<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
</dependency>

<!-- Test dependencies -->

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.camel.component.disruptor;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
* This abstract base class is used to implement the {@link LifecycleAwareExchangeEventHandler} interface with added
* support to await starting/stopping by the Disruptor framework.
*/
abstract class AbstractLifecycleAwareExchangeEventHandler implements LifecycleAwareExchangeEventHandler {

private volatile boolean started = false;
private volatile CountDownLatch startedLatch = new CountDownLatch(1);
private volatile CountDownLatch stoppedLatch = new CountDownLatch(1);

@Override
public abstract void onEvent(final ExchangeEvent event, long sequence, boolean endOfBatch)
throws Exception;

@Override
public void awaitStarted() throws InterruptedException {
if (!started) {
startedLatch.await();
}
}

@Override
public boolean awaitStarted(final long timeout, final TimeUnit unit) throws InterruptedException {
return started || startedLatch.await(timeout, unit);
}

@Override
public void awaitStopped() throws InterruptedException {
if (started) {
stoppedLatch.await();
}
}

@Override
public boolean awaitStopped(final long timeout, final TimeUnit unit) throws InterruptedException {
return !started || stoppedLatch.await(timeout, unit);
}

@Override
public void onStart() {
stoppedLatch = new CountDownLatch(1);
startedLatch.countDown();
started = true;
}

@Override
public void onShutdown() {
startedLatch = new CountDownLatch(1);
stoppedLatch.countDown();
started = false;
}
}
Loading