You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gg...@apache.org on 2015/04/23 17:03:19 UTC
camel git commit: [CAMEL-8690] Use OSGi BundleActivator.stop() to
load hdfs2 classes needed by shutdown hooks
Repository: camel
Updated Branches:
refs/heads/camel-2.15.x 31fac1262 -> d95264770
[CAMEL-8690] Use OSGi BundleActivator.stop() to load hdfs2 classes needed by shutdown hooks
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d9526477
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d9526477
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d9526477
Branch: refs/heads/camel-2.15.x
Commit: d952647707a9b4a717ec220b087dc170fcee3ef7
Parents: 31fac12
Author: Grzegorz Grzybek <gr...@gmail.com>
Authored: Thu Apr 23 17:02:39 2015 +0200
Committer: Grzegorz Grzybek <gr...@gmail.com>
Committed: Thu Apr 23 17:02:39 2015 +0200
----------------------------------------------------------------------
components/camel-hdfs2/pom.xml | 10 ++++
.../camel/component/hdfs2/HdfsActivator.java | 51 ++++++++++++++++++++
2 files changed, 61 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d9526477/components/camel-hdfs2/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-hdfs2/pom.xml b/components/camel-hdfs2/pom.xml
index 4dbb315..78db5b7 100644
--- a/components/camel-hdfs2/pom.xml
+++ b/components/camel-hdfs2/pom.xml
@@ -46,6 +46,9 @@
org.apache.hadoop.hdfs.protocol.proto,
org.apache.hadoop.hdfs.protocol.datatransfer
</camel.osgi.import.additional>
+ <camel.osgi.activator>
+ org.apache.camel.component.hdfs2.HdfsActivator
+ </camel.osgi.activator>
</properties>
<dependencies>
@@ -128,6 +131,13 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
</dependencies>
<!-- skip tests on Windows due CAMEL-8445 -->
http://git-wip-us.apache.org/repos/asf/camel/blob/d9526477/components/camel-hdfs2/src/main/java/org/apache/camel/component/hdfs2/HdfsActivator.java
----------------------------------------------------------------------
diff --git a/components/camel-hdfs2/src/main/java/org/apache/camel/component/hdfs2/HdfsActivator.java b/components/camel-hdfs2/src/main/java/org/apache/camel/component/hdfs2/HdfsActivator.java
new file mode 100644
index 0000000..dafaa08
--- /dev/null
+++ b/components/camel-hdfs2/src/main/java/org/apache/camel/component/hdfs2/HdfsActivator.java
@@ -0,0 +1,51 @@
+/**
+ * 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.hdfs2;
+
+import org.apache.hadoop.util.ShutdownHookManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class HdfsActivator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ // There's problem inside OSGi when framwork is being shutdown
+ // hadoop.fs code registers some JVM shutdown hooks throughout the code and this ordered
+ // list of hooks is run in shutdown thread.
+ // At that time bundle class loader / bundle wiring is no longer valid (bundle is stopped)
+ // so ShutdownHookManager can't load additional classes. But there are some inner classes
+ // loaded when iterating over registered hadoop shutdown hooks.
+ // Let's explicitely load these inner classes when bundle is stopped, as there's last chance
+ // to use valid bundle class loader.
+ // This is based on the knowledge of what's contained in SMX bundle
+ // org.apache.servicemix.bundles.hadoop-client-*.jar
+ // the above is just a warning that hadopp may have some quirks when running inside OSGi
+ ClassLoader hadoopCl = ShutdownHookManager.class.getClassLoader();
+ if (hadoopCl != null) {
+ String shm = ShutdownHookManager.class.getName();
+ hadoopCl.loadClass(shm + "$1");
+ hadoopCl.loadClass(shm + "$2");
+ hadoopCl.loadClass(shm + "$HookEntry");
+ }
+ }
+
+}