camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject camel git commit: [CAMEL-8690] Use OSGi BundleActivator.stop() to load hdfs2 classes needed by shutdown hooks
Date Thu, 23 Apr 2015 15:05:16 GMT
Repository: camel
Updated Branches:
  refs/heads/master 56823320c -> 300ee8dfa


[CAMEL-8690] Use OSGi BundleActivator.stop() to load hdfs2 classes needed by shutdown hooks

(cherry picked from commit d952647707a9b4a717ec220b087dc170fcee3ef7)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/300ee8df
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/300ee8df
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/300ee8df

Branch: refs/heads/master
Commit: 300ee8dfaed255006e88699eca39d366a5404fd1
Parents: 5682332
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
Authored: Thu Apr 23 17:02:39 2015 +0200
Committer: Grzegorz Grzybek <gr.grzybek@gmail.com>
Committed: Thu Apr 23 17:04:49 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/300ee8df/components/camel-hdfs2/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-hdfs2/pom.xml b/components/camel-hdfs2/pom.xml
index a2f6605..b457409 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>
@@ -127,6 +130,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/300ee8df/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");
+        }
+    }
+
+}


Mime
View raw message