You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/06/10 14:25:23 UTC
[camel] 04/04: CAMEL-18127: use a common resume adapter when possible
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 406b4c14d6233f24ed4d797fd0197ab2dcbcdd59
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Fri Jun 10 14:58:53 2022 +0200
CAMEL-18127: use a common resume adapter when possible
---
.../org/apache/camel/resume/adapter.properties | 2 +-
.../support/DefaultCouchbaseResumeAdapter.java | 72 ----------------------
.../org/apache/camel/resume/adapter.properties | 2 +-
.../consumer/DefaultCouchDbResumeAdapter.java | 72 ----------------------
.../org/apache/camel/resume/adapter.properties | 2 +-
.../support/resume/ResumeActionAwareAdapter.java | 10 ++-
6 files changed, 11 insertions(+), 149 deletions(-)
diff --git a/components/camel-cassandraql/src/main/resources/org/apache/camel/resume/adapter.properties b/components/camel-cassandraql/src/main/resources/org/apache/camel/resume/adapter.properties
index 59898d3e1ac..336c53d8298 100644
--- a/components/camel-cassandraql/src/main/resources/org/apache/camel/resume/adapter.properties
+++ b/components/camel-cassandraql/src/main/resources/org/apache/camel/resume/adapter.properties
@@ -16,4 +16,4 @@
## ---------------------------------------------------------------------------
-adapterClass=org.apache.camel.component.cassandra.consumer.support.DefaultCassandraResumeAdapter
+adapterClass=org.apache.camel.support.resume.ResumeActionAwareAdapter
diff --git a/components/camel-couchbase/src/main/java/org/apache/camel/component/couchbase/consumer/support/DefaultCouchbaseResumeAdapter.java b/components/camel-couchbase/src/main/java/org/apache/camel/component/couchbase/consumer/support/DefaultCouchbaseResumeAdapter.java
deleted file mode 100644
index 8162bf5710d..00000000000
--- a/components/camel-couchbase/src/main/java/org/apache/camel/component/couchbase/consumer/support/DefaultCouchbaseResumeAdapter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.couchbase.consumer.support;
-
-import java.nio.ByteBuffer;
-
-import org.apache.camel.resume.Cacheable;
-import org.apache.camel.resume.Deserializable;
-import org.apache.camel.resume.Offset;
-import org.apache.camel.resume.OffsetKey;
-import org.apache.camel.resume.ResumeAction;
-import org.apache.camel.resume.ResumeActionAware;
-import org.apache.camel.resume.cache.ResumeCache;
-
-public class DefaultCouchbaseResumeAdapter implements ResumeActionAware, Cacheable, Deserializable {
- private ResumeAction resumeAction;
- private ResumeCache<Object> cache;
-
- @Override
- public void setResumeAction(ResumeAction resumeAction) {
- this.resumeAction = resumeAction;
- }
-
- @Override
- public void resume() {
- cache.forEach(resumeAction::evalEntry);
- }
-
- private boolean add(Object key, Object offset) {
- cache.add(key, offset);
-
- return true;
- }
-
- @Override
- public boolean add(OffsetKey<?> key, Offset<?> offset) {
- return add(key.getValue(), offset.getValue());
- }
-
- @Override
- public void setCache(ResumeCache<?> cache) {
- this.cache = (ResumeCache<Object>) cache;
- }
-
- @Override
- public ResumeCache<?> getCache() {
- return cache;
- }
-
- @Override
- public boolean deserialize(ByteBuffer keyBuffer, ByteBuffer valueBuffer) {
- Object key = deserializeObject(keyBuffer);
- Object value = deserializeObject(valueBuffer);
-
- return add(key, value);
- }
-}
diff --git a/components/camel-couchbase/src/main/resources/org/apache/camel/resume/adapter.properties b/components/camel-couchbase/src/main/resources/org/apache/camel/resume/adapter.properties
index 5a7ec013b1e..336c53d8298 100644
--- a/components/camel-couchbase/src/main/resources/org/apache/camel/resume/adapter.properties
+++ b/components/camel-couchbase/src/main/resources/org/apache/camel/resume/adapter.properties
@@ -16,4 +16,4 @@
## ---------------------------------------------------------------------------
-adapterClass=org.apache.camel.component.couchbase.consumer.support.DefaultCouchbaseResumeAdapter
+adapterClass=org.apache.camel.support.resume.ResumeActionAwareAdapter
diff --git a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/DefaultCouchDbResumeAdapter.java b/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/DefaultCouchDbResumeAdapter.java
deleted file mode 100644
index 4b7c0550c88..00000000000
--- a/components/camel-couchdb/src/main/java/org/apache/camel/component/couchdb/consumer/DefaultCouchDbResumeAdapter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.couchdb.consumer;
-
-import java.nio.ByteBuffer;
-
-import org.apache.camel.resume.Cacheable;
-import org.apache.camel.resume.Deserializable;
-import org.apache.camel.resume.Offset;
-import org.apache.camel.resume.OffsetKey;
-import org.apache.camel.resume.ResumeAction;
-import org.apache.camel.resume.ResumeActionAware;
-import org.apache.camel.resume.cache.ResumeCache;
-
-public class DefaultCouchDbResumeAdapter implements ResumeActionAware, Cacheable, Deserializable {
- private ResumeCache<Object> cache;
- private ResumeAction resumeAction;
-
- @Override
- public void setResumeAction(ResumeAction resumeAction) {
- this.resumeAction = resumeAction;
- }
-
- @Override
- public void resume() {
- cache.forEach(resumeAction::evalEntry);
- }
-
- private boolean add(Object key, Object offset) {
- cache.add(key, offset);
-
- return true;
- }
-
- @Override
- public boolean add(OffsetKey<?> key, Offset<?> offset) {
- return add(key.getValue(), offset.getValue());
- }
-
- @Override
- public void setCache(ResumeCache<?> cache) {
- this.cache = (ResumeCache<Object>) cache;
- }
-
- @Override
- public ResumeCache<?> getCache() {
- return cache;
- }
-
- @Override
- public boolean deserialize(ByteBuffer keyBuffer, ByteBuffer valueBuffer) {
- Object key = deserializeObject(keyBuffer);
- Object value = deserializeObject(valueBuffer);
-
- return add(key, value);
- }
-}
diff --git a/components/camel-couchdb/src/main/resources/org/apache/camel/resume/adapter.properties b/components/camel-couchdb/src/main/resources/org/apache/camel/resume/adapter.properties
index c8d679476bb..80310b84de3 100644
--- a/components/camel-couchdb/src/main/resources/org/apache/camel/resume/adapter.properties
+++ b/components/camel-couchdb/src/main/resources/org/apache/camel/resume/adapter.properties
@@ -15,4 +15,4 @@
## limitations under the License.
## ---------------------------------------------------------------------------
-org.apache.camel.component.couchdb.consumer.DefaultCouchDbResumeAdapter
+adapterClass=org.apache.camel.support.resume.ResumeActionAwareAdapter
diff --git a/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/consumer/support/DefaultCassandraResumeAdapter.java b/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeActionAwareAdapter.java
similarity index 80%
rename from components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/consumer/support/DefaultCassandraResumeAdapter.java
rename to core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeActionAwareAdapter.java
index 3115aeec590..0bc07685ed7 100644
--- a/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/consumer/support/DefaultCassandraResumeAdapter.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/resume/ResumeActionAwareAdapter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.camel.component.cassandra.consumer.support;
+package org.apache.camel.support.resume;
import java.nio.ByteBuffer;
@@ -27,7 +27,13 @@ import org.apache.camel.resume.ResumeAction;
import org.apache.camel.resume.ResumeActionAware;
import org.apache.camel.resume.cache.ResumeCache;
-public class DefaultCassandraResumeAdapter implements ResumeActionAware, Cacheable, Deserializable {
+/**
+ * A simple resume adapter that support caching, deserialization and actions. This is usually suitable for supporting
+ * resume operations that have simple cache storage requirements, but delegate the resume action to the integrations
+ * (i.e.: such as when resuming from database components, where the resume operation can only be determined by the
+ * integration itself)
+ */
+public class ResumeActionAwareAdapter implements ResumeActionAware, Cacheable, Deserializable {
private ResumeCache<Object> cache;
private ResumeAction resumeAction;