Repository: incubator-reef
Updated Branches:
  refs/heads/master d89c9498a -> 732982480


[REEF-237] Add a DriverStarted handler that generates the ClassHierarchy

This adds `ClassHierarchyGeneratingDriverStartObserver` and registers it
as a `DriverStartHandler`. This new class generates the class hierarchy
for the assemblies found in `reef/global`.

HelloREEF is adapted to no longer generate the class hiearchy.

JIRA:
  [REEF-237](https://issues.apache.org/jira/browse/REEF-237)

Pull Request:
  This closes #222

Author:    Markus Weimer <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/73298248
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/73298248
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/73298248

Branch: refs/heads/master
Commit: 73298248014e08d4f995ce963d8e5283a42e38be
Parents: d89c949
Author: Markus Weimer <[email protected]>
Authored: Wed Jun 10 19:55:10 2015 +0900
Committer: Julia Wang <[email protected]>
Committed: Mon Jun 15 21:17:09 2015 -0700

----------------------------------------------------------------------
 ...assHierarchyGeneratingDriverStartObserver.cs | 96 ++++++++++++++++++++
 .../DriverConfiguration.cs                      |  4 +-
 .../Org.Apache.REEF.Driver.csproj               |  1 +
 .../HelloDriver.cs                              | 48 ++--------
 4 files changed, 106 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73298248/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs
----------------------------------------------------------------------
diff --git 
a/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs 
b/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs
new file mode 100644
index 0000000..85a8254
--- /dev/null
+++ 
b/lang/cs/Org.Apache.REEF.Driver/ClassHierarchyGeneratingDriverStartObserver.cs
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Org.Apache.REEF.Common.Files;
+using Org.Apache.REEF.Driver.Bridge;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Driver
+{
+    /// <summary>
+    /// Utility class that generates the class hierarchy for the assemblies in 
the `global` folder.
+    /// </summary>
+    internal sealed class ClassHierarchyGeneratingDriverStartObserver : 
IObserver<IDriverStarted>
+    {
+        private readonly REEFFileNames _fileNames;
+
+        [Inject]
+        private ClassHierarchyGeneratingDriverStartObserver(REEFFileNames 
fileNames)
+        {
+            _fileNames = fileNames;
+        }
+
+        /// <summary>
+        /// Generates the class hieararchy file
+        /// </summary>
+        /// <param name="value"></param>
+        public void OnNext(IDriverStarted value)
+        {
+            
ClrHandlerHelper.GenerateClassHierarchy(GetAssembliesInGlobalFolder());
+        }
+
+        /// <summary>
+        /// Silently ignored, assuming that a user-bound Observer will catch 
it.
+        /// </summary>
+        /// <param name="error"></param>
+        public void OnError(Exception error)
+        {
+            // Silently ignored, assuming that a user-bound Observer will 
catch it.
+        }
+
+        /// <summary>
+        /// Silently ignored, assuming that a user-bound Observer will catch 
it.
+        /// </summary>
+        public void OnCompleted()
+        {
+            // Silently ignored, assuming that a user-bound Observer will 
catch it.
+        }
+
+        /// <summary>
+        /// </summary>
+        /// <returns>The paths of all assemblies in the reef/global 
folder.</returns>
+        private ISet<string> GetAssembliesInGlobalFolder()
+        {
+            return new 
HashSet<string>(Directory.GetFiles(_fileNames.GetGlobalFolderPath())
+                .Where(e => !(string.IsNullOrWhiteSpace(e)))
+                .Select(Path.GetFullPath)
+                .Where(File.Exists)
+                .Where(IsAssembly)
+                .Select(Path.GetFileNameWithoutExtension));
+        }
+
+        /// <summary>
+        /// </summary>
+        /// <param name="path"></param>
+        /// <returns>True, if the path given is an assembly</returns>
+        private static Boolean IsAssembly(string path)
+        {
+            if (string.IsNullOrWhiteSpace(path))
+            {
+                return false;
+            }
+            var extension = Path.GetExtension(path).ToLower();
+            return extension.EndsWith("dll") || extension.EndsWith("exe");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73298248/lang/cs/Org.Apache.REEF.Driver/DriverConfiguration.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Driver/DriverConfiguration.cs 
b/lang/cs/Org.Apache.REEF.Driver/DriverConfiguration.cs
index 206d0e9..c72a9da 100644
--- a/lang/cs/Org.Apache.REEF.Driver/DriverConfiguration.cs
+++ b/lang/cs/Org.Apache.REEF.Driver/DriverConfiguration.cs
@@ -203,7 +203,9 @@ namespace Org.Apache.REEF.Driver
                     
.BindSetEntry(GenericType<DriverBridgeConfigurationOptions.DriverRestartRunningTaskHandlers>.Class,
                         OnDriverRestartTaskRunning)
                     
.BindNamedParameter(GenericType<DriverBridgeConfigurationOptions.TraceLevel>.Class,
 CustomTraceLevel)
-                    .Build();
+                    .Build()
+                    // TODO: Move this up
+                    .Set(OnDriverStarted, 
GenericType<ClassHierarchyGeneratingDriverStartObserver>.Class);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73298248/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj 
b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj
index 4c6fdb6..705cc08 100644
--- a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj
+++ b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj
@@ -87,6 +87,7 @@ under the License.
     <Compile Include="Bridge\ILogger.cs" />
     <Compile Include="Bridge\ReefHttpRequest.cs" />
     <Compile Include="Bridge\ReefHttpResponse.cs" />
+    <Compile Include="ClassHierarchyGeneratingDriverStartObserver.cs" />
     <Compile Include="Constants.cs" />
     <Compile Include="Context\ContextConfiguration.cs" />
     <Compile Include="Context\ContextConfigurationOptions.cs" />

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73298248/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs 
b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs
index faf051d..e1dbde1 100644
--- a/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs
+++ b/lang/cs/Org.Apache.REEF.Examples.HelloREEF/HelloDriver.cs
@@ -18,13 +18,8 @@
  */
 
 using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using Org.Apache.REEF.Common.Files;
 using Org.Apache.REEF.Common.Tasks;
 using Org.Apache.REEF.Driver;
-using Org.Apache.REEF.Driver.Bridge;
 using Org.Apache.REEF.Driver.Evaluator;
 using Org.Apache.REEF.Tang.Annotations;
 using Org.Apache.REEF.Tang.Util;
@@ -38,29 +33,15 @@ namespace Org.Apache.REEF.Examples.HelloREEF
     public sealed class HelloDriver : IObserver<IAllocatedEvaluator>, 
IObserver<IDriverStarted>
     {
         private static readonly Logger _Logger = 
Logger.GetLogger(typeof(HelloDriver));
-
-        private readonly REEFFileNames _fileNames;
         private readonly IEvaluatorRequestor _evaluatorRequestor;
 
         [Inject]
-        private HelloDriver(REEFFileNames fileNames, IEvaluatorRequestor 
evaluatorRequestor)
+        private HelloDriver(IEvaluatorRequestor evaluatorRequestor)
         {
-            _fileNames = fileNames;
-            ClrHandlerHelper.GenerateClassHierarchy(GetGlobalAssemblies());
             _evaluatorRequestor = evaluatorRequestor;
         }
 
         /// <summary>
-        /// Called to start the user mode driver
-        /// </summary>
-        /// <param name="driverStarted"></param>
-        public void OnNext(IDriverStarted driverStarted)
-        {
-            _Logger.Log(Level.Info, string.Format("HelloDriver started at 
{0}", driverStarted.StartTime));
-            _evaluatorRequestor.Submit(new EvaluatorRequest(number: 1, 
megaBytes: 64));
-        }
-
-        /// <summary>
         /// Submits the HelloTask to the Evaluator.
         /// </summary>
         /// <param name="allocatedEvaluator"></param>
@@ -83,30 +64,13 @@ namespace Org.Apache.REEF.Examples.HelloREEF
         }
 
         /// <summary>
+        /// Called to start the user mode driver
         /// </summary>
-        /// <returns>All DLLs in the global folder</returns>
-        private ISet<string> GetGlobalAssemblies()
-        {
-            return new 
HashSet<string>(Directory.GetFiles(_fileNames.GetGlobalFolderPath())
-                .Where(e => !(string.IsNullOrWhiteSpace(e)))
-                .Select(Path.GetFullPath)
-                .Where(File.Exists)
-                .Where(IsBinary)
-                .Select(Path.GetFileNameWithoutExtension));
-        }
-
-        /// <summary>
-        /// </summary>
-        /// <param name="path"></param>
-        /// <returns>True, if the path refers to an EXE or DLL</returns>
-        private static Boolean IsBinary(string path)
+        /// <param name="driverStarted"></param>
+        public void OnNext(IDriverStarted driverStarted)
         {
-            if (string.IsNullOrWhiteSpace(path))
-            {
-                return false;
-            }
-            var extension = Path.GetExtension(path).ToLower();
-            return extension.EndsWith("dll") || extension.EndsWith("exe");
+            _Logger.Log(Level.Info, string.Format("HelloDriver started at 
{0}", driverStarted.StartTime));
+            _evaluatorRequestor.Submit(new EvaluatorRequest(1, 64));
         }
     }
 }
\ No newline at end of file

Reply via email to